:root {
  color-scheme: dark;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: #141e1a;
  color: #f5f2e8;
  --muted: #bac9bf;
  --line: #43564c;
  --accent: #e6bb73;
  --panel: #1d2b24;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid #ffcb73; outline-offset: 3px; }
.masthead {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 70px; padding: 12px max(22px, calc((100% - 1080px) / 2)); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; font-weight: 700; white-space: nowrap; }
.logo { background: var(--accent); color: #241c12; font-size: 24px; width: 36px; height: 36px; border-radius: 9px; text-align: center; }
.engine-tag, .eyebrow { font-size: .72rem; font-weight: 750; letter-spacing: .13em; color: var(--accent); }
.engine-tag { border: 1px solid var(--line); padding: 7px 10px; border-radius: 20px; text-align: center; }
main { max-width: 1124px; padding: 35px 22px 50px; margin: auto; }
.intro { margin-bottom: 26px; }
h1, h2, p { margin: 0; }
h1 { margin: 5px 0 7px; font: 600 clamp(2.1rem, 5vw, 3.5rem)/1.08 Georgia, serif; letter-spacing: -.035em; }
h2 { margin: 3px 0 8px; font: 600 1.55rem/1.15 Georgia, serif; }
p { line-height: 1.5; color: var(--muted); }
.workspace { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); gap: 23px; align-items: start; }
.board-panel, .card { border: 1px solid var(--line); border-radius: 16px; background: var(--panel); }
.board-panel { padding: 15px; }
.board-heading, .board-footer { display: flex; justify-content: space-between; align-items: center; gap: 8px; color: var(--muted); font-size: .88rem; }
.board-heading { margin-bottom: 12px; }
.board-footer { margin-top: 12px; min-height: 28px; }
.board-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px; }
#turn-badge { color: #f3e0bc; background: #35453b; border-radius: 20px; padding: 5px 10px; }
.board-frame { position: relative; overflow: hidden; border-radius: 7px; }
.board {
  display: grid;
  grid-template: repeat(8, minmax(0, 1fr)) / repeat(8, minmax(0, 1fr));
  aspect-ratio: 1;
  container-type: inline-size;
}
.square { padding: 0; border: 0; position: relative; display: grid; place-items: center; min-width: 0; min-height: 0; }
.square:focus-visible { outline-offset: -4px; z-index: 1; }
.square.light { background: #e1ddc4; color: #324c40; }
.square.dark { background: #64816b; color: #fff8e5; }
.square.last { box-shadow: inset 0 0 0 100px #e4b54055; }
.square.marked { box-shadow: inset 0 0 0 100px #edab3d99; }
.square:not(:disabled):hover { box-shadow: inset 0 0 0 3px #f8c978; }
.square::before, .square::after { position: absolute; font-size: clamp(8px, 2.1cqw, 13px); font-weight: 700; }
.square[data-rank]::before { content: attr(data-rank); top: 2px; left: 4px; }
.square[data-file]::after { content: attr(data-file); bottom: 2px; right: 4px; }
.destination .piece { border-radius: 50%; box-shadow: 0 0 0 3px #17352dbb; }
.destination:not(:has(.piece)) { background-image: radial-gradient(circle, #17352d88 0 14%, transparent 15%); }
.piece { font: 9.9cqw/1 "Segoe UI Symbol", "DejaVu Sans", sans-serif; }
.piece.w { color: #fff8e9; -webkit-text-stroke: 1px #273328; text-shadow: 0 2px 2px #0008; }
.piece.b { color: #16221e; -webkit-text-stroke: .5px #e4e0d0; text-shadow: 0 2px 2px #0006; }
.cracked-king { display: grid; }
.king-fragment {
  grid-area: 1 / 1;
  transform: translate(var(--split-x), var(--split-y)) rotate(var(--split-angle));
}
.king-fragment.left {
  clip-path: polygon(0 0, 54% 0, 47% 32%, 56% 43%, 45% 56%, 53% 68%, 43% 100%, 0 100%);
  --split-x: -.055em;
  --split-y: .02em;
  --split-angle: -8deg;
}
.king-fragment.right {
  clip-path: polygon(54% 0, 100% 0, 100% 100%, 43% 100%, 53% 68%, 45% 56%, 56% 43%, 47% 32%);
  --split-x: .06em;
  --split-y: .06em;
  --split-angle: 10deg;
}
@media (prefers-reduced-motion: no-preference) {
  .cracking .king-fragment { animation: king-crack 650ms ease-out; }
}
@keyframes king-crack {
  0%, 24% { transform: none; }
  15% { transform: translateY(-.06em); }
  55% { transform: translate(calc(var(--split-x) * 1.35), var(--split-y)) rotate(var(--split-angle)); }
}
.overlay { position: absolute; inset: 0; width: 100%; height: 100%; color: #9b5008; pointer-events: none; opacity: .9; }
.sidebar { display: grid; gap: 15px; }
.card { padding: 22px; }
.side-buttons, .choices { display: grid; gap: 9px; margin-top: 17px; }
.choices:empty { display: none; }
.primary, .secondary, .choice, input, select {
  min-height: 43px; border-radius: 8px; border: 1px solid transparent; padding: 8px 12px; font-weight: 650;
}
.primary { color: #251b0f; background: var(--accent); }
.primary:hover:not(:disabled) { background: #f4ce91; }
.primary:disabled { opacity: .48; }
.secondary, .choice, input, select { border-color: var(--line); background: #27382f; color: #f5f2e8; }
.secondary:hover, .choice:hover, .choice[aria-pressed="true"] { border-color: var(--accent); }
.side-buttons button { text-align: left; }
.side-buttons span { margin-right: 7px; font-size: 1.2rem; }
.text-button { color: var(--accent); background: none; border: 0; padding: 5px; text-decoration: underline; }
form { margin-top: 16px; }
label { display: block; margin-bottom: 6px; font-size: .9rem; font-weight: 650; }
.input-row { display: flex; gap: 7px; }
input, select { min-width: 0; flex: 1; }
input::placeholder { color: var(--muted); }
#error { color: #ffc8a9; margin-top: 10px; }
.choice { display: grid; grid-template-columns: 26px 1fr auto; align-items: center; gap: 10px; text-align: left; }
.choice[aria-pressed="true"] { background: #423922; }
.rank { background: #17241e; text-align: center; border-radius: 5px; font-size: .82rem; padding: 3px; }
.evaluation { color: var(--accent); font-variant-numeric: tabular-nums; }
.commit, #retry { margin-top: 13px; width: 100%; }
.history-card h2 { font-size: 1.3rem; }
#history { max-height: 150px; overflow: auto; font-size: .94rem; }
#history ol { margin: 0; padding-left: 30px; }
#history li { padding: 4px 0; }
#history li::marker { color: var(--muted); }
#history li span { display: inline-block; width: 44%; }
@media (max-width: 760px) {
  main { padding-top: 23px; }
  .workspace { grid-template-columns: minmax(0, 1fr); max-width: 590px; margin: auto; }
  .board-panel { padding: 9px; }
  .card { padding: 17px; }
}
