:root {
  color-scheme: light;
  --paper: #f4eee3;
  --ink: #382719;
  --muted: #665449;
  --line: #9c8977;
  --green: #304c36;
  --ivory: #fff8eb;
  --serif: Georgia, "Noto Serif", serif;
  --sans: Roboto, system-ui, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.35 var(--sans);
}
#app { max-width: 460px; margin: auto; padding: 18px 22px 24px; }
#app[data-screen=home] { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }
#app[data-screen=home] > .footer { margin-top: auto; padding-top: 24px; }
h1, h2, p { margin: 0; }
h1, h2 { font-family: var(--serif); line-height: 1.12; }
h1 { font-size: clamp(29px, 7.5vw, 36px); }
h2 { font-size: 25px; }
.hero { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 19px 0 15px; }
.hero h1 { font-size: clamp(39px, 12vw, 61px); letter-spacing: -.05em; }
.hero img { width: clamp(46px, 14vw, 64px); height: 64px; object-fit: contain; }
.hero-rule { width: 48%; border-top: 1px solid var(--line); margin: 0 auto 28px; }
.page-head { position: relative; display: grid; align-items: center; text-align: center; min-height: 54px; margin-bottom: 20px; padding: 0 42px; }
.page-head.game-head { margin-bottom: 7px; }
.back {
  position: absolute; left: -9px; top: 0; width: 44px; height: 44px;
  border: 0; background: transparent;
}
.back::before, .back::after { position: absolute; top: 21px; left: 13px; content: ""; }
.back::before { width: 21px; height: 2px; background: currentColor; }
.back::after { width: 11px; height: 11px; border-left: 2px solid; border-bottom: 2px solid; transform: translateY(-45%) rotate(45deg); }
.code-button { min-height: 28px; font-size: 17px; color: var(--muted); border: 0; background: transparent; padding: 0 10px; }
.field { display: grid; gap: 7px; margin: 0 0 19px; }
label, legend { font-weight: 680; }
input, button { font: inherit; color: inherit; }
input {
  width: 100%; min-width: 0; min-height: 49px; padding: 10px 15px;
  border: 1px solid var(--line); border-radius: 11px; background: #ffffff37;
}
button { cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: default; opacity: .58; }
button:focus-visible, input:focus-visible { outline: 3px solid #6f8e71; outline-offset: 2px; }
.action {
  display: inline-flex; align-items: center; justify-content: center; width: 100%;
  min-height: 53px; padding: 10px 12px; border: 1.5px solid var(--ink);
  border-radius: 12px; background: transparent; font-family: var(--serif);
  font-weight: bold; font-size: clamp(19px, 5.4vw, 25px); line-height: 1.15;
}
.primary { background: var(--green); color: var(--ivory); border-color: var(--green); }
.stack { display: grid; gap: 12px; }
.saved { margin-top: 26px; border-top: 1px solid var(--line); padding-top: 17px; }
.saved h2 { margin-bottom: 8px; }
.saved ul { list-style: none; padding: 0; margin: 0; }
.saved li + li { border-top: 1px solid #bba78f; }
.saved-row {
  display: grid; grid-template-columns: 61px minmax(0, 1fr) 13px;
  gap: 14px; align-items: center; text-align: left; width: 100%; padding: 10px 0;
  border: 0; background: transparent;
}
.saved-row strong { display: block; font: bold 22px/1.1 var(--serif); overflow-wrap: anywhere; }
.saved-row small, .muted, .fine { color: var(--muted); }
.saved-row small { display: block; margin-top: 4px; }
.mini-board {
  width: 59px; aspect-ratio: 1; border-radius: 5px; border: 3px solid #815735;
  display: grid; grid-template: repeat(8, 1fr) / repeat(8, 1fr); overflow: hidden;
}
.mini-board img { display: block; width: 100%; height: 100%; object-fit: contain; }
.fine { text-align: center; font-size: 14px; margin-top: 18px; }
.text-button { padding: 8px; min-height: 40px; border: 0; background: transparent; color: var(--muted); text-decoration: underline; }
.footer { text-align: center; margin-top: 30px; }
.footer .fine { margin-top: 0; }
.empty { padding: 10px 0; color: var(--muted); }
fieldset { margin: 0 0 19px; padding: 0; border: 0; min-width: 0; }
legend { padding: 0; margin-bottom: 8px; }
.options { display: flex; align-items: stretch; border: 1px solid var(--line); border-radius: 11px; }
.option {
  flex: 1 1 0; min-height: 46px; min-width: 0; padding: 7px 3px;
  border: 0; border-radius: 10px; background: transparent; font-size: clamp(12px, 3.8vw, 17px);
}
.option + .option { border-left: 1px solid #bba78f; }
.option[aria-pressed=true] { color: var(--ivory); background: var(--green); border-color: var(--green); font-weight: 670; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); margin: 15px 0; }
.divider::before, .divider::after { content: ""; height: 1px; background: var(--line); flex: 1; }
#room { text-transform: uppercase; }
.error { margin-top: 12px; color: #842e20; overflow-wrap: anywhere; }
.player { display: flex; align-items: center; gap: 8px; min-height: 44px; margin: 5px 0; }
.player img { width: 31px; height: 33px; object-fit: contain; }
.player strong { font: bold 22px/1.1 var(--serif); flex: 1; min-width: 0; overflow-wrap: anywhere; }
.clock { padding: 3px 8px; min-width: 64px; border: 1px solid var(--line); border-radius: 8px; text-align: center; font-weight: 750; font-size: 23px; font-variant-numeric: tabular-nums; }
.clock[data-running=true] { background: var(--green); color: var(--ivory); border-color: var(--green); }
.board-shell {
  margin: 5px -14px;
  display: grid; aspect-ratio: 1; grid-template: 19px minmax(0, 1fr) 19px / 18px minmax(0, 1fr) 18px;
  border-radius: 11px; border: 2px solid #59371f;
  background: #6b4328 url('./art/walnut.webp') center / 100% auto;
  overflow: hidden; box-shadow: 0 3px 8px #5538203b; color: #fff4d9;
}
.files, .ranks { display: grid; text-align: center; place-items: center; font: 12px/1 var(--serif); }
.files { grid-template-columns: repeat(8, 1fr); grid-column: 2; }
.ranks { grid-template-rows: repeat(8, 1fr); grid-row: 2; }
.file-top { grid-row: 1; } .file-bottom { grid-row: 3; }
.rank-left { grid-column: 1; } .rank-right { grid-column: 3; }
.board {
  grid-column: 2; grid-row: 2; display: grid; grid-template: repeat(8, 1fr) / repeat(8, 1fr);
  box-shadow: 0 0 0 1px #472d18; overflow: hidden;
}
.square { min-width: 0; min-height: 0; position: relative; isolation: isolate; display: grid; place-items: center; padding: 0; border: 0; }
.light { background: #dfbd88 url('./art/oak.webp') center / cover; }
.dark { background: #9a6b45 url('./art/medium.webp') center / cover; }
.square img { pointer-events: none; width: 100%; height: 98%; min-height: 0; object-fit: contain; align-self: end; padding-bottom: 2%; }
.square.last::before, .square.selected::before, .square.check::before { content: ""; position: absolute; inset: 0; z-index: -1; }
.square.last::before { background: #e8ba3199; }
.square.selected::before { background: #dced6a9c; box-shadow: inset 0 0 0 2px #5e7125; }
.square.check::before { background: #b4242294; }
.square.legal::after { content: ""; position: absolute; width: 24%; aspect-ratio: 1; pointer-events: none; border-radius: 50%; background: #294432aa; }
.square.legal.capture::after { width: 86%; background: transparent; border: 3px solid #294432aa; }
.square:focus-visible { z-index: 1; outline-offset: -3px; }
.turn { padding: 8px; border-radius: 9px; background: #dbc39f; color: #28442d; text-align: center; font: bold 21px/1.2 var(--serif); }
.moves { padding: 8px 11px; margin: 10px 0 0; border: 1px solid #c8b090; border-radius: 9px; font-variant-numeric: tabular-nums; max-height: 70px; overflow: auto; }
.moves span { display: inline-block; margin-right: 12px; }
.game-actions { display: flex; gap: 10px; margin-top: 14px; }
.game-actions .action { min-height: 45px; font: 650 16px/1.2 var(--sans); }
.wait-panel { margin-top: 15px; }
.wait-panel .action { margin-top: 9px; }
dialog { color: var(--ink); background: var(--paper); border: 1px solid var(--line); border-radius: 15px; width: min(390px, calc(100% - 34px)); padding: 20px; }
dialog::backdrop { background: #23170e80; }
dialog h2 { margin-bottom: 12px; }
dialog p { margin-bottom: 12px; }
.promotion { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 12px; }
.promotion button { padding: 4px; background: #e1c69e; border: 1px solid var(--line); border-radius: 8px; }
.promotion img { display: block; height: 49px; width: 100%; object-fit: contain; }
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); width: max-content; max-width: calc(100% - 36px); z-index: 2; padding: 10px 14px; background: var(--ink); color: var(--ivory); border-radius: 8px; text-align: center; }
@media (max-width: 360px) {
  #app { padding-inline: 16px; }
  .board-shell { margin-inline: -8px; }
  .player strong { font-size: 20px; }
}
