:root {
  color-scheme: dark;
  font-family: "Avenir Next", "Segoe UI", system-ui, sans-serif;
  color: #f4effc;
  background: #141222;
  --muted: #b8afcb;
  --surface: #211d33;
  --border: #3b344e;
  --accent: #c9b7fc;
  --accent-text: #251845;
  --light: #f2e0b8;
  --dark: #85966f;
  --pieces: "DejaVu Sans", "Segoe UI Symbol", "Apple Symbols", "Noto Sans Symbols 2", serif;
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: radial-gradient(ellipse at 22% 0%, #29223b, transparent 53%), #141222; }
button, select, input { font: inherit; }
button, select { cursor: pointer; }
button:disabled { opacity: .48; cursor: default; }
button:focus-visible, select:focus-visible, input:focus-visible { outline: 3px solid #f5c879; outline-offset: 3px; }
[hidden] { display: none !important; }
h1, h2, p { margin: 0; }

.shell { width: min(100% - 48px, 1000px); margin-inline: auto; padding-block: 30px 32px; }
.masthead { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding-bottom: 19px; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.identity { display: flex; align-items: center; gap: 13px; }
.brand-mark { display: grid; place-items: center; width: 50px; height: 50px; border: 1px solid #685884; border-radius: 15px; background: #3a2d56; color: #f4d393; font: 33px/1 var(--pieces); }
h1 { font-family: Georgia, serif; font-size: clamp(28px, 4vw, 37px); line-height: 1.05; font-weight: 600; letter-spacing: -.045em; }
.identity p { color: var(--muted); font-size: .88rem; margin-top: 4px; }
.primary, .secondary, .quiet { display: inline-flex; gap: 6px; align-items: center; justify-content: center; min-height: 39px; padding: 7px 13px; border: 1px solid transparent; border-radius: 8px; white-space: nowrap; font-weight: 650; font-size: .88rem; }
.primary { color: var(--accent-text); background: var(--accent); }
.primary:not(:disabled):hover { background: #dfd3ff; }
.secondary { background: #312a45; border-color: #514763; color: #f5efff; }
.secondary:not(:disabled):hover, .quiet:hover { background: #3c3353; }
.quiet { color: var(--accent); background: transparent; }

.layout { display: grid; grid-template-columns: minmax(0, 1.58fr) minmax(272px, 1fr); align-items: start; gap: clamp(18px, 3vw, 32px); }
.table { min-width: 0; }
.player { display: flex; align-items: center; gap: 11px; min-height: 50px; }
.player-mark { display: grid; place-items: center; width: 37px; height: 37px; border-radius: 11px; font: 25px/1 var(--pieces); }
.black-mark { color: #d2c2f0; background: #332945; border: 1px solid #5d4e73; }
.white-mark { color: #33284a; background: #efddbd; }
.player-name { font-size: 1rem; font-weight: 650; display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.player-role { font-size: .85rem; font-weight: 500; color: var(--muted); }
.turn-tag { font-size: .8rem; font-weight: 650; color: #dfd1ff; background: #3d3155; padding: 4px 8px; border-radius: 5px; }
.clock { display: grid; margin-left: auto; min-width: 91px; place-items: center; padding: 6px 11px; border-radius: 9px; border: 1px solid #4b425e; background: #272139; font-size: 1.45rem; font-weight: 650; font-variant-numeric: tabular-nums; line-height: 1.12; color: #e1d9f1; }
.player.active .clock { color: #271b3f; background: #d5c5ff; border-color: #d5c5ff; }
.player .clock.low { background: #ffb1a9; color: #3c1722; border-color: #ffb1a9; }

.board-frame { padding: 7px; background: #433754; border: 1px solid #685b79; border-radius: 13px; margin-block: 4px; box-shadow: 0 12px 30px #100d1b68; }
.board { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); grid-template-rows: repeat(8, minmax(0, 1fr)); aspect-ratio: 1; overflow: hidden; border-radius: 6px; container-type: inline-size; isolation: isolate; }
.square { position: relative; display: grid; place-items: center; min-width: 0; min-height: 0; padding: 0; border: 0; border-radius: 0; touch-action: manipulation; }
.square.light { background: var(--light); color: #4d543b; }
.square.dark { background: var(--dark); color: #282f20; }
.square.last { background: #e5c777; }
.square.dark.last { background: #b8af61; }
.square.selected { background: #cbb7f4; }
.square.check { background: #e99581; }
.square:focus-visible { outline: 3px solid #4f286e; outline-offset: -4px; z-index: 2; }
.square.moving { z-index: 3; }
.board[aria-busy="true"] .square { cursor: wait; }
.square.target::after { content: ""; width: 24%; aspect-ratio: 1; background: #2339217d; border-radius: 50%; position: absolute; pointer-events: none; }
.square.capture::after { width: 89%; background: transparent; border: max(3px, .8cqw) solid #253c2585; }
.square.target:hover::after { background: #233921ab; }
.square.capture:hover::after { background: transparent; border-color: #253c25bf; }
.coordinate { position: absolute; z-index: 1; font-size: clamp(9px, 2.2cqw, 14px); line-height: 1; font-weight: 750; }
.rank { top: 6%; left: 6%; }
.file { bottom: 6%; right: 6%; }
.piece { display: block; font-family: var(--pieces); font-weight: 400; font-variant-emoji: text; line-height: 1; user-select: none; pointer-events: none; }
.square .piece { font-size: 10.25cqw; transform: translateY(-.03em); }
.piece.white { color: #fff8e9; -webkit-text-stroke: .032em #493b49; paint-order: stroke fill; text-shadow: 0 .027em .045em #241b18a0; }
.piece.black { color: #241b36; -webkit-text-stroke: .024em #f8dbc5; paint-order: stroke fill; text-shadow: 0 .027em .045em #1d182ba0; }
.game-footer { margin-top: 5px; min-height: 40px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
#status { font-size: .95rem; font-weight: 650; color: #e5d9f6; }
.game-footer .quiet { padding-right: 0; }
.game-footer .quiet:hover { padding-right: 8px; }

.sidebar { display: grid; align-content: start; gap: 14px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 15px; padding: 17px 18px; }
.panel h2, dialog h2 { font-weight: 700; font-size: 1.05rem; letter-spacing: -.02em; margin-bottom: 14px; }
.clock-controls { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 9px; }
.field { display: grid; gap: 6px; }
.field label, .speed label { font-size: .92rem; font-weight: 650; }
select { min-height: 39px; appearance: none; border-radius: 8px; border: 1px solid #514763; color: #f5efff; background-color: #191629; background-image: linear-gradient(45deg, transparent 50%, #c9b7fc 50%), linear-gradient(135deg, #c9b7fc 50%, transparent 50%); background-position: right 15px center, right 10px center; background-size: 5px 5px; background-repeat: no-repeat; padding: 6px 30px 6px 10px; font-size: .9rem; }
.speed { margin-top: 15px; border-top: 1px solid var(--border); padding-top: 14px; }
.speed-label, .range-labels { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
output { border-radius: 5px; background: #403458; color: #e8ddff; padding: 3px 7px; font-size: .83rem; font-weight: 650; line-height: 1.2; font-variant-numeric: tabular-nums; }
input[type=range] { display: block; width: 100%; margin: 10px 0 3px; height: 18px; accent-color: var(--accent); cursor: pointer; }
.range-labels { font-size: .8rem; color: var(--muted); }
.preview-row { display: flex; align-items: center; gap: 7px; margin-top: 12px; }
.preview-track { display: flex; align-items: center; flex: 1; height: 32px; border: 1px solid #4a405f; border-radius: 6px; padding-inline: 6px; overflow: hidden; background: repeating-linear-gradient(90deg, #28213c 0 25%, #352a4b 25% 50%); }
#preview-piece { display: block; color: #f3d39b; font: 26px/1 var(--pieces); }
.preview-row button { min-height: 32px; padding-block: 4px; border: 1px solid #54456b; }
.capture-row { display: grid; grid-template-columns: 72px 1fr; gap: 7px; align-items: center; min-height: 33px; }
.capture-row + .capture-row { margin-top: 5px; }
.capture-row > span, #empty-history { font-size: .88rem; color: var(--muted); }
.tray { display: flex; flex-wrap: wrap; align-items: center; min-height: 32px; border-radius: 6px; background: #181526; border: 1px solid #3c344d; padding: 3px 6px; gap: 1px; font-size: 21px; }
.tray:empty::before { content: "—"; color: #aa9abe; font-size: .86rem; padding-left: 4px; }
.history ol { list-style: none; padding: 0; margin: 0; max-height: 150px; overflow: auto; scrollbar-color: #665675 #211d33; }
.history li { display: grid; grid-template-columns: 2.4rem 1fr 1fr; gap: 5px; padding: 5px 8px; font-size: .9rem; font-variant-numeric: tabular-nums; }
.history li:nth-child(odd) { background: #2a243c; border-radius: 5px; }
.move-number { color: var(--muted); }

dialog { width: min(100% - 32px, 390px); color: #f4effc; background: #241e37; border: 1px solid #635675; border-radius: 15px; padding: 20px; }
dialog::backdrop { background: #121020bb; }
dialog p { color: var(--muted); font-size: .94rem; }
.mode-options { display: grid; gap: 8px; margin: 0; padding: 0; border: 0; }
.mode-options legend { margin-bottom: 8px; padding: 0; color: var(--muted); font-size: .9rem; }
.mode-option { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 9px; background: #211b31; cursor: pointer; }
.mode-option:has(input:checked) { border-color: #a18ac9; background: #372a4c; }
.mode-option:hover { border-color: #a18ac9; }
.mode-option input { flex: none; width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }
.mode-option strong, .mode-option small { display: block; }
.mode-option small { margin-top: 3px; color: var(--muted); font-size: .83rem; }
#replace-game { margin-top: 11px; }
.dialog-actions { margin-top: 18px; display: flex; justify-content: flex-end; gap: 8px; }
#promotion-options { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; }
#promotion-options button { background: #9582aa; min-height: 55px; border: 0; border-radius: 8px; font-size: 39px; }
#promotion-options button:hover { background: #c9b7e1; }

@media (max-width: 700px) {
  .shell { width: min(100% - 24px, 540px); padding-top: 15px; }
  .masthead { margin-bottom: 10px; padding-bottom: 12px; }
  .layout { grid-template-columns: minmax(0, 1fr); gap: 13px; }
  .sidebar { gap: 10px; }
  .board-frame { padding: 5px; }
}
@media (max-width: 360px) {
  .brand-mark { display: none; }
  .panel { padding-inline: 13px; }
  .turn-tag { padding-inline: 5px; }
}
