:root{font-family:system-ui,sans-serif;color:#15120f;background:#faf5ec;color-scheme:light}*{box-sizing:border-box}body{margin:0}main{max-width:940px;margin:auto;padding:clamp(10px,3vw,32px)}button{font:inherit;min-height:44px;padding:10px 16px;border:1px solid #15120f;background:#faf5ec;color:#15120f;cursor:pointer}button:focus-visible{outline:3px solid #f65313;outline-offset:2px}button:disabled{opacity:.5}
.chess-app{max-width:780px;margin:auto}.topline{display:flex;justify-content:space-between;align-items:center;min-height:58px;gap:10px}.topline h1{font-size:clamp(30px,7vw,48px);line-height:1;margin:8px 0;letter-spacing:-.06em}.top-tools{display:flex;align-items:center;gap:10px}.text-button{border:0;text-decoration:underline;background:none}.icon-button{font-size:22px;line-height:1;padding:8px 10px;min-width:44px;border:0;background:transparent;color:#17120f}.sound-icon{display:block;width:23px;height:23px;fill:none;stroke:currentColor;stroke-width:1.8;stroke-linecap:round;stroke-linejoin:round}.connection-dot{width:13px;height:13px;border-radius:50%;display:inline-block;border:0;box-shadow:none}.connection-dot.online{background:#16834a}.connection-dot.offline{background:#c63832}
.players{display:flex;justify-content:space-between;font-weight:750}.player{display:flex;align-items:center;gap:8px;padding:6px 0;border-bottom:2px solid transparent}.player-name{max-width:34vw;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.seat-piece{display:block;width:30px;height:30px;flex:none}.turn-banner{margin:6px 0 2px;padding:8px;background:#f65313;text-align:center;font-size:clamp(16px,3.8vw,25px);font-weight:900;text-transform:uppercase;min-height:52px;display:grid;place-items:center;line-height:1.1;overflow-wrap:anywhere}.feedback{margin:0;min-height:23px;padding:2px 8px;text-align:center;font-size:13px;line-height:19px;color:#a32620}
.board-shell{--coordinate-gutter:clamp(17px,2.8vw,24px);width:100%;margin:0 auto;display:grid;grid-template-columns:var(--coordinate-gutter) minmax(0,1fr);grid-template-rows:minmax(0,1fr) var(--coordinate-gutter)}.board-shell.black{grid-template-columns:minmax(0,1fr) var(--coordinate-gutter)}.board{grid-column:2;grid-row:1;display:grid;grid-template-columns:repeat(8,1fr);width:100%;aspect-ratio:1;border:5px solid #15120f;touch-action:manipulation}.board-shell.black .board{grid-column:1}.rank-coords{grid-column:1;grid-row:1;display:grid;grid-template-rows:repeat(8,1fr);align-items:center;justify-items:center;font-size:clamp(9px,1.8vw,13px);font-weight:750;color:#594131}.board-shell.black .rank-coords{grid-column:2}.file-coords{grid-column:2;grid-row:2;display:grid;grid-template-columns:repeat(8,1fr);align-items:center;justify-items:center;font-size:clamp(9px,1.8vw,13px);font-weight:750;color:#594131}.board-shell.black .file-coords{grid-column:1}
.square{position:relative;display:grid;place-items:center;aspect-ratio:1;min-width:0;min-height:0;padding:0;border:0;border-radius:0;overflow:hidden}.square.light{background:#f4eadb}.square.dark{background:#bd9271}.board-piece{display:block;width:88%;height:88%;pointer-events:none}.square.selected{background:#f5bd78;box-shadow:inset 0 0 0 5px #f65313;z-index:1}.square.last{background-image:linear-gradient(#4b778233,#4b778233);outline:1.5px solid #416b7d;outline-offset:-3px}.square.check-king{background-color:#e2644f;background-image:radial-gradient(circle,#f65313 5%,#e2644f 72%);box-shadow:inset 0 0 0 5px #a32620}.square.selected.check-king{background:#f5bd78;box-shadow:inset 0 0 0 5px #f65313,inset 0 0 0 9px #a32620;z-index:2}.square.threat-pulse{animation:threat-flash 1s ease-out 1}@keyframes threat-flash{0%,35%{background-color:#f65313;filter:brightness(1.2)}100%{background-color:inherit;filter:none}}
.selected-label{font-weight:700;min-height:26px;margin:4px 0;text-align:center}.controls{display:flex;align-items:center;justify-content:center;gap:8px;flex-wrap:wrap;margin:8px 0;min-height:58px}.controls>*{flex:0 1 auto}.primary{background:#15120f;color:white;font-weight:750}.shade{position:fixed;inset:0;background:#0008;display:grid;place-items:center;padding:16px}.dialog{background:#faf5ec;padding:24px;max-width:420px;width:100%;display:flex;gap:10px;flex-wrap:wrap;box-shadow:0 12px 48px #0005}.dialog h2,.dialog p{width:100%}.rules-copy{font-size:18px;line-height:1.6}.notice{padding:12px;background:#f3e2d4}
@media(max-width:520px){main{padding:8px}.board-shell{width:100%}.board{border-width:3px}.square.selected{box-shadow:inset 0 0 0 3px #f65313}.square.check-king{box-shadow:inset 0 0 0 3px #a32620}.square.selected.check-king{box-shadow:inset 0 0 0 3px #f65313,inset 0 0 0 7px #a32620}.square.last{outline-width:1px}.controls>*{flex:1 1 28%;padding:8px 6px}.top-tools{gap:6px}}

.draw-response {
 min-height: 88px;
 height: 88px;
 display: flex;
 flex-wrap: wrap;
 justify-content: center;
 align-content: center;
 gap: 6px;
 overflow: auto;
}
.draw-response p {
 flex-basis: 100%;
 margin: 0;
 text-align: center;
 font-size: 14px;
}
.draw-response button { padding: 6px 16px; }
.controls { flex-wrap: nowrap; min-height: 44px; margin: 4px 0; }
.controls > * { flex: 1 1 0; }
.controls button { overflow-wrap: anywhere; }
.recovery-controls { display: flex; justify-content: center; gap: 8px; }
.result-banner { padding: 12px; gap: 4px; text-transform: none; }
.result-title { font-size: clamp(20px, 4vw, 32px); overflow-wrap: anywhere; }
.result-score { font-size: 18px; }
.result-reason { font-size: 15px; font-weight: 600; }
.saved-result { display: grid; text-align: center; gap: 4px; padding: 12px 0; }
.saved-result strong { font-size: 22px; }
.chess-app:has(.result-banner) .draw-response,
.chess-app:has(.result-banner) .controls { display: none; }
.promotion-choices { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; width: 100%; }
.promotion-choice { display: flex; flex-direction: column; align-items: center; padding: 8px 2px; gap: 6px; min-width: 0; font-size: 13px; }
.promotion-piece { width: 100%; max-width: 65px; aspect-ratio: 1; }
.dialog { max-height: calc(100dvh - 32px); overflow-y: auto; }
.dialog h2 { margin-top: 0; }
.rules-page { padding: 12px 0; }
.rules-page > h2 { font-size: 36px; margin: 8px 0; }
.rule-section { border-top: 2px solid #17120f; padding: 16px 0; }
.rule-section h3 { margin: 0 0 8px; font-size: 23px; }
.rule-section p { margin: 0; line-height: 1.6; }
.rules-page > button { width: 100%; margin-top: 12px; }
@media (max-width: 520px) {
 .controls > * { flex: 1 1 0; }
 .topline { min-height: 48px; }
 .topline h1 { margin: 4px 0; }
 .selected-label { font-size: 13px; min-height: 22px; margin: 2px 0; }
 .turn-banner { font-size: 16px; }
}

.player.turn { border-bottom-color: #f65313; }
.presence { display: flex; justify-content: space-between; gap: 8px; min-height: 22px; font-size: 13px; line-height: 22px; }
.watching-count { margin-left: auto; color: #594131; }
.spectator-label { font-weight: 700; }
.rule-section { display: flex; align-items: flex-start; gap: 18px; }
.rule-number { flex: none; color: #f65313; font-size: clamp(38px, 8vw, 64px); font-weight: 850; line-height: 1; letter-spacing: -.06em; }
.rule-content { min-width: 0; }

/* Waiting games need no space reserved for active-game actions. */
.chess-app[data-status="waiting"] .draw-response,
.chess-app[data-status="waiting"] .selected-label,
.controls:empty,
.recovery-controls:empty { display: none; }

@media (max-width: 520px) and (max-height: 800px) {
 .topline { min-height: 42px; }
 .topline h1 { font-size: 28px; margin: 2px 0; }
 .player { padding: 3px 0; }
 .seat-piece { width: 26px; height: 26px; }
 .presence { min-height: 18px; line-height: 18px; font-size: 12px; }
 .turn-banner { min-height: 42px; margin-top: 4px; padding: 6px; }
 .feedback { min-height: 20px; line-height: 16px; font-size: 12px; padding: 2px 4px; }
 .selected-label { min-height: 20px; line-height: 20px; margin: 2px 0; font-size: 12px; }
 .draw-response { min-height: 44px; height: 44px; flex-wrap: nowrap; gap: 6px; }
 .draw-response p { flex: 1 1 0; font-size: 12px; text-align: left; }
 .draw-response button { flex: none; padding: 6px 10px; }
 .controls { margin: 2px 0; }
}
