:root {
  color-scheme: dark;
  --bg-obsidian: #0c101c;
  --bg-marble: #151c2c;
  --bg-slate: #202b40;
  --border: #34415a;
  --text-ivory: #faf6ee;
  --text-muted: #b2bbcc;
  --accent-gold: #f6cf78;
  --accent-cyan: #91d4ed;
  --accent-emerald: #85dcba;
  --accent-crimson: #ff9b9b;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg-obsidian);
  color: var(--text-ivory);
  line-height: 1.5;
  padding: 28px 32px 48px;
}
body.modal-open, body.tour-open { overflow: hidden; }
button, input { font: inherit; }
button {
  cursor: pointer;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-slate);
  color: var(--text-ivory);
  padding: 10px 16px;
  font-size: .875rem;
  font-weight: 600;
  transition: background-color .16s ease, border-color .16s ease;
}
button:hover:not(:disabled) { background: #303e56; border-color: #8190aa; }
button:disabled { background: #1a2232; color: #929eb3; cursor: not-allowed; }
:focus-visible { outline: 3px solid var(--accent-gold); outline-offset: 4px; }
::selection { background: var(--accent-gold); color: var(--bg-obsidian); }
input { caret-color: var(--accent-gold); }
* { scrollbar-color: #59667d var(--bg-obsidian); scrollbar-width: thin; }
h1, h2, h3 { line-height: 1.2; text-wrap: balance; }
p { max-width: 70ch; }
.muted { color: var(--text-muted); font-size: .875rem; }
.hidden { display: none !important; }

/* Header: navigation and campaign status have separate, predictable rows. */
.temple-hud, .step-guide-bar, .war-grid, .academy-screen {
  width: 100%;
  max-width: 1240px;
  margin-inline: auto;
}
.temple-hud { display: flex; align-items: center; flex-wrap: wrap; gap: 24px; margin-bottom: 24px; }
.title-block { display: flex; align-items: center; gap: 16px; margin-right: auto; }
.temple-crest { display: grid; place-items: center; flex-shrink: 0; width: 48px; height: 48px; }
.title-row { display: flex; align-items: center; flex-wrap: wrap; gap: 16px; }
.title-block h1 { font-family: Georgia, serif; color: var(--accent-gold); font-size: clamp(1.5rem, 3vw, 2rem); font-weight: 500; }
.title-block p { color: var(--text-muted); font-size: .875rem; margin-top: 4px; }
.limit-badge { font-family: Georgia, serif; color: var(--text-muted); font-size: 1.125rem; }
.hud-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-hud { background: transparent; }
.academy-btn { color: var(--accent-gold); }
.active-view { border-color: var(--accent-gold); }
.hud-stats { display: grid; grid-template-columns: repeat(4, 1fr); width: 100%; padding-block: 16px; border-block: 1px solid var(--border); }
.stat-card { display: flex; align-items: baseline; justify-content: center; gap: 12px; }
.stat-card + .stat-card { border-left: 1px solid var(--border); }
.stat-lbl { color: var(--text-muted); font-size: .875rem; }
.stat-val { font-size: 1.25rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.hearts { color: var(--accent-crimson); letter-spacing: 3px; }

/* A short sequence replaces repeated instructions. */
.step-guide-bar { display: grid; grid-template-columns: repeat(3, 1fr); gap: 24px; margin-bottom: 24px; }
.step-pill { text-decoration: none; display: flex; align-items: center; gap: 12px; padding-block: 8px; }
.step-num { display: grid; place-items: center; flex-shrink: 0; width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--border); color: var(--text-muted); font-size: .875rem; }
.step-text strong { display: block; color: var(--text-muted); font-size: 1rem; font-weight: 600; }
.step-text span { display: block; color: var(--text-muted); font-size: .875rem; margin-top: 2px; }
.step-pill.active .step-num { background: var(--accent-gold); border-color: var(--accent-gold); color: var(--bg-obsidian); }
.step-pill.active strong { color: var(--accent-gold); }
.step-pill.done .step-num { color: var(--accent-emerald); border-color: var(--accent-emerald); }

/* Two work areas; optional scores sit below rather than competing beside them. */
.war-grid { display: grid; grid-template-columns: minmax(310px, 360px) minmax(0, 1fr); gap: 28px; align-items: start; }
.panel { min-width: 0; background: var(--bg-marble); border-radius: 16px; padding: 24px; }
.panel-title { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; color: var(--text-ivory); font-size: 1.125rem; font-weight: 600; }
.panel-title > span + span { font-family: inherit; font-size: .8125rem; font-weight: 400; color: var(--text-muted); }
#leftPanel > .panel-title:first-child { font-size: 1rem; }
#leftPanel > .panel-title:nth-of-type(3) { margin-top: 24px; }
#centerPanel .panel-title { font-family: Georgia, serif; font-size: 1.5rem; }
#leftPanel, #centerPanel, #strikeAssembly { scroll-margin-top: 20px; }
#candidateCountLabel { color: var(--accent-cyan); }
.focus-glow > .panel-title:first-child > span:first-child { color: var(--accent-gold); }

.enemy-scene-card { margin-bottom: 28px; }
.scene-art-wrap { height: 100px; overflow: hidden; border-radius: 8px; }
.scene-art-wrap svg { width: 100%; height: 100%; display: block; }
.scene-overlay-content { padding-top: 16px; }
.wave-tag { color: var(--text-muted); font-size: .8125rem; margin-bottom: 8px; }
.enemy-title { font-size: 1.125rem; font-weight: 600; display: inline; }
.enemy-bounds { font-size: .875rem; color: var(--text-muted); margin-top: 4px; }
.congruence-log { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.cong-pill { display: flex; justify-content: space-between; gap: 12px; font-size: .875rem; padding-block: 8px; border-bottom: 1px solid var(--border); }
.rem-highlight { color: var(--accent-gold); font-weight: 700; }

/* Creature portraits retain the game's character, while rows replace nested cards. */
.garrison-list { display: flex; flex-direction: column; }
.creature-card { padding-block: 16px; border-top: 1px solid var(--border); }
.creature-card:last-child { padding-bottom: 0; }
.creature-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.creature-id { display: flex; align-items: center; gap: 12px; min-width: 0; }
.portrait-frame { width: 40px; height: 40px; border-radius: 8px; overflow: hidden; flex-shrink: 0; }
.portrait-frame svg { display: block; width: 100%; height: 100%; }
.creature-name { font-size: .9375rem; font-weight: 600; }
.creature-mod { color: var(--text-muted); font-size: .8125rem; }
.reserve-badge { color: var(--accent-gold); font-size: .8125rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
.creature-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.btn-scout, .btn-strike { padding: 8px 12px; }
.btn-scout { background: #233d50; color: #d3effb; border-color: #45677e; }
.btn-strike { background: transparent; }
.depleted .portrait-frame { filter: grayscale(1); }

.grid-hint { font-size: .9375rem; color: var(--text-muted); margin-bottom: 24px; }
.sieve-wrapper { position: relative; margin-bottom: 24px; }
.astrolabe-watermark { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; opacity: .035; overflow: hidden; }
.sieve-grid { position: relative; display: grid; grid-template-columns: repeat(auto-fill, minmax(48px, 1fr)); gap: 8px; max-height: 424px; overflow-y: auto; padding: 4px; }
.num-cell { aspect-ratio: 1; padding: 0; min-width: 0; min-height: 48px; font-size: 1rem; font-variant-numeric: tabular-nums; background: #232e43; }
.num-cell.eliminated { background: transparent; border-color: #283348; color: #8a97ae; text-decoration: line-through; }
.num-cell.candidate { border-color: #649bb2; color: #bde7f7; background: #1c3448; }
.num-cell.unique-lock { background: #23644f; border-color: var(--accent-emerald); color: #fff; }
.num-cell.selected-target { outline: 2px solid var(--accent-gold); outline-offset: 1px; background: #51412a; color: #fff0ce; }
.num-cell:focus-visible { outline: 3px solid var(--accent-gold); outline-offset: 1px; }
.strike-assembly { border-top: 1px solid var(--border); padding-top: 24px; }
.assembly-top { margin-bottom: 16px; }
.assembly-equation { color: var(--accent-gold); font-size: 1.125rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.assembly-chips { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; min-height: 48px; margin-bottom: 20px; }
.squad-chip { padding: 6px 12px; border-color: #677087; min-height: 40px; }
.squad-chip:hover { border-color: var(--accent-crimson); }
.assembly-buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.btn-aux { background: transparent; }
.btn-engage { margin-left: auto; min-width: 140px; background: var(--accent-gold); border-color: var(--accent-gold); color: #211b10; }
.btn-engage:hover:not(:disabled), .btn-start:hover:not(:disabled) { background: #ffe0a0; border-color: #ffe0a0; }
.btn-engage.ready-glow { background: #85dcba; color: #11251d; border-color: #85dcba; }
.oracle-msg { margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--border); font-size: .9375rem; color: var(--text-muted); line-height: 1.6; }
.oracle-msg.ok { color: #a9e6cb; }
.oracle-msg.err { color: #ffb1b1; }

/* Secondary information is disclosed only when wanted. */
summary { cursor: pointer; padding-block: 16px; min-height: 44px; font-weight: 600; }
summary::marker { color: var(--accent-gold); }
summary:hover { color: var(--accent-gold); }
.leaderboard-disclosure { grid-column: 1 / -1; border-top: 1px solid var(--border); }
.leaderboard-disclosure summary span { float: right; color: var(--text-muted); font-weight: 400; font-size: .875rem; }
.lb-list { list-style: none; max-width: 720px; margin: 8px 0 24px; }
.lb-item { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--border); padding: 16px 0; font-size: .9375rem; }
.lb-item.highlight { color: var(--accent-gold); }

/* Academy: choose a lesson, then explore the calculator. */
.academy-screen { padding-block: 16px; }
.academy-topbar { display: flex; align-items: start; justify-content: space-between; gap: 24px; margin-bottom: 32px; }
.academy-topbar h2 { font-family: Georgia, serif; color: var(--accent-gold); font-size: 1.875rem; font-weight: 500; }
.academy-topbar p { margin-top: 12px; color: var(--text-muted); }
.btn-return-battle { flex-shrink: 0; }
.academy-grid { max-width: 900px; margin-bottom: 40px; }
.lesson-card { border-bottom: 1px solid var(--border); }
.lesson-card > summary { padding-block: 24px; font-size: 1.125rem; }
.lesson-body { max-width: 72ch; color: #d1d8e5; padding: 0 0 28px 24px; line-height: 1.75; }
.lesson-body p + p { margin-top: 16px; }
.formula-banner { font-family: Georgia, serif; color: var(--accent-gold); font-size: 1.0625rem; padding: 20px 0; overflow-wrap: anywhere; }
.step-breakdown { list-style: none; display: grid; gap: 20px; margin-top: 16px; }
.sandbox-card { background: var(--bg-marble); border-radius: 16px; padding: 32px; }
.sandbox-card h3 { font-family: Georgia, serif; font-size: 1.5rem; color: var(--accent-gold); margin-bottom: 12px; }
.sandbox-controls { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 32px; margin: 32px 0; }
.slider-box label { display: flex; flex-direction: column; gap: 4px; color: var(--text-muted); font-size: .875rem; }
.slider-box input { width: 100%; min-height: 44px; accent-color: var(--accent-gold); }
.sandbox-math-output { border-top: 1px solid var(--border); padding-top: 24px; line-height: 1.8; overflow-wrap: anywhere; }

/* Short setup; fuller explanations are one optional disclosure away. */
.modal-backdrop { position: fixed; inset: 0; z-index: 100; background: rgba(5, 8, 16, .92); display: flex; align-items: center; justify-content: center; padding: 24px; }
.modal-card { background: #172033; width: 100%; max-width: 560px; max-height: calc(100dvh - 48px); overflow-y: auto; overscroll-behavior: contain; padding: 32px; border-radius: 16px; box-shadow: 0 24px 64px rgba(0, 0, 0, .4); }
.modal-card h2 { font-family: Georgia, serif; font-size: clamp(1.75rem, 4vw, 2.25rem); font-weight: 500; color: var(--accent-gold); margin-bottom: 12px; }
.modal-card > p { color: #c4cedf; font-size: 1rem; line-height: 1.6; }
.intro-steps { counter-reset: steps; list-style: none; display: grid; gap: 16px; margin: 24px 0; }
.intro-steps li { counter-increment: steps; display: grid; grid-template-columns: 28px 1fr; column-gap: 12px; }
.intro-steps li::before { content: counter(steps); grid-row: span 2; color: var(--accent-gold); font-family: Georgia, serif; font-size: 1.25rem; }
.intro-steps strong { font-size: 1rem; }
.intro-steps span { color: #c4cedf; font-size: .875rem; margin-top: 2px; }
.worked-example { border-block: 1px solid var(--border); margin: 24px 0; font-size: .875rem; }
.worked-example p { color: #c4cedf; margin-bottom: 16px; line-height: 1.65; }
.example-equation { display: flex; flex-wrap: wrap; gap: 8px 24px; color: var(--accent-gold); margin-bottom: 16px; font-variant-numeric: tabular-nums; }
.pace-picker { border: 0; min-width: 0; margin: 24px 0 20px; }
.pace-picker legend, .field-label { display: block; font-size: .875rem; font-weight: 600; margin-bottom: 8px; }
.mode-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.mode-btn { padding: 12px 16px; text-align: left; background: transparent; }
.mode-btn strong, .mode-btn span { display: block; }
.mode-btn span { font-size: .8125rem; color: #c4cedf; font-weight: 400; margin-top: 4px; }
.mode-btn.selected { background: #3c3325; border-color: var(--accent-gold); }
.mode-btn.selected strong { color: var(--accent-gold); }
.name-field { width: 100%; min-height: 44px; padding: 10px 12px; color: var(--text-ivory); background: #101725; border: 1px solid #65728a; border-radius: 8px; margin-bottom: 24px; }
.btn-start { width: 100%; background: var(--accent-gold); border-color: var(--accent-gold); color: #211b10; font-size: 1rem; padding-block: 12px; }
.btn-secondary-modal { display: block; width: 100%; background: transparent; border-color: transparent; color: var(--text-muted); margin-top: 8px; }
#gameOverModal .modal-card > p { margin-bottom: 24px; }

/* Help points at real controls, with an interactive opening in the dimmed page. */
.tour-shade { position: fixed; z-index: 200; background: rgba(5, 8, 16, .78); touch-action: none; }
.tour-spotlight { position: fixed; z-index: 201; pointer-events: none; border: 3px solid var(--accent-gold); border-radius: 10px; }
.tour-target { outline: 3px solid var(--accent-gold) !important; outline-offset: 3px; }
.tour-popover { position: fixed; z-index: 202; background: #202b40; color: var(--text-ivory); border-radius: 12px; padding: 20px; box-shadow: 0 12px 32px rgba(0, 0, 0, .4); overflow-y: auto; overscroll-behavior: contain; }
.tour-popover h2 { font-size: 1.125rem; color: var(--accent-gold); margin-bottom: 10px; }
.tour-popover p { font-size: .9375rem; line-height: 1.6; }
.tour-navigation { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 20px; }
.tour-navigation button { width: 48px; min-height: 44px; padding: 0; font-size: 1.75rem; line-height: 1; }
.tour-navigation span { color: var(--text-muted); font-size: .875rem; font-variant-numeric: tabular-nums; }
.tour-footer { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin-top: 16px; }
.tour-footer span { color: #bdc8db; font-size: .75rem; }
.tour-footer button { padding: 8px 12px; }

@media (max-width: 960px) {
  body { padding: 24px; }
  .temple-hud { gap: 20px; }
  .war-grid { grid-template-columns: minmax(280px, 320px) minmax(0, 1fr); gap: 20px; }
  .panel { padding: 20px; }
  .step-guide-bar { gap: 16px; }
  .step-text span { font-size: .8125rem; }
  .assembly-buttons .btn-engage { flex-basis: 100%; }
  .assembly-buttons .btn-aux { flex: 1; }
  .academy-topbar { flex-wrap: wrap; }
}
@media (max-width: 740px) {
  body { padding: 20px 16px 40px; }
  .temple-hud { gap: 20px; }
  .title-block { gap: 8px; }
  .hud-actions { display: grid; grid-template-columns: repeat(4, 1fr); width: 100%; gap: 6px; }
  .btn-hud { padding: 8px 4px; font-size: .8125rem; }
  .hud-stats { padding-block: 12px; }
  .stat-card { flex-direction: column; align-items: center; gap: 4px; }
  .stat-lbl { font-size: .8125rem; }
  .step-guide-bar { gap: 8px; }
  .step-pill { gap: 8px; }
  .step-text strong { font-size: .875rem; }
  .step-text span { display: none; }
  .step-num { width: 28px; height: 28px; }
  .war-grid { grid-template-columns: minmax(0, 1fr); gap: 20px; }
  .garrison-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 24px; }
  .creature-card:last-child { padding-bottom: 16px; }
  .creature-top { flex-wrap: wrap; }
  .scene-art-wrap { height: 100px; }
  .sieve-grid { grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); }
  .num-cell { min-height: 44px; }
  .sandbox-controls { grid-template-columns: 1fr; gap: 20px; }
  .sandbox-card { padding: 24px; }
  .academy-topbar h2 { font-size: 1.5rem; }
  .lesson-body { padding-left: 0; }
  .leaderboard-disclosure summary span { float: none; display: block; margin-left: 20px; }
}
@media (max-width: 480px) {
  .garrison-list { grid-template-columns: 1fr; }
  .creature-card { padding-block: 12px; }
  .creature-top { flex-wrap: nowrap; margin-bottom: 8px; }
  .panel { padding: 20px 16px; }
  #centerPanel .panel-title { font-size: 1.25rem; }
  .modal-backdrop { padding: 12px; }
  .modal-card { padding: 24px 20px; max-height: calc(100dvh - 24px); }
  .mode-btn { padding: 12px; }
  .stat-val { font-size: 1.125rem; }
  .hearts { letter-spacing: 1px; }
  .assembly-equation { font-size: 1rem; }
  .title-row { gap: 8px; }
  .limit-badge { font-size: 1rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
