/* ==========================================================================
   HOLD THE LINE — UI styles (minimal military)
   ========================================================================== */
:root {
  --bg: #13150f;
  --bg2: #181b14;
  --panel: #1e211a;
  --panel2: #262a21;
  --panel3: #2f3429;
  --line: #363c2f;
  --line2: #454c3c;
  --text: #ebe7d7;
  --muted: #9c9c88;
  --dim: #6d6f5f;
  --accent: #dcb54c;
  --accent-ink: #1d1a0e;
  --olive: #8e9d5e;
  --danger: #d65a3e;
  --ok: #92cf6c;
  --blue: #7cc4e4;
  --a: #f0c75e;
  --b: #7cc4e4;
  --radius: 10px;
  --font: 'Rajdhani', 'Barlow Condensed', 'Segoe UI', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); font-weight: 500; overflow: hidden; -webkit-font-smoothing: antialiased; }
button { font-family: inherit; color: inherit; cursor: pointer; }
b, strong { font-weight: 700; }
#app { position: fixed; inset: 0; }

.screen { position: absolute; inset: 0; display: none; flex-direction: column; }
.screen.active { display: flex; animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--panel2); border: 1px solid var(--line2); color: var(--text);
  padding: 8px 16px; border-radius: 8px; font-size: 16px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  transition: background .15s, border-color .15s, transform .08s, opacity .15s;
}
.btn:hover { background: var(--panel3); border-color: #5a6249; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #e8c35c; }
.btn.danger { background: transparent; border-color: #7a3a2a; color: #ef8e76; }
.btn.danger:hover { background: #3a1f18; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: var(--panel2); }
.btn.big { font-size: 22px; padding: 14px 28px; min-width: 300px; border-radius: 10px; }
.btn:disabled, .btn.disabled { opacity: .4; cursor: not-allowed; }
.pill { background: var(--accent); color: var(--accent-ink); border-radius: 99px; padding: 0 8px; font-size: 13px; line-height: 20px; }
.pill:empty { display: none; }

.seg { display: inline-flex; background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; padding: 3px; gap: 2px; }
.seg button { background: transparent; border: 0; padding: 6px 12px; border-radius: 6px; font-weight: 700; font-size: 15px; color: var(--muted); letter-spacing: .04em; text-transform: uppercase; }
.seg button:hover { color: var(--text); }
.seg button.on { background: var(--panel3); color: var(--text); box-shadow: inset 0 0 0 1px var(--line2); }

.icon-btn { background: var(--panel2); border: 1px solid var(--line2); border-radius: 8px; height: 38px; min-width: 38px; padding: 0 10px; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; letter-spacing: .08em; color: var(--muted); }
.icon-btn svg { width: 18px; height: 18px; fill: currentColor; }
.icon-btn:hover { color: var(--text); background: var(--panel3); }
.icon-btn.toggle.on { color: var(--ok); border-color: #4f6a3a; }

/* ---------- menu ---------- */
#scr-menu { align-items: center; justify-content: center; }
#menu-bg { position: absolute; inset: 0; width: 100%; height: 100%; opacity: .35; filter: saturate(.7); }
#scr-menu::after { content: ''; position: absolute; inset: 0; background: radial-gradient(ellipse at center, rgba(19,21,15,.35) 0%, rgba(19,21,15,.92) 70%); pointer-events: none; }
.menu-wrap { position: relative; z-index: 2; display: flex; flex-direction: column; align-items: center; gap: 36px; padding: 24px; }
.logo { text-align: center; }
.logo h1 { margin: 12px 0 0; font-size: clamp(44px, 8vw, 84px); letter-spacing: .12em; line-height: 1; font-weight: 700; }
.logo p { margin: 6px 0 0; color: var(--accent); letter-spacing: .5em; text-transform: uppercase; font-size: 15px; font-weight: 700; }
.logo-mark { display: inline-flex; gap: 6px; }
.logo-mark span { width: 36px; height: 10px; background: var(--accent); transform: skewX(-30deg); }
.logo-mark span:nth-child(2) { background: var(--olive); }
.logo-mark span:nth-child(3) { background: var(--danger); }
.menu-btns { display: flex; flex-direction: column; gap: 12px; width: 340px; max-width: calc(100vw - 32px); }
/* fixed-width buttons: a growing merit count or stats line never shifts the menu */
.menu-btns .btn.big { min-width: 0; width: 100%; white-space: nowrap; }
.menu-btns .pill { font-variant-numeric: tabular-nums; }
.continue-btn { flex-direction: column; gap: 0; line-height: 1.15; }
.continue-btn small { font-size: 13px; letter-spacing: .04em; text-transform: none; opacity: .75; font-weight: 600; }
.btn.hidden { display: none; }
.menu-stats { color: var(--muted); font-size: 15px; letter-spacing: .08em; text-transform: uppercase; display: flex; gap: 22px; flex-wrap: wrap; justify-content: center; }
.menu-stats b { color: var(--text); }

/* ---------- account (cloud save) ---------- */
.account-chip { position: absolute; z-index: 3; top: max(16px, env(safe-area-inset-top)); right: max(16px, env(safe-area-inset-right)); display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 14px 0 6px; background: rgba(30,33,26,.85); border: 1px solid var(--line2); border-radius: 99px; color: var(--muted); font-weight: 700; font-size: 15px; letter-spacing: .06em; text-transform: uppercase; backdrop-filter: blur(4px); }
.account-chip:hover { color: var(--text); border-color: #5a6249; }
.account-chip.hidden { display: none; }
.account-chip svg { width: 22px; height: 22px; margin-left: 6px; }
.account-chip .ac-name { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ac-avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 15px; flex: none; }
.ac-avatar.big { width: 48px; height: 48px; font-size: 24px; }
.ac-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--dim); }
.ac-dot.ok { background: var(--ok); }
.ac-dot.busy { background: var(--blue); animation: blink 1s ease-in-out infinite alternate; }
.ac-dot.warn { background: var(--danger); }
@keyframes blink { to { opacity: .3; } }
.acct-card { display: flex; align-items: center; gap: 14px; background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.acct-card b { display: block; font-size: 20px; letter-spacing: .04em; }
.acct-card small { color: var(--muted); font-size: 14px; word-break: break-all; }
.acct-msg { background: var(--bg2); border-left: 3px solid var(--ok); border-radius: 6px; padding: 8px 12px; color: var(--text) !important; }
.gsi-slot { display: flex; justify-content: center; align-items: center; min-height: 64px; margin: 8px 0; }
.gsi-wait { color: var(--dim); font-size: 14px; letter-spacing: .06em; text-align: center; }
.modal-card p.fine { font-size: 13px; color: var(--dim); }

/* ---------- topbar ---------- */
.topbar { display: flex; align-items: center; gap: 16px; padding: 12px 20px; border-bottom: 1px solid var(--line); background: var(--bg2); flex-wrap: wrap; }
.topbar h2 { margin: 0; font-size: 26px; letter-spacing: .12em; text-transform: uppercase; }
.topbar-right { margin-left: auto; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.scroll { flex: 1; overflow: auto; padding: 24px; }
.merit-box { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.merit-box b { color: var(--accent); font-size: 22px; }
.merit-icon { width: 16px; height: 16px; background: var(--accent); clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%); }

/* ---------- campaign ---------- */
.level-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 18px; max-width: 1400px; margin: 0 auto; }
.level-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; cursor: pointer; transition: transform .15s, border-color .15s; position: relative; }
.level-card:hover { transform: translateY(-3px); border-color: var(--line2); }
.level-card canvas { display: block; width: 100%; aspect-ratio: 20 / 12; }
.level-card .lc-body { padding: 12px 14px 14px; display: flex; align-items: center; gap: 10px; }
.level-card .lc-num { font-size: 30px; font-weight: 700; color: var(--dim); width: 34px; }
.level-card .lc-name { font-size: 20px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.level-card .lc-sub { font-size: 13px; color: var(--muted); letter-spacing: .06em; text-transform: uppercase; }
.level-card .lc-stars { margin-left: auto; display: flex; gap: 3px; }
.star { width: 16px; height: 16px; background: var(--line2); clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%); }
.star.on { background: var(--accent); }
.level-card.locked { cursor: not-allowed; }
.level-card.locked canvas { filter: grayscale(1) brightness(.35); }
.level-card.locked .lc-lock { position: absolute; top: 0; left: 0; right: 0; aspect-ratio: 20/12; display: flex; align-items: center; justify-content: center; color: var(--muted); font-weight: 700; letter-spacing: .15em; text-transform: uppercase; }
.lc-badges { position: absolute; top: 10px; left: 10px; display: flex; gap: 6px; }
.badge { background: rgba(19,21,15,.85); border: 1px solid var(--line2); padding: 2px 8px; border-radius: 6px; font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.badge.vet { color: var(--danger); border-color: #7a3a2a; }
.badge.new { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }
.badge.endless { color: var(--blue); border-color: #3d6072; }

/* ---------- chapters ---------- */
.chapter-strip { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; max-width: 1400px; margin: 0 auto 14px; }
.chapter-tab { position: relative; text-align: left; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px 12px; overflow: hidden; transition: border-color .15s, background .15s; }
.chapter-tab::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--cc, var(--olive)); opacity: .8; }
.chapter-tab:hover:not(:disabled) { background: var(--panel2); }
.chapter-tab.on { border-color: var(--cc, var(--accent)); background: var(--panel2); }
.chapter-tab:disabled { opacity: .45; cursor: not-allowed; }
.chapter-tab .ct-num { font-size: 11px; color: var(--muted); letter-spacing: .16em; text-transform: uppercase; font-weight: 700; }
.chapter-tab .ct-name { font-size: 18px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; margin: 1px 0 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chapter-tab .ct-meta { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); font-weight: 700; letter-spacing: .04em; }
.chapter-tab .ct-bar { height: 4px; background: var(--bg2); border-radius: 2px; margin-top: 6px; overflow: hidden; }
.chapter-tab .ct-bar i { display: block; height: 100%; background: var(--cc, var(--accent)); }
.chapter-strip.compact .chapter-tab { padding: 7px 10px 9px; }
.chapter-strip.compact .ct-name { font-size: 15px; margin-bottom: 2px; }
.chapter-desc { max-width: 1400px; margin: 0 auto 16px; color: var(--muted); }
.chapter-desc b { color: var(--text); letter-spacing: .06em; text-transform: uppercase; }
.badge.twist { color: var(--text); }
@media (max-width: 900px) { .chapter-strip { grid-template-columns: repeat(5, minmax(120px, 1fr)); overflow-x: auto; } }

/* ---------- endless ---------- */
.endless-wrap { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 24px; max-width: 1500px; margin: 0 auto; align-items: start; }
.endless-wrap > * { min-width: 0; }
.endless-view { display: none; }
.hof-scroll { overflow-x: auto; }
.endless-wrap .level-grid { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.endless-intro { margin: 0 0 16px; color: var(--muted); line-height: 1.5; }
.endless-intro b { color: var(--text); }
.lc-best { margin-left: auto; text-align: right; line-height: 1.1; }
.lc-best b { display: block; color: var(--accent); font-size: 20px; font-variant-numeric: tabular-nums; }
.lc-best small { color: var(--muted); font-size: 12px; letter-spacing: .06em; text-transform: uppercase; }
.hof { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; position: sticky; top: 0; }
.hof-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.hof-head h3 { margin: 0; font-size: 18px; letter-spacing: .16em; text-transform: uppercase; }
.callsign { font-size: 12px; color: var(--muted); letter-spacing: .08em; text-transform: uppercase; font-weight: 700; display: flex; align-items: center; gap: 6px; }
.callsign input { background: var(--bg2); border: 1px solid var(--line2); border-radius: 6px; color: var(--text); font: inherit; font-size: 15px; font-weight: 700; padding: 4px 8px; width: 140px; letter-spacing: .04em; text-transform: none; }
.callsign input:focus { outline: none; border-color: var(--accent); }
.hof-filter { width: 100%; margin-bottom: 10px; }
.hof-filter button { flex: 1; padding: 5px 0; font-size: 12px; }
.hof table { width: 100%; border-collapse: collapse; font-size: 14px; }
.hof th { text-align: left; font-size: 11px; color: var(--dim); letter-spacing: .1em; text-transform: uppercase; padding: 4px 6px; border-bottom: 1px solid var(--line); }
.hof td { padding: 7px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.hof td.num { text-align: right; font-variant-numeric: tabular-nums; }
.hof td.sc { color: var(--accent); font-weight: 700; }
.hof td small { color: var(--muted); display: block; font-size: 11px; letter-spacing: .04em; }
.hof tr.me td { background: #2c2a1c; }
.hof tr:nth-child(-n+4) td:first-child { color: var(--accent); font-weight: 700; }
.hof-empty { color: var(--dim); padding: 18px 4px; text-align: center; font-size: 14px; }
.diff-tag { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.diff-tag.recruit { color: var(--ok); } .diff-tag.regular { color: var(--text); } .diff-tag.veteran { color: #e79a7a; } .diff-tag.nightmare { color: #d27ad8; }
.new-hs { text-align: center; font-size: 20px; font-weight: 700; letter-spacing: .2em; color: var(--accent); text-transform: uppercase; margin: 6px 0 2px; animation: starpop .5s ease; }
.score-big { text-align: center; font-size: 52px; font-weight: 700; color: var(--text); line-height: 1; margin: 10px 0 4px; font-variant-numeric: tabular-nums; }
.score-big small { display: block; font-size: 13px; color: var(--muted); letter-spacing: .12em; text-transform: uppercase; margin-top: 6px; font-weight: 600; }
.stat.hidden { display: none; }
.stat.score i { background: #2e2238; color: #d27ad8; }
.stat.score small { color: var(--muted); font-size: 12px; margin-left: 2px; }
@media (max-width: 1100px) {
  .endless-wrap { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .hof { position: static; }
  .endless-view { display: flex; width: max-content; }
  .endless-wrap > .hof { display: none; }
  .endless-wrap.show-hof > .hof { display: block; }
  .endless-wrap.show-hof > .endless-maps { display: none; }
}

/* ---------- HQ ---------- */
.research-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 22px; max-width: 1500px; margin: 0 auto; }
.rcol h3 { margin: 0 0 12px; font-size: 16px; letter-spacing: .2em; color: var(--muted); text-transform: uppercase; border-bottom: 1px solid var(--line); padding-bottom: 8px; }
.rnode { background: var(--panel); border: 1px solid var(--line); border-radius: 9px; padding: 11px 13px; margin-bottom: 10px; display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center; }
.rnode .rn-name { font-weight: 700; font-size: 17px; letter-spacing: .03em; }
.rnode .rn-desc { font-size: 14px; color: var(--muted); grid-column: 1; }
.rnode .rn-ranks { display: flex; gap: 4px; grid-column: 1; margin-top: 3px; }
.rnode .rn-ranks i { width: 18px; height: 5px; border-radius: 2px; background: var(--line2); }
.rnode .rn-ranks i.on { background: var(--accent); }
.rnode .rn-buy { grid-column: 2; grid-row: 1 / span 3; }
.rnode .rn-buy .btn { padding: 6px 12px; font-size: 14px; min-width: 76px; }
.rnode.maxed { border-color: #4e5a36; }
.rnode.locked { opacity: .45; }
.rnode .rn-req { font-size: 12px; color: var(--danger); letter-spacing: .04em; }
.rnode.doc { grid-template-columns: auto 1fr auto; }
.rnode.doc img { grid-row: 1 / span 3; width: 40px; height: 40px; }
.rnode.doc .rn-name, .rnode.doc .rn-desc, .rnode.doc .rn-ranks, .rnode.doc .rn-req { grid-column: 2; }
.rnode.doc .rn-buy { grid-column: 3; }

.arsenal { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; max-width: 1500px; margin: 0 auto; }
.unit-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: grid; grid-template-columns: 64px 1fr; gap: 6px 14px; }
.unit-card img { width: 64px; height: 64px; grid-row: 1 / span 3; }
.unit-card h4 { margin: 0; font-size: 20px; letter-spacing: .04em; text-transform: uppercase; }
.unit-card p { margin: 0; color: var(--muted); font-size: 14px; }
.unit-card .ustats { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 8px; }
.unit-card .ustats div { background: var(--bg2); border-radius: 6px; padding: 5px 8px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.unit-card .ustats b { display: block; color: var(--text); font-size: 16px; }
.unit-card .branches { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 4px; }
.unit-card .branches div { font-size: 13px; color: var(--muted); border-left: 3px solid var(--a); padding-left: 8px; }
.unit-card .branches div + div { border-color: var(--b); }
.unit-card .branches b { color: var(--text); display: block; font-size: 14px; text-transform: uppercase; letter-spacing: .04em; }
.unit-card.locked { opacity: .5; }
.licenses { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.lic { background: var(--bg2); border: 1px solid var(--line); border-radius: 7px; padding: 6px 8px; display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 52px; }
.lic b { display: block; font-size: 13px; letter-spacing: .04em; text-transform: uppercase; color: var(--text); }
.lic small { display: block; font-size: 11.5px; color: var(--muted); line-height: 1.25; }
.lic .btn { padding: 4px 9px; font-size: 13px; flex-shrink: 0; }
.lic.ba { border-left: 3px solid var(--a); }
.lic.bb { border-left: 3px solid var(--b); }
.lic.owned { border-color: #4e5a36; background: #1f2418; }
.lic.dim { opacity: .55; }
.lic-owned { color: var(--ok); font-weight: 700; font-size: 13px; white-space: nowrap; }
.lic-req { color: var(--dim); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
.upg.locked { opacity: .6; border-style: dashed; }
.upg .u-lock { font-size: 12px; color: var(--accent); margin-top: 3px; font-weight: 700; letter-spacing: .04em; }
.unit-card.locked img { filter: grayscale(1); }
.unit-card .lock-note { color: var(--accent); font-size: 13px; letter-spacing: .06em; text-transform: uppercase; font-weight: 700; }

/* ---------- game HUD ---------- */
#scr-game { background: #0f110c; }
.hud { display: flex; align-items: center; gap: 14px; padding: 8px 12px; background: var(--bg2); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.hud-group { display: flex; align-items: center; gap: 10px; }
.hud-group.stats { margin: 0 auto; gap: 8px; }
.hud-title { display: flex; flex-direction: column; line-height: 1.05; }
.hud-title b { font-size: 18px; letter-spacing: .08em; text-transform: uppercase; }
.hud-title small { color: var(--muted); font-size: 12px; letter-spacing: .12em; text-transform: uppercase; }
.stat { display: flex; align-items: center; gap: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 4px 14px 4px 6px; min-width: 110px; }
.stat i { width: 28px; height: 28px; border-radius: 6px; display: inline-flex; align-items: center; justify-content: center; font-style: normal; font-weight: 700; font-size: 16px; }
.stat i svg { width: 16px; height: 16px; fill: currentColor; }
.stat b { font-size: 22px; font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.stat.cash i { background: #3c3518; color: var(--accent); }
.stat.lives i { background: #1f3040; color: var(--blue); }
.stat.wave i { background: #33251d; color: #e79a7a; }
.stat.flash { animation: flash .5s; }
.stat.hurt { animation: hurt .5s; }
@keyframes flash { 0% { border-color: var(--accent); } 100% { border-color: var(--line); } }
@keyframes hurt { 0% { background: #5a2418; border-color: var(--danger); } 100% { background: var(--panel); } }
.next-btn { flex-direction: column; gap: 0; padding: 4px 16px; min-width: 150px; line-height: 1.1; }
.next-btn small { font-size: 11px; letter-spacing: .08em; opacity: .8; }
.next-btn small:empty { display: none; }
.next-btn.pulse { animation: pulse 1.4s infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(220,181,76,.6); } 50% { box-shadow: 0 0 0 7px rgba(220,181,76,0); } }

.game-main { flex: 1; display: flex; min-height: 0; }
.stage { flex: 1; position: relative; display: flex; align-items: center; justify-content: center; min-width: 0; min-height: 0; overflow: hidden; }
#cv { display: block; touch-action: none; }
.side { width: 316px; background: var(--bg2); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.side-head { padding: 10px 14px 6px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; font-size: 14px; color: var(--muted); display: flex; justify-content: space-between; align-items: baseline; }
.side-head small { font-size: 11px; letter-spacing: .06em; color: var(--dim); }
.build-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 4px 12px 12px; border-bottom: 1px solid var(--line); }
.bitem { position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 6px 4px 5px; display: flex; flex-direction: column; align-items: center; gap: 1px; user-select: none; transition: border-color .12s, background .12s, opacity .12s; }
.bitem img { width: 40px; height: 40px; }
.bitem .bn { font-size: 12px; font-weight: 700; letter-spacing: .03em; text-transform: uppercase; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.bitem .bc { font-size: 14px; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.bitem .bk { position: absolute; top: 3px; left: 5px; font-size: 11px; color: var(--dim); font-weight: 700; }
.bitem:hover { border-color: var(--line2); background: var(--panel2); }
.bitem.sel { border-color: var(--accent); background: #2c2a1c; }
.bitem.poor { opacity: .45; }
.bitem.poor .bc { color: var(--danger); }
.bitem.locked { opacity: .25; cursor: not-allowed; }
.bitem.locked img { filter: grayscale(1); }
.bitem .bwall { position: absolute; top: 3px; right: 5px; font-size: 11px; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.bitem[data-t="wall"] { border-color: rgba(185,167,124,.45); }
.bitem[data-t="wall"].sel { border-color: var(--accent); }
.bitem.new::after { content: 'NEW'; position: absolute; top: 3px; right: 4px; font-size: 10px; background: var(--accent); color: var(--accent-ink); padding: 0 4px; border-radius: 3px; font-weight: 700; }

.tower-panel { flex: 1; overflow-y: auto; padding: 12px; }
.tp-empty { color: var(--dim); font-size: 14px; line-height: 1.5; padding: 6px 2px; }
.tp-empty kbd, .kbd { background: var(--panel2); border: 1px solid var(--line2); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; font-family: inherit; font-size: 12px; color: var(--text); font-weight: 700; }
.tp-head { display: flex; gap: 10px; align-items: center; }
.tp-head img { width: 52px; height: 52px; }
.tp-head h3 { margin: 0; font-size: 20px; letter-spacing: .05em; text-transform: uppercase; }
.tp-head small { color: var(--muted); font-size: 13px; letter-spacing: .06em; text-transform: uppercase; }
.tp-head .tp-close { margin-left: auto; align-self: flex-start; background: none; border: 0; color: var(--dim); font-size: 20px; }
.tp-kd { display: flex; gap: 14px; font-size: 13px; color: var(--muted); margin: 8px 0; letter-spacing: .04em; text-transform: uppercase; }
.tp-kd b { color: var(--text); }
.tp-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
.tp-stats div { background: var(--panel); border-radius: 6px; padding: 4px 8px; font-size: 11px; color: var(--muted); letter-spacing: .06em; text-transform: uppercase; }
.tp-stats b { display: block; font-size: 16px; color: var(--text); letter-spacing: .02em; font-variant-numeric: tabular-nums; }
.tp-tags { display: flex; flex-wrap: wrap; gap: 4px; margin: 8px 0; }
.tag { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; padding: 2px 7px; border-radius: 4px; background: var(--panel2); color: var(--muted); border: 1px solid var(--line); }
.tag.hi { color: var(--accent); border-color: #5d4f22; }
.tag.buff { color: var(--blue); border-color: #3d6072; }
.tp-label { font-size: 12px; color: var(--dim); letter-spacing: .14em; text-transform: uppercase; margin: 12px 0 5px; font-weight: 700; }
.tp-modes { display: flex; width: 100%; }
.tp-modes button { flex: 1; padding: 5px 0; font-size: 13px; }
.upg { width: 100%; text-align: left; background: var(--panel); border: 1px solid var(--line2); border-radius: 8px; padding: 9px 11px; margin-bottom: 6px; display: block; transition: border-color .12s, background .12s; }
.upg:hover:not(:disabled) { border-color: var(--accent); background: #26261a; }
.upg:disabled { opacity: .5; cursor: not-allowed; }
.upg .u-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.upg .u-name { font-weight: 700; font-size: 15px; letter-spacing: .04em; text-transform: uppercase; }
.upg .u-cost { font-weight: 700; color: var(--accent); font-size: 16px; font-variant-numeric: tabular-nums; }
.upg.poor .u-cost { color: var(--danger); }
.upg .u-desc { font-size: 13px; color: var(--muted); margin-top: 2px; line-height: 1.3; }
.upg .u-delta { font-size: 12px; color: var(--ok); margin-top: 3px; letter-spacing: .03em; }
.upg.ba { border-left: 3px solid var(--a); }
.upg.bb { border-left: 3px solid var(--b); }
.upg .u-bdesc { font-size: 12px; color: var(--dim); font-style: italic; }
.tp-max { text-align: center; color: var(--accent); font-weight: 700; letter-spacing: .14em; text-transform: uppercase; padding: 10px; border: 1px dashed #5d4f22; border-radius: 8px; font-size: 14px; }
.tp-sell { width: 100%; margin-top: 10px; }
.btn.undo { background: transparent; border-color: #4f6a3a; color: var(--ok); }
.btn.undo:hover { background: #1f2a18; }
.undo-note { font-size: 12px; color: var(--muted); text-align: center; margin-top: 5px; }

.wave-preview { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 10px; background: rgba(19,21,15,.82); border: 1px solid var(--line); padding: 4px 12px; border-radius: 99px; font-size: 13px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); pointer-events: none; backdrop-filter: blur(4px); white-space: nowrap; max-width: calc(100% - 20px); overflow: hidden; }
.wave-preview:empty { display: none; }
.wave-preview .wp-item { display: inline-flex; align-items: center; gap: 2px; color: var(--text); pointer-events: auto; cursor: help; border-radius: 6px; padding: 0 3px; margin: 0 -3px; transition: background .12s; }
.wave-preview .wp-item:hover { background: rgba(255,255,255,.08); }
.toast.wp-toast .tt-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 10px; margin-top: 6px; font-size: 13px; }
.toast.wp-toast .tt-grid b { color: var(--text); }
.wave-preview img { width: 22px; height: 22px; }
.wave-preview .boss { color: var(--danger); }
.wave-preview .wp-name { color: var(--accent); }

.abilities { position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%); display: flex; gap: 8px; }
.abil { position: relative; width: 64px; height: 64px; background: rgba(30,33,26,.92); border: 1px solid var(--line2); border-radius: 10px; display: flex; flex-direction: column; align-items: center; justify-content: center; overflow: hidden; backdrop-filter: blur(4px); }
.abil svg { width: 26px; height: 26px; fill: var(--text); position: relative; z-index: 1; }
.abil span { font-size: 10px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; position: relative; z-index: 1; }
.abil .ak { position: absolute; top: 2px; left: 5px; font-size: 10px; color: var(--dim); }
.abil svg, .abil span { transition: opacity .2s, fill .2s, color .2s; }
/* cooling down: icon + label fade into the background, the remaining time sweeps over them */
.abil:not(.ready) svg { fill: var(--dim); opacity: .4; filter: grayscale(1); }
.abil:not(.ready) span { color: var(--dim); opacity: .6; }
.abil:not(.ready) .ak { opacity: .5; }
.abil .cdov { position: absolute; left: 0; right: 0; bottom: 0; z-index: 1; background: rgba(0,0,0,.5); }
.abil .cdt { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 20px; font-weight: 700; z-index: 2; color: var(--text); text-shadow: 0 1px 3px rgba(0,0,0,.9); }
.abil.flash { animation: abil-ready .6s ease-out; }
@keyframes abil-ready { 0% { box-shadow: 0 0 0 0 rgba(220,181,76,.8); } 100% { box-shadow: 0 0 0 10px rgba(220,181,76,0); } }
.abil.ready { border-color: var(--accent); }
.abil.ready:hover { background: #2c2a1c; }
.abil.armed { background: #4a2a1c; border-color: var(--danger); }

.toasts { position: absolute; top: 48px; right: 12px; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; pointer-events: none; max-width: 340px; }
.toast { background: rgba(24,27,20,.95); border: 1px solid var(--line2); border-left: 3px solid var(--accent); border-radius: 8px; padding: 9px 13px; font-size: 14px; box-shadow: 0 6px 20px rgba(0,0,0,.35); animation: tin .25s ease; pointer-events: auto; }
.toast.out { animation: tout .3s ease forwards; }
.toast b { letter-spacing: .04em; }
.toast.intel { display: grid; grid-template-columns: 44px 1fr; gap: 3px 10px; border-left-color: var(--danger); }
.toast.intel img { width: 44px; height: 44px; grid-row: 1 / span 3; }
.toast.intel .ti-h { font-size: 11px; color: var(--danger); letter-spacing: .16em; font-weight: 700; }
.toast.intel .ti-n { font-size: 17px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.toast.intel .ti-d { font-size: 13px; color: var(--muted); }
.toast.tip { border-left-color: var(--blue); }
.toast.good { border-left-color: var(--ok); }
.toast.bad { border-left-color: var(--danger); }
@keyframes tin { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }
@keyframes tout { to { opacity: 0; transform: translateX(20px); } }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(8,9,6,.72); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; backdrop-filter: blur(3px); }
.modal.hidden { display: none; }
.modal-card { background: var(--panel); border: 1px solid var(--line2); border-radius: 14px; width: min(560px, 100%); max-height: calc(100vh - 32px); overflow: auto; padding: 24px; box-shadow: 0 20px 60px rgba(0,0,0,.5); animation: pop .22s ease; }
.modal-card.wide { width: min(820px, 100%); }
@keyframes pop { from { transform: scale(.96); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-card h2 { margin: 0 0 4px; font-size: 32px; letter-spacing: .1em; text-transform: uppercase; }
.modal-card .sub { color: var(--muted); letter-spacing: .1em; text-transform: uppercase; font-size: 14px; margin-bottom: 16px; }
.modal-card p { color: var(--muted); line-height: 1.45; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; flex-wrap: wrap; }
.big-stars { display: flex; gap: 10px; justify-content: center; margin: 14px 0; }
.big-stars .star { width: 54px; height: 54px; }
.big-stars .star.on { animation: starpop .4s ease backwards; }
.big-stars .star.on:nth-child(2) { animation-delay: .15s; }
.big-stars .star.on:nth-child(3) { animation-delay: .3s; }
@keyframes starpop { from { transform: scale(0) rotate(-40deg); } to { transform: none; } }
.result-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 12px 0; }
.result-grid div { background: var(--bg2); border-radius: 8px; padding: 8px 10px; font-size: 12px; color: var(--muted); letter-spacing: .06em; text-transform: uppercase; }
.result-grid b { display: block; font-size: 20px; color: var(--text); }
.rewards { background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin-top: 12px; }
.rewards h4 { margin: 0 0 6px; font-size: 13px; letter-spacing: .14em; color: var(--muted); text-transform: uppercase; }
.rewards .rw { display: flex; justify-content: space-between; padding: 3px 0; font-size: 15px; }
.rewards .rw b { color: var(--accent); }
.unlock-list { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.unlock-item { display: flex; align-items: center; gap: 8px; background: #2c2a1c; border: 1px solid #5d4f22; border-radius: 8px; padding: 6px 12px 6px 6px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; font-size: 14px; }
.unlock-item img { width: 36px; height: 36px; }
.brief-map { width: 100%; height: auto; max-height: 30vh; object-fit: contain; border-radius: 8px; display: block; margin-bottom: 14px; }
.brief-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.brief-row img { width: 34px; height: 34px; background: var(--bg2); border-radius: 6px; }
.field { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); gap: 12px; }
.field label { font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.field small { display: block; color: var(--muted); font-weight: 500; letter-spacing: 0; text-transform: none; font-size: 13px; }
input[type=range] { accent-color: var(--accent); width: 160px; }
.lic-item { border: 1px solid var(--line); border-radius: 8px; margin: 6px 0; background: var(--bg2); }
.lic-item summary { padding: 8px 12px; cursor: pointer; font-size: 14px; }
.lic-item pre { margin: 0; padding: 0 12px 12px; white-space: pre-wrap; font-size: 11px; color: var(--muted); max-height: 220px; overflow: auto; font-family: ui-monospace, Menlo, monospace; -webkit-user-select: text; user-select: text; }
.help-grid { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 14px; color: var(--muted); }

.tooltip { position: fixed; z-index: 60; background: rgba(20,23,17,.97); border: 1px solid var(--line2); border-radius: 8px; padding: 10px 12px; width: 270px; pointer-events: none; font-size: 13px; color: var(--muted); box-shadow: 0 10px 30px rgba(0,0,0,.45); }
.tooltip.hidden { display: none; }
.tooltip h4 { margin: 0 0 2px; color: var(--text); font-size: 17px; letter-spacing: .05em; text-transform: uppercase; }
.tooltip .tt-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 3px 10px; margin-top: 8px; }
.tooltip .tt-grid b { color: var(--text); }

/* ---------- responsive ---------- */
@media (max-width: 980px) {
  .game-main { flex-direction: column; }
  .side { width: 100%; height: 38vh; border-left: 0; border-top: 1px solid var(--line); flex-direction: row; }
  .side-head { display: none; }
  .build-list { grid-template-columns: repeat(4, 1fr); width: 55%; overflow-y: auto; border-bottom: 0; border-right: 1px solid var(--line); padding-top: 10px; align-content: start; }
  .tower-panel { width: 45%; }
  .hud-group.stats { margin: 0; }
  .stat { min-width: 0; padding-right: 10px; }
  .stat b { font-size: 18px; }
  .btn.big { min-width: 240px; }
}
@media (max-width: 640px) {
  .hud { gap: 6px; padding: 6px; }
  .hud-title { display: none; }
  .next-btn { min-width: 0; padding: 4px 10px; }
  .abil { width: 52px; height: 52px; }
  .side { height: 44vh; flex-direction: column; }
  .build-list, .tower-panel { width: 100%; }
  .build-list { grid-template-columns: repeat(6, 1fr); border-right: 0; border-bottom: 1px solid var(--line); max-height: 45%; }
  .bitem .bn { display: none; }
  .bitem img { width: 30px; height: 30px; }
  .result-grid { grid-template-columns: repeat(2, 1fr); }
  .scroll { padding: 14px; }
}

/* ---------- zoom controls & drag-and-drop ---------- */
.zoom-seg button { min-width: 34px; font-size: 19px; line-height: 1; padding: 4px 8px; color: var(--text); }
.zoom-seg button svg { width: 15px; height: 15px; display: block; }
.zoom-seg button[data-z="fit"] { display: none; color: var(--accent); }
.zoom-seg.zoomed button[data-z="fit"] { display: block; }
/* the unit list scrolls vertically on touch screens; swipes across it are drags onto the map (js/ui.js) */
.bitem { touch-action: pan-y; }
.abil.paused .cdt { opacity: .55; }
.abil.paused .cdt::after { content: '❚❚'; font-size: 9px; letter-spacing: -1px; margin-left: 3px; vertical-align: middle; opacity: .8; }

.place-confirm { position: absolute; left: 0; top: 0; z-index: 7; display: flex; gap: 6px; padding: 5px; background: rgba(24,27,20,.96); border: 1px solid var(--line2); border-radius: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.45); will-change: transform; }
.place-confirm.hidden { display: none; }
.place-confirm button { height: 40px; border-radius: 8px; font: inherit; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; font-size: 15px; border: 1px solid transparent; }
.place-confirm .pc-ok { background: var(--accent); color: var(--accent-ink); padding: 0 16px; white-space: nowrap; }
.place-confirm .pc-ok:disabled { background: var(--panel3); color: var(--danger); }
.place-confirm .pc-no { width: 40px; background: var(--panel2); color: var(--muted); border-color: var(--line2); font-size: 16px; }

/* ---------- tutorial coach marks ---------- */
.coach-target { position: relative; z-index: 3; animation: coach 1.3s ease-in-out infinite; }
@keyframes coach { 0%, 100% { box-shadow: 0 0 0 2px var(--accent), 0 0 0 0 rgba(220,181,76,.55); } 50% { box-shadow: 0 0 0 2px var(--accent), 0 0 0 9px rgba(220,181,76,0); } }
.toast.coach { border-left-color: var(--accent); background: rgba(36,34,22,.97); }

/* ---------- collapsible side panel ---------- */
.game-main.collapsed .side { display: none; }
.panel-toggle .pt-col { transition: opacity .15s; }
.panel-toggle.closed { color: var(--accent); border-color: #5d4f22; }
.panel-toggle.closed .pt-col { opacity: 0; }

/* ---------- touch & app shell ---------- */
html, body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; touch-action: manipulation; overscroll-behavior: none; }
input { -webkit-user-select: text; user-select: text; }
.screen { left: env(safe-area-inset-left); right: env(safe-area-inset-right); }
@media (hover: none) {
  .btn:hover, .bitem:hover, .icon-btn:hover, .upg:hover:not(:disabled) { background: inherit; }
  .btn.primary:hover { background: var(--accent); }
  .level-card:hover { transform: none; }
}

/* ---------- landscape phones (iPhone) ---------- */
@media (orientation: landscape) and (max-height: 520px) {
  .hud { padding: 4px 8px; gap: 6px; flex-wrap: nowrap; }
  .hud-title { display: none; }
  .hud-group { gap: 6px; }
  .hud-group.stats { margin: 0 auto; gap: 5px; }
  .stat { min-width: 0; padding: 2px 8px 2px 3px; gap: 5px; }
  .stat i { width: 22px; height: 22px; font-size: 13px; }
  .stat b { font-size: 17px; }
  .stat.score small { display: none; }
  .icon-btn { height: 32px; min-width: 32px; padding: 0 8px; font-size: 12px; }
  .seg button { padding: 4px 8px; font-size: 13px; }
  .next-btn { min-width: 0; padding: 2px 12px; font-size: 13px; }
  .next-btn small { font-size: 11px; }

  .game-main { flex-direction: row; }
  .side { width: 236px; height: auto; flex-direction: column; border-left: 1px solid var(--line); border-top: 0; }
  .side-head { display: none; }
  .build-list { width: 100%; grid-template-columns: repeat(3, 1fr); gap: 5px; padding: 6px; border-right: 0; border-bottom: 1px solid var(--line); max-height: none; overflow-y: auto; flex: 1 1 auto; align-content: start; }
  .bitem { padding: 4px 2px 3px; border-radius: 8px; min-height: 50px; justify-content: center; }
  .bitem img { width: 30px; height: 30px; }
  .bitem .bc { font-size: 13px; }
  /* a selected unit gets the whole sidebar; the build list returns on deselect */
  .side.has-selection .build-list { display: none; }
  .side:not(.has-selection) .tower-panel { flex: 0 0 auto; max-height: 34%; }
  .side:not(.has-selection) .tower-panel .tp-empty { display: none; }
  .icon-btn { height: 36px; min-width: 36px; }
  .seg button { padding: 7px 10px; }
  .bitem .bn { display: none; }
  .bitem .bk { display: none; }
  .bitem.new::after { font-size: 9px; top: 1px; right: 1px; padding: 0 3px; }
  .tower-panel { width: 100%; padding: 9px; font-size: 14px; }
  .tp-head img { width: 36px; height: 36px; }
  .tp-head h3 { font-size: 17px; }
  .tp-head small { font-size: 12px; }
  .tp-stats { grid-template-columns: repeat(3, 1fr); gap: 3px; }
  .tp-stats div { padding: 3px 6px; font-size: 11px; letter-spacing: .03em; }
  .tp-stats b { font-size: 15px; }
  .tp-kd { margin: 5px 0; font-size: 12px; }
  .tp-label { margin: 9px 0 5px; font-size: 12px; }
  .tp-modes button { font-size: 12px; padding: 6px 0; }
  .upg { padding: 6px 8px; }
  .upg .u-name { font-size: 14px; }
  .upg .u-cost { font-size: 15px; }
  .upg .u-desc, .upg .u-delta, .upg .u-lock, .upg .u-bdesc { font-size: 13px; line-height: 1.3; }
  .tp-empty { font-size: 13px; line-height: 1.45; }
  .tag { font-size: 11px; padding: 2px 6px; }

  .stage { padding: 0; }
  .abilities { bottom: 6px; gap: 5px; }
  .abil { width: 50px; height: 50px; border-radius: 9px; }
  .zoom-seg button { min-width: 36px; padding: 6px 8px; }
  .abil svg { width: 20px; height: 20px; }
  .abil span { font-size: 10px; }
  .wave-preview { top: 4px; font-size: 12px; padding: 2px 10px; gap: 6px; }
  .wave-preview img { width: 18px; height: 18px; }
  .toasts { top: 30px; right: 6px; max-width: 250px; gap: 5px; }
  .toast { font-size: 13px; padding: 7px 10px; }
  .toast.intel { grid-template-columns: 34px 1fr; }
  .toast.intel img { width: 34px; height: 34px; }
  .toast.intel .ti-n { font-size: 14px; }

  .modal { padding: 8px; }
  .modal-card { padding: 14px 18px; max-height: calc(100vh - 16px); border-radius: 12px; }
  .modal-card h2 { font-size: 24px; }
  .modal-card .sub { margin-bottom: 8px; font-size: 12px; }
  .modal-card p { margin: 6px 0; font-size: 14px; }
  .brief-map { max-height: 34vh; margin-bottom: 8px; }
  .modal { padding-left: max(8px, env(safe-area-inset-left)); padding-right: max(8px, env(safe-area-inset-right)); }
  .modal-card.wide { width: min(860px, 100%); }
  .modal-card.wide > .brief-map { float: left; width: 40%; max-height: none; margin: 0 18px 6px 0; }
  .modal-card.wide .result-grid { grid-template-columns: repeat(4, 1fr); }
  .modal-card.wide .modal-actions { clear: both; }
  .modal-card.wide .brief-row img { width: 28px; height: 28px; }
  .result-grid { margin: 8px 0; gap: 6px; }
  .result-grid div { padding: 5px 8px; }
  .result-grid b { font-size: 16px; }
  .big-stars .star { width: 38px; height: 38px; }
  .big-stars { margin: 6px 0; }
  .score-big { font-size: 38px; }
  .modal-actions { margin-top: 12px; position: sticky; bottom: -14px; background: var(--panel); padding: 8px 0 10px; z-index: 2; box-shadow: 0 -10px 14px -8px var(--panel); }

  .menu-wrap { gap: 16px; padding: 12px; }
  .logo h1 { font-size: 44px; margin-top: 6px; }
  .logo p { font-size: 12px; }
  .logo-mark span { width: 26px; height: 7px; }
  .menu-btns { gap: 8px; width: 270px; }
  .btn.big { font-size: 17px; padding: 9px 22px; min-width: 240px; }
  .menu-stats { font-size: 12px; gap: 14px; }

  .topbar { padding: 6px 10px; gap: 10px; flex-wrap: nowrap; }
  .topbar h2 { font-size: 19px; }
  .topbar .btn { padding: 6px 10px; font-size: 13px; }
  .topbar-right { gap: 8px; }
  .scroll { padding: 10px; }
  .level-grid { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
  .level-card .lc-body { padding: 8px 10px; }
  .level-card .lc-name { font-size: 15px; }
  .level-card .lc-num { font-size: 22px; width: 26px; }
  .chapter-strip { grid-template-columns: repeat(5, minmax(130px, 1fr)); overflow-x: auto; gap: 6px; }
  .chapter-tab { padding: 6px 9px 8px; }
  .chapter-tab .ct-name { font-size: 14px; margin-bottom: 3px; }
  .chapter-desc { font-size: 13px; margin-bottom: 10px; }
  .endless-wrap { grid-template-columns: minmax(0, 1fr); }
  .endless-intro { font-size: 13px; line-height: 1.4; margin-bottom: 10px; }
  #endless-diff .mul { display: none; }
  .endless-wrap .level-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
  #endless-diff button { padding: 4px 7px; }
  .hof { padding: 10px 12px; }
  .hof-head { margin-bottom: 8px; }
  .hof td { padding: 5px 6px; font-size: 13px; }
  .merit-box { font-size: 12px; }
  .merit-box b { font-size: 17px; }
}

/* ---------- versus (1v1) ---------- */
#scr-game.versus #speed-seg, #scr-game.versus #btn-auto { display: none; }
.stat.income i { background: #1f3324; color: var(--ok); font-size: 13px; letter-spacing: -.04em; }
.vs-pill { margin-left: 6px; font-size: 12px; vertical-align: 2px; }
#cv { transition: transform .35s ease, opacity .35s; }
.stage.show-opp #cv { transform: translateX(-14%); opacity: .4; }

/* enemy strip (top left) and the enemy base sliding in from the right */
.vs-bar { position: absolute; top: 10px; left: 10px; z-index: 3; display: flex; align-items: center; gap: 8px; background: rgba(19,21,15,.86); border: 1px solid var(--line2); border-left: 3px solid var(--danger); border-radius: 99px; padding: 4px 6px 4px 12px; font: inherit; font-weight: 700; font-size: 14px; color: var(--text); backdrop-filter: blur(4px); font-variant-numeric: tabular-nums; }
.vs-bar.hidden { display: none; }
#scr-game:not(.versus) .vs-bar { display: none; }
.vs-bar.hurt { animation: vs-hit .5s; }
@keyframes vs-hit { 0% { background: rgba(140,180,90,.55); } 100% { background: rgba(19,21,15,.86); } }
.vb-tag { color: var(--danger); letter-spacing: .14em; text-transform: uppercase; font-size: 12px; }
.vb-stat { display: inline-flex; align-items: center; gap: 4px; }
.vb-heart, .opp-stats .vb-heart { display: inline-block; width: 11px; height: 12px; background: var(--blue); clip-path: polygon(50% 0, 100% 18%, 100% 55%, 50% 100%, 0 55%, 0 18%); }
.vb-warn { color: var(--accent); font-size: 13px; }
.vb-go { width: 26px; height: 26px; border-radius: 50%; background: var(--panel3); display: inline-flex; align-items: center; justify-content: center; font-size: 20px; line-height: 1; color: var(--accent); }
.opp-view { position: absolute; inset: 0; z-index: 4; background: #0f110c; display: flex; align-items: center; justify-content: center; transform: translateX(100%); visibility: hidden; transition: transform .35s ease, visibility 0s linear .35s; touch-action: pan-y; }
.stage.show-opp .opp-view { transform: none; visibility: visible; transition: transform .35s ease, visibility 0s; }
#cv-opp { display: block; }
.opp-view::after { content: ''; position: absolute; inset: 0; box-shadow: inset 0 0 0 2px rgba(214,90,62,.55), inset 0 0 40px rgba(214,90,62,.18); pointer-events: none; }
.opp-head { position: absolute; top: 10px; left: 10px; right: 10px; display: flex; align-items: center; gap: 10px; pointer-events: none; }
.opp-back { pointer-events: auto; display: flex; align-items: center; gap: 6px; background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 99px; padding: 6px 14px 6px 8px; font: inherit; font-weight: 700; font-size: 15px; letter-spacing: .06em; text-transform: uppercase; box-shadow: 0 6px 18px rgba(0,0,0,.4); }
.opp-back svg { width: 20px; height: 20px; }
.opp-back b { font-variant-numeric: tabular-nums; margin-left: 2px; }
.opp-stats { display: flex; gap: 12px; align-items: center; background: rgba(19,21,15,.86); border: 1px solid var(--line2); border-left: 3px solid var(--danger); border-radius: 99px; padding: 5px 14px; font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; backdrop-filter: blur(4px); }
.opp-stats span { display: inline-flex; align-items: center; gap: 4px; }
.opp-stats .opp-doc { color: var(--danger); font-weight: 700; letter-spacing: .05em; text-transform: uppercase; font-size: 12px; border: 1px solid rgba(214,90,62,.5); border-radius: 99px; padding: 0 8px; }
/* the opponent bot answering you: retaliation, counters, a change of tactics */
.toast.bot { border-left-color: var(--danger); font-weight: 600; }
.toast.bot .bot-note { color: var(--danger); font-weight: 700; margin-right: 2px; }
.tooltip .send-vs { color: var(--text); line-height: 1.35; }
.opp-stats b { color: var(--text); }
.opp-stats .opp-name { color: var(--danger); font-weight: 700; letter-spacing: .12em; text-transform: uppercase; font-size: 12px; }
.toasts { z-index: 6; }

/* send bar (bottom): visible on both views */
.sends { position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%); z-index: 6; display: flex; gap: 5px; max-width: calc(100% - 16px); overflow-x: auto; padding: 4px; background: rgba(19,21,15,.82); border: 1px solid var(--line); border-radius: 12px; backdrop-filter: blur(4px); scrollbar-width: none; }
.sends::-webkit-scrollbar { display: none; }
.sends.hidden { display: none; }
.send { position: relative; flex: none; width: 54px; padding: 3px 0 2px; background: var(--panel); border: 1px solid var(--line2); border-radius: 8px; display: flex; flex-direction: column; align-items: center; gap: 0; font: inherit; font-weight: 700; line-height: 1.05; }
.send img { width: 26px; height: 26px; }
.send .sn { position: absolute; top: 2px; right: 4px; font-size: 11px; color: var(--muted); }
.send .sc { font-size: 13px; color: var(--accent); font-variant-numeric: tabular-nums; }
.send .sl { display: none; font-size: 12px; color: var(--dim); }
.send:hover:not(.locked) { border-color: var(--danger); background: #2e221c; }
.send:active:not(.locked) { transform: scale(.94); }
.send.poor { opacity: .55; }
.send.poor .sc { color: var(--danger); }
.send.sent { animation: send-pop .35s ease; }
@keyframes send-pop { 0% { transform: scale(.9); background: #4a2a1c; border-color: var(--danger); } 100% { transform: none; } }
.send.locked { opacity: .35; }
.send.locked img { filter: grayscale(1); }
.send.locked .sc { display: none; }
.send.locked .sl { display: block; }

.toast.incoming { display: flex; align-items: center; gap: 8px; }
.toast.incoming img { width: 28px; height: 28px; flex: none; }
.toast.incoming small { color: var(--muted); }

/* setup + results */
.vs-seg { display: flex; flex-wrap: wrap; width: 100%; }
.vs-seg button { flex: 1 1 auto; display: flex; flex-direction: column; align-items: center; line-height: 1.15; }
.vs-seg button small { font-size: 11px; color: var(--dim); letter-spacing: .04em; text-transform: none; font-weight: 600; }
.vs-maps button { flex: 1 1 22%; font-size: 13px; padding: 6px 8px; }
.vs-record { margin-top: 12px; color: var(--muted); font-size: 14px; line-height: 1.5; }
.vs-record b { color: var(--text); }
.vs-record small { color: var(--dim); }
.vs-table { width: 100%; border-collapse: collapse; margin: 6px 0 4px; font-size: 15px; }
.vs-table th { text-align: left; font-size: 12px; color: var(--dim); letter-spacing: .12em; text-transform: uppercase; padding: 4px 8px; }
.vs-table td { padding: 5px 8px; border-top: 1px solid var(--line); color: var(--muted); }
.vs-table .num { text-align: right; color: var(--text); font-variant-numeric: tabular-nums; }
.vs-table th.num { color: var(--dim); }
.vs-table small { color: var(--dim); }

@media (orientation: landscape) and (max-height: 520px) {
  .vs-bar { top: 4px; left: 6px; font-size: 13px; padding: 2px 4px 2px 9px; gap: 6px; }
  .vb-go { width: 22px; height: 22px; font-size: 17px; }
  .sends { bottom: 4px; gap: 3px; padding: 3px; }
  .send { width: 46px; }
  .send img { width: 22px; height: 22px; }
  .send .sc { font-size: 12px; }
  .opp-head { top: 4px; left: 6px; right: 6px; }
  .opp-back { padding: 4px 12px 4px 6px; font-size: 13px; }
  .opp-stats { padding: 3px 10px; font-size: 13px; gap: 9px; }
  .vs-maps button { flex-basis: 30%; }
}
@media (max-width: 640px) {
  .vs-bar .vb-tag { display: none; }
  .opp-stats .opp-name { display: none; }
  .send { width: 46px; }
}

/* ---------- versus: friend matches ---------- */
.vs-mode { display: flex; width: 100%; margin: 4px 0 2px; }
.vs-mode button { flex: 1; font-size: 16px; padding: 8px 12px; }
.vs-offline { background: #2e221c; border: 1px solid #5d3a2a; border-radius: 8px; padding: 8px 12px; font-size: 14px; }
.vs-offline code, .modal-card p code { font-family: ui-monospace, Menlo, monospace; font-size: 12px; color: var(--text); }
.vs-name { border-bottom: 0; padding: 4px 0 8px; }
.vs-name input, .vs-code { background: var(--bg2); border: 1px solid var(--line2); color: var(--text); border-radius: 8px; padding: 8px 10px; font: inherit; font-weight: 700; font-size: 16px; width: 200px; }
.vs-name input:focus, .vs-code:focus { outline: none; border-color: var(--accent); }
.vs-friend { display: grid; grid-template-columns: 1.6fr 1fr; gap: 16px; }
.vs-col { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.vs-col .tp-label { margin-top: 4px; }
.vs-code { width: 100%; text-align: center; letter-spacing: .4em; font-size: 26px; text-transform: uppercase; padding: 6px 10px; }
.vs-code::placeholder { color: var(--dim); letter-spacing: .3em; }
.vs-wide { width: 100%; justify-content: center; }
.vs-msg { color: var(--danger); font-size: 14px; min-height: 1em; }
.room-code { text-align: center; font-size: 64px; font-weight: 700; letter-spacing: .3em; padding-left: .3em; color: var(--accent); line-height: 1; margin: 6px 0 10px; font-variant-numeric: tabular-nums; user-select: text; -webkit-user-select: text; }
.room-share { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }
.room-players { display: flex; justify-content: center; gap: 24px; margin: 16px 0 6px; font-weight: 700; font-size: 17px; flex-wrap: wrap; }
.room-players small { color: var(--dim); font-weight: 500; }
.room-players .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 7px; vertical-align: 1px; }
.room-players .dot.ok { background: var(--ok); }
.room-players .dot.wait { background: var(--dim); animation: blink 1.2s infinite; }
@keyframes blink { 50% { opacity: .25; } }
.room-status { text-align: center; color: var(--muted); font-size: 14px; letter-spacing: .06em; min-height: 1.2em; }
.rematch-note { text-align: center; color: var(--muted); font-size: 15px; min-height: 1.2em; margin-top: 10px; }
.rematch-note.hot { color: var(--accent); font-weight: 700; }
.countdown { position: absolute; inset: 0; z-index: 5; display: flex; align-items: center; justify-content: center; font-size: 140px; font-weight: 700; color: var(--accent); text-shadow: 0 6px 30px rgba(0,0,0,.6); pointer-events: none; }
.countdown.hidden { display: none; }
@media (max-width: 640px) {
  .vs-friend { grid-template-columns: 1fr; }
  .room-code { font-size: 48px; }
}
@media (orientation: landscape) and (max-height: 520px) {
  .vs-about.friend { display: none; }
  .room-code { font-size: 44px; margin: 2px 0 6px; }
  .room-players { margin: 8px 0 4px; }
  .countdown { font-size: 96px; }
  .vs-code { font-size: 22px; }
}

.modal-card p.fine a { color: var(--muted); }
a.btn { text-decoration: none; }

/* ---------- native sign-in buttons (iOS app) ---------- */
.gsi-slot.sso-list { flex-direction: column; gap: 10px; }
.sso { display: flex; align-items: center; justify-content: center; gap: 10px; width: min(290px, 100%); height: 46px; border-radius: 23px; border: 1px solid #747775; background: #fff; color: #1f1f1f; font: 600 17px -apple-system, system-ui, sans-serif; letter-spacing: 0; text-transform: none; }
.sso.apple { color: #000; border-color: #fff; }
.sso .sso-logo { font-size: 21px; line-height: 1; margin-top: -3px; }
.sso svg.sso-logo { width: 18px; height: 18px; margin: 0; }
.sso:disabled { opacity: .6; }

/* ---------- main menu on landscape phones: logo left, buttons right (6 stacked buttons don't fit) ---------- */
@media (orientation: landscape) and (max-height: 520px) {
  .menu-wrap { display: grid; grid-template-columns: auto auto; grid-template-areas: "logo btns" "stats btns"; align-items: center; column-gap: 44px; row-gap: 16px; padding: 8px max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left)); }
  .menu-wrap .logo { grid-area: logo; align-self: end; }
  .menu-wrap .menu-btns { grid-area: btns; gap: 7px; width: 250px; }
  /* width 0 + min-width 100%: the stats wrap inside the logo's column instead of widening it */
  .menu-wrap .menu-stats { grid-area: stats; align-self: start; width: 0; min-width: 100%; gap: 4px 14px; }
  .menu-wrap .btn.big { min-width: 230px; padding: 8px 20px; }
  .account-chip { top: max(10px, env(safe-area-inset-top)); left: max(12px, env(safe-area-inset-left)); right: auto; height: 36px; font-size: 13px; }
}

/* Sign in with Apple / Google on the web (rendered by Apple JS and Google Identity Services) */
.gsi-slot.sso-list .apple-web { width: 290px; height: 44px; cursor: pointer; }
.gsi-slot.sso-list .gsi-btn { min-height: 44px; }

.vs-name .vs-acct { font-size: 18px; color: var(--accent); letter-spacing: .04em; }

/* versus: call-ins sit above the troop send bar */
#scr-game.versus .abilities { bottom: 82px; }
@media (orientation: landscape) and (max-height: 520px) {
  #scr-game.versus .abilities { bottom: 58px; }
}

/* online Hall of Fame */
.hof-scope { display: flex; width: 100%; margin-bottom: 8px; }
.hof-scope button { flex: 1; }
.hof-scope.hidden, .hof .callsign.hidden { display: none; }
.hof tr.gap td { text-align: center; color: var(--dim); padding: 2px; }
.hof-note { font-size: 12px; color: var(--dim); margin: 8px 2px 0; }
.world-rank { text-align: center; margin: 4px 0; color: var(--muted); }

/* rebindable hotkeys */
.keys { display: grid; grid-template-columns: 1fr 1fr; gap: 0 28px; }
.keys .tp-label { grid-column: 1 / -1; margin-top: 12px; }
.key-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 4px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.key-btn { min-width: 64px; padding: 3px 10px; font-size: 14px; cursor: pointer; }
.key-btn:hover { border-color: var(--accent); }
.key-btn.listening { border-color: var(--accent); color: var(--accent); animation: blink 1s infinite; }
.key-btn.unbound { color: var(--dim); }
@media (max-width: 640px) { .keys { grid-template-columns: 1fr; } }

/* versus: long opponent names are cut off ("Maximilian…") so the enemy strip stays small */
.vb-tag, .opp-stats .opp-name { display: inline-block; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: middle; }
@media (orientation: landscape) and (max-height: 520px) {
  .vb-tag, .opp-stats .opp-name { max-width: 80px; }
  /* phones: the wave preview moves to the right so it never sits under the enemy strip */
  #scr-game.versus .wave-preview { left: auto; right: 6px; transform: none; max-width: 45%; }
  #scr-game.versus .toasts { top: 32px; }
}
@media (max-width: 640px) {
  #scr-game.versus .wave-preview { left: auto; right: 6px; transform: none; max-width: 50%; }
}

/* ---------- heroes ---------- */
.bitem.hero { border-color: rgba(220,181,76,.55); background: linear-gradient(180deg, #2c2a1a, var(--panel)); }
.bitem.hero .bc { color: var(--accent); }
.bitem.hero.pending { animation: hero-pulse 1.6s ease-in-out infinite; }
@keyframes hero-pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(220,181,76,0); } 50% { box-shadow: 0 0 0 3px rgba(220,181,76,.35); } }
.abil.hero-ab { border-color: rgba(220,181,76,.45); }
.abil.hero-ab.ready { border-color: var(--accent); box-shadow: inset 0 0 0 1px rgba(220,181,76,.4); background: rgba(44,42,26,.94); }
.abil.hero-ab.lvl-lock .cdt { font-size: 13px; letter-spacing: .04em; }
.abil.hero-ab + .abil:not(.hero-ab) { margin-left: 10px; }
.xpbar { height: 6px; background: var(--bg2); border-radius: 3px; overflow: hidden; }
.xpbar i { display: block; height: 100%; background: var(--accent); border-radius: 3px; transition: width .3s; }
.hero-lvl { display: flex; justify-content: space-between; align-items: baseline; margin: 10px 0 4px; font-size: 14px; color: var(--muted); }
.hero-lvl b { color: var(--accent); text-transform: uppercase; letter-spacing: .06em; }
.heroes { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; max-width: 1500px; margin: 0 auto; }
.hero-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: grid; grid-template-columns: 80px 1fr; gap: 8px 14px; align-content: start; }
.hero-card.active { border-color: var(--accent); box-shadow: inset 0 0 0 1px rgba(220,181,76,.25); }
.hero-card img { width: 80px; height: 80px; grid-row: 1 / span 2; }
.hc-head h4 { margin: 0; font-size: 19px; letter-spacing: .03em; text-transform: uppercase; }
.hc-head small { color: var(--accent); font-size: 12px; letter-spacing: .06em; text-transform: uppercase; }
.hc-bio { margin: 0; color: var(--muted); font-size: 14px; font-style: italic; }
.hero-card .ustats, .hc-ab, .hc-rank, .hc-action { grid-column: 1 / -1; }
.hero-card .ustats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.hero-card .ustats div { background: var(--bg2); border-radius: 6px; padding: 5px 8px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.hero-card .ustats b { display: block; color: var(--text); font-size: 16px; }
.hc-ab { background: var(--bg2); border-left: 3px solid var(--accent); border-radius: 6px; padding: 6px 10px; }
.hc-ab.passive { border-left-color: var(--b); }
.hc-ab b { display: block; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; }
.hc-ab em { float: right; color: var(--dim); font-style: normal; font-weight: 600; }
.hc-ab span { font-size: 13px; color: var(--muted); }
.hc-rank-top { display: flex; justify-content: space-between; font-size: 14px; color: var(--muted); margin-bottom: 4px; }
.hc-rank-top b { color: var(--text); text-transform: uppercase; letter-spacing: .05em; }
.hc-rank small { display: block; margin-top: 5px; color: var(--dim); font-size: 12px; }
.hc-action { display: flex; justify-content: flex-end; align-items: center; min-height: 36px; }
.brief-hero { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--muted); }
.brief-hero img { width: 40px; height: 40px; }
.brief-hero b { color: var(--text); }
