:root {
  color-scheme: light;
  --bg: #f4f2ed;
  --surface: #fbfaf7;
  --ink: #16150f;
  --muted: #6b6860;
  --line: #dcd8cd;
  --accent: #d9411e;
  --on-accent: #fff;
  --sq-light: #ebe6d8;
  --sq-dark: #b9b196;
  --piece-w: #fbfaf5;
  --piece-b: #24231d;
  --stroke-w: #24231d;
  --stroke-b: #e9e5d8;
  --font-display: "Space Grotesk", system-ui, sans-serif;
  --font-body: "Inter", system-ui, sans-serif;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f0f0d;
  --surface: #171714;
  --ink: #ecebe4;
  --muted: #8f8c82;
  --line: #2b2a26;
  --accent: #ff6a3d;
  --on-accent: #16150f;
  --sq-light: #4a483f;
  --sq-dark: #2a2924;
  --piece-w: #f1eee3;
  --piece-b: #11110e;
  --stroke-w: #0f0f0d;
  --stroke-b: #cfcbbd;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.5 var(--font-body); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.icons { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.topbar { border-bottom: 1px solid var(--line); }
.top-inner, main { max-width: 1120px; margin: 0 auto; padding-inline: 24px; }
.top-inner { min-height: 64px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { color: var(--ink); text-decoration: none; font: 600 17px var(--font-display); letter-spacing: -.02em; }
.brand-accent { color: var(--accent); }
.top-actions { display: flex; gap: 8px; }
.game-picker { text-decoration: none; }
@media (max-width: 520px) {
  .game-picker span { display: none; }
  .game-picker { width: 38px; padding: 0; }
}
@media (max-width: 410px) {
  .game-picker:not([hidden]) ~ .help-button span { display: none; }
  .game-picker:not([hidden]) ~ .help-button { width: 38px; padding: 0; }
}
.button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 38px; padding: 7px 14px; border: 1px solid var(--line); border-radius: 8px; background: transparent; color: var(--ink); font-size: 13px; font-weight: 500; transition: border-color .15s, filter .15s, transform .1s; }
.button:hover:not(:disabled) { border-color: var(--muted); }
.button:active:not(:disabled) { transform: translateY(1px); }
.button:disabled { opacity: .45; }
.icon-button { width: 38px; padding: 0; }
.icon-button[aria-pressed="true"] { border-color: var(--ink); }
.button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.button.primary:hover:not(:disabled) { filter: brightness(1.08); border-color: var(--accent); }
.button.wide { width: 100%; margin-top: 12px; }
.eyebrow { margin: 0 0 6px; color: var(--muted); font-size: 11px; font-weight: 500; letter-spacing: .1em; text-transform: uppercase; }
.intro { padding: 40px 0 28px; }
.intro h1 { margin: 0; font: 600 clamp(36px, 5vw, 56px)/1 var(--font-display); letter-spacing: -.04em; }
.intro p { margin: 12px 0 0; color: var(--muted); }
.layout { display: grid; grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr); align-items: start; gap: 24px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; min-width: 0; }
.board-panel { padding: 16px; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.panel-heading h2 { margin: 0; font: 600 15px var(--font-display); letter-spacing: -.01em; }
.badge { padding: 2px 8px; border: 1px solid var(--line); border-radius: 99px; color: var(--muted); font-size: 11px; white-space: nowrap; }
.muted { color: var(--muted); }

.strip { width: min(100%, 600px); margin: 0 auto; display: flex; align-items: center; gap: 10px; min-height: 40px; padding: 4px 2px; }
.who { display: flex; align-items: center; gap: 10px; min-width: 0; }
.chip { width: 26px; height: 26px; flex: none; border-radius: 50%; border: 2px solid var(--stroke-w); background: var(--piece-w); }
.chip.b { background: var(--piece-b); border-color: var(--stroke-b); }
.who b { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who small { color: var(--muted); }
.strip .active-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); opacity: 0; transition: opacity .2s; flex: none; }
.strip.on .active-dot { opacity: 1; }
.taken { margin-left: auto; display: flex; align-items: center; flex-wrap: wrap; justify-content: flex-end; min-height: 22px; }
.taken .piece { width: 20px; height: 20px; margin-left: -6px; }
.taken .piece:first-child { margin-left: 0; }
.taken em { margin-left: 8px; color: var(--muted); font: normal 12px var(--font-body); }

.board-wrap { position: relative; width: min(100%, 600px); margin: 0 auto; }
.board { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); grid-template-rows: repeat(8, minmax(0, 1fr)); aspect-ratio: 1; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; touch-action: none; user-select: none; }
.sq { position: relative; display: block; min-width: 0; min-height: 0; overflow: hidden; padding: 0; border: 0; border-radius: 0; background: var(--sq-light); }
.sq.dark { background: var(--sq-dark); }
.sq.last::before { content: ""; position: absolute; inset: 0; background: color-mix(in srgb, var(--accent) 28%, transparent); }
.sq.sel::before { content: ""; position: absolute; inset: 0; background: color-mix(in srgb, var(--accent) 45%, transparent); }
.sq.check::before { content: ""; position: absolute; inset: 0; background: radial-gradient(circle, #e0221a 0%, #e0221a66 45%, transparent 75%); }
.sq.hint::before { content: ""; position: absolute; inset: 0; box-shadow: inset 0 0 0 4px #2f9e6a; }
.sq.target::after { content: ""; position: absolute; width: 28%; aspect-ratio: 1; border-radius: 50%; background: color-mix(in srgb, var(--ink) 30%, transparent); pointer-events: none; }
.sq.target.cap::after { width: 86%; background: transparent; border: 5px solid color-mix(in srgb, var(--ink) 30%, transparent); }
.sq:focus-visible { outline: 3px solid var(--accent); outline-offset: -3px; z-index: 2; }
.sq .coord { position: absolute; font-size: 10px; font-weight: 600; line-height: 1; color: var(--ink); opacity: .55; pointer-events: none; }
.sq .coord.rank { top: 3px; left: 4px; }
.sq .coord.file { bottom: 3px; right: 4px; }
.sq.drag-over { box-shadow: inset 0 0 0 3px var(--accent); }
.piece { width: 88%; height: 88%; display: block; pointer-events: none; z-index: 1; }
.sq > .piece { position: absolute; inset: 6%; }
.sq.target::after, .sq.target.cap::after { left: 50%; top: 50%; translate: -50% -50%; }
.piece * { fill: var(--pf); stroke: var(--ps); stroke-width: 3.2; stroke-linejoin: round; stroke-linecap: round; }
.piece .cut { fill: var(--ps); stroke: none; }
.piece .slit { fill: none; stroke: var(--ps); }
.piece.w { --pf: var(--piece-w); --ps: var(--stroke-w); }
.piece.b { --pf: var(--piece-b); --ps: var(--stroke-b); }
.piece.lift { opacity: .3; }
.ghost { position: fixed; z-index: 20; width: 72px; height: 72px; margin: -36px 0 0 -36px; pointer-events: none; filter: drop-shadow(0 8px 10px #0005); }
.ghost .piece { width: 100%; height: 100%; }
.sq .piece.slide { transition: transform .22s cubic-bezier(.3,.7,.3,1); }

.overlay { position: absolute; inset: 0; display: grid; place-items: center; background: color-mix(in srgb, var(--bg) 72%, transparent); backdrop-filter: blur(3px); border-radius: 6px; animation: fade .3s ease both; }
.overlay-card { width: min(88%, 340px); padding: 22px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); text-align: center; animation: rise .35s cubic-bezier(.2,.8,.3,1) both; }
.overlay-card h2 { margin: 0; font: 600 30px/1.1 var(--font-display); letter-spacing: -.03em; }
.overlay-card p:not(.eyebrow) { margin: 8px 0 16px; color: var(--muted); }
.overlay-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(12px) scale(.97); } }

.tools { display: flex; flex-wrap: wrap; gap: 8px; width: min(100%, 600px); margin: 10px auto 0; }
.tools .button { flex: 1; min-width: 110px; }

.sidebar { display: grid; gap: 12px; }
.turn-card { padding: 18px; color: var(--bg); background: var(--ink); border-color: var(--ink); min-height: 120px; }
.turn-kicker { display: inline-flex; align-items: center; gap: 7px; font-size: 11px; font-weight: 500; letter-spacing: .1em; opacity: .7; }
.turn-kicker span, .footer-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); display: inline-block; }
.turn-card h2 { margin: 8px 0 4px; font: 600 24px/1.1 var(--font-display); letter-spacing: -.03em; overflow-wrap: anywhere; }
.turn-card p { margin: 0; font-size: 13px; opacity: .75; }
.turn-card.thinking p::after { content: ""; display: inline-block; width: 1.2em; text-align: left; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }
.mode-panel, .history-panel { padding: 14px; }
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); margin: 12px 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.segmented button { padding: 8px 4px; border: 0; background: transparent; font-size: 13px; font-weight: 500; color: var(--muted); transition: background .15s, color .15s; }
.segmented button + button { border-left: 1px solid var(--line); }
.segmented button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }
.options { display: grid; gap: 6px; margin-bottom: 4px; }
.options .row, .row { display: flex; gap: 8px; }
.row .button { flex: 1; }
label { display: block; font-size: 13px; font-weight: 500; }
label small { color: var(--muted); font-weight: 400; }
input, select { display: block; width: 100%; min-height: 40px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.moves { margin: 12px 0 0; padding: 0; list-style: none; max-height: 220px; overflow: auto; display: grid; grid-template-columns: 28px 1fr 1fr; gap: 2px 6px; font-variant-numeric: tabular-nums; }
.moves li { padding: 3px 6px; border-radius: 6px; font-size: 13px; }
.moves li.n { color: var(--muted); padding-inline: 0; text-align: right; }
.moves li.latest { background: var(--bg); box-shadow: inset 0 0 0 1px var(--line); font-weight: 600; }
.moves li.empty { grid-column: 1 / -1; color: var(--muted); }
footer { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; padding: 28px 2px 32px; color: var(--muted); font-size: 12px; }
footer > span:first-child { display: flex; align-items: center; gap: 7px; font-size: 11px; letter-spacing: .08em; }

dialog { width: min(92vw, 440px); max-height: 85dvh; border: 1px solid var(--line); border-radius: 12px; padding: 22px; color: var(--ink); background: var(--surface); box-shadow: 0 20px 60px #0006; }
dialog::backdrop { background: #0008; }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.dialog-heading h2 { margin: 2px 0 0; font: 600 24px var(--font-display); letter-spacing: -.03em; }
form { display: grid; gap: 8px; }
.rules { padding-left: 20px; margin: 0; color: var(--muted); line-height: 1.6; }
.rules li + li { margin-top: 8px; }
.form-message { color: var(--accent); font-size: 13px; margin: 0; }
.promo-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.promo-grid button { aspect-ratio: 1; display: grid; place-items: center; padding: 6px; border: 1px solid var(--line); border-radius: 10px; background: var(--sq-light); transition: transform .15s, border-color .15s; }
.promo-grid button:hover { transform: translateY(-3px); border-color: var(--accent); }
.promo-grid .piece { width: 100%; height: 100%; }
.toast { position: fixed; z-index: 30; bottom: 18px; left: 50%; transform: translateX(-50%); width: max-content; max-width: 90vw; padding: 9px 14px; border-radius: 8px; background: var(--ink); color: var(--bg); font-size: 13px; }

@media (max-width: 900px) {
  .top-inner, main { padding-inline: 16px; }
  .layout { grid-template-columns: minmax(0, 1fr); gap: 12px; }
}
@media (max-width: 680px) {
  .top-inner { min-height: 56px; }
  .intro { padding: 24px 0 18px; }
  .board-panel { padding: 10px; }
  .tools .button span { display: none; }
  .tools .button { min-width: 0; }
  .ghost { width: 60px; height: 60px; margin: -30px 0 0 -30px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
@media (max-width: 360px) {
  .help-button span { display: none; }
  .help-button { width: 38px; padding: 0; }
  .top-actions { gap: 5px; }
}
