:root {
  color-scheme: dark;
  --page: #151815;
  --panel: #20241f;
  --line: #373e34;
  --ink: #f5efdf;
  --muted: #b8baaa;
  --gold: #dfbc7d;
  --light-square: #ceba97;
  --dark-square: #667465;
  --body: "DM Sans", system-ui, sans-serif;
  --display: "Instrument Serif", Georgia, serif;
  --mono: "IBM Plex Mono", monospace;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  min-width: 280px;
  color: var(--ink);
  font: 15px var(--body);
  background: radial-gradient(ellipse at 30% 15%, #292f26 0%, var(--page) 62%) fixed;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { opacity: .46; cursor: default; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }
.masthead {
  height: 66px; padding: 0 max(24px, calc((100vw - 1080px) / 2));
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  border-bottom: 1px solid var(--line);
}
.wordmark, .mode { display: flex; gap: 9px; align-items: center; font: 500 11px var(--mono); letter-spacing: .13em; }
.wordmark img { width: 22px; height: 32px; object-fit: contain; }
.wordmark span, .mode { color: var(--muted); }
i { width: 6px; height: 6px; display: inline-block; background: var(--gold); border-radius: 50%; }
main { max-width: 1080px; margin: auto; padding: 25px 0 32px; }
.intro { display: flex; align-items: baseline; gap: 20px; margin-bottom: 18px; }
h1 { margin: 0; font: 400 clamp(49px, 6.7vw, 88px)/.98 var(--display); letter-spacing: -.025em; }
h1 em { color: var(--gold); font-weight: 400; }
p { margin: 0; }
.intro p { color: var(--muted); }
.match { display: grid; grid-template-columns: minmax(0, 660px) minmax(275px, 1fr); gap: 40px; align-items: start; }
.table { min-width: 0; }
.player { display: flex; gap: 11px; align-items: center; min-height: 55px; padding: 5px 1px; }
.player > img { width: 36px; height: 36px; object-fit: contain; background: #424b3e; padding: 4px; border: 1px solid #566150; border-radius: 50%; }
.player strong, .player small { display: block; }
.player small { color: var(--muted); font-size: 11px; margin-top: 1px; }
.captures { display: flex; margin-left: auto; flex-wrap: wrap; justify-content: end; }
.captures img { width: 17px; height: 22px; object-fit: contain; object-position: bottom; }
.board-frame {
  padding: 9px; background: #2c352a;
  border: 1px solid #4e5947; border-radius: 6px;
}
#board { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); grid-template-rows: repeat(8, minmax(0, 1fr)); aspect-ratio: 1; overflow: hidden; }
.square { position: relative; display: grid; place-items: center; min-width: 0; padding: 0; border: 0; isolation: isolate; }
.square.light { background: var(--light-square); color: #384537; }
.square.dark { background: var(--dark-square); color: #fff0d4; }
.square.last { box-shadow: inset 0 0 0 100px #dfbc7d58; }
.square.selected { box-shadow: inset 0 0 0 3px #fff0b7, inset 0 0 0 100px #f3c86b73; }
.square.check { background: #aa6357; }
.square:focus-visible { outline: 3px solid #fff4c7; outline-offset: -3px; z-index: 1; }
.square img { position: absolute; bottom: 7%; width: 89%; height: 87%; object-fit: contain; object-position: bottom; pointer-events: none; filter: drop-shadow(0 3px 2px #15181570); }
.square img.pawn { height: 68%; }
.square img.tall { height: 93%; }
.square img.black { filter: brightness(1.2) drop-shadow(0 3px 2px #11151085); }
.coord { position: absolute; z-index: 2; font: 500 clamp(8px, 1vw, 11px) var(--mono); pointer-events: none; }
.rank { left: 4px; top: 3px; }
.file { right: 4px; bottom: 2px; }
.square.target::after { content: ""; width: 22%; aspect-ratio: 1; border-radius: 50%; background: #15231880; z-index: 1; pointer-events: none; }
.square.target.occupied::after { width: 87%; background: transparent; border: 3px solid #fff0b7; }
.panel { border: 1px solid var(--line); border-radius: 7px; background: var(--panel); margin-top: 55px; overflow: hidden; }
.panel section, .actions { padding: 21px 22px; }
.panel section + section, .actions { border-top: 1px solid var(--line); }
h2 { margin: 9px 0 4px; font: 400 42px/1 var(--display); }
.match-status p { color: var(--muted); font-size: 13px; min-height: 2.8em; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend, h3 { font-size: 13px; font-weight: 700; margin: 0 0 10px; padding: 0; }
.levels { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 3px; background: var(--page); padding: 4px; border-radius: 5px; }
.levels label { position: relative; cursor: pointer; text-align: center; }
.levels input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.levels span { display: block; padding: 7px 3px; border-radius: 3px; color: var(--muted); font-size: 13px; }
.levels input:checked + span { background: #3a4736; color: #f8edcf; }
.levels input:focus-visible + span { outline: 2px solid var(--gold); outline-offset: 1px; }
.history { min-height: 176px; }
.history-head { display: flex; justify-content: space-between; }
#move-count, #moves { font: 12px var(--mono); }
#move-count, #empty { color: var(--muted); }
#empty { font-size: 13px; margin-top: 6px; }
#moves { padding: 0; margin: 0; list-style: none; max-height: 126px; overflow: auto; }
#moves li { display: grid; grid-template-columns: 2.75em 1fr 1fr; gap: 8px; padding: 6px 4px; }
#moves li:nth-child(odd) { background: #ffffff06; }
#moves li span:first-child { color: var(--muted); }
.actions { display: grid; grid-template-columns: 1fr 1.2fr; gap: 8px; }
.primary, .secondary { border: 1px solid var(--line); border-radius: 4px; min-height: 42px; padding: 7px; font-size: 13px; font-weight: 700; }
.secondary { background: #282e26; }
.primary { background: var(--gold); color: #252014; border-color: var(--gold); }
.actions span { margin-right: 4px; font-size: 16px; }
button:not(:disabled):hover { filter: brightness(1.08); }
dialog { width: min(90vw, 420px); color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 24px; }
dialog::backdrop { background: #0b100ac4; }
#promotion-options { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 16px 0; }
#promotion-options button { background: #354032; border: 1px solid var(--line); border-radius: 4px; padding: 7px 2px; font-size: 11px; }
#promotion-options img { display: block; width: 100%; height: 55px; object-fit: contain; margin-bottom: 4px; }
@media (max-width: 1130px) { main { margin-inline: 24px; } }
@media (max-width: 800px) {
  .match { grid-template-columns: 1fr; gap: 16px; }
  main { max-width: 615px; margin-inline: auto; padding-inline: 14px; }
  .panel { margin: 0; }
  .intro { display: block; margin-bottom: 8px; }
  .intro p { margin-top: 7px; }
  .masthead { padding-inline: 15px; height: 54px; }
  .board-frame { padding: 5px; }
}
@media (max-width: 345px) { .mode { letter-spacing: 0; } }

[hidden] { display: none !important; }
.play-controls { display: flex; flex-wrap: wrap; gap: 8px 20px; margin: 0 0 12px; }
.switch-group { display: inline-flex; gap: 3px; padding: 3px; background: var(--page); border: 1px solid var(--line); border-radius: 5px; }
.switch-group button { padding: 8px 12px; min-height: 40px; background: transparent; border: 0; border-radius: 3px; color: var(--muted); font-size: 13px; font-weight: 600; }
.switch-group button[aria-pressed="true"] { background: #3a4736; color: #f8edcf; }
.switch-group button:disabled { cursor: default; }
.lobby.panel { margin: 10px 0 12px; padding: 18px 22px; }
.lobby-heading { display: flex; justify-content: space-between; gap: 8px 24px; flex-wrap: wrap; align-items: baseline; }
.lobby-heading h2 { margin: 0; font-size: 34px; }
.lobby-controls { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin: 12px 0 16px; }
.lobby-controls form { display: flex; gap: 6px; max-width: 100%; }
.lobby-controls button { padding-inline: 14px; }
#join-code { font: inherit; background: var(--page); border: 1px solid var(--line); color: var(--ink); border-radius: 4px; padding: 8px 10px; width: min(155px, 52vw); min-width: 0; }
#lobby-message, #room-empty, #online-error, #board-help { color: var(--muted); font-size: 13px; }
#board-help { margin: 3px 0 0; }
#room-code { font-family: var(--mono); color: var(--gold); }
#lobby-invite { margin-top: 12px; }
#lobby-invite .lobby-controls { margin-bottom: 0; }
#room-list { margin: 0; padding: 0; list-style: none; max-height: 230px; overflow: auto; }
#room-list li { border-top: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 6px 0; font-family: var(--mono); font-size: 12px; }
#room-list li button { padding-inline: 14px; }
#online-actions { grid-template-columns: 1fr; }
#online-error:empty { display: none; }
#board { touch-action: none; user-select: none; }
.square.marked::before { content: ""; position: absolute; inset: 7%; border: clamp(2px, .4vw, 4px) solid #e33b42; border-radius: 50%; z-index: 3; pointer-events: none; }
.square img.dragging-source { opacity: .25; }
.dragging-piece { position: fixed; z-index: 5; object-fit: contain; pointer-events: none; transform: translate(-50%, -60%); filter: drop-shadow(0 5px 4px #15181590); }
@media (max-width: 410px) {
  .play-controls { gap: 7px; }
  .switch-group button { padding-inline: 8px; }
  .lobby.panel { padding: 14px; }
}
