:root {
  color-scheme: dark;
  --ink: #f6e9b6;
  --muted: #a8bc98;
  --grid: #4b7167;
  --panel: #06252a;
  --bg: #031920;
  --red: #f0444e;
  --blue: #2875d7;
  --lime: #c5e84f;
  --pixel-shadow: 4px 4px 0 #0008;
  --piece-size: 40px;
}

* { box-sizing: border-box; letter-spacing: 0; }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100svh;
  color: var(--ink);
  background: var(--bg);
  font-family: "Courier New", "PingFang SC", monospace;
  image-rendering: pixelated;
}
button { font: inherit; touch-action: manipulation; }
button:focus-visible { outline: 3px solid var(--lime); outline-offset: 5px; }
h1, h2, h3, p { margin: 0; }
.app-shell {
  width: min(100%, 620px);
  margin: auto;
  padding: max(12px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom));
}
.topbar, .brand, .player-heading, .legend { display: flex; align-items: center; }
.topbar { justify-content: space-between; min-height: 38px; gap: 12px; }
.brand { gap: 8px; }
.brand-mark { color: var(--lime); font-size: 18px; }
.brand h1 { font-size: 16px; }
.brand .eyebrow { display: none; }
.ghost-button {
  min-height: 40px;
  padding: 7px 10px;
  color: var(--ink);
  background: var(--panel);
  border: 2px solid var(--grid);
  border-radius: 0;
  box-shadow: var(--pixel-shadow);
  font-size: 12px;
  cursor: pointer;
}
.ghost-button:active { transform: translate(2px, 2px); box-shadow: 2px 2px 0 #0008; }
.hero {
  display: grid;
  place-items: center;
  min-height: 188px;
  margin: 8px -16px 0;
  padding: 24px 16px;
  text-align: center;
  background: #073039 url('./assets/moonlit-forest.png') center 48% / cover;
}
.hero > div { padding: 12px 20px; text-shadow: 3px 3px 0 #031920; }
.hero .eyebrow { display: none; }
h2 { font-size: 56px; line-height: 1.15; }
.hero-copy { margin-top: 12px; font-size: 17px; line-height: 1.5; }

/* One layout and palette at every width; only dimensions change on phones. */
.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr);
  grid-template-areas: "blue turn" "board board" "red note" "tip tip";
  gap: 18px 16px;
  padding: 20px 0;
}
.side-panel { display: contents; }
.blue-card { grid-area: blue; }
.red-card { grid-area: red; }
.turn-card { grid-area: turn; }
.win-note { grid-area: note; }
.tip-box { grid-area: tip; }
.board-stage { grid-area: board; min-width: 0; }
.rules-panel, footer { display: none; }
.player-card, .turn-card {
  min-width: 0;
  min-height: 98px;
  padding: 14px;
  border: 2px solid var(--grid);
  background: var(--panel);
  box-shadow: var(--pixel-shadow);
}
.player-card.active { border-color: var(--lime); }
.player-heading { gap: 8px; font-size: 18px; }
.player-heading b { margin-left: auto; font-size: 22px; }
.player-card p { margin: 6px 0 10px; color: var(--muted); font-size: 11px; }
.player-dot, .mini-pieces i { display: block; width: 12px; height: 12px; }
.red, .red-card .mini-pieces i { background: var(--red); }
.blue, .blue-card .mini-pieces i { background: var(--blue); }
.mini-pieces { display: flex; gap: 7px; }
.mini-pieces i { box-shadow: 2px 2px 0 #0009; }
.turn-card { display: grid; grid-template-columns: 1fr auto; gap: 6px; align-content: center; }
.turn-card span, .turn-card small { grid-column: 1 / -1; color: var(--muted); font-size: 11px; line-height: 1.5; overflow-wrap: anywhere; }
.turn-card strong { font-size: 21px; }
.turn-card i { align-self: center; width: 10px; height: 10px; background: var(--red); }
.win-note { align-self: center; display: grid; gap: 8px; padding-left: 12px; border-left: 3px solid var(--grid); }
.win-note strong { font-size: 16px; color: var(--lime); }
.win-note span { font-size: 12px; line-height: 1.6; color: var(--muted); }

.board-wrap {
  width: 100%;
  aspect-ratio: 1;
  padding: 38px;
  border: 7px ridge #65877b;
  background: #123c30;
  box-shadow: var(--pixel-shadow), inset 0 0 0 4px #071d22;
}
.board {
  position: relative;
  width: 100%;
  height: 100%;
  border: 4px solid #e4d89d;
  /* Internal lines are explicit: percentage box-shadow offsets are invalid CSS. */
  background:
    linear-gradient(90deg, transparent calc(33.333% - 2px), #e4d89d calc(33.333% - 2px), #e4d89d calc(33.333% + 2px), transparent calc(33.333% + 2px), transparent calc(66.667% - 2px), #e4d89d calc(66.667% - 2px), #e4d89d calc(66.667% + 2px), transparent calc(66.667% + 2px)),
    linear-gradient(transparent calc(33.333% - 2px), #e4d89d calc(33.333% - 2px), #e4d89d calc(33.333% + 2px), transparent calc(33.333% + 2px), transparent calc(66.667% - 2px), #e4d89d calc(66.667% - 2px), #e4d89d calc(66.667% + 2px), transparent calc(66.667% + 2px)),
    #17452f;
}
.node {
  position: absolute;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  transform: translate(-50%, -50%);
  cursor: pointer;
}
.node::before { content: ""; width: 13px; height: 13px; background: #b3ac83; border: 3px solid #f6e9b6; box-shadow: 0 0 0 3px #283f35; }
.node.has-piece::before {
  width: var(--piece-size);
  height: var(--piece-size);
  border: 4px solid #061c28;
  background: var(--player);
  clip-path: polygon(25% 0, 75% 0, 75% 8%, 92% 8%, 92% 25%, 100% 25%, 100% 75%, 92% 75%, 92% 92%, 75% 92%, 75% 100%, 25% 100%, 25% 92%, 8% 92%, 8% 75%, 0 75%, 0 25%, 8% 25%, 8% 8%, 25% 8%);
  box-shadow: inset 3px 3px 0 #ffffff60, inset -4px -4px 0 #0005;
  filter: brightness(.75);
}
.node.current-turn::before { filter: brightness(1.15) drop-shadow(0 0 5px var(--player)); animation: activePiece 1.4s steps(2) infinite; }
.node.selected { outline: 3px solid var(--lime); outline-offset: 3px; box-shadow: 0 0 14px #c5e84f80; }
.node.selected::before { animation: none; filter: brightness(1.35); }
.node.movable::after { content: ""; position: absolute; width: 28px; height: 28px; border: 3px dashed var(--lime); animation: pixelPulse 1s steps(2) infinite; }
.node.capture::after { content: "×"; position: absolute; top: -22px; color: var(--lime); font-size: 19px; }
.legend { justify-content: center; gap: 22px; margin-top: 12px; color: var(--muted); font-size: 10px; }
.legend span { display: flex; align-items: center; gap: 7px; }
.legend-line { width: 10px; height: 10px; border: 2px dashed var(--lime); }
.legend-capture::after { content: "×"; color: var(--lime); font-style: normal; }
.tip-box { display: flex; align-items: center; gap: 14px; padding: 16px; border: 2px solid var(--grid); background: var(--panel); box-shadow: var(--pixel-shadow); }
.tip-box > span { color: var(--red); font-size: 26px; }
.tip-box strong { font-size: 13px; }
.tip-box p { margin-top: 5px; color: var(--muted); font-size: 12px; line-height: 1.6; }
.toast { position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); z-index: 8; width: max-content; max-width: calc(100% - 32px); padding: 12px 18px; background: var(--lime); color: var(--bg); border: 2px solid var(--grid); box-shadow: var(--pixel-shadow); opacity: 0; transform: translate(-50%, 10px); pointer-events: none; font-size: 13px; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.game-over-dialog {
  width: min(340px, calc(100% - 40px));
  padding: 28px 22px;
  border: 3px solid var(--lime);
  border-radius: 0;
  background: var(--panel);
  color: var(--ink);
  text-align: center;
  box-shadow: 8px 8px 0 #0009;
}
.game-over-dialog::backdrop { background: #031920cc; }
.result-caption { color: var(--muted); font-size: 12px; }
.game-over-dialog h3 { margin-top: 12px; font-size: 28px; }
#gameOverMessage { margin-top: 12px; color: var(--muted); font-size: 14px; line-height: 1.6; }
.restart-button {
  display: block;
  width: 100%;
  min-height: 48px;
  margin-top: 24px;
  border: 2px solid var(--ink);
  border-radius: 0;
  background: var(--lime);
  color: var(--bg);
  font-size: 16px;
  font-weight: bold;
  box-shadow: var(--pixel-shadow);
  cursor: pointer;
}
.restart-button:active { transform: translate(2px, 2px); }
.destruction-fx { position: absolute; z-index: 6; pointer-events: none; width: 0; height: 0; animation: vanish 1s steps(5) forwards; }
.destruction-fx::before, .destruction-fx.double::after { content: ""; position: absolute; width: 34px; height: 34px; left: -17px; top: -17px; background: var(--lime); box-shadow: 0 0 0 6px var(--ink); animation: flash .3s steps(3) forwards; }
.destruction-fx.double::before { background: var(--red); box-shadow: 0 0 0 6px var(--blue); }
.destruction-fx.double::after { left: calc(-17px + var(--second-x)); top: calc(-17px + var(--second-y)); background: var(--blue); box-shadow: 0 0 0 6px var(--red); animation-delay: .1s; }
.destruction-fx i { position: absolute; width: 7px; height: 7px; background: var(--lime); animation: pixelParticle .5s steps(4) var(--delay) forwards; }
.destruction-fx.double i:nth-child(even) { background: var(--red); }
@keyframes pixelPulse { 50% { opacity: .45; transform: scale(1.15); } }
@keyframes activePiece { 50% { filter: brightness(1.4) drop-shadow(0 0 7px var(--player)); } }
@keyframes flash { to { opacity: 0; transform: scale(1.7); } }
@keyframes pixelParticle { from { transform: rotate(var(--angle)) translateY(-12px); } to { opacity: 0; transform: rotate(var(--angle)) translateY(-58px); } }
@keyframes vanish { to { opacity: 0; } }

@media (max-width: 480px) {
  :root { --piece-size: 34px; }
  .app-shell { padding-inline: 12px; }
  .hero { min-height: 132px; margin-inline: -12px; padding: 16px 12px; }
  h2 { font-size: 42px; }
  .hero-copy { font-size: 14px; margin-top: 8px; }
  .game-layout { gap: 14px 10px; padding-top: 14px; }
  .player-card, .turn-card { min-height: 88px; padding: 10px; }
  .player-heading { font-size: 15px; }
  .player-heading b { font-size: 20px; }
  .player-card p { font-size: 10px; }
  .mini-pieces { gap: 5px; }
  .mini-pieces i { width: 10px; height: 10px; }
  .turn-card strong { font-size: 18px; }
  .turn-card span, .turn-card small { font-size: 10px; }
  .board-wrap { padding: 28px; border-width: 6px; }
  .win-note { padding-left: 8px; }
  .win-note strong { font-size: 13px; }
  .win-note span { font-size: 11px; }
  .tip-box { padding: 12px; }
  .tip-box p { font-size: 11px; }
}
@media (prefers-reduced-motion: reduce) {
  .node.current-turn::before, .node.movable::after { animation: none; }
  .destruction-fx { animation-duration: .15s; }
}
