/* Self-hosted variable font (latin subset, SIL OFL - see OFL-dm-sans.txt), so no visitor data goes to Google. */
@font-face { font-family: 'DM Sans'; font-style: normal; font-weight: 400 700; font-display: swap; src: url(dm-sans.woff2) format('woff2'); }

:root {
  --bg: #f6f5f0;
  --surface: #fdfcf8;
  --surface-2: #eeede5;
  --line: #e0dfd5;
  --line-strong: #cfcfc3;
  --ink: #1f2d27;
  --muted: #66716a;
  --green: #2a5446;
  --green-hover: #1f4236;
  --green-soft: #e2ebe2;
  --accent: #c25f3a;
  --accent-soft: #f6e7dc;
  --board-light: #e9e7d8;
  --board-dark: #6b8f7b;
  --piece-stroke: #243f35;
  --radius: 8px;
  --radius-sm: 6px;
  font-family: 'DM Sans', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  font-synthesis: none;
  -webkit-text-size-adjust: 100%;
}

/* Base */
* { box-sizing: border-box; }
body { margin: 0; }
h1, h2, h3, h4, p { margin: 0; }
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: default; opacity: .5; }
button svg { width: 20px; height: 20px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

/* Form controls */
.field-label { display: block; font-size: 13px; font-weight: 600; margin: 16px 0 6px; }
select, input:not([type="checkbox"]) {
  width: 100%;
  min-height: 42px;
  padding: 9px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
}
select:hover, input:not([type="checkbox"]):hover { border-color: #b8b9ab; }
.help, .account-note { font-size: 13px; color: var(--muted); margin-top: 8px; }

/* Buttons */
.primary-button, .secondary-button, .new-game-button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 0 16px;
  border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 600;
  transition: background-color .15s;
}
.primary-button, .new-game-button { background: var(--green); color: #fff; }
.primary-button { width: 100%; }
.primary-button:not(:disabled):hover, .new-game-button:not(:disabled):hover { background: var(--green-hover); }
.secondary-button { background: var(--surface); border: 1px solid var(--line-strong); text-decoration: none; }
.secondary-button:not(:disabled):hover { background: var(--surface-2); }
.link-button { font-size: 13px; font-weight: 600; color: var(--green); text-decoration: underline; text-underline-offset: 3px; text-decoration-color: #2a544655; }
.link-button:not(:disabled):hover { text-decoration-color: currentColor; }
.link-button.danger { color: var(--accent); text-decoration-color: #c25f3a55; }
.text-button { font-size: 14px; font-weight: 500; color: var(--muted); padding: 6px 2px; }
.text-button:hover { color: var(--ink); }
.icon-button { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: var(--radius-sm); color: var(--muted); font-size: 24px; line-height: 1; flex-shrink: 0; }
.icon-button:hover { background: var(--surface-2); color: var(--ink); }

/* Page */
.page-shell { max-width: 1200px; margin: 0 auto; padding: 0 32px; }
.site-header { display: flex; align-items: center; justify-content: space-between; gap: 24px; height: 68px; margin-bottom: 20px; border-bottom: 1px solid var(--line); }
.wordmark { display: flex; align-items: center; gap: 10px; font-size: 19px; font-weight: 700; letter-spacing: -.2px; text-decoration: none; }
.wordmark-mark { width: 30px; height: 30px; }
.wordmark-mark rect { fill: var(--green); }
.wordmark-mark path { fill: #faf6ed; }
.site-header nav { display: flex; align-items: center; gap: 20px; min-width: 0; }
.account-button { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.new-game-button { white-space: nowrap; margin-left: 4px; }

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, min(700px, max(440px, calc(100svh - 230px)))) 340px;
  justify-content: center;
  align-items: start;
  gap: 40px;
}
.table-area { min-width: 0; }

footer { display: flex; gap: 20px; margin-top: 48px; padding: 20px 0 28px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); }
footer span { margin-right: auto; font-weight: 600; }
footer a:hover { color: var(--ink); }

/* Players */
.player-strip { display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 8px 0; }
.player-info { display: flex; align-items: center; gap: 10px; min-width: 0; margin-right: auto; }
.player-info > div:last-child { min-width: 0; }
.avatar { width: 36px; height: 36px; border-radius: var(--radius-sm); background: var(--surface-2); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.avatar .chess-piece { width: 28px; height: 28px; }
.player-info h2 { font-size: 15px; font-weight: 600; line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-info p { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-elo { font-weight: 400; color: var(--muted); margin-left: 4px; }
.mini-tag { display: inline-block; margin-left: 6px; padding: 1px 6px; border: 1px solid var(--line-strong); border-radius: 4px; font-size: 12px; font-weight: 500; color: var(--muted); vertical-align: 1px; }
.you-tag { background: var(--surface-2); border-color: transparent; }
.player-status { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.status-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; display: inline-block; flex-shrink: 0; }
.player-status .status-dot { background: #7f9a83; }
.captured-pieces { display: flex; flex-wrap: wrap; justify-content: flex-end; max-width: 150px; }
.captured-pieces svg { width: 18px; height: 22px; margin-left: -3px; }
.player-clock {
  flex-shrink: 0; min-width: 72px; padding: 6px 10px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--muted);
  font-size: 17px; font-weight: 600; text-align: center; font-variant-numeric: tabular-nums;
}
.player-clock.running { background: var(--green); border-color: var(--green); color: #fff; }
.player-clock.low-time { background: var(--accent-soft); border-color: #e0b49c; color: #9c4524; }
.player-clock.running.low-time { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Board */
.board-toolbar { display: flex; gap: 8px; margin-bottom: 8px; }
.board-status {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px;
  min-height: 36px; padding: 6px 12px; border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--muted); font-size: 14px; font-weight: 500;
}
.board-status::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: #8f998f; flex-shrink: 0; }
.board-status.ready { background: var(--green-soft); color: var(--green); }
.board-status.ready::before { background: #3e8452; }
.board-status.waiting { background: #f2eadb; color: #7a5830; }
.board-status.waiting::before { background: #b0834a; }
.board-status.finished { background: var(--green-soft); color: var(--green); }
.preview-toggle { flex-shrink: 0; min-height: 36px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface); font-size: 13px; font-weight: 500; }
.preview-toggle[aria-pressed="false"] { color: var(--muted); border-style: dashed; }
.preview-toggle:hover { background: var(--surface-2); }

.board-wrap { position: relative; border-radius: 4px; overflow: hidden; box-shadow: 0 1px 2px #1f2d2714, 0 8px 24px #1f2d270d; }
.board { display: grid; grid-template-columns: repeat(8, 1fr); aspect-ratio: 1; touch-action: manipulation; }
.square {
  position: relative; isolation: isolate;
  display: flex; align-items: center; justify-content: center;
  min-width: 0; min-height: 0; aspect-ratio: 1; padding: 6%;
  background: var(--board-light); color: #4f705e;
}
.square.dark { background: var(--board-dark); color: #eef0e3; }
.square.movable:hover, .square.legal:hover { box-shadow: inset 0 0 0 3px #ffffff59; }
.square.last-from { background: #d6d6b2; }
.square.last-from.dark { background: #98aa82; }
.square.last-to { background: #d3d29a; }
.square.last-to.dark { background: #9aab74; }
.square.pending-to { background: #dcc488; }
.square.pending-to.dark { background: #b2a76a; }
.square.selected { background: #e2b46e; }
.square.selected.dark { background: #c99d58; }
.square.legal::before { content: ''; position: absolute; width: 26%; height: 26%; border-radius: 50%; background: #1f2d2740; z-index: 2; pointer-events: none; }
.square.legal.has-piece::before { width: 86%; height: 86%; background: transparent; border: 4px solid #1f2d2740; }
.square.movable { cursor: pointer; }
.square.movable::after { content: ''; position: absolute; left: 7%; bottom: 7%; width: 7%; height: 7%; border-radius: 50%; background: #fff8cf; box-shadow: 0 0 0 1px #1f2d2755; z-index: 2; }
.square.movable:hover > .chess-piece, .square.selected .chess-piece { transform: translateY(-2px); }
.square .chess-piece { width: 94%; height: 94%; pointer-events: none; filter: drop-shadow(0 2px 1px #1e382930); transition: transform .15s; }
.white-piece { color: #fcf6e7; --piece-stroke: #355345; }
.black-piece { color: #213f35; --piece-stroke: #172f27; }
.black-piece .piece-eye { fill: #f9f3e4; }
.white-piece .piece-eye { fill: #304a3d; }
.coord { position: absolute; z-index: 3; font-size: 11px; font-weight: 600; line-height: 1; pointer-events: none; }
.rank-coord { left: 5px; top: 5px; }
.file-coord { right: 5px; bottom: 4px; }
.rest-marker {
  position: absolute; right: 4px; top: 4px; z-index: 4;
  display: flex; align-items: center; justify-content: center;
  width: 17px; height: 17px; border-radius: 50%;
  background: #e8b26f; color: #4b3a24; border: 1.5px solid var(--board-light);
  font-size: 10px; font-weight: 700; line-height: 1;
}
.square.queued-from > .chess-piece { opacity: .25; filter: grayscale(1); }
.square.queued-to { box-shadow: inset 0 0 0 3px #e1b36a; }
.square.queued-to > .chess-piece { opacity: .35; }
.move-ghost { position: absolute; inset: 6%; display: flex; align-items: center; justify-content: center; pointer-events: none; z-index: 2; }
.square .move-ghost .chess-piece { opacity: .55; filter: grayscale(1) drop-shadow(0 1px 1px #1118); }
.square.team-reserved, .square.planned-from { outline: 2px dashed #e1b36a; outline-offset: -5px; }
.square.team-reserved.movable::after { display: none; }
.square.planned-from { cursor: pointer; }
.square.planned-from > .chess-piece { opacity: .45; }
.board.revealing .square.last-to .chess-piece { animation: reveal .45s ease; }
.board.revealing .square.last-to { animation: highlight .7s ease; }
@keyframes reveal { 0% { opacity: .3; transform: scale(.7); } 70% { transform: scale(1.06); } 100% { opacity: 1; transform: scale(1); } }
@keyframes highlight { 0%, 30% { background: #e2b46e; } }

.flip-button svg { width: 20px; height: 20px; }

.handoff-overlay {
  position: absolute; inset: 0; z-index: 10;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  padding: 32px; text-align: center;
  background: var(--green); color: #f4f2e8;
}
/* The lobby only invites; the pass & play handoff must hide the board completely. */
body[data-phase="lobby"] .handoff-overlay { background: #1f3a31d9; backdrop-filter: blur(3px); }
body[data-phase="lobby"] .round-section { display: none; }
.handoff-overlay h2 { font-size: 28px; font-weight: 600; letter-spacing: -.3px; line-height: 1.2; }
.handoff-overlay p { font-size: 15px; color: #c9d6cc; max-width: 320px; }
.handoff-overlay .handoff-kicker { font-size: 13px; font-weight: 600; color: #a9bfae; }
.handoff-overlay button { margin-top: 8px; min-height: 44px; padding: 0 22px; border-radius: var(--radius-sm); background: #f4f2e6; color: var(--green); font-size: 14px; font-weight: 600; }
.handoff-overlay button:not(:disabled):hover { background: #fff; }

/* Sidebar */
.game-sidebar { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.mode-tabs { display: flex; gap: 2px; padding: 3px; border-radius: var(--radius); background: var(--surface-2); }
.mode-tabs button { flex: 1; min-height: 36px; padding: 0 6px; border-radius: var(--radius-sm); font-size: 14px; font-weight: 500; color: var(--muted); white-space: nowrap; }
.mode-tabs button.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px #1f2d271f; }
.mode-tabs button:not(.active):not(:disabled):hover { color: var(--ink); }

.panel { padding: 20px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.panel h2 { font-size: 20px; font-weight: 600; letter-spacing: -.2px; line-height: 1.3; }
.panel-intro { font-size: 14px; color: var(--muted); margin-top: 4px; }
.room-settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.room-settings-grid > div { min-width: 0; }
#create-room { margin-top: 16px; }

.rated-toggle { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); cursor: pointer; }
.rated-toggle strong { display: block; font-size: 14px; font-weight: 600; }
.rated-toggle small { display: block; font-size: 13px; color: var(--muted); }
.rated-toggle input { appearance: none; -webkit-appearance: none; position: relative; flex-shrink: 0; width: 40px; height: 24px; margin: 0; border-radius: 12px; background: #c9cdc0; cursor: pointer; transition: background-color .15s; }
.rated-toggle input::before { content: ''; position: absolute; left: 3px; top: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px #1f2d2740; transition: transform .15s; }
.rated-toggle input:checked { background: var(--green); }
.rated-toggle input:checked::before { transform: translateX(16px); }
.rated-toggle.is-disabled { opacity: .5; cursor: not-allowed; }
.rated-toggle.is-disabled input { background: #c9cdc0; cursor: not-allowed; }
.rated-toggle.is-disabled input::before { transform: none; }

.join-room-form { margin-top: 20px; padding-top: 20px; border-top: 1px solid var(--line); }
.join-room-form h3 { font-size: 15px; font-weight: 600; }
.join-row { display: flex; gap: 8px; margin-top: 8px; }
.join-row input { min-width: 0; flex: 1; }
#room-code-input, .watch-code-form input { font-size: 18px; letter-spacing: 4px; font-variant-numeric: tabular-nums; }
.watch-lobby-actions { display: flex; justify-content: space-between; gap: 12px; margin-top: 14px; }

.room-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--muted); }
.connection-label { display: flex; align-items: center; gap: 6px; font-weight: 600; color: var(--accent); white-space: nowrap; }
.connection-label::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.connection-label.connected { color: #3e8452; }
.room-code-line { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin: 6px 0 2px; }
.room-code-line strong { font-size: 28px; font-weight: 700; letter-spacing: 5px; font-variant-numeric: tabular-nums; }
.room-player-status { font-size: 13px; color: var(--muted); }
.party-exit { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.party-exit .secondary-button { min-height: 36px; font-size: 13px; white-space: nowrap; }
.party-exit small { font-size: 12px; color: var(--muted); text-align: right; }
.team-roster { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.roster-team > strong { display: block; font-size: 13px; margin-bottom: 4px; }
.roster-member { padding: 4px 0; min-width: 0; }
.roster-member > span { display: block; font-size: 14px; overflow-wrap: anywhere; }
.roster-member small { display: block; font-size: 12px; color: var(--muted); }
.roster-member.is-you > span { font-weight: 600; }
.roster-member.is-you small { color: var(--green); }
.room-details { margin-top: 14px; padding-top: 10px; border-top: 1px solid var(--line); }
.room-details summary { cursor: pointer; font-size: 13px; font-weight: 600; color: var(--muted); padding: 4px 0; }
.room-details summary:hover { color: var(--ink); }
.room-details[open] summary { margin-bottom: 8px; }
.invite-url { font-size: 13px !important; color: var(--muted) !important; text-overflow: ellipsis; }
.room-actions { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; margin-top: 12px; }
.notice { margin-top: 12px; padding: 8px 12px; border-radius: var(--radius-sm); background: #f2eadb; color: #7a5830; font-size: 13px; }
.error { margin-top: 12px; padding: 8px 12px; border-radius: var(--radius-sm); background: var(--accent-soft); color: #9c4524; font-size: 13px; }

.move-panel { position: relative; }
.round-line { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-size: 13px; color: var(--muted); }
.phase-label { display: flex; align-items: center; gap: 6px; font-weight: 600; color: var(--accent); }
.move-panel .turn-description { font-size: 14px; color: var(--muted); margin-top: 4px; }
.move-selection { display: flex; align-items: center; gap: 10px; min-height: 54px; margin: 16px 0 12px; padding: 8px 12px; border: 1px dashed var(--line-strong); border-radius: var(--radius-sm); background: var(--bg); }
.move-selection.has-move { border-style: solid; background: var(--green-soft); border-color: #c3d3c3; }
.move-selection > svg { width: 30px; height: 34px; flex-shrink: 0; }
.selection-symbol { display: flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: 50%; background: var(--green); color: #fff; font-size: 14px; font-weight: 600; flex-shrink: 0; }
.selection-label { font-size: 13px; color: var(--muted); min-width: 0; }
.selection-label strong { display: block; font-size: 14px; font-weight: 600; color: var(--ink); }
.clear-move { margin-left: auto; width: 32px; height: 32px; border-radius: var(--radius-sm); font-size: 20px; color: var(--muted); flex-shrink: 0; }
.clear-move:hover { background: #ffffff80; color: var(--ink); }
.lock-note { margin-top: 10px; font-size: 12px; color: var(--muted); text-align: center; }
body:not([data-mode="local"]) .move-panel:has(#lock-button:not([hidden])) .turn-description { margin-bottom: 16px; }

.round-section { padding: 4px 0 0; }
.section-label { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.section-label h2 { font-size: 15px; font-weight: 600; }
.empty-round { font-size: 13px; color: var(--muted); }
.round-moves { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.round-move { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: var(--radius-sm); background: var(--surface-2); min-width: 0; }
.round-move svg { width: 22px; height: 28px; flex-shrink: 0; }
.round-move .move-color { display: block; font-size: 12px; color: var(--muted); }
.round-move .move-color::first-letter { text-transform: uppercase; }
.round-move .move-route { display: block; font-size: 14px; font-weight: 600; }
.round-events { font-size: 13px; color: var(--muted); }
.round-events .event-more { color: var(--accent); }
.rule-teaser { padding-top: 16px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); }

/* Dialogs */
dialog {
  width: min(640px, calc(100vw - 32px)); max-height: min(90dvh, 900px); overflow: auto;
  padding: 28px; border: 0; border-radius: 12px;
  background: var(--surface); color: var(--ink);
  box-shadow: 0 24px 80px #12221c40;
}
dialog::backdrop { background: #17261f99; }
.dialog-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.dialog-header h2 { font-size: 22px; font-weight: 600; letter-spacing: -.3px; line-height: 1.3; }
.dialog-header .icon-button { margin: -6px -8px 0 0; }
.dialog-lead { font-size: 15px; color: var(--muted); margin-bottom: 20px; }
.close-dialog.primary-button { margin-top: 8px; }

.rules-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px 28px; }
.rules-grid h3 { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.rules-grid p { font-size: 14px; color: var(--muted); }
.strength-order { display: flex; justify-content: space-between; margin: 12px 0 2px; }
.strength-order svg { width: 30px; height: 32px; }
.strength-caption { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.fine-rules { margin: 20px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.fine-rules summary { cursor: pointer; padding: 14px 0; font-size: 15px; font-weight: 600; }
.fine-rules ul { margin: 0 0 16px; padding-left: 18px; font-size: 14px; color: var(--muted); }
.fine-rules li + li { margin-top: 8px; }

.new-game-dialog, .account-dialog, .result-dialog { max-width: 420px; }
.new-game-dialog .field-label:first-child { margin-top: 0; }
.new-game-dialog .help { margin: 16px 0; }
.history-dialog, .players-dialog { max-width: 520px; }
.history-round { padding: 16px 0; border-top: 1px solid var(--line); }
.history-round h3 { font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 8px; }
.history-empty { padding: 16px 0; color: var(--muted); }

.promotion-dialog { max-width: 440px; }
#promotion-options { display: flex; gap: 8px; }
#promotion-options button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 4px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--bg); font-size: 13px; font-weight: 500; }
#promotion-options button:hover { background: var(--green-soft); border-color: #b5c8b5; }
#promotion-options svg { width: 44px; height: 50px; }

.account-tabs { display: flex; gap: 2px; padding: 3px; border-radius: var(--radius); background: var(--surface-2); }
.account-tabs button { flex: 1; min-height: 36px; border-radius: var(--radius-sm); font-size: 14px; font-weight: 500; color: var(--muted); }
.account-tabs button.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px #1f2d271f; }
.account-dialog .primary-button { margin-top: 20px; }
.account-dialog .help { margin-top: 16px; }
#account-profile h3 { font-size: 17px; font-weight: 600; }
#account-signed-in .secondary-button { width: 100%; margin-top: 16px; }
.account-dialog:has(#account-signed-in:not([hidden])) #account-signed-out { margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--line); }
.profile-ratings { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.profile-ratings section { padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--bg); }
.profile-ratings h4 { font-size: 13px; font-weight: 600; color: var(--muted); }
.profile-ratings strong { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.profile-ratings p { font-size: 12px; color: var(--muted); }

.players-filters { display: grid; grid-template-columns: 110px 1fr; gap: 8px; }
#players-count { margin: 12px 0; }
.public-player { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 0; border-top: 1px solid var(--line); }
.public-player strong { font-size: 15px; overflow-wrap: anywhere; }
.public-player span { display: block; font-size: 13px; color: var(--muted); }
.public-elo { font-size: 20px; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.public-elo small { display: block; font-size: 12px; font-weight: 400; color: var(--muted); white-space: nowrap; }
#players-more { width: 100%; margin-top: 12px; }

.games-dialog { max-width: 560px; }
.watch-code-form { display: flex; gap: 8px; margin: 16px 0; }
.watch-code-form input { flex: 1; min-width: 0; }
.games-list-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.games-list-heading p { margin: 0; }
.watch-game { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 0; border-top: 1px solid var(--line); }
.watch-game > div { min-width: 0; }
.watch-game strong { font-size: 18px; letter-spacing: 3px; font-variant-numeric: tabular-nums; }
.watch-game strong span { margin-left: 8px; font-size: 13px; font-weight: 500; letter-spacing: 0; color: var(--muted); }
.watch-game p { font-size: 14px; overflow-wrap: anywhere; }
.watch-game small { font-size: 13px; color: var(--muted); }
.watch-link { flex-shrink: 0; }

.result-dialog { text-align: center; }
.result-dialog .dialog-header { margin-bottom: 0; }
.result-symbol { display: flex; align-items: center; justify-content: center; width: 76px; height: 76px; margin: 0 auto 16px; border-radius: 50%; background: var(--green-soft); color: var(--green); font-size: 34px; font-weight: 700; }
.result-symbol .chess-piece { width: 50px; height: 50px; }
.result-dialog[data-result="loss"] .result-symbol { background: var(--accent-soft); }
.result-dialog[data-result="draw"] .result-symbol { background: var(--surface-2); color: var(--muted); }
.result-dialog h2 { font-size: 26px; font-weight: 600; letter-spacing: -.4px; }
#result-reason { margin: 6px 0 20px; font-size: 15px; color: var(--muted); }
#result-rating { margin-bottom: 20px; }
.result-rating-mode { font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.rating-result-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); font-size: 14px; text-align: left; }
.rating-result-row > span { overflow-wrap: anywhere; }
.rating-result-row.own-rating { font-weight: 600; }
.rating-result-row strong { white-space: nowrap; font-variant-numeric: tabular-nums; }
.elo-change { display: inline-block; min-width: 34px; text-align: right; margin-left: 4px; }
.positive { color: #2f7445; }
.negative { color: #a54c2c; }
.result-dialog .secondary-button { width: 100%; margin-top: 8px; }

/* Toast and mobile action bar */
.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 100;
  max-width: calc(100vw - 32px); padding: 10px 18px; border-radius: var(--radius-sm);
  background: var(--ink); color: #f6f5ef; font-size: 14px; text-align: center;
  box-shadow: 0 8px 24px #1f2d2733;
  opacity: 0; transform: translate(-50%, 10px); pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.toast.visible { opacity: 1; transform: translate(-50%, 0); }
.mobile-action { display: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Medium screens: narrower sidebar */
@media (max-width: 1040px) {
  .page-shell { padding: 0 24px; }
  .game-layout { grid-template-columns: minmax(0, 1fr) 300px; gap: 28px; }
  .site-header nav { gap: 14px; }
  .account-button { max-width: 150px; }
}

/* Small screens: one column, compact header */
@media (max-width: 820px) {
  .page-shell { padding: 0 max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left)); }
  .site-header {
    display: grid; grid-template-columns: repeat(4, auto) 1fr auto; align-items: center;
    gap: 4px 18px; height: auto; padding: 10px 0 6px; margin-bottom: 12px;
  }
  .site-header nav { display: contents; }
  .wordmark { grid-column: 1 / -2; grid-row: 1; }
  .new-game-button { grid-column: -2; grid-row: 1; min-height: 38px; padding: 0 14px; margin: 0; }
  #players-button, #watch-games-button, #rules-button, #account-button { grid-row: 2; justify-self: start; min-height: 36px; }
  #account-button { max-width: 140px; text-align: left; }
  #sound-button { display: none; }

  .game-layout { display: flex; flex-direction: column; gap: 16px; }
  .table-area { width: min(100%, calc(100svh - 250px)); min-width: min(100%, 320px); margin: 0 auto; }
  body[data-mode="network"][data-phase="lobby"] .table-area { display: none; }
  .game-sidebar { width: 100%; }
  .mode-tabs { order: 0; }
  .move-panel { order: 1; }
  .network-panel { order: 2; }
  body[data-phase="lobby"] .network-panel { order: 1; }
  .round-section { order: 3; }
  .rule-teaser { order: 4; }

  select, input:not([type="checkbox"]) { font-size: 16px; min-height: 46px; }
  .mode-tabs button { min-height: 42px; }

  .player-strip { min-height: 48px; padding: 6px 0; gap: 8px; }
  .player-info p { display: none; }
  .avatar { width: 30px; height: 30px; }
  .avatar .chess-piece { width: 24px; height: 24px; }
  .player-info h2 { font-size: 14px; }
  .mini-tag { font-size: 12px; }
  .player-clock { min-width: 64px; font-size: 16px; padding: 5px 8px; }
  .has-network-clock .opponent .player-status { display: none; }
  .captured-pieces { max-width: 90px; }
  .board-status { font-size: 13px; min-height: 34px; }
  .coord { font-size: 10px; }
  .rank-coord { left: 3px; top: 3px; }
  .file-coord { right: 3px; bottom: 3px; }
  .rest-marker { width: 14px; height: 14px; right: 2px; top: 2px; font-size: 9px; }
  .square { padding: 4%; }

  .panel { padding: 16px; }
  dialog { width: calc(100vw - 24px); max-height: calc(100dvh - 24px); padding: 22px; }
  .rules-grid { grid-template-columns: 1fr; }
  footer { margin-top: 32px; }

  body[data-mode="local"] { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
  .mobile-action {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 12px max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
    background: #f6f5f0f2; backdrop-filter: blur(10px); border-top: 1px solid var(--line);
  }
  .mobile-action > div { min-width: 0; }
  .mobile-action > div > span { display: block; font-size: 12px; color: var(--muted); }
  .mobile-action strong { display: block; font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .mobile-action .mobile-time { font-size: 12px; color: var(--green); font-weight: 600; }
  .mobile-action .mobile-time.low-time { color: var(--accent); }
  .mobile-action .primary-button { width: auto; min-width: 150px; min-height: 46px; flex-shrink: 0; }
  body[data-mode="local"] .toast { bottom: 96px; }
}

@media (max-width: 380px) {
  .site-header { column-gap: 14px; }
  .room-settings-grid { grid-template-columns: 1fr; }
  .mini-tag { display: none; }
}
