:root {
  color-scheme: light;
  --paper: #f4eee3;
  --surface: #fffbf2;
  --ink: #1a3736;
  --muted: #4b6460;
  --line: #dcd6c7;
  --teal: #23544e;
  --clay: #914a30;
  font: 15px/1.45 system-ui, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; color: var(--ink); background: radial-gradient(ellipse at 78% 0, #fbf6eb, transparent 52%), var(--paper); }
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { opacity: .48; cursor: default; }
button:focus-visible { outline: 2px solid #ac5c28; outline-offset: 3px; }
button, .board-card, .match-card { border: 1px solid var(--line); }
button { min-height: 37px; border-radius: 7px; padding: .35rem .75rem; background: var(--surface); font-size: .86rem; font-weight: 650; white-space: nowrap; }
button:hover:not(:disabled) { background: #e8ede2; }
button[aria-pressed="true"], .primary { color: #fff8ea; background: var(--teal); border-color: var(--teal); }
button[aria-pressed="true"]:hover:not(:disabled), .primary:hover:not(:disabled) { background: #23665a; }
.quiet { background: transparent; border-color: transparent; }
.quiet span { margin-left: .2rem; color: #975325; }
.masthead { display: flex; align-items: center; justify-content: space-between; padding: .7rem max(1rem, calc((100% - 1190px)/2)); border-bottom: 1px solid var(--line); background: #f9f3e9; }
main { max-width: 1222px; margin: 0 auto; padding: 0 16px 24px; }
.intro { display: flex; align-items: baseline; gap: 1.2rem; margin: 1rem 0 1.1rem; }
h1, h2 { font-family: Georgia, serif; font-weight: 500; }
h1 { font-size: clamp(2.5rem, 5.5vw, 4.25rem); letter-spacing: -.055em; margin: 0; line-height: 1.05; }
.intro p::before { content: ""; display: inline-block; width: 6px; height: 6px; margin: 0 .52rem .13rem 0; border-radius: 50%; background: var(--clay); }
h1 em { color: var(--clay); font-weight: inherit; }
.intro p { margin: 0; color: var(--muted); }
.game { display: grid; grid-template-columns: minmax(0, 1fr) minmax(245px, 285px); gap: 15px; align-items: stretch; }
.board-card, .match-card { background: var(--surface); border-radius: 13px; box-shadow: 0 6px 18px #44312714; overflow: hidden; }
.board-card { border-color: #263d3b; }
.board-toolbar, .board-footer, .camera-extra { display: flex; align-items: center; justify-content: space-between; gap: 5px; padding: 7px 10px; }
.board-toolbar, .board-footer, .camera-extra { background: #223c3a; color: #f6ebd8; }
.board-toolbar button, .camera-extra button { background: #2e4945; border-color: #5b7168; }
.board-toolbar button:hover:not(:disabled), .board-footer button:hover:not(:disabled), .camera-extra button:hover:not(:disabled) { background: #3e5a54; }
.board-toolbar button[aria-pressed="true"], .camera-extra button[aria-pressed="true"] { background: #e9d4ae; border-color: #e9d4ae; color: #203a39; }
.board-toolbar button[aria-pressed="true"]:hover:not(:disabled), .camera-extra button[aria-pressed="true"]:hover:not(:disabled) { background: #f9e4bd; }
.board-card button:focus-visible { outline-color: #f4cc82; }
.presets, .view-actions { display: flex; gap: 4px; }
.view-actions button { min-width: 33px; }
.board-footer { color: #dedfce; font-size: .79rem; padding-block: 3px; }
.board-footer .quiet span { color: #e9c890; }
.camera-extra { justify-content: flex-end; flex-wrap: wrap; border-top: 1px solid #526860; }
.stage { position: relative; height: clamp(410px, calc(100svh - 252px), 720px); isolation: isolate; background: #4e696a; }
#viewport, #grid { position: absolute; inset: 0; }
#viewport canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; }
#viewport canvas:active { cursor: grabbing; }
#grid { pointer-events: none; overflow: hidden; }
.square { position: absolute; width: 1px; height: 1px; min-height: 0; padding: 0; overflow: hidden; opacity: 0; top: 50%; left: 50%; }
#hover-label { position: absolute; top: 8px; left: 50%; transform: translateX(-50%); width: max-content; max-width: calc(100% - 16px); text-align: center; padding: .38rem .7rem; border-radius: 6px; background: #143a34; color: #fff9ee; pointer-events: none; box-shadow: 0 2px 10px #13241e46; font-size: .83rem; }
#webgl-error { color: white; padding: 1rem; }
.match-card { display: flex; flex-direction: column; padding: 18px; min-height: 0; }
.mode, h3 { margin: 0; font-size: .73rem; font-weight: 800; letter-spacing: .09em; text-transform: uppercase; }
.mode { color: var(--clay); }
.turn { display: flex; align-items: flex-start; gap: 10px; margin: 13px 0 15px; border: 1px solid #e6dbc5; border-radius: 9px; padding: 11px 10px; background: #f5ecdb; }
.turn h2, .dialog-head h2 { margin: 0; font-size: 1.65rem; line-height: 1.1; }
.turn p, .piece-panel p, .history p { margin: .3rem 0 0; color: var(--muted); font-size: .86rem; }
.side-marker { width: 15px; height: 15px; flex: 0 0 15px; margin-top: 6px; border-radius: 50%; background: #f3dcb1; border: 1px solid #886443; }
.side-marker.dark { background: #1b5c54; border-color: #1b5c54; }
.piece-panel, .history { border-top: 1px solid var(--line); padding: 12px 0; }
.piece-panel { min-height: 82px; }
.piece-panel #piece-name { color: var(--ink); }
.history { flex: 1; }
#history { list-style: none; padding: 0; margin: .5rem 0 0; max-height: 165px; overflow: auto; }
#history li { display: grid; grid-template-columns: 2rem 1fr 1fr; padding: .21rem .37rem; font-size: .88rem; font-variant-numeric: tabular-nums; }
#history li:nth-child(odd) { background: #f1f1e7; }
.match-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.match-actions .primary { margin-left: auto; }
dialog { width: min(520px, calc(100% - 24px)); max-height: 85svh; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 13px; padding: 18px; }
dialog::backdrop { background: #102e2bd0; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.dialog-head button { font-size: 1.1rem; }
#guide-list { list-style: none; padding: 0; margin: .75rem 0 0; }
#guide-list li { display: grid; grid-template-columns: 2.4rem 1fr; align-items: center; border-top: 1px solid var(--line); padding: .55rem 0; }
#guide-list span { font-size: 1.55rem; }
#guide-list p { margin: .15rem 0 0; color: var(--muted); font-size: .86rem; }
#choice-actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: 1rem; }
@media (pointer: coarse) { button { min-height: 42px; } }
@media (max-width: 720px) {
  main { padding-inline: 8px; }
  .intro { display: block; margin: .85rem 6px; }
  .intro p { margin-top: .27rem; }
  .game { grid-template-columns: 1fr; gap: 9px; }
  .stage { height: clamp(345px, 105vw, 570px); }
  .match-card { padding: 13px; }
  .board-toolbar, .board-footer, .camera-extra { padding-inline: 6px; }
  .board-toolbar button { padding-inline: .5rem; }
}
@media (max-height: 530px) and (orientation: landscape) {
  .stage { height: max(300px, 78svh); }
}
@media (max-width: 350px) {
  .board-toolbar { flex-wrap: wrap; }
}
