:root {
  --bg: #efe9dd;
  --surface: #fbf8f2;
  --ink: #221f1a;
  --muted: #6d665a;
  --line: #d9cfbd;
  --light: #eadfc8;
  --dark: #b09572;
  --accent: #2c7a63;
  --capture: #c2452d;
  --last: #e2b93b;
  --select: #f0cf52;
  --scene: #e7e0d2;
  --piece-w: #fbf6ea;
  --piece-b: #26221e;
  --piece3d-w: #f5eedd;
  --piece3d-b: #2b2622;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141517;
    --surface: #1d1f22;
    --ink: #ece6da;
    --muted: #9c9588;
    --line: #34373b;
    --light: #6d6454;
    --dark: #463e33;
    --accent: #4cc39b;
    --capture: #ef6a4f;
    --last: #c79d2c;
    --select: #e5bf3c;
    --scene: #17191c;
    --piece3d-b: #6a5746;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141517; --surface: #1d1f22; --ink: #ece6da; --muted: #9c9588; --line: #34373b;
  --light: #6d6454; --dark: #463e33; --accent: #4cc39b; --capture: #ef6a4f; --last: #c79d2c;
  --select: #e5bf3c; --scene: #17191c; --piece3d-b: #6a5746; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 Manrope, system-ui, sans-serif;
}
button {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; cursor: pointer;
}
button:hover { border-color: var(--muted); }
button.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
button:disabled { opacity: .45; cursor: default; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.app { display: grid; grid-template-columns: 1fr 380px; height: 100vh; }

.stage { position: relative; min-height: 0; background: var(--scene); }
#scene { position: absolute; inset: 0; touch-action: none; }
#scene canvas { display: block; }
.hud { position: absolute; left: 12px; right: 12px; display: flex; gap: 8px; flex-wrap: wrap; pointer-events: none; }
.hud-top { top: 12px; }
.hud-bottom { bottom: 12px; font-size: 13px; color: var(--muted); min-height: 1.4em; }
.chip {
  pointer-events: auto; display: inline-flex; align-items: center; gap: 6px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px; font-size: 13px;
  backdrop-filter: blur(6px);
}
.chip input[type=range] { width: 110px; accent-color: var(--accent); }
.chip input[type=checkbox] { accent-color: var(--accent); margin: 0; }

.side {
  background: var(--surface); border-left: 1px solid var(--line);
  padding: 18px 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px;
}
.head h1 { font: 700 26px/1.1 Cinzel, serif; margin: 0; letter-spacing: .02em; }
.head .sub { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

.status {
  font-weight: 600; padding: 10px 12px; border-radius: 10px; background: var(--bg);
  display: flex; align-items: center; gap: 10px; min-height: 44px;
}
.status .dot { width: 14px; height: 14px; border-radius: 50%; border: 1.5px solid var(--ink); flex: none; }
.status .dot.w { background: var(--piece-w); }
.status .dot.b { background: var(--piece-b); }
.status.check { background: color-mix(in srgb, var(--capture) 18%, var(--bg)); }
.status .spin { width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.layers { display: grid; grid-template-columns: repeat(8, 1fr); gap: 5px; }
.layer {
  padding: 3px 2px 2px; border-radius: 7px; background: transparent; border: 1.5px solid transparent;
  display: flex; flex-direction: column; align-items: center; gap: 2px; position: relative;
}
.layer canvas { width: 100%; aspect-ratio: 1; border-radius: 3px; display: block; }
.layer span { font-size: 12px; font-weight: 700; color: var(--muted); }
.layer[aria-selected="true"] { border-color: var(--ink); }
.layer[aria-selected="true"] span { color: var(--ink); }
.layer .badge {
  position: absolute; top: -6px; right: -4px; background: var(--accent); color: #fff;
  font-size: 10px; font-weight: 700; line-height: 1; padding: 3px 5px; border-radius: 999px;
}

.panelhead { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.panelname { text-align: center; font-weight: 700; }
.panelname small { display: block; font-weight: 500; color: var(--muted); font-size: 12px; }
.icon { width: 36px; height: 36px; padding: 0; display: grid; place-items: center; }
.icon svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.boardwrap { display: grid; grid-template-columns: 14px 1fr; grid-template-rows: 1fr 16px; gap: 3px; }
.ranks { display: grid; grid-template-rows: repeat(8, 1fr); font-size: 11px; color: var(--muted); text-align: center; align-items: center; }
.files { grid-column: 2; display: grid; grid-template-columns: repeat(8, 1fr); font-size: 11px; color: var(--muted); text-align: center; }
.board {
  display: grid; grid-template-columns: repeat(8, 1fr); aspect-ratio: 1;
  border-radius: 6px; overflow: hidden; border: 1px solid var(--line);
}
.cell {
  border: 0; border-radius: 0; padding: 0; position: relative; aspect-ratio: 1;
  display: grid; place-items: center; background: var(--light);
  font: 30px/1 "Noto Sans Symbols 2", "Segoe UI Symbol", serif;
}
.cell.dk { background: var(--dark); }
.cell.last::before, .cell.sel::before, .cell.chk::before { content: ""; position: absolute; inset: 0; }
.cell.last::before { background: color-mix(in srgb, var(--last) 45%, transparent); }
.cell.sel::before { background: color-mix(in srgb, var(--select) 70%, transparent); }
.cell.chk::before { background: radial-gradient(circle, var(--capture) 20%, transparent 75%); }
.cell .pc { position: relative; z-index: 1; }
.cell .pc.w { color: var(--piece-w); -webkit-text-stroke: 1.2px #2a241c; paint-order: stroke fill; }
.cell .pc.b { color: var(--piece-b); -webkit-text-stroke: .6px #f3ead6; paint-order: stroke fill; }
.cell.tgt::after { content: ""; position: absolute; width: 30%; height: 30%; border-radius: 50%; background: var(--accent); opacity: .85; z-index: 2; }
.cell.cap::after { content: ""; position: absolute; inset: 6%; border-radius: 50%; border: 3px solid var(--capture); z-index: 2; }
.cell .mark { position: absolute; bottom: 1px; font: 700 9px/1 Manrope, sans-serif; color: var(--ink); opacity: .55; z-index: 1; letter-spacing: .02em; }
.cell:hover { filter: brightness(1.06); }

.controls { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }

.movelist {
  margin: 0; padding: 0 0 0 30px; font: 13px/1.6 Manrope, sans-serif; font-variant-numeric: tabular-nums;
  columns: 1; flex: 1; min-height: 60px;
}
.movelist li::marker { color: var(--muted); }
.movelist li span { display: inline-block; min-width: 118px; }
.movelist li span.now { font-weight: 700; }

dialog { border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--ink); padding: 0; max-width: min(520px, calc(100vw - 32px)); }
dialog::backdrop { background: rgb(0 0 0 / .4); }
.dlg { padding: 20px 22px; }
.dlg h2 { font: 700 22px/1.2 Cinzel, serif; margin: 0 0 12px; }
.dlg h3 { margin: 16px 0 4px; font-size: 15px; }
.dlg fieldset { border: 0; padding: 0; margin: 0 0 14px; display: grid; gap: 4px; }
.dlg legend { font-weight: 700; margin-bottom: 4px; }
.dlg label { display: flex; gap: 8px; align-items: center; }
.dlg input[type=radio] { accent-color: var(--accent); }
.dlgbtns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.rules { max-height: 80vh; overflow-y: auto; }
.rules p, .rules li { color: var(--ink); }
.rules ul { padding-left: 18px; margin: 4px 0; }
.rules li { margin-bottom: 6px; }
.promos { display: flex; gap: 8px; }
.promos button { font: 40px/1 "Noto Sans Symbols 2", serif; width: 64px; height: 64px; padding: 0; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 55vh auto; height: auto; }
  .stage { height: 55vh; }
  .side { border-left: 0; border-top: 1px solid var(--line); padding: 16px; }
  .cell { font-size: 7.5vw; }
}
