:root {
  color-scheme: light;
  --paper: #f7f4ee;
  --surface: #fffdf8;
  --ink: #26231f;
  --secondary: #554d42;
  --muted: #6a6054;
  --line: #d8d0c2;
  --accent: #34523f;
  --accent-hover: #253e30;
  --wood: #664837;
  --sand-square: #e5cfae;
  --wood-square: #997052;
  --focus: #34523f;
  --radius: 8px;
  font: 16px/1.5 'Segoe UI', system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
}

*, *::before, *::after { box-sizing: border-box; }
body { min-height: 100vh; margin: 0; display: flex; flex-direction: column; }
button, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
a { color: inherit; text-underline-offset: 0.22em; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 4px; }
.hidden { display: none !important; }
.shell { width: min(100% - 64px, 1120px); margin-inline: auto; }

.site-header, .site-footer { background: var(--surface); }
.site-header { border-bottom: 1px solid var(--line); }
.topbar { min-height: 68px; display: flex; gap: 64px; align-items: center; }
.brand, .footer-brand { text-decoration: none; font-weight: 600; }
.brand { display: inline-flex; gap: 12px; align-items: center; font-size: 20px; }
.brand-mark {
  width: 20px;
  aspect-ratio: 1;
  border: 1px solid currentColor;
  background: conic-gradient(var(--ink) 25%, transparent 0 50%, var(--ink) 0 75%, transparent 0);
}
.game-nav { display: flex; align-self: stretch; gap: 24px; }
.game-nav button {
  padding: 0 4px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--secondary);
  white-space: nowrap;
}
.game-nav button[aria-pressed='true'] { border-color: var(--accent); color: var(--ink); font-weight: 600; }
.game-nav button:hover, .footer-links a:hover { color: var(--accent); }
.game-nav button:focus-visible { outline-offset: -4px; }

.game-layout {
  display: grid;
  grid-template-columns: minmax(248px, 320px) minmax(0, 576px);
  grid-template-areas: 'heading board' 'info board';
  grid-template-rows: min-content 1fr;
  justify-content: space-between;
  gap: 32px 64px;
  padding-block: 48px 56px;
  flex: 1;
  align-content: start;
}
.game-heading { grid-area: heading; padding-top: 12px; }
.game-heading h1, .legal-page h1 {
  margin: 0;
  font: 400 clamp(2.5rem, 5vw, 4.5rem)/1.06 Georgia, 'Times New Roman', serif;
  letter-spacing: -0.035em;
}
.game-mode { margin: 12px 0 0; color: var(--secondary); }
.game-info { grid-area: info; }
.turn-status {
  margin: 0;
  padding-block: 16px;
  border-block: 1px solid var(--line);
  color: var(--accent);
  font-size: 18px;
  font-weight: 600;
}
.players { margin: 16px 0 0; color: var(--secondary); }
.players div { display: flex; justify-content: space-between; gap: 16px; padding-block: 4px; }
.players dd { margin: 0; color: var(--ink); }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 20px; }
.setting-row select { min-height: 44px; padding: 8px 12px; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 24px; }
.primary-button, .secondary-button {
  min-height: 44px;
  padding: 8px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 14px;
  transition: background-color 140ms ease-out;
}
.primary-button { background: var(--accent); border-color: var(--accent); color: white; }
.primary-button:hover { background: var(--accent-hover); }
.secondary-button { color: var(--ink); background: var(--surface); }
.secondary-button:hover:enabled { background: #efeae0; }
.secondary-button:disabled { color: var(--muted); opacity: 0.65; }
.rule-note, .friend-note { font-size: 14px; color: var(--secondary); margin: 20px 0 0; }
.friend-note { margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--line); color: var(--muted); }

.board-frame {
  grid-area: board;
  align-self: start;
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  grid-template-rows: auto 24px;
  padding: 0 24px 0 0;
  border: 1px solid #52392b;
  border-top-width: 24px;
  border-radius: 12px;
  background: var(--wood);
  color: #fff4e4;
  box-shadow: 0 4px 0 #49362b, 0 12px 24px #2a21151c;
}
.rank-labels, .file-labels {
  display: grid;
  text-align: center;
  align-items: center;
  font: 500 12px/1 ui-monospace, Consolas, monospace;
}
.rank-labels { grid-template-rows: repeat(8, minmax(0, 1fr)); }
.file-labels { grid-column: 2; grid-template-columns: repeat(8, minmax(0, 1fr)); }
.board-frame:has(.tic-board) { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto; padding: 24px; border: 1px solid #52392b; }
.board-frame:has(.tic-board) :is(.file-labels, .rank-labels) { display: none; }
.board {
  display: grid;
  grid-template-columns: repeat(var(--cols, 8), minmax(0, 1fr));
  grid-template-rows: repeat(var(--cols, 8), minmax(0, 1fr));
  aspect-ratio: 1;
  outline: 1px solid #362519;
  color: var(--ink);
  background: var(--sand-square);
  user-select: none;
  touch-action: manipulation;
}
.cell {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: var(--sand-square);
  color: var(--ink);
}
.cell:is(.dark, .dark-square) { background: var(--wood-square); }
.cell.selected { box-shadow: inset 0 0 0 3px #284734, inset 0 0 0 5px #f5f4d7; }
.cell:focus-visible { z-index: 2; outline-offset: -3px; outline-color: #253e30; }
.cell.legal::after { content: ''; position: absolute; width: 20%; aspect-ratio: 1; border-radius: 50%; background: #253e30; border: 1px solid #f4e9c7; pointer-events: none; }
.cell.legal:has(.chess-piece)::after { width: 84%; background: transparent; border: 2px solid #253e30; }
.cell.legal:hover::after { background: #496b52; }
.piece {
  display: grid;
  place-items: center;
  position: relative;
  width: 76%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 1px solid var(--edge);
  background: var(--face);
  box-shadow: inset 0 1px 1px var(--rim), 0 3px 0 var(--edge), 0 5px 4px #2d1e1860;
}
.piece.light { --face: #f4e7cc; --rim: #fffaf0; --edge: #aa8b67; --ring: #c8af8b; color: #533a26; }
.piece.dark-piece { --face: #452e22; --rim: #87624a; --edge: #2d1d16; --ring: #78543e; color: #f4e7cc; }
.piece::before { content: ''; position: absolute; inset: 14%; border: 1px solid var(--ring); border-radius: 50%; box-shadow: inset 0 1px 1px var(--edge); }
.piece.king::after { content: '♛'; line-height: 1; font-size: clamp(12px, 2.5vw, 24px); }
.chess-piece { font: clamp(20px, 5vw, 46px)/1 'Segoe UI Symbol', 'DejaVu Sans', serif; }
.chess-piece.white { color: #fff9e9; -webkit-text-stroke: 1px #38291e; }
.chess-piece.black { color: #2d2019; }
.tic-board { background: #a88b70; gap: 1px; }
.tic-cell { background: #f1e4ce; }
.tic-cell:hover { background: #f8efdd; }
.tic-cell::before, .tic-cell.x-mark::after { content: ''; position: absolute; width: 52%; }
.tic-cell.x-mark::before, .tic-cell.x-mark::after { height: 7%; border-radius: 2px; background: #34523f; transform: rotate(45deg); }
.tic-cell.x-mark::after { transform: rotate(-45deg); }
.tic-cell.o-mark::before { aspect-ratio: 1; border: max(1px, min(0.38vw, 5px)) solid #784c36; border-radius: 50%; }
.tic-cell.win-cell { background: #dce3c8; }

.site-footer { margin-top: auto; border-top: 1px solid var(--line); }
.footer-inner { min-height: 68px; display: flex; gap: 24px; align-items: center; }
.footer-links { display: flex; flex-wrap: wrap; gap: 8px 24px; margin-inline: auto; color: var(--muted); font-size: 14px; }
.footer-links a { text-decoration: none; }
.footer-links a:hover { text-decoration: underline; }
.age-mark { color: var(--secondary); font-size: 14px; font-weight: 600; margin-left: auto; }
.cookie-banner {
  position: fixed;
  z-index: 4;
  inset: auto 24px 24px;
  width: min(100% - 48px, 624px);
  margin-inline: auto;
  display: flex;
  gap: 16px;
  align-items: center;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 8px 24px #29231a1c;
}
.cookie-banner h2 { margin: 0; font-size: 15px; font-weight: 600; }
.cookie-banner p { margin: 4px 0 0; color: var(--secondary); font-size: 13px; }
.consent-dialog {
  width: min(100% - 32px, 680px);
  max-height: min(88vh, 760px);
  padding: 32px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 16px 48px #29231a29;
}
.consent-dialog::backdrop { background: #1e1b17a8; }
.consent-dialog h1 {
  margin: 0;
  font: 400 clamp(2rem, 5vw, 3rem)/1.1 Georgia, 'Times New Roman', serif;
}
.consent-kicker { margin: 0 0 12px; color: var(--muted); font-size: 14px; }
.consent-copy { margin-top: 20px; color: var(--secondary); }
.consent-copy p { margin: 0 0 12px; }
.consent-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 24px; }
.consent-footnote { margin: 16px 0 0; color: var(--muted); font-size: 13px; }
.legal-page { width: min(100% - 64px, 720px); margin-inline: auto; padding-block: 48px 64px; }
.legal-page h1 { font-size: clamp(2rem, 5vw, 3.25rem); margin: 24px 0 12px; overflow-wrap: anywhere; }
.legal-page h2 { font-size: 18px; font-weight: 600; margin: 24px 0 8px; }
.legal-page p { color: var(--secondary); margin: 0 0 12px; }
.legal-page .updated, .back-link { color: var(--muted); font-size: 14px; }
.legal-page .updated { margin-bottom: 24px; }

@media (max-width: 950px) {
  .game-layout { gap: 24px 40px; padding-top: 40px; }
}
@media (max-width: 720px) {
  .shell, .legal-page { width: calc(100% - 32px); }
  .topbar { display: block; padding-top: 16px; }
  .game-nav { min-height: 48px; gap: clamp(8px, 4vw, 24px); }
  .game-nav button { font-size: 14px; padding-inline: 0; }
  .game-layout { grid-template-columns: minmax(0, 1fr); grid-template-areas: 'heading' 'board' 'info'; grid-template-rows: auto; padding-block: 24px 32px; }
  .game-heading { padding-top: 0; }
  .game-mode { margin-top: 4px; }
  .game-info { display: contents; }
  .game-layout { grid-template-areas: 'heading' 'status' 'options' 'board' 'players' 'actions' 'rules' 'friend'; row-gap: 16px; }
  .turn-status { grid-area: status; padding-block: 8px; }
  .setting-row { grid-area: options; margin: 0; }
  .players { grid-area: players; margin: 0; }
  .actions { grid-area: actions; margin: 0; }
  .rule-note { grid-area: rules; margin: 0; }
  .friend-note { grid-area: friend; margin: 0; }
  .game-layout:has(.setting-row.hidden) { grid-template-areas: 'heading' 'status' 'board' 'players' 'actions' 'rules' 'friend'; }
  .board-frame { grid-template-columns: 16px minmax(0, 1fr); grid-template-rows: auto 16px; padding-right: 16px; border-top-width: 16px; }
  .board-frame:has(.tic-board) { padding: 12px; }
  .rank-labels, .file-labels { font-size: 10px; }
  .footer-inner { flex-wrap: wrap; gap: 8px 16px; padding-block: 16px; }
  .footer-links { order: 1; width: 100%; margin: 0; gap: 8px 16px; }
  .cookie-banner { inset: auto 12px 12px; width: calc(100% - 24px); }
  .consent-dialog { max-height: 92vh; padding: 24px 20px; overflow-y: auto; }
  .consent-actions { display: grid; grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  .primary-button, .secondary-button { transition: none; }
}
