:root {
  color-scheme: dark;
  --forest-950: #101a12;
  --forest-900: #142018;
  --forest-850: #1b2a1e;
  --forest-800: #223526;
  --forest-700: #344c35;
  --tile-a: #4a6741;
  --tile-b: #3d5836;
  --lake: #0e3d5c;
  --red: #9b1b30;
  --player-l: #c4253e;
  --blue: #1b3a5c;
  --comp-l: #2a5580;
  --gold: #d4a017;
  --gold-light: #f0c040;
  --ink: #f0e6d0;
  --muted: #a99e86;
  --line: rgba(210, 190, 145, .17);
  --panel: rgba(25, 39, 28, .91);
  --serif: Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-width: 320px; min-height: 100%; background: var(--forest-950); }
body { margin: 0; min-height: 100vh; color: var(--ink); background: radial-gradient(ellipse at 30% 0%, rgba(74,103,65,.18), transparent 44%), radial-gradient(ellipse at 100% 100%, rgba(155,27,48,.07), transparent 45%), var(--forest-950); font: 14px/1.5 var(--sans); }
button, select { font: inherit; }
button { color: inherit; }
button:focus-visible, select:focus-visible, a:focus-visible { outline: 3px solid var(--gold-light); outline-offset: 3px; }
a { color: var(--gold-light); }

#app { width: min(1440px, 100%); margin: 0 auto; padding: 0 30px 36px; }
.topbar { min-height: 82px; display: grid; grid-template-columns: 1fr minmax(220px, 1.2fr) 1fr; align-items: center; gap: 22px; border-bottom: 1px solid var(--line); }
.brand { display: inline-flex; align-items: center; gap: 11px; width: fit-content; color: var(--ink); text-decoration: none; font: 800 17px/1 var(--serif); letter-spacing: .19em; }
.brand-mark { color: var(--gold-light); font-size: 24px; text-shadow: 0 0 18px rgba(240,192,64,.38); }
.turn-summary { text-align: center; }
.eyebrow { color: #c7ad69; font-size: 10px; font-weight: 800; letter-spacing: .17em; }
#status { min-height: 22px; margin: 2px 0 0; color: var(--ink); font-size: 14px; }
#status.hl { color: var(--gold-light); }
.hdr-btns { display: flex; justify-content: flex-end; align-items: center; gap: 8px; }
.quiet-button, .secondary-button { border: 1px solid var(--line); border-radius: 7px; background: rgba(255,255,255,.025); cursor: pointer; transition: background .18s, border-color .18s, transform .18s; }
.quiet-button { padding: 8px 12px; color: #ded5c2; font-size: 12px; }
.quiet-button:hover, .secondary-button:hover { border-color: rgba(240,192,64,.56); background: rgba(240,192,64,.08); }
.key-hint { margin-left: 4px; padding: 0 5px; border: 1px solid var(--line); border-radius: 4px; color: var(--muted); font-size: 10px; }

.game-wrap { display: grid; grid-template-columns: minmax(0, 1fr) 286px; align-items: start; gap: clamp(24px, 4vw, 58px); padding: 26px 0 0; }
.play-area { min-width: 0; }
.board-heading { display: flex; justify-content: space-between; align-items: end; margin: 0 0 15px; }
.board-heading h1 { margin: 3px 0 0; color: #f1e8d6; font: 500 clamp(22px, 2.5vw, 30px)/1.1 var(--serif); letter-spacing: -.02em; }
.board-size { padding: 5px 9px; border: 1px solid var(--line); border-radius: 5px; color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .12em; }
.board-frame { width: min(100%, calc(100vh - 180px)); margin: 0 auto; padding: clamp(5px, .8vw, 10px); border: 1px solid rgba(212,160,23,.36); border-radius: 10px; background: linear-gradient(145deg, #2c402d, #18251a); box-shadow: 0 24px 64px rgba(0,0,0,.38), inset 0 1px rgba(255,255,255,.07); }
.board { display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); width: 100%; aspect-ratio: 1; gap: clamp(1px, .2vw, 3px); overflow: hidden; border-radius: 4px; background: #263b2b; }
.cell { position: relative; min-width: 0; aspect-ratio: 1; overflow: hidden; border-radius: 2px; background: var(--tile-a); cursor: default; }
.cell:nth-child(even) { background-color: var(--tile-b); }
.cell svg { display: block; width: 100%; height: 100%; }
.cell.clickable { cursor: pointer; }
.cell.clickable:hover { z-index: 2; box-shadow: inset 0 0 0 2px rgba(240,192,64,.8); }
.cell.selected { z-index: 3; box-shadow: inset 0 0 0 3px var(--gold-light), inset 0 0 18px rgba(240,192,64,.22) !important; }
.cell.valid-move { z-index: 2; box-shadow: inset 0 0 0 3px #63db8a, inset 0 0 12px rgba(99,219,138,.2) !important; }
.cell.valid-move::after, .cell.valid-attack::after, .cell.selected::after { content: ""; position: absolute; top: 50%; left: 50%; width: 18%; aspect-ratio: 1; border-radius: 50%; transform: translate(-50%, -50%); pointer-events: none; }
.cell.valid-move::after { background: #80f0a2; box-shadow: 0 0 9px rgba(77,235,129,.7); }
.cell.valid-attack { z-index: 2; box-shadow: inset 0 0 0 3px #ff9a60, inset 0 0 12px rgba(255,125,67,.24) !important; }
.cell.valid-attack::after { top: 13%; left: auto; right: 13%; width: 24%; border: 2px solid #ffb17b; border-radius: 2px; transform: none; }
.cell.selected::after { top: auto; left: auto; right: 7%; bottom: 7%; width: 18%; border: 2px solid var(--gold-light); border-radius: 2px; transform: none; }
.cell svg { position: relative; z-index: 0; }
.cell.valid-move svg, .cell.valid-attack svg, .cell.selected svg { position: relative; }
.board-legend { display: flex; flex-wrap: wrap; align-items: center; gap: 13px 18px; padding: 12px 4px 0; color: #c4baa5; font-size: 11px; }
.board-legend > span { display: inline-flex; align-items: center; gap: 6px; }
.legend-dot { width: 11px; height: 11px; border-radius: 50%; }
.move-dot { background: #80f0a2; box-shadow: 0 0 7px rgba(77,235,129,.5); }
.attack-dot { border: 2px solid #ffb17b; border-radius: 2px; }
.selected-dot { border: 2px solid var(--gold-light); border-radius: 2px; }
.legend-help { margin-left: auto; color: #8e897b; }

.command-rail { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.panel { overflow: hidden; padding: 16px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); box-shadow: 0 8px 28px rgba(0,0,0,.13); }
.panel-title { display: flex; align-items: center; justify-content: space-between; margin: 0 0 12px; }
.mission-star { color: var(--gold); }
.mission-copy { margin: 0 0 17px; color: #e3d9c5; font: 17px/1.4 var(--serif); }
.mission-copy strong { color: var(--gold-light); font-weight: 600; }
.control-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.control-row select { max-width: 145px; padding: 6px 27px 6px 9px; border: 1px solid var(--line); border-radius: 5px; background: #1b2b1e; color: var(--ink); }
.turn-stat { display: flex; justify-content: space-between; align-items: center; padding: 10px 0 13px; color: var(--muted); font-size: 12px; }
.turn-stat strong { color: var(--ink); font-size: 13px; }
.action-stack { display: grid; gap: 7px; }
.primary-button { min-height: 40px; padding: 9px 14px; border: 1px solid #edbd42; border-radius: 7px; background: linear-gradient(180deg, #e3b83f, #c89823); color: #1c2115; font-weight: 800; cursor: pointer; box-shadow: inset 0 1px rgba(255,255,255,.25), 0 3px 10px rgba(0,0,0,.18); transition: filter .16s, transform .16s; }
.btn { min-height: 38px; padding: 8px 15px; border: 1px solid #edbd42; border-radius: 7px; background: linear-gradient(180deg, #e3b83f, #c89823); color: #1c2115; font-weight: 800; cursor: pointer; }
.primary-button:hover { filter: brightness(1.12); }
.primary-button:active, .quiet-button:active, .secondary-button:active { transform: translateY(1px); }
.secondary-button { min-height: 36px; padding: 7px 12px; color: #ded5c2; font-size: 12px; }
.save-note, .dialog-save-note { margin: 11px 0 0; color: #8f927e; font-size: 10px; text-align: center; }
.captures-panel { padding-bottom: 10px; }
.cap-box { padding: 11px 0 12px; border-top: 1px solid var(--line); }
.cap-box h2 { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; color: #d7cdb8; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .09em; }
.enemy h2 { color: #84a8ce; }.own h2 { color: #df8792; }
.side-marker { width: 7px; height: 7px; border-radius: 50%; }.enemy-marker { background: #4f83b7; }.own-marker { background: #c54a5b; }
.cap-list { display: flex; flex-wrap: wrap; gap: 4px; min-height: 24px; }
.cap-list svg { width: 25px; height: 25px; flex: 0 0 25px; }
.log-panel { padding-bottom: 12px; }
.move-log { display: flex; flex-direction: column; gap: 5px; max-height: 116px; overflow: auto; padding: 0; margin: 0; list-style: none; scrollbar-color: #536447 transparent; }
.move-log li { display: flex; gap: 8px; align-items: baseline; color: #d5cbb7; font-size: 11px; }
.move-log li::before { content: ""; width: 5px; height: 5px; flex: 0 0 5px; border-radius: 50%; background: var(--gold); }
.move-log .empty-log { color: #858879; font-style: italic; }
.move-log .empty-log::before { display: none; }
.rail-footer { display: grid; gap: 4px; padding: 5px 3px 0; color: #8f927e; font-size: 10px; }
.rail-footer a { width: fit-content; text-decoration: none; }.rail-footer a:hover { text-decoration: underline; }
.rail-footer small { max-width: 270px; color: #747b6d; font-size: 9px; line-height: 1.4; }

.overlay { position: fixed; z-index: 100; inset: 0; display: flex; align-items: center; justify-content: center; padding: 22px; overflow-y: auto; background: rgba(5,11,6,.84); backdrop-filter: blur(8px); opacity: 0; visibility: hidden; pointer-events: none; transition: opacity .22s ease, visibility .22s; }
.overlay.active { opacity: 1; visibility: visible; pointer-events: auto; }
.ov-card { width: min(100%, 440px); max-height: calc(100dvh - 36px); overflow: auto; padding: clamp(22px, 5vw, 36px); border: 1px solid rgba(212,160,23,.42); border-radius: 14px; background: linear-gradient(145deg, #243827, #17241a 70%); text-align: center; box-shadow: 0 25px 90px rgba(0,0,0,.6), inset 0 1px rgba(255,255,255,.06); }
.dialog-emblem { display: block; margin-bottom: 10px; color: var(--gold-light); font-size: 30px; text-shadow: 0 0 24px rgba(240,192,64,.3); }
.start-card h2 { margin: 7px 0 10px; color: #f2e9d7; font: 500 clamp(29px, 7vw, 42px)/1.1 var(--serif); }
.start-card > p:not(.eyebrow):not(.dialog-save-note) { max-width: 340px; margin: 0 auto 23px; color: #bbb5a3; line-height: 1.7; }
.start-card .primary-button { min-width: 195px; }
.text-button { display: block; margin: 13px auto 0; padding: 4px; border: 0; background: transparent; color: #d4c8ab; text-decoration: underline; text-decoration-color: rgba(212,200,171,.35); text-underline-offset: 3px; cursor: pointer; font-size: 12px; }
.text-button:hover { color: var(--gold-light); }
.rules-card { width: min(100%, 540px); padding: 24px clamp(19px, 5vw, 34px); text-align: left; }
.rules-card > .eyebrow { text-align: center; }
.rules-card h2 { margin: 3px 0 14px; color: var(--gold-light); font: 600 26px/1.2 var(--serif); text-align: center; }
.rules-content { padding: 0 2px 8px; color: #c0baa9; font-size: 12px; line-height: 1.6; }
.rules-content h3 { margin: 13px 0 4px; color: var(--gold-light); font-size: 11px; letter-spacing: .09em; text-transform: uppercase; }
.rules-content h3 span { color: #9f9989; font-size: 10px; font-weight: 400; letter-spacing: 0; text-transform: none; }
.rules-content p { margin: 0; }.rules-content ul { margin: 4px 0 0; padding-left: 18px; }.rules-content li { margin: 2px 0; }
.rank-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px 8px; margin: 7px 0 0; padding: 0; list-style: none; }
.rank-list li { display: flex; gap: 7px; align-items: baseline; padding: 3px 6px; border-radius: 4px; background: rgba(255,255,255,.035); }
.rank-list b { min-width: 17px; color: var(--gold-light); text-align: center; }
kbd { padding: 1px 5px; border: 1px solid rgba(255,255,255,.18); border-radius: 4px; background: rgba(0,0,0,.2); color: var(--ink); font: 11px var(--sans); }
.rules-card > .primary-button { display: block; min-width: 200px; margin: 14px auto 0; }
.battle-display { display: flex; justify-content: center; align-items: center; gap: 16px; margin: 16px 0; }
.bp { display: flex; flex-direction: column; align-items: center; gap: 4px; }.bp svg { width: 62px; height: 62px; }.bp .lbl { font-size: 11px; font-weight: 700; }
.bvs { color: var(--gold-light); font: 900 22px var(--serif); }.bres { margin-top: 7px; font-size: 15px; font-weight: 800; }.bres.win { color: #76d994; }.bres.lose { color: #df8792; }.bres.draw { color: var(--gold-light); }
.toast { position: fixed; z-index: 200; bottom: 20px; left: 50%; max-width: calc(100vw - 24px); padding: 10px 17px; transform: translate(-50%, 80px); border: 1px solid var(--line); border-radius: 8px; background: #243827; color: var(--ink); box-shadow: 0 8px 32px rgba(0,0,0,.35); text-align: center; pointer-events: none; transition: transform .22s ease; }
.toast.show { transform: translate(-50%, 0); }

@media (min-width: 1200px) {
  .game-wrap { grid-template-columns: minmax(0, 1fr) 300px; }
  .board-frame { width: min(100%, calc(100vh - 166px)); }
}
@media (max-width: 860px) {
  #app { padding: 0 18px 26px; }
  .game-wrap { grid-template-columns: minmax(0, 1fr) 250px; gap: 18px; padding-top: 19px; }
  .board-frame { width: 100%; }
  .panel { padding: 13px; }
  .board-legend { gap: 9px 13px; }.legend-help { width: 100%; margin-left: 0; }
}
@media (max-width: 680px) {
  #app { padding: 0 12px 22px; }
  .topbar { min-height: 70px; grid-template-columns: 1fr auto; gap: 8px; }
  .brand { gap: 7px; font-size: 14px; letter-spacing: .13em; }.brand-mark { font-size: 20px; }
  .turn-summary { grid-row: 2; grid-column: 1 / -1; display: flex; align-items: baseline; justify-content: center; gap: 8px; padding: 0 0 8px; }
  .turn-summary .eyebrow { font-size: 8px; } #status { min-height: 0; font-size: 12px; }
  .topbar { padding-top: 9px; }
  .hdr-btns { gap: 5px; }.quiet-button { padding: 7px 9px; font-size: 11px; }
  .game-wrap { display: flex; flex-direction: column; gap: 15px; padding-top: 16px; }
  .play-area, .command-rail { width: 100%; }
  .board-heading { margin-bottom: 10px; }.board-heading h1 { font-size: 23px; }
  .board-frame { width: min(100%, calc(100vw - 24px)); padding: 5px; }
  .board { gap: 1px; }
  .board-legend { padding: 9px 2px 0; font-size: 10px; gap: 8px 13px; }
  .legend-help { width: auto; margin-left: auto; }
  .command-rail { display: grid; grid-template-columns: 1fr 1fr; align-items: start; gap: 10px; }
  .mission-panel { grid-column: 1 / -1; }
  .captures-panel, .log-panel { min-height: 100%; }
  .rail-footer { grid-column: 1 / -1; }
  .rank-list { grid-template-columns: repeat(2, 1fr); }
  .rules-card { max-height: calc(100dvh - 24px); padding-top: 19px; padding-bottom: 19px; }
}
@media (max-width: 600px) {
  /* Give rank numerals enough visual weight to read on a phone-sized board. */
  .cell svg text[font-size="18"] { font-size: 40px !important; }
  .cell svg text[font-size="11"] { font-size: 26px !important; }
  .cell svg text[font-size="9"] { display: none; }
}
@media (max-width: 390px) {
  .command-rail { display: flex; }
  .board-heading h1 { font-size: 21px; }
  .board-size { font-size: 9px; }
  .legend-help { width: 100%; margin-left: 0; }
  .rank-list { grid-template-columns: repeat(2, 1fr); }
  .overlay { padding: 12px; }.ov-card { max-height: calc(100dvh - 24px); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
