:root {
  color-scheme: dark;
  font-family: system-ui, sans-serif;
  color: #f3f5fb;
  --page: #070a13;
  --paper: #f3f5fb;
  --muted: #b6bed4;
  --line: #37415f;
  --panel: #11182a;
  --surface: #17213a;
  --blue: #8eb8ff;
  --pink: #f2a4ce;
  --gold: #e7c488;
  --serif: Georgia, "Times New Roman", serif;
  background: var(--page);
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; min-width: 290px; min-height: 100vh; background: radial-gradient(ellipse at 12% 9%, #122653b0, transparent 55%), radial-gradient(ellipse at 97% 26%, #45173b96, transparent 52%), var(--page); }
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
button:focus-visible { outline: 2px solid var(--blue); outline-offset: 3px; }
button, p, h1, h2, h3, dl, dd { margin: 0; }
svg { vertical-align: middle; }
[hidden] { display: none !important; }
.icon-library { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 1.25em; height: 1.25em; flex: none; fill: none; stroke: currentColor; stroke-width: 1.65; stroke-linecap: round; stroke-linejoin: round; }

.topbar { background: #070a13e8; border-bottom: 1px solid transparent; border-image: linear-gradient(90deg, #73a1ff60, #8083b943 54%, #df76b06b) 1; }
.topbar-inner { width: min(100% - 64px, 1232px); min-height: 68px; margin-inline: auto; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand, .top-controls { display: flex; align-items: center; }
.brand { gap: 11px; padding: 0; border: 0; background: transparent; color: var(--paper); font: bold 1.29rem/1.05 var(--serif); }
.brand img { width: 34px; height: 39px; }
.top-controls { gap: 8px; }
.quiet { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 40px; padding: 7px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: #dce5fa; font-size: .875rem; font-weight: 650; }
.quiet:hover { background: #252d4a; color: var(--paper); }
.icon-button { min-width: 40px; padding-inline: 8px; font-size: 1rem; }
.icon-button[aria-pressed="true"] { color: var(--gold); }

.game-shell { width: min(100% - 64px, 1232px); margin-inline: auto; padding: 27px 0 25px; }
.map-heading { display: flex; align-items: end; justify-content: space-between; gap: 15px 28px; margin-bottom: 20px; }
.map-heading h1 { font: 700 clamp(2.3rem, 3.65vw, 3.5rem)/1.02 var(--serif); color: var(--paper); letter-spacing: -.042em; }
.map-heading p { color: var(--muted); margin-top: 9px; font-size: 1rem; }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.stat { min-width: 107px; display: flex; align-items: center; gap: 9px; padding: 8px 11px; border: 1px solid var(--line); background: var(--panel); border-radius: 8px; }
.stat > .icon { width: 25px; height: 25px; }
.stat dt { font-size: .78rem; color: var(--muted); }
.stat dd { font: 700 1.32rem/1.05 var(--serif); white-space: nowrap; font-variant-numeric: tabular-nums; }
.stat dd small { font: 600 .8rem/1 system-ui, sans-serif; color: var(--muted); }
.stat-coin > .icon { color: var(--gold); }
.stat-health > .icon { color: var(--pink); }
.stat-wave > .icon { color: var(--blue); }

.game-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(270px, 314px); grid-template-areas: "map shop" "map wave"; grid-template-rows: auto 1fr; gap: 14px; align-items: start; }
.command { display: contents; }
.map-panel, .panel { min-width: 0; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); box-shadow: 0 9px 26px #03050d70; }
.map-panel { grid-area: map; padding: 8px 8px 0; }
.shop { grid-area: shop; padding: 16px; background: linear-gradient(145deg, #172647, var(--panel) 40%, #21162c); }
.wave-panel { grid-area: wave; padding: 16px; background: linear-gradient(120deg, var(--panel), #22162e); }
.board { position: relative; width: 100%; aspect-ratio: 12 / 8; overflow: hidden; isolation: isolate; border-radius: 7px; background: #3d5a5a; box-shadow: 0 0 0 1px #090f1c; }
.board canvas, .grid, .board-overlay { position: absolute; inset: 0; width: 100%; height: 100%; }
.board canvas { image-rendering: pixelated; pointer-events: none; }
.grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); grid-template-rows: repeat(8, minmax(0, 1fr)); }
.cell { border: 0; padding: 0; background: transparent; appearance: none; border-radius: 0; touch-action: manipulation; }
.cell:focus-visible { position: relative; outline: 2px solid var(--paper); outline-offset: -3px; }
.cell[data-road] { cursor: default; }
.map-tag { --tag-color: var(--blue); position: absolute; z-index: 1; pointer-events: none; display: flex; align-items: center; gap: 5px; padding: 4px 7px 4px 4px; background: #10162ce8; border: 1px solid color-mix(in srgb, var(--tag-color) 45%, transparent); color: var(--paper); border-radius: 6px; font-size: clamp(.64rem, 1.1vw, .79rem); font-weight: 650; box-shadow: 0 2px 3px #0b152d90; white-space: nowrap; }
.map-tag b { display: grid; place-items: center; width: 1.55em; height: 1.55em; border-radius: 4px; background: var(--tag-color); color: var(--page); }
.entrance { left: 1.05%; top: 15%; }
.lane-tag { left: 4.7%; padding: 3px; transform: translateY(-50%); }
.lane-tag b { width: auto; min-width: 2em; padding-inline: .2em; }
.castle { --tag-color: var(--pink); right: 1%; top: 27.1%; }
.board-overlay { display: grid; place-items: center; z-index: 2; background: #080e226e; pointer-events: none; }
.board-overlay span { padding: .5em 1.2em; border: 1px solid var(--blue); border-radius: 8px; background: var(--panel); color: var(--paper); font: bold 1.5rem var(--serif); }
.map-footer { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 3px 12px; padding: 11px 6px 12px; color: var(--muted); }
.status { min-width: 150px; flex: 1 1 250px; font-size: .875rem; color: #dce5fa; }
.status[data-tone="error"] { color: #ffc0cc; }
.status[data-tone="success"] { color: #b5ceff; }
.legend { display: flex; column-gap: 13px; font-size: .75rem; white-space: nowrap; }
.legend span { display: flex; align-items: center; gap: 5px; }
.legend i { width: 10px; height: 10px; border: 1px solid #d5e0f245; border-radius: 2px; }
.grass-key { background: #48706e; }
.path-key { background: #a59783; }

.panel h2 { font: 700 1.4rem/1.13 var(--serif); color: var(--paper); }
.shop-cards { display: grid; gap: 8px; margin-top: 12px; }
.hero-card { --hero-color: var(--blue); --hero-shadow: #122653; --hero-border: #73a1ff; width: 100%; min-width: 0; display: grid; grid-template-columns: 61px minmax(0, 1fr) auto; gap: 10px; text-align: left; align-items: center; padding: 6px 8px 6px 6px; background: linear-gradient(110deg, var(--hero-shadow), var(--panel) 92%); border: 1px solid color-mix(in srgb, var(--hero-border) 42%, var(--panel)); border-radius: 8px; transition: border-color .15s, box-shadow .15s; }
.hero-card.germina { --hero-color: var(--pink); --hero-shadow: #45173b; --hero-border: #df76b0; }
.hero-card:hover, .hero-card[aria-pressed="true"] { border-color: var(--hero-border); box-shadow: 0 0 16px color-mix(in srgb, var(--hero-color) 15%, transparent); }
.hero-card:disabled { opacity: .63; }
.portrait { aspect-ratio: 1; border-radius: 5px; border: 1px solid color-mix(in srgb, var(--hero-color) 45%, var(--panel)); background: var(--hero-shadow) url("assets/heroines.webp") no-repeat 0 50% / 200% 100%; display: block; }
.germina .portrait { background-position: 100% 50%; }
.hero-detail { min-width: 0; display: grid; gap: 2px; }
.hero-detail strong { color: var(--paper); font: bold 1rem/1.1 var(--serif); }
.hero-role, .hero-range { color: var(--hero-color); font-size: .77rem; line-height: 1.2; }
.hero-role { font-weight: 650; }
.hero-role .icon { width: 13px; height: 13px; }
.hero-range { color: var(--muted); }
.cost { display: inline-flex; align-items: center; gap: 3px; padding: 4px 6px; border-radius: 5px; color: var(--gold); background: #e7c48817; font-size: .875rem; font-weight: 750; }
.cost .icon { width: 14px; height: 14px; }
.merge-tip { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); display: flex; align-items: flex-start; gap: 9px; }
.merge-tip > .icon { width: 22px; height: 22px; color: var(--pink); }
.merge-tip h3 { font-size: .875rem; color: var(--paper); }
.merge-tip p { margin-top: 3px; font-size: .8rem; color: var(--muted); line-height: 1.4; }

.wave-dashes { display: flex; gap: 5px; margin-bottom: 12px; }
.wave-dashes i { flex: 1; height: 3px; border-radius: 5px; background: var(--line); }
.wave-dashes .past { background: #7195cb; }
.wave-dashes .current { background: linear-gradient(90deg, var(--blue), var(--pink)); }
.wave-heading { display: flex; flex-wrap: wrap; gap: 5px 8px; align-items: center; justify-content: space-between; }
.wave-heading span { color: #e5b7d9; font-size: .78rem; white-space: nowrap; }
.wave-info { list-style: none; padding: 0; margin: 8px 0; color: var(--muted); font-size: .875rem; line-height: 1.42; }
.wave-info li { display: flex; align-items: baseline; justify-content: space-between; gap: .5em; }
.wave-info li[data-kind="rush"] { color: #99ddd8; }
.wave-info li[data-kind="tank"] { color: #f0ad93; }
.wave-info li[data-kind="boss"] { color: var(--pink); }
.wave-reward { display: flex; align-items: center; gap: .45em; margin: 0 0 11px; color: var(--gold); font-size: .81rem; }
progress { display: block; width: 100%; margin-bottom: 10px; height: 5px; border: 0; border-radius: 6px; background: var(--line); accent-color: var(--blue); }
progress::-webkit-progress-bar { background: var(--line); border-radius: 6px; }
progress::-webkit-progress-value { background: linear-gradient(90deg, var(--blue), var(--pink)); border-radius: 6px; }
.primary { width: 100%; min-height: 43px; display: flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid #e8c8ed; border-radius: 7px; background: linear-gradient(105deg, var(--blue), #cfbbf0 55%, var(--pink)); box-shadow: 0 3px 14px #a887d931; color: #17172a; padding: 8px 12px; font-size: .94rem; font-weight: 750; }
.primary:hover { background: linear-gradient(105deg, #adc9ff, #f8c3e3); }
.primary:active { background: linear-gradient(105deg, #7d9ee5, #e28dbd); }
.primary:disabled { background: var(--surface); color: var(--muted); border-color: var(--line); box-shadow: none; }

.modal { width: min(410px, 100% - 26px); text-align: center; border: 1px solid #a477a8; border-radius: 12px; padding: 25px; background: linear-gradient(140deg, #172548, #24152f); color: var(--paper); box-shadow: 0 15px 80px #070914c9; }
.modal::backdrop { background: #060811c9; }
.modal h2 { font: 700 1.95rem/1.05 var(--serif); margin: 9px 0; }
.modal p { color: var(--muted); line-height: 1.5; margin-bottom: 19px; }
.modal-cancel { margin-top: 8px; width: 100%; }

@media (max-width: 880px) {
  .topbar-inner, .game-shell { width: min(100% - 36px, 1232px); }
  .game-layout { grid-template-columns: minmax(0, 1fr); grid-template-areas: "shop" "map" "wave"; grid-template-rows: auto; gap: 10px; }
  .shop, .wave-panel { padding: 12px; }
  .shop-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-top: 8px; }
  .merge-tip { margin-top: 9px; padding-top: 8px; }
  .merge-tip h3, .merge-tip p { display: inline; }
  .merge-tip h3 { margin-right: 5px; }
}

@media (max-width: 580px) {
  .topbar-inner, .game-shell { width: calc(100% - 24px); }
  .topbar-inner { min-height: 54px; }
  .brand { font-size: 1.07rem; gap: 6px; }
  .brand img { width: 28px; height: 32px; }
  .quiet { min-height: 36px; }
  .game-shell { padding-top: 15px; }
  .map-heading { display: grid; margin-bottom: 10px; }
  .map-heading p { font-size: .88rem; margin-top: 5px; }
  .stats { gap: 5px; }
  .stat { min-width: 0; padding: 6px 8px; gap: 5px; }
  .stat > .icon { width: 20px; height: 20px; }
  .stat dd { font-size: 1.15rem; }
  .shop-cards { gap: 5px; }
  .hero-card { grid-template-columns: 40px minmax(0, 1fr) auto; gap: 5px; padding: 5px; }
  .hero-detail strong { font-size: .85rem; }
  .hero-range { display: none; }
  .cost { padding: 3px; font-size: .75rem; }
  .map-panel { padding: 4px 4px 0; }
  .map-footer { padding: 6px 4px 7px; }
  .map-tag { padding: 2px 4px 2px 2px; gap: 3px; }
}

@media (max-width: 360px) {
  .hero-card { grid-template-columns: 32px minmax(0, 1fr); position: relative; }
  .cost { position: absolute; right: 3px; top: 3px; transform: scale(.85); transform-origin: top right; }
  .hero-detail strong { padding-right: 17px; }
  .restart-button span { display: none; }
}

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; } }
