@font-face{font-family:Instrument Serif;src:url("assets/instrument-normal.woff2") format("woff2");font-display:swap}
@font-face{font-family:Instrument Serif;src:url("assets/instrument-italic.woff2") format("woff2");font-style:italic;font-display:swap}
@font-face{font-family:DM Sans;src:url("assets/dm-sans.woff2") format("woff2");font-weight:100 1000;font-display:swap}
@font-face{font-family:DM Mono;src:url("assets/dm-mono.woff2") format("woff2");font-display:swap}

:root {
  --serif: "Instrument Serif", Georgia, serif;
  --mono: "DM Mono", monospace;
  font-family: "DM Sans", system-ui, sans-serif;
  background: #f4eee4;
  font-synthesis: none;
}

body {
  --board-size: clamp(480px, 100svh - 184px, 820px);
  --game-width: min(calc(100% - 64px), calc(var(--board-size) + 418px));
  --fade: 0%;
  --page: color-mix(in srgb, #f4eee4, #180b0a var(--fade));
  --panel: color-mix(in srgb, #fcf8ef, #231313 var(--fade));
  --inset: color-mix(in srgb, #f1e8d9, #382020 var(--fade));
  --stroke: color-mix(in srgb, #ded1bf, #55312d var(--fade));
  --accent: color-mix(in srgb, #843944, #ff9d94 var(--fade));
  --action: color-mix(in srgb, #653c35, #872d29 var(--fade));
  --frame: color-mix(in srgb, #6d4b3b, #492523 var(--fade));
  --board-light: #e9d1aa;
  --board-dark: #a7795b;
  --text: #2e201b;
  --muted: #6f5a4e;
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: radial-gradient(ellipse at 46% 5%, color-mix(in srgb, var(--panel), transparent 24%), transparent 66%), var(--page);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body[data-stage="1"] { --fade: 14%; --text: #271a19; --muted: #4f3b3b; }
body[data-stage="2"] { --fade: 28%; --text: #241717; --muted: #443130; }
body[data-stage="3"] { --fade: 62%; --text: #fff8f1; --muted: #fff2e8; --accent: #fff1ed; --action: #78312c; }
body[data-stage="4"] { --fade: 82%; --text: #fff3ef; --muted: #e8ceca; --accent: #ffc2b7; }
body[data-stage="5"] { --fade: 100%; --text: #fff1ef; --muted: #d7b9b4; }
body[data-palette="sage"] { --board-light: #e9e4c7; --board-dark: #7a916d; }
body[data-palette="slate"] { --board-light: #e2e8ec; --board-dark: #788da3; }
body[data-palette="rose"] { --board-light: #f1d6cc; --board-dark: #ae737d; }

button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .58; }
a { color: var(--accent); text-underline-offset: .2em; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.icon-library { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { display: inline-block; flex: none; width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.65; stroke-linecap: round; stroke-linejoin: round; vertical-align: middle; }
.topbar { border-bottom: 1px solid var(--stroke); background: color-mix(in srgb, var(--panel), transparent 34%); }
.topbar-inner { width: var(--game-width); min-height: 64px; margin: auto; display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.wordmark { display: flex; align-items: center; gap: 11px; font: 28px/.9 var(--serif); white-space: nowrap; }
.wordmark em, h1 em { color: var(--accent); font-weight: 400; }
.brand-icon { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 10px; background: #563632; }
.brand-icon img { width: 28px; height: 28px; transform: scaleX(-1); }
.toolbar { display: flex; gap: 8px; }
.button, .icon-button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 39px; padding: 8px 13px; border: 1px solid transparent; border-radius: 8px; background: transparent; color: var(--text); font-size: 13px; font-weight: 680; white-space: nowrap; transition: background-color .16s, border-color .16s; }
.button .icon { width: 16px; height: 16px; }
.button.primary { background: var(--action); color: #fff7ee; border-color: color-mix(in srgb, var(--action), #fff 12%); }
.button.primary:hover { background: color-mix(in srgb, var(--action), #fff 10%); }
.button.ghost:hover, .icon-button:hover, .button.secondary { background: var(--inset); }
.button.secondary { border-color: var(--stroke); }
.button.secondary:hover:not(:disabled) { border-color: var(--accent); }

.page { width: var(--game-width); margin: auto; }
.intro { grid-area: intro; padding: 8px 0 3px; }
h1, h2, p { margin: 0; }
.intro h1 { font: clamp(43px, 4.2vw, 60px)/.94 var(--serif); letter-spacing: -.035em; }
.intro p { max-width: 36ch; margin-top: 9px; color: var(--muted); font-size: 14px; line-height: 1.5; }
.game-layout {
  display: grid;
  grid-template-columns: minmax(0, var(--board-size)) minmax(270px, 1fr);
  grid-template-rows: auto 1fr;
  grid-template-areas: "play intro" "play info";
  gap: 17px 28px;
  align-items: start;
  padding-top: 15px;
}
.play-area { grid-area: play; min-width: 0; }
.pause-panel {
  grid-area: play;
  width: 100%;
  min-height: clamp(230px, 58vh, 480px);
  display: grid;
  place-items: center;
  text-align: center;
}
.pause-panel p, .victory-panel p { margin-top: 8px; color: var(--muted); font-size: 14px; }
.pause-panel .button { margin-top: 18px; }
.victory-panel { border-top: 3px solid var(--accent); }
.panel.victory-panel h2 { font: clamp(46px, 5vw, 74px)/.95 var(--serif); }
.victory-stats { display: grid; margin: 18px 0; }
.victory-stats div { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--stroke); }
.victory-stats dt { color: var(--muted); font-size: 13px; }
.victory-stats dd { margin: 0; font: 14px var(--mono); overflow-wrap: anywhere; }
#pause-run, #view-results { min-height: 32px; padding: 4px 10px; }
@media (min-width: 691px) {
  body[data-victory-open] .play-area { width: 90%; justify-self: center; }
}
.player { display: flex; gap: 10px; align-items: center; min-height: 40px; }
.bot { margin-bottom: 10px; }
.human { margin-top: 11px; }
.avatar { display: grid; place-items: center; width: 39px; height: 39px; border-radius: 9px; border: 1px solid var(--stroke); }
.avatar.dark { background: color-mix(in srgb, var(--frame), #fff 36%); border-color: var(--frame); }
.avatar.light { background: var(--panel); }
.avatar img { width: 32px; }
.player-meta { min-width: 0; display: flex; flex-direction: column; gap: 2px; font-size: 14px; }
.player-name { display: flex; align-items: baseline; flex-wrap: wrap; column-gap: 6px; }
.player-name span { font-size: 12px; color: var(--muted); }
.captures { display: flex; align-items: center; flex-wrap: wrap; gap: 2px 4px; min-height: 18px; }
.capture-group { display: inline-flex; }
.capture-group img { width: 18px; height: 18px; filter: drop-shadow(0 1px 1px #67484180); }
.capture-group img + img { margin-inline-start: -9px; }
.material-score { color: var(--accent); font: 12px/1 var(--mono); white-space: nowrap; }
.player-side { margin-left: auto; font: 11px var(--mono); letter-spacing: .11em; color: var(--muted); }
.turn-status { display: inline-flex; align-items: center; flex-shrink: 0; max-width: 46%; gap: 7px; margin-left: auto; padding: 7px 10px; border: 1px solid var(--stroke); border-radius: 6px; background: var(--panel); font-size: 12px; font-weight: 680; }
.turn-status::before, .checkpoint-dot { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); flex: none; }

.board-shell { position: relative; overflow: hidden; padding: 8px; border: 1px solid color-mix(in srgb, var(--frame), #fff 22%); border-radius: 8px; background: linear-gradient(125deg, color-mix(in srgb, var(--frame), #ffe0a6 20%), var(--frame) 60%); box-shadow: 0 7px 24px #34211029, inset 0 0 0 2px #fff2; }
.board { position: relative; aspect-ratio: 1; width: 100%; overflow: hidden; border-radius: 2px; touch-action: manipulation; background: var(--board-light); }
.board-annotations { position: absolute; inset: 0; z-index: 4; width: 100%; height: 100%; pointer-events: none; }
.board-row { display: grid; grid-template-columns: repeat(8, 1fr); height: 12.5%; }
.square { appearance: none; position: relative; padding: 0; display: grid; place-items: center; min-width: 0; min-height: 0; border: none; border-radius: 0; color: #49352b; background: var(--board-light); -webkit-tap-highlight-color: transparent; isolation: isolate; }
.square.dark { background: var(--board-dark); color: #fff8e6; }
.square:focus-visible { outline: 3px solid #60211e; outline-offset: -3px; z-index: 2; }
.square.is-last { background-image: linear-gradient(#ffe26375, #ffe26375); }
.square.is-selected { background-image: linear-gradient(#f5e378ba, #f5e378ba); box-shadow: inset 0 0 0 3px #574127af; }
.square.is-checked { background-image: radial-gradient(#e95769, #ac2339b0 61%, transparent 72%); }
.square img { width: 90%; height: 90%; object-fit: contain; position: relative; z-index: 1; pointer-events: none; user-select: none; filter: drop-shadow(0 1px 1px #230e0c42); }
.square.can-drag { cursor: grab; touch-action: none; }
.board.is-dragging .square { cursor: grabbing; }
.square.is-drag-origin img { visibility: hidden; }
.drag-ghost { position: fixed; z-index: 9; top: 0; left: 0; height: auto; pointer-events: none; user-select: none; will-change: transform; }
.square.is-target::after { content: ""; width: 23%; aspect-ratio: 1; position: absolute; border-radius: 50%; background: #38232455; pointer-events: none; }
.square.is-capture::after { content: ""; position: absolute; inset: 3px; border: 4px solid #38232465; border-radius: 50%; pointer-events: none; }
.rank, .file { position: absolute; z-index: 2; font: clamp(8px, 1vw, 11px) var(--mono); pointer-events: none; }
.rank { top: 3px; left: 4px; }
.file { bottom: 2px; right: 4px; }
.rewind-effect { display: none; position: absolute; inset: 0; z-index: 5; color: #ffe9e5; background: linear-gradient(165deg,#30100fdc,#4f0d0be8), repeating-linear-gradient(0deg, #fb4d4524 0 2px, transparent 2px 6px); place-content: center; justify-items: center; gap: 12px; pointer-events: none; }
.rewind-effect .icon { width: 47px; height: 47px; }
.rewind-effect span { font: clamp(13px, 3vw, 22px) var(--mono); letter-spacing: .22em; }
.rewind-effect.active { display: grid; animation: rewind-overlay 1s both; }
@keyframes rewind-overlay { 0%,100% { opacity: 0; } 18%,64% { opacity: 1; } 76% { opacity: .7; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
.game-feedback { margin-top: 12px; color: var(--muted); font-size: 13px; line-height: 1.45; }
.game-feedback button { margin-left: 8px; }

.sidebar { grid-area: info; display: grid; gap: 13px; min-width: 0; }
.panel { border: 1px solid var(--stroke); border-radius: 11px; padding: 16px 17px; background: var(--panel); box-shadow: 0 2px 2px #35191a08; }
.panel h2 { font: 29px/.95 var(--serif); display: flex; align-items: center; gap: 8px; }
.panel h2 .icon { color: var(--accent); width: 16px; height: 16px; }
.timers { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.timer { min-width: 0; display: flex; flex-direction: column; gap: 7px; padding: 9px 10px; background: var(--inset); border: 1px solid var(--stroke); border-radius: 7px; }
.timer span, .mate-stat span { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.timer .icon, .mate-stat .icon { color: var(--accent); width: 15px; height: 15px; }
.timer output { font: clamp(18px, 2.5vw, 27px)/1.1 var(--mono); letter-spacing: -.05em; }
.timer output.long { font-size: clamp(14px, 1.65vw, 22px); }
.mate-stat { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; padding: 9px 10px 0; border-top: 1px solid var(--stroke); }
.mate-stat output { font: 20px/1 var(--mono); color: var(--accent); }
.section-top { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.mode-label { color: var(--accent); font-size: 11px; font-weight: 720; padding: 4px 6px; border: 1px solid var(--stroke); border-radius: 5px; background: var(--inset); }
.checkpoint-panel p, .history-panel p { margin-top: 10px; font-size: 13px; line-height: 1.45; color: var(--muted); }
.checkpoint-detail { display: flex; align-items: center; gap: 8px; margin-top: 12px; padding: 9px 10px; font-size: 12px; font-weight: 720; background: var(--inset); border-radius: 6px; }
.checkpoint-panel .button { margin-top: 9px; width: 100%; }
.history-panel { min-height: 103px; }
.history-panel ol { padding: 0; margin: 11px 0 0; list-style: none; max-height: 125px; overflow: auto; scrollbar-color: var(--stroke) transparent; }
.history-panel li { display: grid; grid-template-columns: 36px 1fr 1fr; align-items: center; padding: 2px 8px; font: 12px var(--mono); }
.history-panel li:nth-child(odd) { background: var(--inset); border-radius: 4px; }
.history-panel li > span:first-child { color: var(--muted); }
.history-move { justify-self: start; max-width: 100%; min-height: 28px; padding: 2px 6px; border: 1px solid transparent; border-radius: 4px; background: none; color: var(--text); font: inherit; }
.history-move:hover, .history-controls .icon-button { background: var(--inset); }
.history-move[aria-current] { border-color: var(--accent); background: var(--inset); color: var(--accent); }
.history-move:focus-visible, .history-controls :focus-visible { outline-offset: -2px; }
.history-controls { display: flex; align-items: center; gap: 5px; margin-top: 9px; }
.history-move, .history-controls button { touch-action: manipulation; }
.history-controls .button { margin-left: auto; min-height: 34px; padding-block: 4px; }

.footer { width: var(--game-width); margin: 19px auto 0; padding: 12px 0 16px; border-top: 1px solid var(--stroke); display: flex; justify-content: space-between; gap: 10px; color: var(--muted); font-size: 12px; }
dialog { width: min(435px, calc(100% - 32px)); max-height: calc(100% - 32px); padding: 23px; border: 1px solid var(--stroke); border-radius: 13px; background: var(--panel); color: var(--text); box-shadow: 0 22px 90px #230e0ca0; }
dialog::backdrop { background: #30181688; backdrop-filter: blur(3px); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.dialog-head h2 { font: 43px/.95 var(--serif); }
.icon-button { min-height: 34px; width: 34px; padding: 0; }
.field { display: block; margin: 18px 0 0; padding: 0; border: 0; min-width: 0; }
.field-label, .field legend { color: var(--text); font-weight: 730; font-size: 14px; padding: 0; }
.field-label { display: flex; justify-content: space-between; gap: 10px; }
.field-label output { color: var(--accent); font: 13px var(--mono); }
.field-hint { display: block; color: var(--muted); font-size: 12px; margin-top: 7px; line-height: 1.4; }
.custom-board-sounds { margin-top: 10px; padding: 8px 10px; border: 1px solid var(--stroke); border-radius: 7px; font-size: 12px; }
.custom-board-sounds summary { cursor: pointer; font-weight: 680; }
.custom-sound { display: grid; gap: 5px; margin-top: 10px; }
.custom-sound label { font-weight: 680; }
.custom-sound input { width: 100%; min-width: 0; }
.custom-sound .field-hint { margin: 0; overflow-wrap: anywhere; }
.custom-sound .button { justify-self: start; min-height: 28px; padding: 3px 8px; font-size: 11px; }
input[type="range"] { width: 100%; margin: 11px 0; accent-color: var(--action); }
input[type="checkbox"] { accent-color: var(--action); }
input[type="number"], select { width: 100%; display: block; height: 40px; margin-top: 7px; padding: 0 10px; border: 1px solid var(--stroke); border-radius: 7px; color: var(--text); background: var(--inset); }
.elo-heading { display: flex; justify-content: space-between; align-items: center; }
.elo-heading input { width: 82px; height: 34px; margin: 0; text-align: center; font-family: var(--mono); }
.elo-scale { display: flex; justify-content: space-between; color: var(--muted); font: 12px var(--mono); }
.draw-reason { margin-top: 14px; font-size: 15px; }
.select-wrap { display: block; position: relative; }
.select-wrap select { appearance: none; padding-right: 35px; }
.select-wrap .icon { position: absolute; right: 9px; top: 11px; pointer-events: none; }
.settings-actions, .dialog-actions { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.dialog-actions { justify-content: flex-end; margin-top: 20px; }
#draw-dialog .dialog-actions { flex-wrap: wrap; }
.check { display: flex; align-items: center; gap: 5px; font-size: 13px; }
.palettes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 8px; }
.palette { display: grid; justify-items: center; gap: 5px; position: relative; padding: 8px 4px; border: 1px solid var(--stroke); border-radius: 7px; cursor: pointer; font-size: 12px; }
.palette input { position: absolute; opacity: 0; }
.palette:has(:checked) { border-color: var(--accent); background: var(--inset); }
.palette:has(:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.swatch { width: 29px; aspect-ratio: 1; border-radius: 4px; background: conic-gradient(var(--a) 25%, var(--b) 0 50%, var(--a) 0 75%, var(--b) 0); border: 1px solid #392a2140; }
.swatch.walnut { --a: #e9d1aa; --b: #a7795b; }
.swatch.sage { --a: #e9e4c7; --b: #7a916d; }
.swatch.slate { --a: #e2e8ec; --b: #788da3; }
.swatch.rose { --a: #f1d6cc; --b: #ae737d; }
.promotion-choices { display: flex; gap: 8px; margin-top: 16px; }
.promotion-choices button { min-width: 0; flex: 1; padding: 4px; border: 1px solid var(--stroke); background: var(--inset); border-radius: 6px; }
.promotion-choices button:hover { border-color: var(--accent); }
.promotion-choices img { width: 100%; vertical-align: middle; }
.credits { margin: 45px auto; max-width: 640px; }
.credits h1 { font: 60px/1 var(--serif); }
.credits p, .credits li { font-size: 15px; line-height: 1.55; }
.credits h1, .credits li { margin-bottom: 12px; }

@media (max-width: 950px) {
  .game-layout { grid-template-columns: minmax(0, 1.6fr) minmax(245px, 1fr); column-gap: 20px; }
}
@media (max-width: 690px) {
  .topbar-inner, .page, .footer { width: calc(100% - 30px); }
  .topbar-inner { min-height: 61px; gap: 6px; }
  .wordmark { font-size: 23px; gap: 6px; }
  .brand-icon { width: 30px; height: 30px; border-radius: 6px; }
  .brand-icon img { width: 23px; height: 23px; }
  .toolbar { gap: 3px; }
  .toolbar .button { min-height: 34px; padding: 6px 8px; font-size: 11px; gap: 4px; }
  .toolbar .icon { width: 13px; height: 13px; }
  #new-game { white-space: normal; max-width: 132px; line-height: 1.15; }
  .intro { padding: 0; }
  .intro h1 { font-size: clamp(49px, 11vw, 68px); }
  .intro p { margin-top: 8px; font-size: 13px; }
  .game-layout { display: flex; flex-direction: column; gap: 15px; padding-top: 21px; }
  .play-area, .sidebar { width: 100%; }
  body[data-victory-open] .play-area { width: 94%; align-self: center; }
  .sidebar .history-panel { order: -1; }
  .board-shell { padding: 5px; }
  .timer output { font-size: 25px; }
}
@media (max-width: 420px) {
  #new-game .icon { display: none; }
}
@media (max-width: 355px) {
  .toolbar .icon, .brand-icon { display: none; }
  .wordmark { font-size: 21px; }
}
