﻿:root {
  font-family: "Segoe UI", system-ui, sans-serif;
  color: #f0f4f7;
  background: #101b29;
  font-synthesis: none;
  --gold: #ffda70;
  --muted: #b4c4d1;
  --line: #496071;
  --panel: #1b2c3c;
  --cyan: #8ae4f3;
  --danger: #ffad99;
}
* { box-sizing: border-box; }
body { display: flex; flex-direction: column; margin: 0; min-height: 100vh; min-height: 100dvh; background: radial-gradient(ellipse at 50% 25%, #263d4b, transparent 75%), #101b29; }
button, input { font: inherit; }
button { cursor: pointer; min-height: 44px; min-width: 44px; border: 1px solid var(--line); border-radius: 8px; padding: 9px 14px; background: #263b4b; color: #f0f4f7; font-size: 14px; font-weight: 750; transition: background .15s, transform .15s; }
button:hover:not(:disabled) { background: #354e60; }
button:active:not(:disabled) { transform: translateY(2px); }
button:disabled { cursor: default; color: #b4c4d1; background: #1b2b39; }
button, a, input, canvas, [tabindex] { outline-offset: 3px; }
:focus-visible { outline: 3px solid var(--gold); }
a { color: #ffdf8d; text-underline-offset: 3px; }
p { line-height: 1.65; }
h1, h2, h3, p { margin-top: 0; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
.site-shell {
  width: min(100%, 1540px, calc((100dvh - 152px) * 2.24 + 200px));
  margin: auto;
  padding: max(14px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.hud { display: flex; gap: 16px; align-items: center; margin-bottom: 14px; min-height: 56px; }
.resource-pill { display: flex; gap: 8px; align-items: center; flex-shrink: 0; padding: 0 8px 0 0; }
.resource-pill canvas { width: 46px; height: 46px; }
.resource-pill strong { color: var(--gold); font-size: 32px; font-weight: 900; font-variant-numeric: tabular-nums; }
.wave-block { flex: 1; min-width: 100px; }
.wave-block strong { display: block; font-size: 14px; font-weight: 850; letter-spacing: .3px; }
progress { display: block; appearance: none; width: 100%; height: 7px; border: 0; border-radius: 4px; overflow: hidden; background: #0d1824; margin-top: 7px; }
progress::-webkit-progress-bar { background: #0d1824; }
progress::-webkit-progress-value { background: var(--gold); border-radius: 4px; }
progress::-moz-progress-bar { background: var(--gold); }
#boss-health::-webkit-progress-value { background: var(--danger); }
#boss-health::-moz-progress-bar { background: var(--danger); }
.game-actions { display: flex; gap: 6px; align-items: center; }
.game-actions button { display: flex; gap: 6px; align-items: center; justify-content: center; height: 44px; }
.control-icon { font-size: 22px; line-height: 1; }
#coin-count { background: #101b29; color: var(--gold); border-radius: 4px; min-width: 22px; padding: 2px 4px; font-size: 12px; }
#touch-shovel[aria-pressed="true"] { border: 2px solid var(--gold); color: var(--gold); }
.play-layout { display: grid; grid-template-columns: 176px minmax(0, 1fr); gap: 14px; align-items: start; }
.seed-panel { min-width: 0; }
.plant-cards { display: grid; gap: 9px; }
.plant-card { width: 100%; min-height: 88px; position: relative; display: grid; grid-template-columns: 54px minmax(0, 1fr); align-items: center; gap: 7px; overflow: hidden; text-align: left; padding: 9px 8px; border: 2px solid #536c79; border-radius: 9px; background: linear-gradient(135deg, #304951, #20343d); box-shadow: 0 3px 0 #08121b; }
.plant-card:hover:not(:disabled) { background: #3b5660; }
.plant-card.active { border-color: var(--gold); background: linear-gradient(135deg, #485546, #2c4142); }
.plant-card.active::before { content: "◆"; position: absolute; top: 2px; right: 4px; color: var(--gold); font-size: 12px; }
.plant-card.unaffordable { border-style: dashed; }
.plant-card.cooling { border-style: dotted; }
.plant-card canvas { width: 54px; height: 60px; }
.plant-card-main { min-width: 0; position: relative; z-index: 1; }
.plant-card-main strong { display: block; font-size: 13px; line-height: 1.2; overflow-wrap: normal; }
.card-cost { display: block; margin-top: 5px; color: #ffe295; font-size: 14px; font-weight: 900; white-space: nowrap; }
.card-status { position: absolute; left: 6px; bottom: 6px; min-width: 24px; width: max-content; white-space: nowrap; padding: 2px 3px; background: #101b29ee; border-radius: 4px; font-size: 12px; color: #f0f4f7; text-align: center; font-variant-numeric: tabular-nums; }
.hotkey { position: absolute; top: 3px; left: 5px; font-size: 12px; color: #d3dfe5; }
.cooldown-fill { position: absolute; left: 0; bottom: 0; height: 4px; background: var(--gold); width: var(--cooldown, 0%); pointer-events: none; }
.arena-wrap { min-width: 0; }
.arena-border { position: relative; border: 2px solid #68818a; border-radius: 12px; background: #1a2933; box-shadow: 0 5px 0 #080f18, 0 12px 30px #0003; }
.canvas-container { overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: thin; scrollbar-color: #c8a45c #182a38; border-radius: 10px; }
#game-canvas { display: block; width: 100%; height: auto; cursor: crosshair; touch-action: pan-x pinch-zoom; }
#game-canvas:focus-visible { outline-offset: -4px; }
#overview-button { display: none; }
.toast, .board-tutorial { position: absolute; z-index: 1; left: 50%; transform: translateX(-50%); width: max-content; max-width: calc(100% - 20px); pointer-events: none; padding: 9px 14px; border: 1px solid var(--gold); border-radius: 7px; background: #101b29f5; color: #ffe295; font-size: 14px; font-weight: 700; line-height: 1.4; text-align: center; }
.toast { top: 8px; }
.board-tutorial { top: 4px; margin: 0; border: 0; font-weight: 500; color: #f0f4f7; }
dialog { color: #f0f4f7; border: 1px solid #71858e; padding: 0; border-radius: 14px; background: #1b2c3c; box-shadow: 0 25px 100px #0009; max-height: 94vh; max-height: 94dvh; max-width: calc(100vw - 24px); }
dialog::backdrop { background: #060e19e8; backdrop-filter: blur(4px); }
#stage-dialog { width: 860px; overflow: hidden; }
#stage-dialog[open] { display: flex; flex-direction: column; }
#stage-content { display: block; min-height: 0; }
#intro-banner { display: none; }
.dialog-copy { display: flex; flex-direction: column; max-height: calc(94dvh - 72px); min-width: 0; }
.stage-heading { flex: none; padding: 24px 30px 0; }
.eyebrow { display: block; font-size: 12px; font-weight: 800; color: var(--gold); letter-spacing: .6px; margin-bottom: 10px; }
.stage-heading h2 { margin-bottom: 20px; font-size: 30px; font-weight: 900; line-height: 1.15; letter-spacing: -.4px; overflow-wrap: anywhere; }
#stage-body { min-height: 0; overflow-y: auto; overscroll-behavior-y: contain; padding: 0 30px 16px; scrollbar-gutter: stable; }
#stage-body, #library-content { scrollbar-width: thin; scrollbar-color: #bfaa76 #162432; overflow-wrap: anywhere; }
#overlay-description { font-size: 18px; }
.stage-actions { flex: none; padding: 12px 30px 20px; background: #1b2c3c; border-top: 1px solid #496071; }
.primary-button { width: 100%; border: 2px solid #ffe7a7; color: #17232e; background: #ffda70; box-shadow: 0 4px 0 #99713c; font-size: 15px; font-weight: 900; letter-spacing: .5px; padding: 13px 18px; transition: none; }
.primary-button:hover:not(:disabled) { background: #ffe59a; }
.primary-button:disabled { color: #20303b; background: #ceb575; }
.reading-hint { margin: 0 0 7px; text-align: center; font-size: 12px; line-height: 1.4; color: var(--muted); }
.narration-buttons { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-bottom: 8px; }
.narration-buttons button { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; padding: 10px; }
.narration-buttons svg { flex-shrink: 0; width: 22px; height: 22px; fill: currentColor; }
#narration-toggle { gap: 8px; width: auto; max-width: 100%; height: auto; padding: 10px 14px; color: #ffe295; border-color: #9b8961; }
#narration-toggle-label { min-width: 0; line-height: 1.25; }
#narration-status:empty { display: none; }
.help-nav, .dialog-links { display: flex; gap: 8px; }
.help-nav { justify-content: flex-end; margin-bottom: 8px; }
.help-nav button, .dialog-links button { min-height: 44px; font-size: 16px; color: #ffe295; border-color: #9b8961; }
.dialog-links { flex: none; justify-content: center; padding: 10px 16px; border-top: 1px solid var(--line); background: #142332; }
.dialog-links button { flex: 1; max-width: 300px; }
.editorial-text { font-size: 18px; line-height: 1.65; max-width: 65ch; }
.editorial-text > p { margin: 0 0 1em; }
.editorial-text strong { color: #fff0cb; }
.fact-meta, .review-date { font-size: 14px; line-height: 1.65; color: var(--muted); }
.fact-note { border-left: 3px solid var(--gold); background: #142332; padding: 12px 16px; font-size: 16px; line-height: 1.65; color: #d7e1e7; }
.editorial-text .fact-note { font-size: inherit; }
.fact-sources { margin: 18px 0; border: 1px solid var(--line); border-radius: 7px; background: #142332; }
.fact-sources summary { min-height: 44px; cursor: pointer; padding: 12px 14px; font-size: 16px; font-weight: 750; color: var(--gold); }
.source-list { padding: 0 18px 0 36px; font-size: 16px; line-height: 1.65; }
.source-list li { margin-bottom: 12px; }
.result-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 24px 0 0; }
.result-stats div { font-size: 14px; color: var(--muted); }
.result-stats strong { display: block; color: var(--gold); font-size: 28px; margin-bottom: 4px; }
#stage-dialog[data-phase="won"] {
  --result-background: #461f27;
  --result-accent: #ef7c89;
  --result-title: #ffd0d5;
}
#stage-dialog[data-phase="lost"] {
  --result-background: #143c2e;
  --result-accent: #65d99b;
  --result-title: #b9f6d2;
}
#stage-dialog:is([data-phase="won"], [data-phase="lost"]) {
  background: var(--result-background);
  border-color: var(--result-accent);
}
#stage-dialog:is([data-phase="won"], [data-phase="lost"]) :is(.stage-actions, .dialog-links) {
  background: transparent;
  border-color: var(--result-accent);
}
#stage-dialog:is([data-phase="won"], [data-phase="lost"]) #overlay-kicker {
  display: inline-block;
  padding: 6px 12px;
  border-radius: 6px;
  background: var(--result-accent);
  color: #101b29;
  font-weight: 900;
}
#stage-dialog:is([data-phase="won"], [data-phase="lost"]) #overlay-title {
  color: var(--result-title);
  font-size: clamp(28px, 4vw, 38px);
  font-weight: 900;
}
#stage-dialog:is([data-phase="won"], [data-phase="lost"]) .result-stats strong {
  color: var(--result-accent);
}
.pause-settings { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.pause-settings label { display: flex; align-items: center; gap: 8px; min-height: 44px; font-size: 16px; }
.pause-settings input { width: 22px; height: 22px; accent-color: var(--gold); }
#library-dialog { width: 940px; overflow: hidden; }
#library-dialog[open] { display: flex; flex-direction: column; }
.library-header { display: flex; flex: none; align-items: center; justify-content: space-between; gap: 12px; padding: 22px 26px 0; }
.library-header h2 { font-size: 26px; margin: 0; }
.library-tabs { flex: none; display: flex; gap: 8px; margin: 16px 26px; }
.library-tabs button[aria-pressed="true"] { background: var(--gold); color: #17232e; border-color: #ffe7a7; }
#library-content { min-height: 0; overflow-y: auto; overscroll-behavior-y: contain; padding: 0 26px 26px; }
.guide-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.guide-entry { display: flex; align-items: flex-start; gap: 14px; min-width: 0; border-bottom: 1px solid var(--line); padding-bottom: 20px; }
.guide-entry canvas { flex-shrink: 0; width: 68px; height: 68px; }
.guide-entry > div { min-width: 0; }
.guide-entry h3 { font-size: 18px; margin-bottom: 8px; }
.guide-entry p { font-size: 16px; margin-bottom: 10px; color: #d7e1e7; }
.guide-entry small { display: block; font-size: 14px; line-height: 1.6; color: #ffe295; }
.guide-section { font-size: 22px; color: #ffe295; margin: 28px 0 16px; }
.guide-intro { font-size: 16px; color: #d7e1e7; }
.fact-article { border-top: 1px solid var(--line); padding: 24px 0; }
.fact-article h3 { font-size: 25px; line-height: 1.25; margin: 10px 0 20px; }
.summary-label { font-size: 12px; color: var(--gold); font-weight: 800; }
#stage-dialog.is-ready { width: min(980px, calc((94dvh - 68px) * 1.32)); }
#stage-dialog.is-ready #stage-content { position: relative; }
#stage-dialog.is-ready #intro-banner { display: block; width: 100%; height: auto; }
#stage-dialog.is-ready .dialog-copy { position: absolute; inset: 0; max-height: none; justify-content: flex-end; pointer-events: none; }
#stage-dialog.is-ready .stage-heading, #stage-dialog.is-ready #stage-body, #stage-dialog.is-ready #reading-hint { display: none; }
#stage-dialog.is-ready .stage-actions { display: flex; justify-content: center; padding: 0 20px clamp(18px, 4vw, 36px); border: 0; background: transparent; }
#stage-dialog.is-ready .primary-button {
  width: min(260px, 80%);
  pointer-events: auto;
  color: #ffe34a;
  background: #0752c7;
  border: 3px solid #ffce24;
  box-shadow: inset 0 2px 0 #529bff, 0 5px 0 #03265c, 0 0 0 2px #06152d, 0 9px 20px #0008;
  font-size: clamp(18px, 2vw, 22px);
  letter-spacing: 1.2px;
  text-shadow: 0 2px 0 #03265c;
}
#stage-dialog.is-ready .primary-button:hover:not(:disabled) { background: #0643a2; color: #fff18a; }
#stage-dialog.is-ready .primary-button:active:not(:disabled) { transform: translateY(3px); box-shadow: inset 0 2px 0 #529bff, 0 2px 0 #03265c, 0 0 0 2px #06152d; }
#stage-dialog.is-ready .primary-button:focus-visible { outline: 3px solid #fff8c3; outline-offset: 5px; }
#stage-dialog.is-ready .primary-button:disabled { color: #c6d6ec; background: #234b82; border-color: #879fbf; text-shadow: none; box-shadow: 0 3px 0 #06152d; }
@media (max-width: 1150px), (max-height: 700px) {
  .site-shell { width: min(100%, calc((100dvh - 132px) * 2.24 + 156px)); padding: 8px; }
  .hud { min-height: 44px; gap: 10px; margin-bottom: 10px; }
  .play-layout { grid-template-columns: 140px minmax(0, 1fr); gap: 8px; }
  .plant-cards { gap: 7px; }
  .plant-card { min-height: 54px; height: calc((100dvh - 154px) / 5); max-height: 90px; padding: 5px; gap: 4px; grid-template-columns: 38px minmax(0, 1fr); }
  .plant-card canvas { width: 38px; height: 44px; }
  .plant-card-main strong { font-size: 12px; }
  .card-cost { font-size: 12px; margin-top: 3px; }
  .hotkey { display: none; }
}
@media (orientation: landscape) and (max-height: 600px) {
  .site-shell { padding: max(6px, env(safe-area-inset-top)) max(6px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left)); width: min(100%, calc((100dvh - 120px) * 2.24 + 140px)); }
  .hud { gap: 7px; margin-bottom: 6px; }
  .resource-pill { gap: 3px; padding: 0; }
  .resource-pill canvas { width: 32px; height: 32px; }
  .resource-pill strong { font-size: 24px; }
  .wave-block strong { font-size: 12px; }
  .game-actions { gap: 4px; }
  .game-actions button { padding: 6px 8px; font-size: 12px; }
  .control-label { display: none; }
  .play-layout { grid-template-columns: 124px minmax(0, 1fr); gap: 6px; }
  .plant-cards { gap: 5px; }
  .plant-card { grid-template-columns: 26px minmax(0, 1fr); min-height: 48px; height: calc((100dvh - 134px) / 5); max-height: 78px; padding: 2px; gap: 2px; }
  .plant-card canvas { width: 27px; height: 36px; }
  .plant-card-main strong { line-height: 1; }
  .card-cost { line-height: 1.1; margin-top: 2px; }
  .card-status { bottom: 4px; left: 2px; min-width: 23px; padding: 1px; }
  .board-tutorial, .toast { font-size: 12px; padding: 6px 9px; }
  .stage-heading { padding: 12px 20px 0; }
  .stage-heading h2 { font-size: 20px; margin-bottom: 12px; }
  .eyebrow { margin-bottom: 6px; }
  #stage-body { padding: 0 20px 12px; }
  .stage-actions { padding: 9px 20px 13px; }
  .stage-actions .primary-button { padding: 10px 16px; }
  #stage-dialog[data-phase="reading"] .stage-actions { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; align-items: start; }
  #stage-dialog[data-phase="reading"] #reading-hint { grid-column: 1 / -1; margin-bottom: 0; }
  #stage-dialog[data-phase="reading"] .narration-buttons { margin-bottom: 0; }
  #stage-dialog[data-phase="reading"] #narration-status:not(:empty) { margin: 6px 0 0; }
  .library-header { padding-top: 12px; }
  .library-tabs { margin-top: 10px; margin-bottom: 10px; }
}
@media (max-width: 800px) {
  .editorial-text, #overlay-description { font-size: 16px; }
  .guide-grid { grid-template-columns: 1fr; }
  .stage-heading { padding-left: 20px; padding-right: 20px; }
  #stage-body { padding-left: 20px; padding-right: 20px; }
  .stage-actions { padding-left: 20px; padding-right: 20px; }
}
@media (orientation: portrait) and (max-width: 1000px) {
  .site-shell { width: 100%; padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); }
  .hud { flex-wrap: wrap; gap: 8px; }
  .resource-pill canvas { width: 34px; height: 34px; }
  .resource-pill strong { font-size: 26px; }
  .wave-block strong { font-size: 12px; }
  .game-actions { flex-basis: 100%; justify-content: flex-end; }
  #collect-button { margin-right: auto; }
  .play-layout { display: flex; flex-direction: column; gap: 12px; }
  .seed-panel, .arena-wrap { width: 100%; }
  .plant-cards { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 5px; }
  .plant-card { display: flex; flex-direction: column; text-align: center; justify-content: flex-start; gap: 3px; padding: 5px 2px 9px; min-height: 130px; height: auto; max-height: none; }
  .plant-card canvas { flex: none; width: 42px; height: 44px; }
  .plant-card-main strong { min-height: 43px; font-size: 12px; line-height: 1.2; overflow-wrap: anywhere; }
  .card-cost { font-size: 12px; margin-top: 4px; }
  .card-status { top: 28px; bottom: auto; left: 50%; transform: translateX(-50%); }
  #overview-button { display: block; padding: 3px; width: 100%; margin-bottom: 8px; border-radius: 6px; }
  #board-overview { display: block; width: 100%; height: 44px; }
  #game-canvas { width: 700px; max-width: none; }
  .toast { position: fixed; top: auto; bottom: max(16px, env(safe-area-inset-bottom)); max-width: calc(100vw - 24px); }
  .board-tutorial { font-size: 12px; }
}
@media (max-width: 450px) {
  .control-label { display: none; }
  .stage-heading { padding: 16px 16px 0; }
  .stage-heading h2 { font-size: 23px; margin-bottom: 16px; }
  #stage-body { padding: 0 16px 12px; }
  .stage-actions { padding: 10px 16px 16px; }
  .eyebrow { font-size: 12px; }
  .library-header { padding: 16px 16px 0; }
  .library-header h2 { font-size: 22px; }
  .library-tabs { margin: 14px 16px; }
  #library-content { padding: 0 16px 20px; }
  .guide-entry { gap: 10px; }
  .guide-entry canvas { width: 48px; height: 48px; }
  .fact-article h3 { font-size: 22px; }
  .result-stats { gap: 8px; }
  .result-stats div { font-size: 12px; }
}
.guide-allies { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.guide-ally { flex-direction: column; align-items: center; padding: 16px; border: 1px solid var(--line); border-radius: 12px; background: #142332; }
.guide-ally canvas { width: 220px; height: 220px; max-width: 100%; object-fit: contain; }
.guide-ally > div { width: 100%; }
.guide-ally h3 { color: var(--gold); font-size: 22px; }
.wave-celebration { position: absolute; z-index: 2; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 16px; pointer-events: none; text-align: center; background: radial-gradient(ellipse, #142332b8, transparent 75%); }
.wave-celebration strong { color: #ffe295; font-size: clamp(24px, 4vw, 42px); line-height: 1.15; text-shadow: 0 3px 12px #000; }
.wave-celebration span { padding: 8px 18px; border: 1px solid var(--gold); border-radius: 30px; background: #142332ed; color: #ffe295; font-size: 20px; font-weight: 800; }
.wave-celebration strong, .wave-celebration span { animation: celebration-enter .2s ease-out both; }
@keyframes celebration-enter { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes stage-enter { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes backdrop-enter { from { opacity: 0; } to { opacity: 1; } }
@keyframes content-enter { from { opacity: 0; } to { opacity: 1; } }
#stage-dialog.stage-enter { animation: stage-enter .24s ease-out both; }
#stage-dialog.stage-exit { animation: stage-enter .18s ease-in reverse both; }
#stage-dialog.stage-enter::backdrop { animation: backdrop-enter .24s ease-out both; }
#stage-dialog.stage-exit::backdrop { animation: backdrop-enter .18s ease-in reverse both; }
.stage-swap-out #stage-content { animation: content-enter .09s ease-in reverse both; }
.stage-swap-in #stage-content { animation: content-enter .09s ease-out both; }
@media (max-width: 699px) {
  .guide-allies { grid-template-columns: 1fr; }
  .guide-ally canvas { width: 180px; height: 180px; }
  .help-nav button { flex: 1; }
  .help-nav button, .dialog-links button { padding: 8px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; } }
.motion-reduced *, .motion-reduced *::before, .motion-reduced *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
