:root {
  --bg: #11141a;
  --panel: #1a1f29;
  --border: #2a3242;
  --text: #e6e9ef;
  --muted: #8b93a5;
  --accent: #ffb84d;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, sans-serif;
}
nav {
  display: flex;
  gap: 1.2rem;
  align-items: center;
  padding: 0.8rem 1.5rem;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  /* keep the menu visible while scrolling */
  position: sticky;
  top: 0;
  z-index: 100;
}
nav a { color: var(--muted); text-decoration: none; font-weight: 500; }
nav a:hover { color: var(--text); }
nav .brand { color: var(--accent); font-size: 1.15rem; font-weight: 700; }

/* Admin dropdown (native <details>, no JS) */
.nav-admin { position: relative; }
.nav-admin summary {
  list-style: none; cursor: pointer; color: var(--muted);
  font-weight: 500; user-select: none;
}
.nav-admin summary::-webkit-details-marker { display: none; }
.nav-admin[open] summary, .nav-admin summary:hover { color: var(--text); }
.nav-admin-menu {
  position: absolute; top: 1.7rem; left: 0; z-index: 200;
  display: flex; flex-direction: column; min-width: 9rem;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; padding: 0.3rem; gap: 0.1rem;
  box-shadow: 0 6px 20px rgba(0,0,0,0.4);
}
.nav-admin-menu a { padding: 0.35rem 0.6rem; border-radius: 5px; }
.nav-admin-menu a:hover { background: #232a38; }
main { max-width: 1100px; margin: 0 auto; padding: 1.5rem; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; margin-top: 2rem; }
a { color: var(--accent); }
.muted { color: var(--muted); }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1rem; }
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.1rem 1.3rem;
}
.card h3 { margin: 0 0 0.3rem; }
.card h3 a { text-decoration: none; }
.stat-row { display: flex; justify-content: space-between; padding: 0.18rem 0; }

table { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: 10px; overflow: hidden; }
th, td { padding: 0.5rem 0.8rem; text-align: left; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; }
tr:hover td { background: #20283600; }
tbody tr:hover { background: #202836; }
td a { text-decoration: none; }

.tier {
  display: inline-block;
  padding: 0.1rem 0.55rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
}
.tier-legendary-iii { background: #4a2a5e; color: #e3b8ff; border: 1px solid #9a5ce0; }
.tier-legendary-ii { background: #3d2c54; color: #c9a0ff; }
.tier-legendary-i { background: #322546; color: #ab87e6; }
.tier-gold { background: #4a3b14; color: #ffd54d; }
.tier-silver { background: #333a45; color: #c0c9d8; }
.tier-bronze { background: #45301d; color: #e0a06a; }

.chart-box {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 1rem; margin: 1rem 0;
  /* Fixed height so the chart (maintainAspectRatio:false) doesn't get squished
     on narrow/mobile widths. */
  height: 260px; box-sizing: border-box; position: relative;
}
form.inline { display: inline; }
input, select, button {
  background: #232a38;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.4rem 0.7rem;
}
button { cursor: pointer; }
button:hover { border-color: var(--accent); }
.error { color: #ff7b72; }
.up { color: #7ee787; }
.down { color: #ff7b72; }

.nav-right { margin-left: auto; font-size: 0.85rem; display: inline-flex; align-items: center; gap: 0.45rem; }
.nav-right a { color: var(--muted); }
.nav-right a:hover { color: var(--text); }
.nav-avatar { width: 24px; height: 24px; border-radius: 50%; border: 1px solid var(--border); }
.nav-user { display: inline-flex; align-items: center; gap: 0.45rem; text-decoration: none; }

/* /me page */
.me-header { display: flex; align-items: center; gap: 1rem; }
.me-avatar { width: 64px; height: 64px; border-radius: 50%; border: 2px solid var(--border); }
.me-player { margin: 0.7rem 0; }
.me-player-head { display: flex; align-items: baseline; gap: 0.5rem; flex-wrap: wrap; }
.me-player-name { font-size: 1.1rem; font-weight: 700; text-decoration: none; }
.me-player-trophies { margin-left: auto; }
.me-player-stats { font-size: 0.85rem; margin: 0.25rem 0 0.4rem; }
.me-player-deck { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.me-name { text-decoration: none; color: var(--text); }
.me-name-pen { font-size: 0.9rem; color: var(--muted); }
.me-name:hover .me-name-pen { color: var(--accent); }
.me-name-form input { font-size: 1.2rem; font-weight: 700; }
/* current-war strip on each claimed player */
.me-war {
  display: flex; gap: 1.4rem; flex-wrap: wrap;
  background: #20283a; border-radius: 6px;
  padding: 0.35rem 0.7rem; margin: 0.35rem 0;
  font-size: 0.9rem;
}
/* no attacks yet today -> dark red; all 4 decks played -> dark green */
.me-war-missing { background: #3a1d1d; }
.me-war-done { background: #1d3a26; }
.me-war-cell { display: inline-flex; flex-direction: column; }
.me-war-lbl {
  color: var(--muted); font-size: 0.68rem;
  text-transform: uppercase; letter-spacing: 0.05em;
}

/* Dashboard: last-war MVPs (non war days) */
.mvp-title {
  color: var(--muted); font-size: 0.8rem; text-transform: uppercase;
  letter-spacing: 0.05em; margin: 0.5rem 0 0.25rem;
}
.mvp-row {
  display: grid; grid-template-columns: 1.4rem 1fr auto;
  gap: 0.5rem; padding: 0.2rem 0; align-items: baseline;
  border-top: 1px solid var(--border);
}
.mvp-rank { color: var(--accent); font-weight: 700; }
.mvp-names { line-height: 1.45; }
.mvp-score { font-weight: 700; }

/* promotion-check button on the player page */
.promo-box { margin: 0.5rem 0 0.2rem; max-width: 640px; }
.promo-btn {
  padding: 0.3rem 0.8rem; font-size: 0.9rem;
  background: #2a2350; color: #c9a0ff; border: 1px solid #5a4e7a; border-radius: 6px;
}
.promo-btn:hover:not(:disabled) { border-color: var(--accent); color: #e3b8ff; }
.promo-btn:disabled { opacity: 0.5; cursor: default; }
.promo-box .deck-analysis { max-width: 640px; }

/* claim badge on the player page */
.claim-badge {
  font-size: 0.8rem; font-weight: 600; vertical-align: middle;
  background: #1f3d29; color: #7ee787; padding: 0.15rem 0.6rem; border-radius: 999px;
}
/* "Mini account" sticker shown next to a player's name. */
.mini-badge {
  font-size: 0.7rem; font-weight: 700; vertical-align: middle; letter-spacing: 0.03em;
  background: #3a2f12; color: #ffd54d; border: 1px solid #6b5410;
  padding: 0.08rem 0.45rem; border-radius: 999px; text-transform: uppercase;
}

/* message-the-owner form on the player page */
.msg-form { display: flex; gap: 0.5rem; margin: 0.6rem 0 0.2rem; max-width: 520px; }
.msg-form input { flex: 1; }
.msg-result { font-size: 0.82rem; margin: 0.2rem 0; }

.landing { max-width: 540px; margin: 4rem auto; text-align: center; }
.landing h1 { font-size: 2.2rem; margin-bottom: 0.3rem; }
.landing p { line-height: 1.6; }
.discord-btn {
  display: inline-flex; align-items: center; gap: 0.6rem;
  margin-top: 1.5rem; padding: 0.7rem 1.4rem;
  background: #5865F2; color: #fff; font-weight: 600;
  border-radius: 8px; text-decoration: none;
}
.discord-btn:hover { background: #4752c4; }
.login-buttons { display: flex; flex-direction: column; gap: 0.6rem; align-items: center; margin-top: 1.5rem; }
.login-buttons .discord-btn { margin-top: 0; }
.google-btn {
  display: inline-flex; align-items: center; gap: 0.6rem;
  padding: 0.7rem 1.4rem; background: #fff; color: #1f1f1f; font-weight: 600;
  border: 1px solid #dadce0; border-radius: 8px; text-decoration: none;
}
.google-btn:hover { background: #f5f5f5; }
.google-btn-sm { padding: 0.25rem 0.7rem; font-size: 0.85rem; font-weight: 500; }

.status { padding: 0.1rem 0.5rem; border-radius: 999px; font-size: 0.78rem; font-weight: 600; }
.status-pending { background: #4a3b14; color: #ffd54d; }
.status-approved { background: #1f3d29; color: #7ee787; }
.status-rejected { background: #45211d; color: #ff7b72; }
.badge-pending { background: #4a3b14; color: #ffd54d; font-size: 0.8rem; padding: 0.15rem 0.6rem; border-radius: 999px; vertical-align: middle; }

.colosseum { color: #ffb84d; font-weight: 600; font-size: 0.85rem; }

/* Jobs page: highlight the cadence column in use right now */
.sched-active { background: #20283a; box-shadow: inset 3px 0 0 var(--accent); }

.clan-tabs { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.5rem 0 1.2rem; }
.clan-tab {
  padding: 0.35rem 0.85rem; border-radius: 999px; text-decoration: none;
  background: var(--panel); border: 1px solid var(--border); color: var(--muted);
  font-size: 0.9rem;
}
.clan-tab.active { background: var(--accent); color: #1a1f29; border-color: var(--accent); font-weight: 600; }
.clan-tab:hover { color: var(--text); }

.war-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 0.6rem; margin-bottom: 0.5rem; }
.war-day-badge { display: inline-block; background: #3d2c54; color: #c9a0ff; padding: 0.15rem 0.7rem; border-radius: 999px; font-size: 0.85rem; font-weight: 600; }
.us-row td { background: #20283a; }
.muted-row td { opacity: 0.55; }
.tag-note { color: var(--accent); cursor: help; }
/* War page player names: current members vs players who left the clan */
a.member-name { color: var(--accent); }
a.ex-member, span.ex-member { color: #6fd3ff; }
.partial { color: #ffd54d; font-size: 0.85rem; }

/* War battle list (player page) */
.battles { display: flex; flex-direction: column; gap: 0.35rem; }
.battle {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; padding: 0.15rem 0.6rem;
}
.battle summary {
  cursor: pointer; padding: 0.35rem 0.2rem;
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem;
}
.battle summary::-webkit-details-marker { display: none; }
.battle-when { font-size: 0.8rem; min-width: 7.5rem; }
.battle-mode { font-weight: 600; min-width: 3.2rem; }
.battle-crowns { font-weight: 700; }
.battle-trophies { font-size: 0.8rem; margin-left: auto; }
.battle-detail { border-top: 1px solid var(--border); padding: 0.5rem 0.2rem 0.4rem; }
.battle-round { margin-bottom: 0.5rem; }
.round-head { font-size: 0.85rem; margin-bottom: 0.2rem; }
/* Fixed owner column so the card images align regardless of name length */
.deck-line {
  display: grid; grid-template-columns: 8.5rem 1fr auto;
  gap: 0.5rem; align-items: center;
  margin: 0.3rem 0; font-size: 0.85rem;
}
.deck-owner {
  font-weight: 600; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
.bcards { display: flex; flex-wrap: wrap; align-items: center; }
.deck-extra { display: flex; align-items: center; gap: 0.6rem; text-align: right; }

/* Remaining tower HP: king on top, princess towers below */
.towers { display: grid; grid-template-columns: repeat(2, 3rem); gap: 2px; }
.tw {
  font-size: 0.68rem; text-align: center; padding: 0 2px;
  background: #20283a; border: 1px solid var(--border); border-radius: 3px;
}
.tw-king { grid-column: 1 / span 2; background: #2a3242; font-weight: 600; }
.tw-dead { opacity: 0.4; }

/* War decks list (player page) */
.wardecks { display: flex; flex-direction: column; gap: 0.4rem; }
.wardeck {
  display: flex; align-items: center; gap: 0.8rem; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; padding: 0.35rem 0.6rem;
}
.wardeck-meta { font-size: 0.85rem; white-space: nowrap; }
/* Decks page: two-line deck rows with per-tier rates + players */
.wardeck-col { flex-direction: column; align-items: stretch; gap: 0.2rem; }
.wardeck-top { display: flex; align-items: center; gap: 0.8rem; flex-wrap: wrap; }
.wardeck-top .wardeck-meta { margin-left: auto; }
.wardeck-sub {
  display: flex; align-items: baseline; gap: 1rem; flex-wrap: wrap;
  font-size: 0.82rem; border-top: 1px solid var(--border); padding-top: 0.3rem;
}
.deck-tiers { display: flex; gap: 0.8rem; flex-wrap: wrap; }
.deck-tier { white-space: nowrap; }
.deck-tier-active { box-shadow: inset 0 -2px 0 var(--accent); padding-bottom: 2px; }
/* AI deck analysis */
.analyze-btn {
  margin-left: 0.5rem; padding: 0.1rem 0.5rem; font-size: 0.8rem;
  background: #2a2350; color: #c9a0ff; border: 1px solid #5a4e7a; border-radius: 6px;
}
.analyze-btn:hover:not(:disabled) { border-color: var(--accent); color: #e3b8ff; }
.analyze-btn:disabled { opacity: 0.5; cursor: default; }
.deck-analysis {
  margin-top: 0.5rem; padding: 0.6rem 0.9rem; font-size: 0.86rem; line-height: 1.5;
  background: #1b1726; border: 1px solid #3d2c54; border-radius: 8px;
}
.deck-analysis .deck-sec { margin: 0.28rem 0; }
.deck-analysis .deck-sec strong { color: #c9a0ff; }
.deck-analysis ul.deck-bullets { margin: 0.1rem 0 0.4rem; padding-left: 1.2rem; }
.deck-analysis ul.deck-bullets li { margin: 0.1rem 0; }
.analysis-comment {
  display: flex; gap: 0.4rem; align-items: center; flex-wrap: wrap;
  margin-top: 0.6rem; padding-top: 0.5rem; border-top: 1px solid #3d2c54;
}
.analysis-comment input { flex: 1 1 16rem; min-width: 10rem; }
.analysis-comment-status { font-size: 0.78rem; }
.analysis-comments { margin-top: 0.4rem; }
.analysis-comment-item { font-size: 0.82rem; margin: 0.2rem 0; }
.deck-players { margin-left: auto; }
.deck-players a { color: var(--muted); }
.deck-players a:hover { color: var(--accent); }
.bcard {
  display: inline-block; background: #232a38; border: 1px solid var(--border);
  border-radius: 5px; padding: 0 0.35rem; margin: 0.06rem 0.12rem 0.06rem 0;
  white-space: nowrap;
}
.bcard-lvl { color: var(--muted); font-size: 0.78rem; }
.deck-meta { font-size: 0.78rem; }

/* Sortable table headers (players page) */
table.sortable thead th { cursor: pointer; user-select: none; white-space: nowrap; }
table.sortable thead th:hover { color: var(--text); }
table.sortable thead th[data-dir="asc"]::after { content: " ▲"; font-size: 0.7em; }
table.sortable thead th[data-dir="desc"]::after { content: " ▼"; font-size: 0.7em; }
.player-filters { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.player-filters #player-search { min-width: 16rem; }
.active-toggle { display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.9rem; color: var(--muted); }
.active-toggle input { width: auto; }

/* Clan badge in the war standings grid */
.clan-badge { width: 26px; vertical-align: middle; display: block; }
/* Player grids (War page + Players page): Discord avatar slot left of the name;
   fixed width so names line up whether or not a player has a connected account. */
.war-player { display: flex; align-items: center; gap: 0.45rem; }
.war-player-avatar { width: 20px; height: 20px; border-radius: 50%; flex: 0 0 auto; }
.war-player-avatar-empty { visibility: hidden; }

/* Card image chips (battle decks) */
.bcard-pic {
  position: relative; display: inline-block; width: 42px;
  margin: 0.1rem 0.15rem 0.1rem 0; vertical-align: middle;
}
.bcard-pic img { width: 100%; display: block; border-radius: 4px; }
.bcard-pic-lvl {
  position: absolute; left: 0; right: 0; bottom: 1px; text-align: center;
  font-size: 0.68rem; font-weight: 700; color: #fff;
  background: rgba(10, 12, 18, 0.65); border-radius: 0 0 4px 4px;
}
/* Card image in the Current deck grid */
.deck-card { gap: 0.5rem; }
.deck-img { width: 34px; border-radius: 4px; flex-shrink: 0; }
.deck-card .deck-name { flex: 1; }

.profile-banner { display: flex; align-items: center; gap: 1rem; margin: 1rem 0; }
.collection-badge {
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center;
  min-width: 4rem; padding: 0.4rem 0.7rem;
  background: linear-gradient(160deg, #3d2c54, #241a33);
  border-radius: 8px; border: 1px solid #9a5ce0;
}
.collection-badge .coll-num { font-size: 1.4rem; font-weight: 800; color: #e3b8ff; line-height: 1; }
.collection-badge .coll-label { font-size: 0.65rem; color: #9a86b8; text-transform: uppercase; letter-spacing: 0.05em; }
.profile-meta div { line-height: 1.4; }

.levelbars { display: flex; flex-direction: column; gap: 0.3rem; max-width: 520px; }
.levelbar-row { display: flex; align-items: center; gap: 0.6rem; }
.levelbar-lvl { width: 3.5rem; font-size: 0.82rem; color: var(--muted); }
.levelbar-lvl.hi { color: var(--accent); font-weight: 600; }
.levelbar-track { flex: 1; height: 1rem; background: #202836; border-radius: 4px; overflow: hidden; }
.levelbar-fill { display: block; height: 100%; background: #5a4e7a; }
.levelbar-fill.hi { background: var(--accent); }
.levelbar-count { width: 2rem; text-align: right; font-size: 0.85rem; }

.deck { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 0.5rem; }
.deck-card {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; padding: 0.5rem 0.7rem;
}
.deck-name { font-size: 0.9rem; }
.deck-lvl { font-size: 0.8rem; font-weight: 600; }
.rarity-common { color: #c0c9d8; }
.rarity-rare { color: #ffb84d; }
.rarity-epic { color: #c9a0ff; }
.rarity-legendary { color: #6fd3ff; }
.rarity-champion { color: #ffd54d; }

/* Footer with version + copyright (links to /about). */
.site-footer {
  max-width: 1100px; margin: 2.5rem auto 0; padding: 1rem 1.5rem 2rem;
  border-top: 1px solid var(--border); color: var(--muted);
  font-size: 0.8rem; text-align: center;
}
.site-footer a { color: var(--muted); text-decoration: none; font-weight: 600; }
.site-footer a:hover { color: var(--accent); }
.badge-prerelease {
  display: inline-block; font-size: 0.65rem; font-weight: 700; letter-spacing: 0.04em;
  text-transform: uppercase; vertical-align: middle;
  background: #2a2440; color: #c9a0ff; border: 1px solid #4a3a6e;
  padding: 0.05rem 0.4rem; border-radius: 999px; margin: 0 0.2rem;
}

/* Changelog (About page). */
.changelog { max-width: 680px; }
.changelog-entry { margin-bottom: 0.8rem; }
.changelog-head { display: flex; align-items: baseline; gap: 0.5rem; flex-wrap: wrap; }
.changelog-version { font-size: 1.05rem; font-weight: 700; color: var(--accent); }
.changelog-title { font-weight: 600; }
.changelog-date { margin-left: auto; font-size: 0.8rem; }
.changelog-list { margin: 0.5rem 0 0; padding-left: 1.2rem; }
.changelog-list li { margin: 0.18rem 0; }

/* ---------- Responsive: phones / narrow screens ---------- */
/* Columns marked .hide-sm drop off below this width to keep the key columns
   readable; whatever remains can still be swiped (tables scroll horizontally). */
@media (max-width: 640px) {
  main { padding: 0.8rem; }
  nav { gap: 0.6rem 0.9rem; padding: 0.6rem 0.9rem; flex-wrap: wrap; }
  nav .brand { font-size: 1.05rem; }
  /* the user/avatar/logout block drops to its own line */
  .nav-right { margin-left: 0; width: 100%; }
  h1 { font-size: 1.3rem; }
  h2 { font-size: 1.05rem; margin-top: 1.4rem; }

  /* Tables fill the screen and wrap; once the low-priority .hide-sm columns are
     gone the essentials fit without a horizontal scroll. overflow-x stays as a
     safety net for any table that's still too wide. */
  table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  th, td { padding: 0.45rem 0.4rem; font-size: 0.9rem; }
  th { font-size: 0.7rem; letter-spacing: 0; }
  .hide-sm { display: none; }

  .player-filters #player-search { min-width: 0; flex: 1 1 100%; }
  .player-filters select { flex: 1 1 auto; }

  .me-header { gap: 0.7rem; }
  .me-avatar { width: 48px; height: 48px; }
  .profile-banner { flex-wrap: wrap; }
  .msg-form { flex-wrap: wrap; }
  .chart-box { height: 210px; padding: 0.6rem; }

  /* War decks / battle decks: 4 cards per row (8-card decks wrap to 2 rows)
     so they fit a phone instead of overflowing. */
  .bcards { gap: 4px; width: 100%; }
  .bcards .bcard-pic { width: calc(25% - 3px); margin: 0; }
  /* Battle decks: stack owner / cards / extra vertically. */
  .battle-detail .deck-line { grid-template-columns: 1fr; gap: 0.3rem; }
  .battle-detail .deck-owner { white-space: normal; }
  .battle-detail .deck-extra { justify-content: flex-start; text-align: left; }
}
