:root {
  color-scheme: dark;
  --forest-950: #041d17;
  --forest-900: #082f25;
  --forest-800: #0d4435;
  --forest-700: #126044;
  --lime: #b7e33c;
  --lime-soft: #d7f28a;
  --gold: #f4c542;
  --cream: #fff8e8;
  --ink: #10251d;
  --muted: #a9c0b7;
  --light-square: #d9d6b8;
  --dark-square: #4c7657;
  --danger: #ff8b74;
  --shadow: 0 18px 45px rgba(0, 0, 0, .3);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; min-width: 0; color: var(--cream); background: radial-gradient(circle at 50% -10%, #176047 0, var(--forest-950) 42rem); }
button, select { font: inherit; }
button, a, select { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }

.skip-link { position: fixed; left: 1rem; top: -5rem; z-index: 100; padding: .75rem 1rem; color: var(--ink); background: var(--lime); border-radius: .5rem; font-weight: 800; }
.skip-link:focus { top: 1rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.site-header { position: sticky; top: 0; z-index: 20; background: rgba(4, 29, 23, .92); border-bottom: 1px solid rgba(183, 227, 60, .18); backdrop-filter: blur(12px); }
.header-inner { width: min(1180px, calc(100% - 2rem)); min-height: 68px; margin: auto; display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.brand { display: inline-flex; align-items: center; gap: .7rem; text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 40px; aspect-ratio: 1; color: var(--forest-950); background: var(--lime); border-radius: 12px; font-weight: 950; box-shadow: 0 0 0 3px rgba(183, 227, 60, .12); }
.brand strong, .brand small { display: block; }
.brand small { margin-top: -.12rem; color: var(--muted); font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; }
nav { display: flex; gap: .25rem; }
nav a { padding: .55rem .75rem; color: #d9e9e2; border-radius: .5rem; text-decoration: none; font-size: .9rem; font-weight: 700; }
nav a:hover, nav a:focus-visible { color: var(--forest-950); background: var(--lime); outline: none; }

main { width: min(1180px, calc(100% - 2rem)); margin: 0 auto; }
.hero { display: flex; align-items: end; justify-content: space-between; gap: 1rem; padding: 3.2rem 0 2rem; }
.eyebrow { color: var(--lime); font-size: .75rem; font-weight: 900; letter-spacing: .14em; text-transform: uppercase; }
h1 { margin: .35rem 0 .25rem; font-size: clamp(2.45rem, 8vw, 5.4rem); line-height: .92; letter-spacing: -.055em; }
.hero-line { max-width: 650px; margin: .8rem 0 0; color: #c8ddd4; font-size: clamp(1rem, 2.5vw, 1.3rem); }
.phase-badge { min-width: 150px; padding: .9rem 1rem; border: 1px solid rgba(244, 197, 66, .4); border-radius: 16px; background: rgba(244, 197, 66, .09); text-align: right; }
.phase-badge strong, .phase-badge span { display: block; }
.phase-badge strong { color: var(--gold); }
.phase-badge span { color: var(--muted); font-size: .8rem; }

.game-shell { display: grid; grid-template-columns: minmax(0, 1fr) minmax(280px, 350px); gap: clamp(1rem, 3vw, 2.4rem); align-items: start; padding: clamp(1rem, 3vw, 2rem); background: linear-gradient(145deg, rgba(13, 68, 53, .9), rgba(4, 29, 23, .96)); border: 1px solid rgba(183, 227, 60, .18); border-radius: 26px; box-shadow: var(--shadow); }
.board-column { min-width: 0; }
.board-stage { width: min(100%, 680px); margin: 0 auto; perspective: 1100px; transition: padding .25s ease; }
.board-frame { width: min(100%, 680px); margin: 0 auto; padding: clamp(6px, 1.3vw, 12px); background: #1d1711; border: 1px solid #6a5632; border-radius: 10px; box-shadow: 0 12px 28px rgba(0, 0, 0, .38), inset 0 0 0 2px rgba(244, 197, 66, .08); }
.chessboard { position: relative; display: grid; grid-template-columns: repeat(8, 1fr); width: 100%; aspect-ratio: 1; overflow: hidden; border-radius: 3px; touch-action: manipulation; }
.square { position: relative; display: grid; place-items: center; aspect-ratio: 1; padding: 0; border: 0; color: inherit; cursor: pointer; isolation: isolate; }
.square.light { background: var(--light-square); }
.square.dark { background: var(--dark-square); }
.square::before { content: ""; position: absolute; inset: 5%; z-index: -1; border: 0 solid transparent; border-radius: 8%; }
.square:hover::before { background: rgba(255, 255, 255, .13); }
.square:focus-visible { z-index: 3; outline: 4px solid var(--gold); outline-offset: -4px; }
.square.last-origin::before { inset: 0; border-radius: 0; background: rgba(52, 183, 255, .3); box-shadow: inset 0 0 0 clamp(2px, .35vw, 4px) rgba(145, 221, 255, .72); }
.square.last-destination::before { inset: 0; border-radius: 0; background: rgba(183, 227, 60, .32); box-shadow: inset 0 0 0 clamp(3px, .45vw, 5px) rgba(215, 242, 138, .84); }
.square.landing-origin::before { inset: 2%; border: clamp(3px, .5vw, 5px) solid #70d6ff; border-radius: 8%; background: rgba(30, 139, 190, .42); box-shadow: inset 0 0 0 2px rgba(236, 250, 255, .72); }
.square.landing-destination::before { inset: 2%; border: clamp(4px, .6vw, 6px) solid var(--lime-soft); border-radius: 8%; background: rgba(126, 170, 22, .48); box-shadow: 0 0 18px rgba(183, 227, 60, .62); }
.square.move-origin::before { inset: 3%; border: clamp(3px, .55vw, 6px) solid #70d6ff; background: rgba(12, 107, 153, .42); box-shadow: 0 0 18px rgba(112, 214, 255, .72); }
.square.selected::before { inset: 3%; border-width: clamp(3px, .6vw, 6px); border-color: var(--gold); background: rgba(244, 197, 66, .2); box-shadow: none; }
.square.hint::before { inset: 4%; border: 4px dashed #fff; background: rgba(244, 197, 66, .28); }
.square.legal::after { content: ""; position: absolute; width: 25%; aspect-ratio: 1; border: 3px solid rgba(4, 29, 23, .62); border-radius: 50%; background: rgba(183, 227, 60, .82); box-shadow: 0 0 0 2px rgba(255, 255, 255, .26); }
.square.legal.capture::after { width: 72%; background: transparent; border-width: clamp(4px, .8vw, 8px); border-color: rgba(244, 197, 66, .85); }
.square.in-check::before { inset: 1%; border: clamp(4px, .8vw, 8px) solid #ff3b30; border-radius: 8%; background: rgba(161, 0, 0, .62); box-shadow: inset 0 0 0 2px #fff1ec, 0 0 20px rgba(255, 59, 48, .9); }
.square.in-check::after { content: "!"; position: absolute; top: 4%; right: 5%; z-index: 4; display: grid; place-items: center; width: 25%; aspect-ratio: 1; color: #5b0803; background: #fff1ec; border: 2px solid #ff3b30; border-radius: 50%; font-size: clamp(.62rem, 2.1vw, 1.15rem); font-weight: 1000; line-height: 1; }
.square.in-check.check-pulse { animation: check-attention 720ms ease-out 1; }
.square.animation-piece-hidden .piece-svg { visibility: hidden; }
.square.capture-target::before { inset: 5%; z-index: 1; border: clamp(3px, .5vw, 5px) solid var(--gold); background: rgba(244, 197, 66, .18); box-shadow: 0 0 16px rgba(244, 197, 66, .65); }
.square.capture-target .piece-svg { z-index: 2; transition: opacity 150ms ease, transform 150ms ease; }
.square.capture-impact .piece-svg { opacity: 0; transform: scale(.72); }

.move-layer { position: absolute; inset: 0; z-index: 8; pointer-events: none; }
.travelling-piece { position: absolute; display: grid; place-items: center; width: 12.5%; height: 12.5%; will-change: transform; transition-property: transform; transition-timing-function: cubic-bezier(.2, .75, .25, 1); pointer-events: none; }
.travelling-piece .piece-svg { width: 82%; height: 82%; }
.coord { position: absolute; z-index: 2; color: rgba(3, 24, 18, .72); font-size: clamp(.48rem, 1.4vw, .78rem); font-weight: 900; line-height: 1; pointer-events: none; }
.coord.file { right: 4px; bottom: 3px; }
.coord.rank { left: 4px; top: 3px; }
.piece-svg { width: 82%; height: 82%; overflow: visible; filter: drop-shadow(0 3px 2px rgba(0, 0, 0, .25)); pointer-events: none; }
.piece-svg.white { color: #fff8e5; stroke: #173a2e; }
.piece-svg.black { color: #15231d; stroke: #f4c542; }
.piece-svg .body { fill: currentColor; stroke: inherit; stroke-width: 3.4; stroke-linejoin: round; stroke-linecap: round; }
.piece-svg .detail { fill: none; stroke: inherit; stroke-width: 3.4; stroke-linecap: round; }

.view-perspective .board-stage { padding: 1% 2% 4%; }
.view-perspective .board-frame { transform: rotateX(18deg); transform-origin: center bottom; border-width: 3px 3px 13px; border-color: #775e34 #594522 #2b1e0e; box-shadow: 0 28px 30px rgba(0, 0, 0, .5), inset 0 0 0 2px rgba(244, 197, 66, .1); }
.view-perspective .square.light { background: linear-gradient(145deg, #ebe7c8, #c9c4a4); }
.view-perspective .square.dark { background: linear-gradient(145deg, #5f8b68, #365e43); }
.view-perspective .piece-svg { transform: translateY(-4%) rotateX(-12deg) scale(1.04); transform-origin: center bottom; filter: drop-shadow(0 7px 3px rgba(0, 0, 0, .42)); }

.player-strip { width: min(100%, 680px); min-height: 58px; margin: 0 auto; display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; align-items: center; gap: .7rem; }
.player-strip .avatar { display: grid; place-items: center; width: 40px; aspect-ratio: 1; color: var(--forest-950); background: var(--cream); border-radius: 50%; font-size: 1.5rem; }
.player-strip.opponent .avatar { color: var(--gold); background: #17231e; border: 1px solid rgba(244, 197, 66, .4); }
.player-strip strong, .player-strip small { display: block; }
.player-info { min-width: 0; }
.player-strip small { color: var(--muted); font-size: .77rem; }
.captured-tray { display: flex; align-items: center; min-width: 0; min-height: 20px; margin-top: .12rem; gap: .2rem; overflow: hidden; color: #d5e5de; font-size: .66rem; line-height: 1; }
.captured-label { flex: none; color: var(--muted); }
.captured-empty { min-width: 0; overflow: hidden; color: #80968d; text-overflow: ellipsis; white-space: nowrap; }
.captured-group { position: relative; flex: none; display: inline-flex; align-items: end; height: 19px; }
.captured-group .piece-svg { width: 19px; height: 19px; filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .3)); }
.captured-count { margin: 0 0 0 -2px; color: var(--cream); font-size: .62rem; font-weight: 900; }
.turn-dot { width: 12px; aspect-ratio: 1; background: #53685f; border-radius: 50%; }
.turn-dot.active { background: var(--lime); box-shadow: 0 0 0 5px rgba(183, 227, 60, .13); }
.clock { min-width: 70px; padding: .38rem .52rem; color: #dce9e3; background: rgba(2, 19, 15, .65); border: 1px solid rgba(255, 255, 255, .13); border-radius: 7px; text-align: center; font: 800 .78rem ui-monospace, SFMono-Regular, Menlo, monospace; }
.clock.active { color: var(--forest-950); background: var(--lime); border-color: var(--lime); }
.clock.warning { color: #291b00; background: var(--gold); border-color: #ffe28b; }
.clock.urgent { color: #2b0903; background: var(--danger); border-color: #ffd2c9; box-shadow: 0 0 0 3px rgba(255, 139, 116, .2); }
.status-panel { width: min(100%, 680px); min-height: 62px; margin: .35rem auto 0; padding: .75rem 1rem; background: rgba(4, 29, 23, .82); border-left: 4px solid var(--lime); border-radius: 9px; }
.status-panel.has-check { border: 2px solid #ff6b5d; border-left-width: 7px; background: linear-gradient(100deg, rgba(117, 9, 7, .92), rgba(4, 29, 23, .94)); box-shadow: 0 0 0 2px rgba(255, 241, 236, .12), 0 8px 22px rgba(0, 0, 0, .28); }
.status-heading { display: flex; align-items: center; justify-content: space-between; gap: .65rem; }
.status-heading #gameStatus { min-width: 0; }
.status-badges { display: inline-flex !important; align-items: center; flex: none; gap: .35rem; margin: 0 !important; }
.blitz-badge { margin: 0 !important; padding: .28rem .48rem; color: #13220c !important; background: var(--lime-soft); border: 1px solid var(--lime); border-radius: 999px; font-size: clamp(.62rem, 2.3vw, .75rem) !important; font-weight: 950; letter-spacing: .09em; line-height: 1; }
.blitz-badge[hidden] { display: none !important; }
.check-badge { flex: none; margin: 0 !important; padding: .26rem .48rem; color: #540805 !important; background: #fff1ec; border: 2px solid #ff3b30; border-radius: 999px; font-size: clamp(.68rem, 2.5vw, .82rem) !important; font-weight: 1000; letter-spacing: .06em; line-height: 1; }
.check-badge[hidden] { display: none; }
.check-badge > span { display: inline !important; margin: 0 !important; color: inherit !important; }
.status-panel strong, .status-panel span { display: block; }
.status-panel span { margin-top: .18rem; color: #c0d3cc; font-size: .86rem; }

.control-column { display: grid; gap: .85rem; }
.control-card { padding: 1rem; background: rgba(255, 248, 232, .055); border: 1px solid rgba(255, 248, 232, .1); border-radius: 16px; }
.control-card h2 { margin: 0 0 .8rem; font-size: 1rem; }
.control-card label { display: block; margin: .7rem 0 .32rem; color: #d7e6df; font-size: .77rem; font-weight: 800; }
.control-card select { width: 100%; padding: .68rem .7rem; color: var(--cream); background: var(--forest-950); border: 1px solid #547469; border-radius: 8px; }
.control-card select:focus-visible, .control-card button:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.control-card [hidden] { display: none !important; }
.check-row { display: flex !important; align-items: center; gap: .62rem; min-height: 38px; margin: .2rem 0 !important; cursor: pointer; }
.check-row input { width: 19px; height: 19px; accent-color: var(--lime); }
.setting-note { margin: .55rem 0 0; color: var(--muted); font-size: .75rem; line-height: 1.45; }
.engine-state { display: flex; align-items: center; gap: .55rem; margin: .9rem 0 0; color: var(--muted); font-size: .76rem; }
.engine-dot { width: 9px; aspect-ratio: 1; background: #7b9188; border-radius: 50%; }
.engine-dot.loading { background: var(--gold); animation: pulse 1s infinite; }
.engine-dot.ready { background: var(--lime); }
.engine-dot.error { background: var(--danger); }
.button-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .55rem; }
.button-grid button { min-height: 42px; padding: .55rem .45rem; color: var(--cream); background: #173f32; border: 1px solid #466d5f; border-radius: 9px; cursor: pointer; font-weight: 800; font-size: .78rem; }
.button-grid button:hover { border-color: var(--lime); background: #1c503e; }
.button-grid .primary { color: var(--forest-950); background: var(--lime); border-color: var(--lime); }
.button-grid button:disabled { opacity: .45; cursor: not-allowed; }
.card-heading { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; }
.card-heading span { color: var(--muted); font-size: .72rem; }
.move-list { max-height: 180px; margin: 0; padding: 0; overflow: auto; list-style: none; counter-reset: move; display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: rgba(255, 255, 255, .07); border-radius: 8px; }
.move-list li { min-height: 34px; padding: .45rem .55rem; background: var(--forest-950); font: 700 .78rem ui-monospace, SFMono-Regular, Menlo, monospace; }
.move-list li:nth-child(odd)::before { counter-increment: move; content: counter(move) ". "; color: var(--lime); }
.move-list .empty-moves { grid-column: 1 / -1; color: var(--muted); font-family: inherit; font-weight: 500; }

.learning-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: .9rem; padding: 4.5rem 0 2rem; }
.section-heading { grid-column: 1 / -1; margin-bottom: .5rem; }
.section-heading h2, .prototype-note h2 { margin: .4rem 0; font-size: clamp(1.65rem, 4vw, 2.5rem); letter-spacing: -.035em; }
.learning-grid article { min-height: 190px; padding: 1.15rem; background: var(--cream); border-radius: 17px; color: var(--ink); }
.learning-grid article > span { color: #5f8312; font-size: .73rem; font-weight: 900; }
.learning-grid h3 { margin: 1.6rem 0 .45rem; font-size: 1.3rem; }
.learning-grid p { margin: 0; color: #40554c; line-height: 1.55; font-size: .9rem; }
.prototype-note { display: grid; grid-template-columns: .9fr 1.1fr; gap: 2rem; margin: 1rem 0 4rem; padding: clamp(1.25rem, 4vw, 2.5rem); border: 1px solid rgba(244, 197, 66, .32); border-radius: 22px; background: rgba(244, 197, 66, .07); }
.prototype-note ul { margin: 0; padding-left: 1.2rem; color: #d7e6df; line-height: 1.8; }
.prototype-note li::marker { color: var(--gold); }

footer { padding: 2rem 1rem 3rem; color: var(--muted); background: #02130f; border-top: 1px solid rgba(183, 227, 60, .13); text-align: center; font-size: .8rem; }
footer p { margin: .3rem; }
footer strong { color: var(--lime-soft); }

dialog { width: min(480px, calc(100% - 2rem)); color: var(--cream); background: var(--forest-900); border: 1px solid var(--lime); border-radius: 18px; box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(0, 0, 0, .72); backdrop-filter: blur(3px); }
dialog h2 { margin: 0; }
dialog p { color: var(--muted); }
.promotion-options { display: grid; grid-template-columns: repeat(4, 1fr); gap: .55rem; }
.promotion-options button { padding: .65rem .2rem; color: var(--forest-950); background: var(--cream); border: 2px solid transparent; border-radius: 10px; cursor: pointer; font-size: 2rem; }
.promotion-options button:hover, .promotion-options button:focus-visible { border-color: var(--gold); outline: none; }
.promotion-options span { display: block; margin-top: .1rem; font: 800 .68rem inherit; }
.dialog-actions { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1.2rem; }
.dialog-actions button { min-height: 42px; padding: .6rem .9rem; color: var(--cream); background: #173f32; border: 1px solid #466d5f; border-radius: 9px; cursor: pointer; font-weight: 800; }
.dialog-actions .primary { color: var(--forest-950); background: var(--lime); border-color: var(--lime); }

@keyframes pulse { 50% { opacity: .35; } }
@keyframes check-attention {
  0% { filter: brightness(1); }
  42% { filter: brightness(1.55); }
  100% { filter: brightness(1); }
}

@media (max-width: 900px) {
  .game-shell { grid-template-columns: 1fr; }
  .control-column { grid-template-columns: 1fr 1fr; }
  .move-card { grid-column: 1 / -1; }
  .learning-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 600px) {
  .header-inner { width: min(100% - 1rem, 1180px); min-height: 58px; }
  nav a { padding: .45rem .48rem; font-size: .76rem; }
  .brand-mark { width: 35px; }
  .brand small { display: none; }
  main { width: min(100% - .8rem, 1180px); }
  .hero { align-items: start; padding: 2rem .35rem 1.3rem; }
  .phase-badge { min-width: auto; padding: .55rem .65rem; font-size: .74rem; }
  .game-shell { gap: .8rem; padding: .55rem; border-radius: 17px; }
  .board-frame { padding: 5px; }
  .view-perspective .board-stage { padding-bottom: 3%; }
  .view-perspective .board-frame { transform: rotateX(12deg); border-bottom-width: 9px; }
  .view-perspective .piece-svg { transform: translateY(-2%) rotateX(-8deg) scale(1.02); }
  .player-strip { min-height: 50px; padding: 0 .2rem; }
  .player-strip .avatar { width: 34px; font-size: 1.25rem; }
  .clock { min-width: 62px; padding: .32rem .38rem; font-size: .7rem; }
  .captured-tray { gap: .12rem; }
  .captured-label { font-size: .6rem; }
  .captured-group .piece-svg { width: 17px; height: 17px; }
  .status-panel { min-height: 58px; }
  .control-column { grid-template-columns: 1fr; }
  .move-card { grid-column: auto; }
  .learning-grid { grid-template-columns: 1fr; padding-top: 3.2rem; }
  .learning-grid article { min-height: 150px; }
  .prototype-note { grid-template-columns: 1fr; gap: .6rem; }
}

@media (max-width: 360px) {
  nav a[href="#development"] { display: none; }
  nav a { padding-inline: .38rem; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
  .square.in-check.check-pulse { animation: none !important; }
}
