:root {
  color-scheme: dark;
  --bg: #08090a;
  --bg-elevated: #0f1011;
  --bg-surface: #141516;
  --bg-hover: #1c1d21;
  --border: #23252a;
  --border-strong: #2f3136;
  --text: #f7f8f8;
  --text-secondary: #8a8f98;
  --text-tertiary: #7d828d;
  --accent: #5e6ad2;
  --accent-bright: #6e79d6;
  --accent-soft: #5e6ad22e;
  --mark: #8b93f8;
  --mark-halo: #00000059;
  --danger: #eb5757;
  --blue: var(--accent-bright);
  --glow: #5e6ad224;
  --hover-sq: #ffffff12;
  --last: #5e6ad23d;
  --last-from: #5e6ad221;
  --select: #5e6ad266;
  --check: #eb57574d;
  --board-line: #363b44;
  --board-label: var(--text-secondary);
  --frame: var(--bg-elevated);
  --board: var(--bg-surface);
  --piece-a: #e9ecef;
  --piece-b: #d3d7dc;
  --piece-ink: #0f1011;
  --piece-shadow: #000000a6;
  --promoted: #c0342f;
  --frame-near: #00000080;
  --frame-far: #000000e6;
  --dialog-shadow: #000000bf;
  --scrim: #00000099;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN", "Yu Gothic", "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
  font-synthesis: none;
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #fcfcfd;
  --bg-elevated: #f6f7f8;
  --bg-surface: #ffffff;
  --bg-hover: #eef0f2;
  --border: #e4e7ea;
  --border-strong: #cfd3d8;
  --text: #0f1011;
  --text-secondary: #5b6169;
  --text-tertiary: #6b7078;
  --accent: #5e6ad2;
  --accent-bright: #4c57c4;
  --accent-soft: #5e6ad226;
  --mark: #414bb4;
  --mark-halo: #ffffffb3;
  --danger: #c0342f;
  --blue: var(--accent-bright);
  --glow: #5e6ad214;
  --hover-sq: #0000000a;
  --last: #5e6ad21f;
  --last-from: #5e6ad210;
  --select: #5e6ad233;
  --check: #eb575733;
  --board-line: #d7dade;
  --board-label: var(--text-secondary);
  --frame: var(--bg-elevated);
  --board: var(--bg-surface);
  --piece-a: #2b2d32;
  --piece-b: #141519;
  --piece-ink: #f7f8f8;
  --piece-shadow: #0000002e;
  --promoted: #f08b8b;
  --frame-near: #00000014;
  --frame-far: #0000001a;
  --dialog-shadow: #0000001f;
  --scrim: #00000040;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #fcfcfd;
    --bg-elevated: #f6f7f8;
    --bg-surface: #ffffff;
    --bg-hover: #eef0f2;
    --border: #e4e7ea;
    --border-strong: #cfd3d8;
    --text: #0f1011;
    --text-secondary: #5b6169;
    --text-tertiary: #6b7078;
    --accent: #5e6ad2;
    --accent-bright: #4c57c4;
    --accent-soft: #5e6ad226;
    --mark: #414bb4;
    --mark-halo: #ffffffb3;
    --danger: #c0342f;
    --blue: var(--accent-bright);
    --glow: #5e6ad214;
    --hover-sq: #0000000a;
    --last: #5e6ad21f;
    --last-from: #5e6ad210;
    --select: #5e6ad233;
    --check: #eb575733;
    --board-line: #d7dade;
    --board-label: var(--text-secondary);
    --frame: var(--bg-elevated);
    --board: var(--bg-surface);
    --piece-a: #2b2d32;
    --piece-b: #141519;
    --piece-ink: #f7f8f8;
    --piece-shadow: #0000002e;
    --promoted: #f08b8b;
    --frame-near: #00000014;
    --frame-far: #0000001a;
    --dialog-shadow: #0000001f;
    --scrim: #00000040;
  }
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100svh; background: radial-gradient(1100px 520px at 50% -160px, var(--glow), transparent 70%); }
button, select { font: inherit; }
button, a, select { -webkit-tap-highlight-color: transparent; }
button, select { min-height: 44px; }
button { cursor: pointer; border: 1px solid var(--border); border-radius: 6px; background: var(--bg-elevated); color: var(--text); padding: 9px 17px; font-weight: 550; letter-spacing: -.01em; transition: background .15s, border-color .15s, color .15s; }
button:hover:not(:disabled) { background: var(--bg-hover); border-color: var(--border-strong); }
button:disabled { cursor: default; opacity: .4; }
button:focus-visible, a:focus-visible, select:focus-visible, summary:focus-visible { outline: 3px solid #5e6ad28c; outline-offset: 3px; }
a { color: var(--text-secondary); text-decoration: none; }
a:hover { color: var(--text); }
[hidden] { display: none !important; }
.masthead, main, footer { width: min(100% - 32px, 72svh, 610px); margin-inline: auto; }
.masthead { display: flex; align-items: center; gap: 16px; height: 66px; border-bottom: 1px solid var(--border); }
.brand { color: var(--text); font-size: 20px; font-weight: 600; letter-spacing: -.03em; text-decoration: none; }
#status { flex: 1; text-align: right; font-size: 12px; color: var(--text-secondary); }
.icon-button { display: inline-grid; place-items: center; width: 44px; height: 44px; flex: 0 0 44px; padding: 10px; border-color: transparent; background: transparent; color: var(--text-secondary); }
.icon-button:hover:not(:disabled) { background: var(--bg-hover); color: var(--text); }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.player { display: flex; align-items: center; gap: 8px; min-height: 28px; padding-inline: 5px; }
.player-symbol { font-size: 20px; color: var(--text-tertiary); }
.player h1, .player h2 { margin: 0; font-size: 13px; font-weight: 550; letter-spacing: -.01em; }
.player h1 span { font-size: 11px; font-weight: 400; color: var(--text-secondary); }
.side-label { margin-left: auto; font-size: 10px; color: var(--text-secondary); }
.player.active .player-symbol { color: var(--accent-bright); }
.player.active h1, .player.active h2 { color: var(--accent-bright); }
.hand { display: flex; gap: 4px; align-items: center; min-height: 42px; padding: 2px 5px; flex-wrap: wrap; }
.no-hand { display: none; }
.hand button { min-width: 40px; min-height: 38px; padding: 2px 6px; border-color: transparent; background: transparent; display: flex; align-items: center; gap: 3px; }
.hand button:hover:not(:disabled) { background: var(--bg-hover); }
.hand button.selected { background: var(--accent-soft); border-color: var(--accent); }
.hand-piece { font-size: 24px; font-weight: 600; }
.count { font-size: 10px; color: var(--text-secondary); }
.board-frame { position: relative; padding: 20px 24px 12px 12px; border-radius: 12px; background: var(--frame); border: 1px solid var(--border); box-shadow: 0 1px 2px var(--frame-near), 0 20px 40px -24px var(--frame-far); }
.files { display: grid; grid-template-columns: repeat(9, 1fr); position: absolute; top: 4px; left: 12px; right: 24px; text-align: center; font-size: 10px; color: var(--board-label); }
.ranks { display: grid; grid-template-rows: repeat(9, 1fr); position: absolute; right: 7px; top: 20px; bottom: 12px; font-size: 10px; font-weight: 500; align-items: center; color: var(--board-label); }
.board { display: grid; grid-template: repeat(9, minmax(0, 1fr)) / repeat(9, minmax(0, 1fr)); aspect-ratio: 1 / 1.06; border-top: 1px solid var(--board-line); border-left: 1px solid var(--board-line); background: var(--board); }
.square { position: relative; min-width: 0; min-height: 0; border: 0; border-right: 1px solid var(--board-line); border-bottom: 1px solid var(--board-line); border-radius: 0; background: transparent; padding: 0; display: grid; place-items: center; }
.square:hover:not(:disabled) { background: var(--hover-sq); }
.square:disabled { opacity: 1; }
.square.last { background: var(--last); }
.square.last-from { background: var(--last-from); }
.square.selected { background: var(--select) !important; }
.square.legal::after { content: ""; position: absolute; width: 11px; height: 11px; border-radius: 50%; background: var(--mark); z-index: 2; box-shadow: 0 0 0 3px var(--mark-halo); }
.square.legal:has(.piece)::after { width: 82%; height: 88%; border-radius: 2px; background: transparent; box-shadow: inset 0 0 0 3px var(--mark); }
.square.in-check { background: var(--check); }
.square:focus-visible { z-index: 3; outline-offset: -3px; }
.piece { display: grid; place-items: center; width: 80%; height: 87%; padding-top: 7%; font-size: clamp(18px, 3.7svh, 34px); font-weight: 700; line-height: 1; clip-path: polygon(50% 0, 87% 17%, 100% 100%, 0 100%, 13% 17%); background: linear-gradient(180deg, var(--piece-a), var(--piece-b)); color: var(--piece-ink); filter: drop-shadow(0 1px 2px var(--piece-shadow)); user-select: none; }
.piece.reverse { transform: rotate(180deg); }
.piece.promoted { color: var(--promoted); }
.piece.letters { font-weight: 600; font-size: clamp(17px, 3.3svh, 30px); }
.controls { display: flex; justify-content: space-between; gap: 12px; align-items: center; border-top: 1px solid var(--border); margin-top: 12px; padding-top: 10px; }
.game-actions, .start-actions { display: flex; align-items: center; gap: 3px; }
.start-actions { gap: 8px; }
.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.primary:hover:not(:disabled) { background: var(--accent-bright); border-color: var(--accent-bright); }
#start { min-width: 88px; font-size: 13px; }
#resume { font-size: 13px; }
#declare { font-size: 11px; padding-inline: 7px; }
.detail { font-size: 12px; line-height: 1.7; color: var(--text-secondary); margin: 12px 0; }
.record { margin-top: 10px; font-size: 12px; color: var(--text-secondary); }
.record summary { cursor: pointer; padding: 7px 4px; }
.record summary:hover { color: var(--text); }
#move-count { float: right; }
#history { max-height: 160px; overflow-y: auto; padding: 0; margin: 8px 0; list-style: none; display: grid; grid-template-columns: 1fr 1fr; gap: 1px; font-size: 12px; }
#history li { padding: 7px 10px; display: flex; gap: 10px; border-radius: 4px; color: var(--text); }
#history li:last-child:not(.empty-history) { background: var(--accent-soft); }
#history .move-index { min-width: 18px; color: var(--text-tertiary); }
#history .empty-history { grid-column: 1 / -1; color: var(--text-secondary); }
footer { display: flex; justify-content: center; gap: 24px; font-size: 10px; padding: 20px 0; }
footer a { color: var(--text-tertiary); text-decoration: none; }
footer a:hover { color: var(--text-secondary); }
dialog { border: 1px solid var(--border); border-radius: 12px; background: var(--bg-surface); box-shadow: 0 24px 80px var(--dialog-shadow); color: var(--text); padding: 24px; width: 370px; max-width: calc(100% - 32px); max-height: calc(100svh - 40px); }
dialog::backdrop { background: var(--scrim); backdrop-filter: blur(4px); }
dialog h2 { font-size: 19px; font-weight: 600; letter-spacing: -.02em; margin: 0; }
dialog p { font-size: 12px; line-height: 1.8; color: var(--text-secondary); }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.dialog-heading .icon-button { margin: -10px -10px -10px 0; }
.dialog-actions { display: flex; gap: 10px; margin-top: 24px; }
.dialog-actions button { flex: 1; }
.field { margin-bottom: 16px; display: grid; grid-template-columns: 1fr 1.3fr; align-items: center; gap: 15px; }
.field label { font-size: 12px; color: var(--text-secondary); }
select { width: 100%; border: 1px solid var(--border); border-radius: 6px; background: var(--bg-elevated); color: var(--text); padding: 7px; font-size: 12px; }
select:hover { border-color: var(--border-strong); }
.piece-guide { color: var(--text-secondary); }
.about { font-size: 12px; line-height: 1.8; border-top: 1px solid var(--border); padding-top: 15px; margin-top: 18px; }
.about summary { cursor: pointer; color: var(--text); }
.about a { color: var(--accent-bright); }
.about a:hover { color: var(--text); }
.document { display: block; width: min(100% - 40px, 800px); line-height: 1.9; }
.document h1 { font-size: 25px; font-weight: 600; letter-spacing: -.03em; }
.document h2 { font-size: 18px; font-weight: 600; letter-spacing: -.02em; margin-top: 28px; }
.document p, .document li { font-size: 14px; color: var(--text-secondary); }
.document a { color: var(--accent-bright); text-decoration: underline; text-underline-offset: 2px; }
.document pre { white-space: pre-wrap; font-size: 12px; background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 8px; padding: 20px; color: var(--text-secondary); }
@media (max-width: 600px) {
  .masthead, main, footer { width: calc(100% - 24px); max-width: 480px; }
  .masthead { height: 56px; }
  .brand { font-size: 18px; }
  .board-frame { padding: 18px 20px 10px 9px; }
  .files { left: 9px; right: 20px; top: 3px; font-size: 9px; }
  .ranks { top: 18px; bottom: 10px; right: 5px; font-size: 9px; }
  .piece { font-size: clamp(18px, 6.2vw, 31px); }
  .piece.letters { font-size: clamp(16px, 5.4vw, 28px); }
  .hand { min-height: 39px; }
  .controls { gap: 4px; }
  .game-actions { gap: 0; }
  #start { min-width: 70px; }
  #resume { padding-inline: 10px; }
  footer { padding-top: 18px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }
