:root {
  color-scheme: light;
  --paper: #f7f2e6;
  --ink: #212a40;
  --muted: #4e5665;
  --coral: #ff957e;
  --gold: #ffcd65;
  --orange: #aa3e2b;
  --night: #122752;
  font-family: "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 280px; }
button { font: inherit; color: inherit; cursor: pointer; min-height: 44px; }
button:focus-visible { outline: 3px solid #2764cd; outline-offset: 4px; }
button:disabled { cursor: default; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.shell { width: min(100% - 96px, 1250px); margin-inline: auto; }
.masthead { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 88px; border-bottom: 1px solid #d8cfc0; }
.preferences { display: flex; gap: 8px; }
.utility, .view-toggle { background: transparent; border: 1px solid #c9c1b5; border-radius: 99px; font-weight: 650; font-size: .81rem; padding: 0 14px; }
.utility:hover, .utility[aria-pressed="true"] { background: #e9dfcf; }

.layout { display: grid; grid-template-columns: minmax(275px, .66fr) minmax(0, 1fr); gap: clamp(34px, 6vw, 96px); align-items: center; padding-block: clamp(32px, 5.2vw, 74px); }
.sidebar { padding-block: 12px; }
h1, h2 { font-family: Georgia, "Times New Roman", serif; font-weight: 500; }
h1 { font-size: clamp(5.1rem, 8.7vw, 8.9rem); line-height: .82; letter-spacing: -.087em; margin: 0 0 29px -7px; }
h1 span { color: #bb4933; }
.lede { font-size: clamp(1rem, 1.55vw, 1.22rem); line-height: 1.55; color: var(--muted); max-width: 26ch; margin: 0 0 28px; }
.mode-buttons, .round-actions { display: grid; gap: 11px; width: min(100%, 350px); }
.mode { display: flex; width: 100%; align-items: center; justify-content: space-between; gap: 12px; text-align: left; padding: 14px 18px; min-height: 62px; border: 1px solid transparent; border-radius: 9px; }
.mode strong, .mode small { display: block; }
.mode strong { font-size: 1.07rem; }
.mode small { margin-top: 3px; font-size: .8rem; }
.primary { color: #fff9ef; background: var(--orange); }
.primary:hover { background: #903220; }
.secondary { background: #fffaf0; border-color: #cfc5b7; }
.secondary:hover { background: #f0e7d9; }
.arrow { font-size: 1.35rem; line-height: 1; }
.help { justify-self: start; border: 0; background: transparent; padding: 0 7px; margin: 9px 0 0 -7px; font-weight: 680; font-size: .91rem; }
.help:hover { text-decoration: underline; }
.help span { display: inline-grid; place-items: center; width: 20px; height: 20px; border: 1px solid currentColor; border-radius: 50%; margin-right: 5px; }
.eyebrow { font-size: .76rem; font-weight: 750; letter-spacing: .11em; text-transform: uppercase; }
.round-mode { margin: 0 0 11px; color: var(--muted); }
.round-card { display: flex; align-items: center; gap: 13px; width: min(100%, 350px); padding: 12px 16px; min-height: 83px; border: 1px solid #d9cfbf; border-radius: 12px; background: #fffaf0; }
.turn-icon { display: grid; place-items: center; width: 48px; height: 48px; flex: 0 0 48px; border-radius: 9px; background: #183468; color: var(--gold); font-size: 1.35rem; }
.turn-icon .symbol { width: 60%; }
.turn-label { margin: 0; font: 1.53rem/1.06 Georgia, "Times New Roman", serif; }
.turn-summary { margin: 4px 0 0; color: var(--muted); font-size: .82rem; }
.round-actions { margin-top: 20px; gap: 0; }
.round-actions .mode { min-height: 53px; }

.table { isolation: isolate; min-width: 0; overflow: hidden; border: 1px solid #183468; border-radius: 20px; color: #fff5dd; background: linear-gradient(150deg, #163576, var(--night) 78%); box-shadow: 0 18px 32px #30281922, 0 2px 2px #3028192b; }
.table-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 72px; padding: 14px 23px; position: relative; z-index: 1; }
.table-title { display: flex; align-items: center; gap: 9px; font-size: .72rem; font-weight: 750; letter-spacing: .14em; }
.table-dot { width: 8px; height: 8px; background: var(--gold); border-radius: 50%; box-shadow: 0 0 0 4px #ffcd6524; }
.view-toggle { border-color: #657aab; color: #fff5dd; }
.view-toggle:hover, .table-controls button:hover { background: #35548f; }
.table button:focus-visible { outline-color: var(--gold); }
.stage { position: relative; display: grid; place-items: center; height: clamp(305px, 33vw, 476px); overflow: hidden; perspective: 1150px; touch-action: none; cursor: grab; }
.stage.dragging { cursor: grabbing; }
.stage.dragging * { cursor: inherit; }
.inlay { position: absolute; width: min(120%, 540px); aspect-ratio: 1; border-radius: 50%; pointer-events: none; background: repeating-radial-gradient(circle, transparent 0 34px, #a1baf517 35px, transparent 36px 54px), radial-gradient(circle, #4b71d34a, transparent 67%); }
.camera { position: absolute; width: min(62%, 360px); aspect-ratio: 1; top: 50%; left: 50%; transform-style: preserve-3d; transform: translate(-50%, -50%) translate(var(--pan-x, 0px), var(--pan-y, 0px)) scale(var(--zoom, 1)); }
.board { position: absolute; inset: 0; transform-style: preserve-3d; transform: rotateX(var(--tilt, 39deg)) rotateZ(var(--yaw, -15deg)); }
.board-base { position: absolute; inset: 0; border-radius: 6%; background-color: #eec891; background-image: url("terrazzo.svg"); background-size: 135px 126px; border: 2px solid #fae1b8; box-shadow: 0 5px #b9845b, 0 10px #8f624e, 0 13px #5a4c57, 8px 25px 31px #070f29bb; }
.camera, .board, .board-base, .cells { pointer-events: none; }
.cells { position: absolute; inset: 4.8%; display: grid; grid-template: repeat(3, minmax(0, 1fr)) / repeat(3, minmax(0, 1fr)); gap: 3.3%; transform-style: preserve-3d; transform: translateZ(8px); }
.cell { position: relative; display: grid; place-items: center; min-width: 0; min-height: 44px; appearance: none; border: 0; padding: 0; border-radius: 12%; background: #10285c; transform-style: preserve-3d; pointer-events: auto; touch-action: none; box-shadow: 0 4px #0e2757, 0 6px 4px #352f3b7d; }
.cell[aria-disabled="true"] { cursor: default; }
.cell:focus-visible { outline-offset: 3px; }
.tile { position: absolute; inset: 0; pointer-events: none; transform-style: preserve-3d; border-radius: inherit; }
.face { position: absolute; inset: 0; display: grid; place-items: center; border-radius: inherit; backface-visibility: hidden; border: 1px solid #7592df; background: linear-gradient(139deg, #395db8, #244790 85%); box-shadow: inset 0 2px #b5caff3b; }
.face.back { transform: rotateY(180deg) translateZ(1px); }
.cell.filled .tile { transform: rotateY(180deg); }
.cell:not([aria-disabled="true"]):hover .front { background: linear-gradient(139deg, #5278d3, #345bb0 85%); }
.face .symbol { transform: rotate(calc(0deg - var(--yaw, -15deg))); }
.symbol { display: block; position: relative; width: 57%; aspect-ratio: 1; filter: drop-shadow(0 3px 1px #102355); }
.symbol.x::before, .symbol.x::after { content: ""; position: absolute; top: 41%; left: -8%; width: 116%; height: 18%; border-radius: 99px; background: var(--coral); transform: rotate(45deg); box-shadow: inset 0 2px #ffe1ce7a, inset 0 -2px #ad46376e; }
.symbol.x::after { transform: rotate(-45deg); }
.symbol.o { border-radius: 50%; background: conic-gradient(var(--gold) 0deg var(--sweep, 360deg), transparent var(--sweep, 360deg)); mask: radial-gradient(circle, transparent 46%, black 49%); }
.cell.is-flipping .tile { animation: flip 300ms ease-in-out both; }
.cell.is-flipping .symbol.x::before { animation: stroke 95ms 150ms both; }
.cell.is-flipping .symbol.x::after { animation: stroke 95ms 195ms both; }
.cell.is-flipping .symbol.o { animation: ring 145ms 145ms both; }
@property --sweep { syntax: "<angle>"; inherits: false; initial-value: 360deg; }
@keyframes flip { 0% { transform: rotateY(0); } 50% { transform: translateZ(26px) rotateY(90deg); } 84% { transform: translateZ(5px) rotateY(187deg); } 100% { transform: rotateY(180deg); } }
@keyframes stroke { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0); } }
@keyframes ring { from { --sweep: 0deg; } to { --sweep: 360deg; } }
.win-lines { position: absolute; inset: 4.8%; transform: translateZ(12px); pointer-events: none; }
.win-line { position: absolute; height: max(3px, 1.3%); transform-origin: left center; transform: translateY(-50%) rotate(var(--angle)); background: #fff8e9; border-radius: 99px; box-shadow: 0 0 9px #ffd072; }
@keyframes trace { from { clip-path: inset(-10px 100% -10px -10px); } to { clip-path: inset(-10px); } }
.win-line.tracing { animation: trace 280ms ease-out both; }
.cell.winning .back { background: linear-gradient(145deg, #4f76ce, #2a5bb3 79%); border-color: #ffdb89; }
.board.draw .board-base { outline: 3px solid #c5c5e9; outline-offset: 3px; }
#fireworks { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.celebration { position: absolute; bottom: 6px; z-index: 1; padding: 5px 12px; border-radius: 20px; background: var(--gold); color: #212a40; font-size: .77rem; font-weight: 750; pointer-events: none; }

.stage.flat { perspective: none; cursor: default; touch-action: pan-y; }
.stage.flat .camera, .stage.flat .board, .stage.flat .cells, .stage.flat .win-lines { transform-style: flat; }
.stage.flat .board, .stage.flat .cells, .stage.flat .win-lines, .stage.flat .face .symbol { transform: none; }
.stage.flat .cell { touch-action: pan-y; }
.stage.flat .cell.filled .tile, .stage.flat .face.back { transform: none; }
.stage.flat .face { backface-visibility: visible; }
.stage.flat .back { visibility: hidden; }
.stage.flat .filled .back { visibility: visible; }
.stage.flat .cell.is-flipping .tile { animation: flat-reveal 300ms ease both; }
@keyframes flat-reveal { 0%, 100% { scale: 1; } 50% { scale: .9; } }

.table-controls { display: flex; flex-wrap: wrap; justify-content: center; gap: 9px; padding-inline: 13px; }
.table-controls button { color: #fff5dd; background: #183468; border: 1px solid #596fa4; border-radius: 8px; padding: 0 13px; font-size: .82rem; font-weight: 650; min-width: 44px; }
.presets, .zoom { display: flex; }
.presets button:first-child, .zoom button:first-child { border-radius: 8px 0 0 8px; }
.presets button:last-child, .zoom button:last-child { border-left: 0; border-radius: 0 8px 8px 0; }
.table-controls button[aria-pressed="true"] { color: #172750; background: #ffe0a0; border-color: #ffe0a0; }
.table-controls button:disabled { opacity: .53; }
.zoom button { font-size: 1.18rem; }
.camera-hint { margin: 11px 12px 17px; text-align: center; color: #d4dff7; font-size: .75rem; }

dialog { width: min(420px, calc(100% - 32px)); max-height: calc(100% - 32px); padding: 0; border: 1px solid #d9cfbf; border-radius: 18px; background: #fffaf0; color: var(--ink); box-shadow: 0 22px 55px #080f2866; }
dialog::backdrop { background: #101b3bb8; }
.dialog-content { padding: 27px; }
.dialog-content h2 { font-size: 2.35rem; line-height: 1; margin: 5px 40px 16px 0; }
.dialog-content p { line-height: 1.5; color: var(--muted); margin: 0 0 14px; }
.dialog-content .mode + .mode { margin-top: 10px; }
.dialog-close { position: absolute; right: 12px; top: 12px; min-width: 44px; padding: 0; font-size: 1.3rem; }

@media (max-width: 1040px) {
  .shell { width: calc(100% - 60px); }
  .layout { gap: 36px; }
  .camera { width: min(66%, 345px); }
}
@media (max-width: 735px) {
  .shell { width: calc(100% - 32px); }
  .masthead { min-height: 67px; }
  .preferences { gap: 5px; }
  .utility, .view-toggle { padding-inline: 9px; font-size: .74rem; }
  .layout { grid-template-columns: minmax(0, 1fr); gap: 17px; padding-block: 19px 28px; }
  .sidebar { padding: 0; }
  h1 { font-size: clamp(3.4rem, 11vw, 5.6rem); margin: 4px 0 13px -3px; line-height: .98; }
  .desktop-break { display: none; }
  .lede { max-width: none; margin-bottom: 15px; }
  .mode-buttons { grid-template-columns: repeat(2, minmax(0, 1fr)); width: 100%; gap: 7px; }
  .mode { padding-inline: 10px; }
  .mode strong { font-size: .94rem; }
  .mode small { font-size: .72rem; }
  .table-heading { min-height: 60px; padding: 8px 14px; }
  .stage { height: clamp(255px, 64vw, 385px); }
  .camera { width: clamp(215px, 69%, 305px); }
  .table { border-radius: 15px; }
  .playing .sidebar, .playing #round { display: contents; }
  .playing h1 { grid-row: 1; font-size: clamp(2.35rem, 8vw, 4.5rem); margin: 0 0 -7px; }
  .round-mode { grid-row: 2; margin: 0 0 -11px; }
  .round-card { grid-row: 3; width: 100%; min-height: 63px; padding: 8px 11px; }
  .turn-icon { width: 42px; height: 42px; flex-basis: 42px; }
  .playing .table { grid-row: 4; }
  .round-actions { grid-row: 5; margin: 0; display: flex; align-items: center; flex-wrap: wrap; gap: 10px 15px; }
  .round-actions .mode { width: auto; min-width: 135px; min-height: 44px; }
  .round-actions .help { margin: 0; }
}
@media (max-width: 360px) {
  .shell { width: calc(100% - 20px); }
  .table-controls { gap: 5px; padding-inline: 6px; }
  .table-controls button { padding-inline: 8px; }
  .mode small { min-height: 2em; }
}
@media (max-width: 315px) {
  .masthead { flex-wrap: wrap; padding-block: 8px; }
  .table-controls button { padding-inline: 6px; }
}
@media (max-height: 520px) and (orientation: landscape) and (min-width: 650px) {
  .shell { width: calc(100% - 40px); }
  .masthead { min-height: 56px; }
  .layout { grid-template-columns: minmax(215px, .72fr) minmax(0, 1fr); gap: 22px; padding-block: 14px 20px; }
  h1, .playing h1 { font-size: clamp(3rem, 7vw, 5.5rem); margin: 0 0 13px -3px; }
  .desktop-break { display: none; }
  .lede { margin-bottom: 12px; }
  .mode-buttons { grid-template-columns: 1fr; }
  .mode { min-height: 44px; padding-block: 7px; }
  .stage { height: 248px; }
  .camera { width: min(62%, 213px); }
  .table-heading { min-height: 54px; padding-block: 5px; }
  .playing .sidebar, .playing #round { display: block; }
  .playing .table { grid-row: auto; }
  .round-mode { margin-bottom: 9px; }
  .round-actions { margin-top: 9px; }
}
