:root {
  --bg: #1a2838;
  --bg-2: #1f2f42;
  --surface: #253850;
  --surface-2: #2b405a;
  --surface-3: #354c68;
  --line: rgba(175, 205, 235, 0.16);
  --line-2: rgba(175, 205, 235, 0.3);
  --text: #f0f5f9;
  --muted: #a7bacb;
  --dim: #8195a8;
  --accent: #35bfe3;
  --accent-ink: #04161f;
  --accent-soft: rgba(53, 191, 227, 0.14);
  --teal: #4fcfa3;
  --gold: #e8c26a;
  --warn: #f0a94a;
  --danger: #ec5f5f;
  --ok: #58d08c;
  --r: 8px;
  --r-lg: 12px;
  --font: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;
  --sidebar: 320px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; padding: 0; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.is-hidden { display: none !important; }
.muted { color: var(--muted); }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.ico { width: 18px; height: 18px; flex: none; }
kbd {
  font: 600 11px var(--mono); padding: 1px 5px; border-radius: 4px;
  background: var(--surface-3); border: 1px solid var(--line-2); border-bottom-width: 2px; color: var(--text);
}
.eyebrow {
  font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--muted);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 16px; border-radius: var(--r);
  font-weight: 600; font-size: 14px; white-space: nowrap;
  border: 1px solid var(--line-2); background: var(--surface-2);
  transition: background .15s, border-color .15s, transform .1s;
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn-primary:hover { background: #5ccdec; }
.btn-primary:disabled { background: var(--surface-3); color: var(--muted); }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: rgba(255,255,255,.05); }
.btn-lg { height: 48px; padding: 0 22px; font-size: 15px; }
.btn-block { width: 100%; }
.btn-danger { color: #f3a9a9; }
.btn .ico { width: 16px; height: 16px; }

.ctl {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-width: 36px; height: 36px; padding: 0 10px; border-radius: var(--r);
  border: 1px solid var(--line-2); background: var(--surface);
  font: 600 13px var(--mono); color: var(--text);
  transition: background .15s;
}
.ctl:hover { background: var(--surface-3); }
.ctl span { font-family: var(--font); }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 14px;
}

/* ---------- Screens ---------- */
.screen { position: fixed; inset: 0; overflow-y: auto; z-index: 10; }
.backdrop {
  position: fixed; inset: 0; z-index: -1;
  background:
    radial-gradient(1200px 600px at 75% 10%, rgba(53, 191, 227, 0.16), transparent 60%),
    radial-gradient(900px 500px at 10% 100%, rgba(79, 207, 163, 0.08), transparent 60%),
    linear-gradient(rgba(175,205,235,.06) 1px, transparent 1px) 0 0 / 48px 48px,
    linear-gradient(90deg, rgba(175,205,235,.06) 1px, transparent 1px) 0 0 / 48px 48px,
    var(--bg);
}
.screen-tools { position: absolute; top: 18px; right: 20px; display: flex; gap: 8px; z-index: 2; }
/* language picker: a button that drops a vertical list of plain links between /, /es/ and /vi/,
   so each language keeps its own address */
.lang-menu { position: relative; }
.lang-menu summary { list-style: none; cursor: pointer; user-select: none; }
.lang-menu summary::-webkit-details-marker { display: none; }
.lang-menu summary::after {
  content: ''; width: 6px; height: 6px; margin-left: 2px;
  border: solid currentColor; border-width: 0 1.5px 1.5px 0;
  transform: translateY(-2px) rotate(45deg); transition: transform .15s;
}
.lang-menu[open] summary::after { transform: translateY(1px) rotate(-135deg); }
.lang-menu[open] summary { background: var(--surface-3); }
.lang-list {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 10; min-width: 160px;
  display: flex; flex-direction: column; gap: 2px; padding: 4px;
  border-radius: var(--r); border: 1px solid var(--line-2); background: var(--surface);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
}
.lang-list a {
  display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 8px 10px;
  border-radius: calc(var(--r) - 3px); font: 600 13.5px var(--font); color: var(--muted); text-decoration: none;
}
.lang-list a span { font: 600 11.5px var(--mono); color: var(--dim); }
.lang-list a:hover { color: var(--text); background: var(--surface-3); }
.lang-list a[aria-current] { color: #06222e; background: var(--accent); }
.lang-list a[aria-current] span { color: inherit; }

.hero {
  min-height: 100%;
  max-width: 1280px; margin: 0 auto;
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); gap: 56px; align-items: center;
  padding: 72px 40px 64px;
}
.hero .eyebrow { display: flex; align-items: center; gap: 8px; margin: 0 0 18px; color: var(--teal); }
.hero .eyebrow .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--teal); box-shadow: 0 0 0 4px rgba(79,207,163,.15); }
.hero h1 {
  margin: 0 0 18px;
  font-size: clamp(40px, 5.6vw, 76px); font-weight: 800; line-height: 1.02; letter-spacing: -0.035em;
}
.hero .lead { margin: 0 0 30px; font-size: clamp(15px, 1.4vw, 18px); color: var(--muted); max-width: 520px; line-height: 1.6; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 40px; }
.hero-stats { display: grid; grid-template-columns: repeat(4, auto); justify-content: start; gap: 8px 36px; margin: 0; padding-top: 24px; border-top: 1px solid var(--line); }
.hero-stats div { display: flex; flex-direction: column; }
.hero-stats dt { font: 700 28px/1.1 var(--mono); color: var(--text); }
.hero-stats dd { margin: 4px 0 0; font-size: 12px; color: var(--muted); }
.hero-visual { margin: 0; position: relative; border-radius: var(--r-lg); overflow: hidden; border: 1px solid var(--line-2); box-shadow: 0 30px 80px rgba(0,0,0,.55); background: var(--surface); }
.hero-visual canvas { display: block; width: 100%; aspect-ratio: 1280 / 704; }
.hero-visual figcaption {
  position: absolute; left: 12px; bottom: 12px;
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px; border-radius: 6px; font-size: 12px; font-weight: 600;
  background: rgba(24, 37, 52, 0.8); border: 1px solid var(--line-2); backdrop-filter: blur(6px);
}
.live { width: 7px; height: 7px; border-radius: 50%; background: var(--danger); animation: live 1.6s ease-in-out infinite; }
@keyframes live { 50% { opacity: .3; } }
.footer { position: absolute; bottom: 14px; left: 0; right: 0; text-align: center; font-size: 12px; color: var(--dim); margin: 0; }
.footer { white-space: nowrap; }
.footer .ft-sep { margin: 0 8px; }
.footer a { color: var(--muted); text-decoration: none; }
.footer a:hover { color: var(--accent); text-decoration: underline; }
@media (max-width: 520px) { .footer .ft-long { display: none; } }
/* short screens (phones turned sideways): the menu scrolls, so the footer follows the content instead of sitting on top of it */
@media (max-height: 640px) { .footer { position: static; padding: 4px 16px 16px; } }

.screen-inner { max-width: 1240px; margin: 0 auto; padding: 28px 32px 48px; }
.screen-head { display: flex; align-items: flex-start; gap: 18px; margin-bottom: 26px; flex-wrap: wrap; }
.screen-head h2 { margin: 2px 0 2px; font-size: 26px; font-weight: 800; letter-spacing: -0.02em; }
.screen-head p { margin: 0; font-size: 14px; }
.screen-head .tabs { margin-left: auto; }

/* Level cards */
.level-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(330px, 100%), 1fr)); gap: 18px; }
.level-card {
  text-align: left; display: flex; flex-direction: column;
  border-radius: var(--r-lg); overflow: hidden;
  background: var(--surface); border: 1px solid var(--line);
  transition: border-color .15s, transform .15s, box-shadow .15s;
}
.level-card:not(:disabled):hover { border-color: var(--line-2); transform: translateY(-2px); box-shadow: 0 18px 40px rgba(0,0,0,.4); }
.level-card:disabled { cursor: not-allowed; }
.lc-thumb { position: relative; }
.lc-thumb canvas { display: block; width: 100%; aspect-ratio: 20 / 11; }
.lc-num { position: absolute; top: 10px; left: 10px; font: 700 12px var(--mono); padding: 3px 7px; border-radius: 5px; background: rgba(24,37,52,.85); border: 1px solid var(--line-2); }
.lc-lock { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(24,37,52,.72); color: var(--muted); }
.lc-lock .ico { width: 34px; height: 34px; }
.lc-body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.lc-body h3 { margin: 0; font-size: 17px; font-weight: 700; }
.lc-body p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.55; flex: 1; }
.lc-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-chip { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--accent-soft); color: #9fe3f5; border: 1px solid rgba(53,191,227,.25); }
.tag-chip.new-enemy { background: rgba(236,95,95,.1); color: #f3b0b0; border-color: rgba(236,95,95,.25); }
.lc-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding-top: 10px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.lc-meta { display: flex; gap: 12px; align-items: center; }
.diff { display: inline-flex; gap: 2px; vertical-align: middle; margin-left: 4px; }
.diff i { width: 4px; height: 10px; border-radius: 1px; background: var(--surface-3); }
.diff i.on { background: var(--warn); }
.stars { display: inline-flex; gap: 2px; color: var(--gold); }
.stars .ico { width: 15px; height: 15px; }
.stars .off { color: var(--surface-3); }

/* Handbook */
/* the handbook keeps its title and tabs in view while the long list scrolls under them */
#screen-handbook .screen-head {
  position: sticky; top: 0; z-index: 3;
  margin: -28px -32px 22px; padding: 22px 32px 14px;
  background: rgba(26, 40, 56, 0.94); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.tabs { display: inline-flex; padding: 3px; border-radius: 9px; background: var(--surface); border: 1px solid var(--line); }
.tab { padding: 6px 14px; border-radius: 6px; font-weight: 600; font-size: 13px; color: var(--muted); white-space: nowrap; }
.tab.is-active { background: var(--surface-3); color: var(--text); }
.handbook-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(340px, 100%), 1fr)); gap: 14px; }
.hb-card > div { min-width: 0; }
.hb-card h4, .hb-card p { overflow-wrap: break-word; }
.hb-card { display: flex; gap: 14px; align-items: flex-start; }
.hb-card canvas { flex: none; width: 64px; height: 64px; border-radius: var(--r); background: var(--surface-2); border: 1px solid var(--line); }
.hb-card h4 { margin: 0 0 4px; font-size: 15px; font-weight: 700; }
.hb-card p { margin: 0 0 8px; font-size: 13px; line-height: 1.55; color: #c3d2de; }
.hb-meta { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--muted); }
.hb-meta b { color: var(--text); font-weight: 600; }
.guide-link { display: inline-block; margin-top: 8px; font-size: 13px; font-weight: 700; color: var(--accent); text-decoration: none; }
.guide-link:hover { text-decoration: underline; }
.fact .guide-link { margin-top: 4px; }

/* ---------- Game layout ---------- */
#app { position: fixed; inset: 0; display: grid; grid-template-rows: auto minmax(0, 1fr); background: var(--bg); }
#topbar {
  position: relative;
  display: flex; align-items: center; gap: 16px;
  height: 58px; padding: 0 14px; padding-top: env(safe-area-inset-top);
  background: var(--bg-2); border-bottom: 1px solid var(--line);
}
.tb-brand { display: flex; align-items: center; gap: 10px; min-width: 0; width: 220px; flex: none; }
.tb-brand img { border-radius: 7px; }
.tb-brand > div { display: flex; flex-direction: column; min-width: 0; }
.tb-title { font-weight: 800; font-size: 14px; letter-spacing: -0.01em; }
.tb-level { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tb-stats { flex: 1; display: flex; gap: 8px; min-width: 0; }
.stat {
  display: flex; align-items: center; gap: 10px; min-width: 0;
  height: 42px; padding: 0 12px; border-radius: var(--r);
  background: var(--surface); border: 1px solid var(--line);
}
.stat .ico { color: var(--muted); }
.stat small { display: block; font-size: 10.5px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); line-height: 1.2; white-space: nowrap; }
.stat b { display: block; font-size: 16px; line-height: 1.2; font-weight: 700; }
.stat-money .ico, .stat-money b { color: var(--gold); }
.stat-meter { flex: 1 1 200px; max-width: 320px; }
.meter-wrap { flex: 1; min-width: 0; }
.meter-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.meter-head .num { font-size: 11.5px; color: var(--text); white-space: nowrap; }
.meter { position: relative; height: 5px; margin-top: 5px; border-radius: 3px; background: var(--surface-3); overflow: hidden; }
.meter i { position: absolute; inset: 0 auto 0 0; width: 0; border-radius: 3px; background: var(--teal); transition: width .25s, background .25s; }
#stat-power .meter i { background: var(--gold); }
#stat-power.over { border-color: rgba(236,95,95,.5); }
#stat-power.over .meter i { background: var(--danger); animation: blink .7s steps(2) infinite; }
#stat-power.over .ico { color: var(--danger); }
#stat-tds .meter i { background: var(--accent); }
#stat-tds.warn .meter i { background: var(--warn); }
#stat-tds.danger { border-color: rgba(236,95,95,.5); }
#stat-tds.danger .meter i { background: var(--danger); }
@keyframes blink { 50% { opacity: .45; } }
.tb-actions { display: flex; gap: 6px; flex: none; }

#main { display: grid; grid-template-columns: minmax(0, 1fr) var(--sidebar); min-height: 0; }
#stage {
  position: relative; min-width: 0; min-height: 0;
  display: grid; place-items: center; padding: 14px;
  background: radial-gradient(ellipse at center, #26394f, var(--bg) 80%);
}
#canvas-wrap {
  position: relative; width: 640px; height: 352px;
  border-radius: 10px; overflow: hidden;
  box-shadow: 0 0 0 1px var(--line-2), 0 18px 44px rgba(0,0,0,.3);
}
#game { display: block; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }

#banner {
  position: absolute; left: 50%; top: 12%; transform: translateX(-50%);
  padding: 8px 18px; border-radius: var(--r);
  background: rgba(24, 37, 52, 0.82); border: 1px solid var(--line-2); backdrop-filter: blur(6px);
  font-size: clamp(13px, 1.6vw, 18px); font-weight: 700; letter-spacing: .02em; white-space: nowrap;
  pointer-events: none; opacity: 0;
}
#banner.show { animation: banner 2.4s ease forwards; }
@keyframes banner {
  0% { opacity: 0; transform: translate(-50%, -8px); }
  12%, 80% { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, 0); }
}
#toast {
  position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%);
  max-width: calc(100% - 24px); padding: 7px 14px; border-radius: var(--r);
  background: rgba(24, 37, 52, 0.9); border: 1px solid var(--line-2);
  font-size: 13px; font-weight: 500; text-align: center;
  opacity: 0; transition: opacity .2s; pointer-events: none;
}
#toast.show { opacity: 1; }
#toast.bad { border-color: rgba(236,95,95,.6); color: #f6c4c4; }

/* Sidebar */
#sidebar {
  display: flex; flex-direction: column; gap: 10px; min-height: 0;
  padding: 12px; overflow: hidden;
  background: var(--bg-2); border-left: 1px solid var(--line);
  scrollbar-width: thin; scrollbar-color: var(--surface-3) transparent;
}
.sb-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.kbd-hint { font: 600 11px var(--mono); }
.wave-preview { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; min-height: 30px; }
.wchip {
  display: inline-flex; align-items: center; gap: 5px;
  height: 30px; padding: 0 9px 0 3px; border-radius: 6px;
  background: var(--surface-2); border: 1px solid var(--line);
  font: 600 12px var(--mono);
}
.wchip canvas { width: 24px; height: 24px; }
.wchip.boss { border-color: rgba(236,95,95,.45); color: #f3b0b0; }
.wave-done { font-size: 13px; color: var(--muted); }
#wave-btn.early { background: transparent; color: var(--gold); border: 1px solid rgba(232,194,106,.4); }
#wave-btn.early:hover { background: rgba(232,194,106,.08); }
#wave-btn.ready { animation: ready 1.8s ease-in-out infinite; }
@keyframes ready { 50% { box-shadow: 0 0 0 4px rgba(53,191,227,.22); } }

.shop-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.shop-item {
  position: relative; text-align: left;
  display: grid; grid-template-columns: 38px minmax(0, 1fr); gap: 2px 8px; align-items: center;
  padding: 7px 8px; border-radius: var(--r);
  background: var(--surface-2); border: 1px solid var(--line);
  transition: border-color .12s, background .12s;
}
.shop-item:hover { border-color: var(--line-2); background: var(--surface-3); }
.shop-item.is-selected { border-color: var(--accent); background: var(--accent-soft); }
.shop-item.cant .si-cost { color: var(--danger); }
.shop-item.cant canvas { opacity: .5; }
.shop-item canvas { grid-row: span 2; width: 38px; height: 38px; }
.si-name { font-size: 11.5px; font-weight: 600; line-height: 1.25; overflow: hidden; hyphens: auto; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.si-meta { display: flex; gap: 8px; font: 600 11px var(--mono); color: var(--muted); }
.si-cost { color: var(--gold); }
.si-pow.plus { color: var(--ok); }
.si-tag { display: none; }
.si-key { position: absolute; top: 4px; right: 5px; font: 600 9.5px var(--mono); color: var(--dim); }

.shop-group {
  grid-column: 1 / -1; margin: 6px 0 0; font-size: 10.5px; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: var(--dim);
}
.shop-group:first-child { margin-top: 0; }
.shop-item.nature { background: rgba(79, 160, 90, 0.08); border-color: rgba(120, 190, 120, 0.16); }
.shop-item.nature.is-selected { border-color: var(--ok); background: rgba(88, 208, 140, 0.14); }
.tag-chip.nature { background: rgba(88,208,140,.1); color: #a6e6bf; border-color: rgba(88,208,140,.28); }
.tag-chip.warn { background: rgba(240,169,74,.1); color: #f3c98c; border-color: rgba(240,169,74,.3); }
.nature-tag { color: var(--ok); font-weight: 600; }
.grow { color: var(--ok); }
.sep { color: var(--dim); }
.stat-grid em.up { font: 600 11px var(--mono); color: var(--ok); margin-left: 6px; font-style: normal; }

.sb-wave { flex: none; }
.sb-shop { flex: 1 1 auto; min-height: 150px; overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--surface-3) transparent; }
.sb-info { flex: 0 0 auto; max-height: 50%; overflow-y: auto; font-size: 13px; scrollbar-width: thin; }
.sb-info.mode-guide { display: none; }
.sb-info h3 { margin: 0; font-size: 16px; font-weight: 700; line-height: 1.3; }
.info-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; margin-bottom: 4px; }
.info-sub { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; font-size: 12px; color: var(--muted); }
.info-sub .lvl { color: var(--gold); font-weight: 700; }
.info-close { color: var(--muted); padding: 2px 4px; font-size: 16px; line-height: 1; display: none; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; border-radius: var(--r); overflow: hidden; background: var(--line); border: 1px solid var(--line); margin-bottom: 12px; }
.stat-grid div { background: var(--surface-2); padding: 7px 10px; }
.stat-grid span { display: block; font-size: 10.5px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.stat-grid b { font: 700 14px var(--mono); }
.stat-grid .up { color: var(--ok); font-size: 11px; margin-left: 4px; }
.vs { margin: 0 0 10px; font-size: 12.5px; line-height: 1.55; }
.vs b { font-weight: 600; }
.vs .good { color: var(--ok); }
.vs .bad { color: #f09a9a; }
.fact { margin: 0 0 12px; padding-left: 10px; border-left: 2px solid var(--accent); color: #b9cad7; font-size: 12.5px; line-height: 1.6; }
.info-actions { display: grid; grid-template-columns: 1.4fr 1fr; gap: 8px; }
.info-actions.arming { pointer-events: none; opacity: .55; }
.info-actions { transition: opacity .2s; }
.guide { margin: 0; padding-left: 18px; color: #b9cad7; font-size: 12.5px; line-height: 1.6; }
.guide li { margin-bottom: 6px; }
.guide b { color: var(--text); }

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 16px;
  background: rgba(12, 22, 34, 0.5); backdrop-filter: blur(4px);
  animation: fade .18s ease;
}
@keyframes fade { from { opacity: 0; } }
.modal-card {
  width: min(540px, 100%); max-height: calc(100dvh - 32px); overflow-y: auto;
  padding: 24px; border-radius: var(--r-lg);
  background: var(--surface); border: 1px solid var(--line-2);
  box-shadow: 0 30px 80px rgba(0,0,0,.6);
  animation: rise .22s ease;
}
@keyframes rise { from { transform: translateY(10px); opacity: 0; } }
.modal-card h3 { margin: 4px 0 10px; font-size: 22px; font-weight: 800; letter-spacing: -0.015em; line-height: 1.25; }
.modal-card p { margin: 0 0 12px; color: #c3d2de; line-height: 1.65; }
.modal-card .row { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 18px; }
.enemy-intro { display: flex; gap: 16px; align-items: center; margin-bottom: 12px; }
.enemy-intro canvas { flex: none; width: 84px; height: 84px; border-radius: var(--r-lg); background: var(--surface-2); border: 1px solid var(--line); }
.enemy-intro h3 { margin: 0; }
.counter-box { padding: 10px 12px; border-radius: var(--r); background: rgba(79,207,163,.08); border: 1px solid rgba(79,207,163,.25); font-size: 13.5px; }
.counter-box b { color: var(--teal); }
.quiz-q { font-size: 17px !important; font-weight: 600; color: var(--text) !important; line-height: 1.5 !important; }
.quiz-head .quiz-q { margin-top: 8px; }
.quiz-exp:not(.is-hidden) + .quiz-note { display: none; }
.quiz-opts { display: grid; gap: 8px; }
.quiz-opt {
  display: flex; gap: 10px; align-items: flex-start; text-align: left;
  padding: 11px 14px; border-radius: var(--r);
  background: var(--surface-2); border: 1px solid var(--line-2);
  transition: background .12s, border-color .12s;
}
.quiz-opt .k { font: 700 12px var(--mono); color: var(--muted); padding-top: 2px; }
.quiz-opt:hover:not(:disabled) { background: var(--surface-3); }
.quiz-opt.right { background: rgba(88,208,140,.12); border-color: var(--ok); }
.quiz-opt.wrong { background: rgba(236,95,95,.12); border-color: var(--danger); }
.quiz-opt:disabled { cursor: default; }
.quiz-exp { margin-top: 12px; padding: 12px 14px; border-radius: var(--r); background: var(--surface-2); font-size: 13.5px; line-height: 1.6; color: #c3d2de; }
.quiz-exp strong { display: block; margin-bottom: 4px; font-size: 14px; }
.quiz-note { margin: 12px 0 0 !important; font-size: 12.5px; color: var(--muted) !important; }
.how-list { margin: 0; padding-left: 20px; }
.how-list li { margin-bottom: 8px; line-height: 1.6; color: #c3d2de; }
.end-stars { display: flex; justify-content: center; gap: 8px; margin: 6px 0 14px; color: var(--gold); }
.end-stars .ico { width: 40px; height: 40px; }
.end-stars .off { color: var(--surface-3); }
.end-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; border-radius: var(--r); overflow: hidden; background: var(--line); border: 1px solid var(--line); margin-bottom: 4px; }
.end-grid div { background: var(--surface-2); padding: 10px; text-align: center; }
.end-grid b { display: block; font: 700 18px var(--mono); }
.end-grid span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.menu-list { display: grid; gap: 8px; margin-top: 14px; }
.menu-list .btn { width: 100%; justify-content: flex-start; }

/* ---------- Responsive ---------- */
@media (min-width: 1600px) { :root { --sidebar: 352px; } }

@media (max-width: 1180px) {
  .tb-brand { width: auto; }
  .tb-brand > div { display: none; }
  .stat-wave small, .stat-money small { display: none; }
}

@media (max-width: 980px) {
  .hero { grid-template-columns: 1fr; gap: 36px; padding: 72px 24px 56px; }
  .hero-visual { order: -1; }
  .hero-stats { grid-template-columns: repeat(4, 1fr); gap: 8px 16px; }
  .hero-stats dt { font-size: 22px; }
}

/* Compact: phones and narrow tablets in portrait — sidebar becomes a dock under the map */
@media (max-width: 900px) and (orientation: portrait), (max-width: 640px) {
  #topbar {
    display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; gap: 6px;
    height: auto; padding: 8px; padding-top: max(8px, env(safe-area-inset-top));
  }
  .tb-brand { display: none; }
  .tb-stats { display: contents; }
  .stat { height: 38px; padding: 0 10px; gap: 8px; min-width: 0; max-width: none; }
  .stat-money { grid-column: 1; grid-row: 1; }
  .stat-wave { grid-column: 2; grid-row: 1; }
  .tb-actions { grid-column: 3; grid-row: 1; }
  #stat-gc { grid-column: 1; grid-row: 2; }
  #stat-power { grid-column: 2 / 4; grid-row: 2; }
  #stat-tds { grid-column: 1 / 4; grid-row: 3; }
  .stat-meter .ico { display: none; }
  #main { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
  #sidebar { min-width: 0; }
  #stage { padding: 8px; }
  #sidebar { border-left: 0; border-top: 1px solid var(--line); padding: 8px; gap: 8px; overflow: visible; padding-bottom: max(8px, env(safe-area-inset-bottom)); }
  .sb-wave { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 4px 10px; padding: 8px 10px; }
  .sb-wave .sb-head { grid-column: 1; margin: 0; }
  .sb-wave .wave-preview { grid-column: 1; margin: 0; min-height: 0; flex-wrap: nowrap; overflow-x: auto; }
  .sb-wave #wave-btn { grid-column: 2; grid-row: 1 / span 2; width: auto; }
  .sb-shop { padding: 0; background: none; border: 0; overflow: visible; min-height: 0; flex: none; }
  .shop-group { display: none; }
  .sb-shop .sb-head { display: none; }
  .shop-grid { display: flex; overflow-x: auto; gap: 6px; padding-bottom: 2px; scrollbar-width: none; }
  .shop-item { flex: 0 0 132px; }
  .si-key { display: none; }
  .sb-info { display: none; }
}

/* Short landscape screens (phones turned sideways) */
@media (max-height: 560px) and (orientation: landscape) {
  :root { --sidebar: 236px; }
  #topbar { height: 46px; gap: 8px; padding: 0 8px; }
  .tb-brand { display: none; }
  .stat { height: 34px; padding: 0 8px; gap: 6px; }
  .stat small { font-size: 9.5px; }
  .stat b { font-size: 14px; }
  .meter-head .num { font-size: 10.5px; }
  .ctl { height: 32px; min-width: 32px; }
  #stage { padding: 6px; }
  #sidebar { padding: 6px; gap: 6px; }
  .card { padding: 8px; }
  .sb-head { margin-bottom: 6px; }
  .wave-preview { margin-bottom: 6px; min-height: 0; }
  .wchip { height: 26px; }
  .wchip canvas { width: 20px; height: 20px; }
  .btn { height: 34px; }
  /* four small tiles per row so the whole build menu fits without much scrolling */
  .shop-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; }
  .shop-group { display: none; }  /* nature tiles keep their green tint instead */
  .shop-item { grid-template-columns: 1fr; justify-items: center; text-align: center; padding: 2px 1px; gap: 0; border-radius: 7px; }
  .shop-item canvas { grid-row: auto; width: 22px; height: 22px; }
  .si-name { display: none; }
  .sb-shop .sb-head { display: none; }
  .si-tag { display: block; font-size: 9px; font-weight: 600; letter-spacing: -.02em; line-height: 1.15; max-width: 100%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  .si-meta { font-size: 9px; gap: 4px; line-height: 1.15; }
  .si-pow { display: none; }
  .si-key { display: none; }
  .sb-info { display: none; }
}

/* In compact layouts the info panel becomes a sheet that opens for a selected tower */
@media (max-width: 900px) and (orientation: portrait), (max-width: 640px), (max-height: 560px) and (orientation: landscape) {
  .sb-info.is-open.mode-tower {
    display: block; position: fixed; z-index: 30;
    left: 8px; right: 8px; bottom: 8px; max-height: 58dvh; overflow-y: auto;
    box-shadow: 0 -10px 40px rgba(0,0,0,.55); border-color: var(--line-2);
  }
  .sb-info .info-close { display: block; }
}
@media (max-height: 560px) and (orientation: landscape) {
  .sb-info.is-open.mode-tower { right: auto; width: min(360px, 55vw); top: 54px; bottom: 8px; max-height: none; }
  .sb-info.is-open.mode-tower.sheet-right { left: auto; right: 8px; }
  .sb-info .fact { display: none; }
}


/* Phones: menus, level select and handbook */
@media (max-width: 640px) {
  .screen-inner { padding: 20px max(16px, env(safe-area-inset-right)) 32px max(16px, env(safe-area-inset-left)); }
  .screen-head { gap: 12px; margin-bottom: 18px; }
  .screen-head > div { flex: 1 1 100%; min-width: 0; order: 2; }
  .screen-head h2 { font-size: 22px; }
  /* two rows of two tabs, so long names (Spanish, Vietnamese) never push the bar off screen */
  .screen-head .tabs { order: 3; margin-left: 0; width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: 3px; }
  .screen-head .tabs .tab { padding: 7px 6px; font-size: 12.5px; line-height: 1.3; white-space: normal; }
  #screen-handbook .screen-head {
    margin: -20px calc(-1 * max(16px, env(safe-area-inset-right))) 16px calc(-1 * max(16px, env(safe-area-inset-left)));
    padding: 12px max(16px, env(safe-area-inset-right)) 12px max(16px, env(safe-area-inset-left));
    align-items: center;
  }
  /* back button and title share the first row to keep the pinned header short */
  #screen-handbook .screen-head > div:not(.tabs) { flex: 1 1 auto; }
  .hb-card { padding: 14px; gap: 12px; }
  .hb-card canvas { width: 52px; height: 52px; }
  .hero { padding: 64px max(16px, env(safe-area-inset-right)) 24px max(16px, env(safe-area-inset-left)); gap: 28px; min-height: 0; }
  .hero-actions .btn { flex: 1 1 auto; }
  .hero-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 20px; }
  .hero-stats dd { font-size: 12.5px; line-height: 1.35; }
  /* the menu is taller than many phone screens, so the footer follows the content instead of sitting on top of it */
  .footer { position: static; white-space: normal; padding: 0 16px calc(24px + env(safe-area-inset-bottom)); }
}
/* phones turned sideways: the screen is short, so the pinned handbook header gets tight spacing */
@media (max-height: 560px) and (orientation: landscape) {
  #screen-handbook .screen-head { padding-top: 10px; padding-bottom: 10px; gap: 8px 14px; margin-bottom: 14px; align-items: center; }
  #screen-handbook .screen-head h2 { font-size: 19px; }
}


/* Short landscape screens (phones turned sideways): wider, two-column modals so nothing needs scrolling */
@media (max-height: 560px) and (orientation: landscape) {
  .modal { padding: 8px max(8px, env(safe-area-inset-right)) 8px max(8px, env(safe-area-inset-left)); }
  .modal-card { padding: 16px 18px; max-height: calc(100dvh - 16px); }
  .modal-card.wide { width: min(880px, 100%); }
  .modal-card h3 { font-size: 19px; margin: 2px 0 6px; }
  .modal-card p { font-size: 13.5px; line-height: 1.5; margin-bottom: 8px; }
  .modal-card .row { margin-top: 10px; }
  .modal-card .btn { height: 36px; }
  .quiz-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 4px 20px; align-items: start; }
  .quiz-head { grid-column: 1; grid-row: 1; }
  .quiz-note { grid-column: 1; grid-row: 2; }
  .quiz-exp { grid-column: 1; grid-row: 2; margin-top: 4px; padding: 10px 12px; font-size: 13px; line-height: 1.5; }
  .quiz-opts { grid-column: 2; grid-row: 1 / span 2; gap: 6px; }
  .quiz-q { font-size: 15.5px !important; }
  .quiz-opt { padding: 8px 12px; font-size: 13.5px; }
  .enemy-intro { gap: 12px; margin-bottom: 6px; }
  .enemy-intro canvas { width: 56px; height: 56px; }
  .counter-box { padding: 8px 10px; font-size: 13px; }
  .how-list li { margin-bottom: 4px; font-size: 13.5px; break-inside: avoid; }
  /* the how-to list is long (and longer in Spanish): a wide card with two columns */
  .modal-card:has(.how-list) { width: min(880px, 100%); }
  .how-list { columns: 2; column-gap: 28px; }
}
@media (max-height: 560px) and (orientation: landscape) and (max-width: 720px) {
  .modal-card:has(.how-list) { padding: 12px 14px; }
  .how-list { column-gap: 20px; }
  .how-list li { font-size: 12.5px; line-height: 1.45; margin-bottom: 3px; }
}


/* Phones: keep in-game alerts small and pinned to the top edge of the map */
@media (max-width: 900px) and (orientation: portrait), (max-width: 640px), (max-height: 560px) and (orientation: landscape) {
  #toast { top: 6px; bottom: auto; max-width: 70%; padding: 4px 10px; font-size: 11.5px; border-radius: 6px; }
  #banner { top: auto; bottom: 8px; padding: 4px 10px; font-size: 12px; border-radius: 6px; }
}


/* Desktop: the info card floats over the map as a see-through popover (positioned by game.js) */
body.pop-desktop .sb-info { display: none; }
body.pop-desktop .sb-info.is-open {
  display: block; position: fixed; z-index: 40;
  width: 340px; max-height: calc(100dvh - 90px); overflow: visible;
  padding: 16px 18px; font-size: 13.5px;
  background: rgba(14, 24, 36, 0.42);
  backdrop-filter: blur(10px) saturate(1.15); -webkit-backdrop-filter: blur(10px) saturate(1.15);
  border: 1px solid rgba(175, 205, 235, 0.35); border-radius: 14px;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.32);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
  animation: pop-in .14s ease-out;
}
@keyframes pop-in { from { transform: translateY(6px); } }
body.pop-desktop .sb-info.is-open.mode-shop { pointer-events: none; }
body.pop-desktop .sb-info.is-open.is-preview { pointer-events: none; }
body.pop-desktop .sb-info.is-preview .info-close { display: none; }
body.pop-desktop .sb-info h3 { font-size: 18px; }
body.pop-desktop .sb-info .info-close { display: block; }
body.pop-desktop .sb-info.mode-shop .info-close { display: none; }
body.pop-desktop .sb-info .stat-grid { background: rgba(175, 205, 235, 0.14); border-color: rgba(175, 205, 235, 0.18); }
body.pop-desktop .sb-info .stat-grid div { background: rgba(8, 16, 26, 0.35); }
body.pop-desktop .sb-info .fact { color: #dbe6ef; }
body.pop-desktop .sb-info .btn { text-shadow: none; }
body.pop-desktop .sb-info.is-open::after {
  content: ''; position: absolute; top: var(--ay, 50%); width: 0; height: 0; margin-top: -9px;
  border-top: 9px solid transparent; border-bottom: 9px solid transparent;
}
body.pop-desktop .sb-info.is-open[data-arrow="right"]::after { right: -10px; border-left: 10px solid rgba(175, 205, 235, 0.55); }
body.pop-desktop .sb-info.is-open[data-arrow="left"]::after { left: -10px; border-right: 10px solid rgba(175, 205, 235, 0.55); }


/* Green credits meter */
#stat-gc .ico { color: #7fe08a; }
#stat-gc .meter i { background: linear-gradient(90deg, #4fcf7a, #9be86f); }

/* Emergency kit: a row of six item buttons in the sidebar, between the wave card and the build menu */
.sb-kit { flex: none; }
.sb-kit.is-hidden { display: none; }
.items { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 5px; }
.item {
  position: relative; height: 48px; border-radius: 8px; padding: 4px 0 3px;
  display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  color: var(--text); background: var(--surface-2); border: 1px solid var(--line);
  transition: border-color .12s, background .12s;
}
.item .ico { width: 26px; height: 26px; flex: none; }
.item.tech .ico { color: #f2d28a; }
.item.green { background: rgba(79, 160, 90, 0.08); border-color: rgba(120, 190, 120, 0.2); }
.item.green .ico { color: #8fe58f; }
.item:hover { border-color: var(--line-2); background: var(--surface-3); }
.item.is-selected { border-color: var(--accent); background: var(--accent-soft); }
.item.low .ico, .item.low .ic-cost { opacity: .4; }
.item .ic-cost { font: 700 10px/1 var(--mono); color: #9be86f; }
.item .ic-cd { position: absolute; inset: 0; border-radius: 7px; pointer-events: none; display: none;
  background: conic-gradient(rgba(5, 10, 16, 0.72) calc(var(--cd, 0) * 360deg), transparent 0); }
/* only while cooling down: at 0° phones draw a hairline seam through the icon */
.item.cooling .ic-cd { display: block; }
@media (max-height: 560px) and (orientation: landscape) {
  .sb-kit .sb-head { display: none; }
  .sb-kit { padding: 5px; }
  .items { gap: 3px; }
  .item { height: 38px; padding: 2px 0 2px; border-radius: 6px; }
  .item .ico { width: 22px; height: 22px; }
  .item .ic-cost { font-size: 9px; }
}

/* kit cards in modals and the handbook */
.kit-icon { flex: none; width: 64px; height: 64px; border-radius: 14px; display: grid; place-items: center;
  font: 800 11px var(--mono); letter-spacing: .06em; background: var(--surface-2); border: 1px solid var(--line); }
.kit-icon .ico { width: 34px; height: 34px; }
.kit-icon.tech { color: #f2d28a; }
.kit-icon.green { color: #8fe58f; }
.kit-meta { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 13px !important; color: var(--muted) !important; margin-top: 12px !important; }
.kit-meta b { color: var(--text); }
.combo-card { border-color: rgba(242, 193, 78, 0.35); }
.combo-card.green { border-color: rgba(127, 224, 138, 0.35); }

/* Rotate prompt: covers a running level on phones held upright */
.rotate-gate {
  display: none; position: fixed; inset: 0; z-index: 45;
  align-items: center; justify-content: center; text-align: center;
  padding: max(24px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
  background:
    radial-gradient(600px 400px at 50% 30%, rgba(53, 191, 227, 0.16), transparent 70%),
    linear-gradient(rgba(175,205,235,.06) 1px, transparent 1px) 0 0 / 40px 40px,
    linear-gradient(90deg, rgba(175,205,235,.06) 1px, transparent 1px) 0 0 / 40px 40px,
    var(--bg);
}
@media (orientation: portrait) and (max-width: 900px) {
  body.in-game:not(.portrait-ok) .rotate-gate { display: flex; }
}
.rg-inner { max-width: 340px; display: flex; flex-direction: column; align-items: center; gap: 14px; }
.rg-phone { width: 132px; height: 132px; color: var(--text); }
.rg-phone rect, .rg-phone circle { stroke: currentColor; fill: none; }
.rg-phone circle { fill: currentColor; stroke: none; }
.rg-phone .rg-screen { fill: var(--accent-soft); stroke: none; }
.rg-arrow { stroke: var(--accent); }
.rg-device { transform-box: view-box; transform-origin: 60px 60px; animation: rg-turn 2.6s cubic-bezier(.6,0,.3,1) infinite; }
@keyframes rg-turn { 0%, 20% { transform: rotate(0deg); } 50%, 80% { transform: rotate(-90deg); } 100% { transform: rotate(0deg); } }
.rotate-gate h2 { margin: 6px 0 0; font-size: 24px; font-weight: 800; letter-spacing: -0.02em; text-wrap: balance; }
.rotate-gate p { margin: 0; color: var(--muted); font-size: 15px; line-height: 1.6; text-wrap: pretty; }
.rg-actions { display: flex; flex-direction: column; gap: 8px; width: 100%; margin-top: 10px; }
.rg-actions .btn { width: 100%; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}
