:root {
  --brand-200: #ddd6fe;
  --brand-300: #c4b5fd;
  --brand-400: #a78bfa;
  --brand-500: #8b5cf6;
  --bg: #0a0612;
  --surface: rgba(23, 15, 38, 0.6);
  --line: rgba(167, 139, 250, 0.18);
  --line-strong: rgba(167, 139, 250, 0.42);
  --muted: rgba(221, 214, 254, 0.78);
  --text: #f5f3ff;
  --amber: #ffb84a;
  --warn: #fcd34d;
  --font-sans: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --tilt: 38deg;
  --light: #c9bb9c;
  --dark: #5b4784;
  --frame: #2d1b55;
  --face-a: #4a3080;
  --face-b: #170b30;
  color-scheme: dark;
}
body[data-theme="wood"] { --light: #c9ab80; --dark: #7a5538; --frame: #3a2616; --face-a: #5a3d24; --face-b: #24150a; }
body[data-theme="green"] { --light: #cfd1b0; --dark: #5d8363; --frame: #1f3a2a; --face-a: #2f5a40; --face-b: #0f2218; }
body[data-theme="blue"] { --light: #c6cfdc; --dark: #506f96; --frame: #1c2c4a; --face-a: #2e4a78; --face-b: #0e182c; }

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-height: 100%; }
body { display: flex; flex-direction: column; min-height: 100dvh; margin: 0; background: var(--bg); color: var(--text); font: 400 1rem/1.6 var(--font-sans); overflow-x: hidden; }
:focus-visible { outline: 3px solid var(--brand-300); outline-offset: 3px; border-radius: 6px; }
a { color: var(--brand-400); text-underline-offset: 0.2em; }
#lens-canvas { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 0; }

/* Brand mark, as on krinkerlabs.com: KRINKERLABS with a small TM, a dot, the product, then the BETA badge. */
.sub-brand { --dot-before: 0.25em; --dot-after: 0.14em; display: inline-block; font-weight: 800; letter-spacing: -0.01em; white-space: nowrap; color: #fff; }
.sub-brand-labs { color: var(--brand-400); }
.sub-brand .tm { margin-inline-start: 0.1em; color: var(--muted); font-size: 0.45em; font-weight: 400; letter-spacing: 0; vertical-align: super; }
.sub-brand-product { background: linear-gradient(90deg, #8b5cf6, #7c6af5 55%, #6366f1); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
.sub-brand-dot { display: inline-block; width: 0.24em; height: 0.24em; margin-inline: var(--dot-before) var(--dot-after); border-radius: 50%; background: currentColor; vertical-align: 0.24em; }
@supports (width: 1cap) { .sub-brand-dot { width: calc(1cap / 3); height: calc(1cap / 3); vertical-align: calc(1cap / 3); } }
.brand-line { display: inline-flex; align-items: center; justify-content: center; gap: 0.7rem; }
.beta-badge { padding: 0.15rem 0.7rem; border: 1px solid var(--warn); border-radius: 999px; color: var(--warn); font-size: 0.72rem; font-weight: 700; letter-spacing: 0.12em; }
.mark { margin: 0; font-size: clamp(1.2rem, 3.4vw, 2rem); line-height: 1.2; letter-spacing: -0.02em; text-align: center; }
.mark .sub-brand { font-size: 1em; }

/* Controls */
.tools { position: fixed; z-index: 6; top: max(12px, env(safe-area-inset-top)); inset-inline-end: 12px; display: flex; gap: 8px; align-items: flex-start; }
.btn { width: 46px; height: 46px; color: inherit; font: inherit; font-size: 20px; background: var(--surface); border: 1px solid rgba(255, 255, 255, 0.2); border-radius: 50%; backdrop-filter: blur(6px); cursor: pointer; }
.go, .alt { font: 700 1rem var(--font-sans); border-radius: 40px; cursor: pointer; text-decoration: none; }
.go { padding: 16px 46px; border: 0; font-size: 1.35rem; color: #1a1000; background: linear-gradient(135deg, #ffe08a, #ffb347); box-shadow: 0 0 34px rgba(255, 180, 70, 0.5); }
.alt { padding: 10px 28px; border: 1px solid #ffb347; background: transparent; color: #ffd58a; }
/* Resigning ends the game: a quieter red outline, filled red while it waits for the confirming press. */
.alt.resign { border-color: #e2725b; color: #ffb4a3; }
.alt.resign.armed { background: #c0392b; border-color: #c0392b; color: #fff; }
.go:active, .btn:active { transform: scale(0.97); }

/* Dropdown in the style of the site */
.site-select { position: relative; }
.select-button { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; width: 100%; min-height: 2.6rem; padding: 0.55rem 0.8rem; color: #fff; font: inherit; text-align: start; background: rgba(255, 255, 255, 0.05); border: 1px solid var(--line); border-radius: 10px; cursor: pointer; transition: border-color 0.2s; }
.select-button:hover, .select-button[aria-expanded="true"] { border-color: var(--brand-400); }
.select-arrow { flex: none; border-inline: 0.3rem solid transparent; border-top: 0.35rem solid var(--brand-300); transition: transform 0.2s; }
.select-button[aria-expanded="true"] .select-arrow { transform: rotate(180deg); }
.select-list { position: absolute; inset-inline: 0; top: calc(100% + 0.4rem); z-index: 60; margin: 0; padding: 0.4rem; list-style: none; max-height: 16rem; overflow-y: auto; background: rgba(15, 10, 28, 0.97); border: 1px solid var(--line-strong); border-radius: 12px; box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5); text-align: start; }
.select-list li { display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; padding: 0.55rem 0.7rem; color: var(--muted); border-radius: 8px; cursor: pointer; }
.select-list li.is-active { background: rgba(139, 92, 246, 0.22); color: #fff; }
.select-list li[aria-selected="true"] { color: var(--brand-200); font-weight: 600; }
.select-list li[aria-selected="true"]::after { content: "\2713"; color: var(--brand-400); }
.tools .select-button { height: 46px; padding-inline: 1rem; border-radius: 23px; background: var(--surface); border-color: rgba(255, 255, 255, 0.2); backdrop-filter: blur(6px); }
.tools .select-list { inset-inline: auto 0; min-width: 11rem; }

/* Page layout: moves and clock on the left, the board in the middle, controls on the right */
.stage { position: relative; z-index: 1; flex: 1; display: grid; grid-template-columns: minmax(11rem, 1fr) auto minmax(11rem, 1fr); gap: clamp(1.5rem, 9vw - 3rem, 8.5rem); align-items: center; justify-items: center; padding: 2.6rem 1.5rem 0.5rem; }
.center { display: grid; justify-items: center; gap: 0.9rem; }
.side { display: grid; gap: 1rem; width: 100%; max-width: 21rem; align-self: stretch; }
.side-left { justify-self: end; grid-template-rows: 1fr 1fr; }
.side-left > :first-child { align-self: end; }
.side-left > :last-child { align-self: start; }
/* The right column starts under the language and menu buttons, so the players are at the top right, under them. */
.side-right { justify-self: start; align-content: start; padding-top: 4.4rem; }
.panel { margin: 0; min-height: 2.6rem; padding: 0.6rem 1.6rem; border-radius: 0.8rem; background: linear-gradient(90deg, transparent, var(--surface) 15%, var(--surface) 85%, transparent); text-align: center; }
.panel-box { padding: 0.9rem 1rem; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); backdrop-filter: blur(8px); }
.panel-box h2 { margin: 0 0 0.5rem; color: var(--brand-300); font-size: 0.95rem; font-weight: 700; }
.row { display: flex; flex-wrap: wrap; gap: 0.6rem; justify-content: center; align-items: center; margin: 2.5rem 0 0 0; }
.moves-list { --row-height: 1.6rem; direction: ltr; display: block; height: calc(var(--rows, 10) * var(--row-height)); overflow-y: auto; margin: 0; padding: 0; list-style: none; color: var(--muted); font-size: 0.9rem; font-variant-numeric: tabular-nums; scrollbar-width: thin; scrollbar-color: var(--brand-500) transparent; }
.moves-list li { display: grid; grid-template-columns: 2.4rem 1fr 1fr; height: var(--row-height); line-height: var(--row-height); }
.moves-list li.current { color: #fff; }
.help-box p { margin: 0.5rem 0 0; color: var(--muted); font-size: 0.85rem; line-height: 1.45; }
.help-box .keys { line-height: 2; }
.help-box .help-sub { margin: 0.9rem 0 0; }
.menu-hint { margin: -0.3rem auto 0.4rem; max-width: 22rem; color: var(--muted); font-size: 0.85rem; line-height: 1.4; text-align: center; }

/* Players: a round avatar (the first letter on a colour of its own), the name, the colour, and online a dot that is green while the player is in the game. */
.players { display: grid; gap: 0.55rem; margin: 0; padding: 0; list-style: none; }
.player { display: grid; grid-template-columns: 2.6rem minmax(0, 1fr) auto; align-items: center; gap: 0.65rem; }
.avatar { display: grid; place-items: center; width: 2.6rem; height: 2.6rem; border-radius: 50%; font-weight: 800; font-size: 1.1rem; color: #fff;
  background: linear-gradient(135deg, hsl(var(--hue, 270) 70% 58%), hsl(var(--hue, 270) 65% 38%)); box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.12); }
.player.mine .avatar { box-shadow: 0 0 0 2px #ffb347; }
.player-text { display: grid; min-width: 0; }
.player-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.player-input { width: 100%; min-width: 0; padding: 0.2rem 0.45rem; border: 1px solid var(--line); border-radius: 8px; background: rgba(0, 0, 0, 0.25); color: inherit; font: 700 0.95rem var(--font-sans); }
.player-input:focus { outline: 2px solid #ffb347; outline-offset: 1px; }
.player-sub { color: var(--muted); font-size: 0.8rem; }
.presence { width: 0.7rem; height: 0.7rem; border-radius: 50%; background: #6b6280; }
.presence.here { background: #3ddc84; box-shadow: 0 0 8px #3ddc84; }
kbd { display: inline-block; min-width: 1.7rem; margin: 0.1rem; padding: 0.1rem 0.45rem; border: 1px solid rgba(255, 255, 255, 0.3); border-bottom-width: 3px; border-radius: 6px; background: rgba(255, 255, 255, 0.08); font: 600 0.8rem ui-monospace, monospace; text-align: center; }
.clock-svg { display: block; width: 100%; height: auto; }
.clock-rim.active { stroke: #ffb84a; }
.clock-rim.low { stroke: #e5484d; }
.clock-button { cursor: pointer; transition: transform 0.08s; }
.clock-button.pressed { transform: translateY(5px); }
.site-note { position: relative; z-index: 1; padding: 0 1rem 1.4rem; text-align: center; font-size: 0.85rem; line-height: 1.5; color: var(--muted); }
.site-note p { margin: 0 auto; max-width: 60rem; }
@media (max-width: 1100px) {
  .stage { grid-template-columns: minmax(0, 1fr); padding-bottom: 2rem; }
  /* On a narrow screen the panels follow the board one by one: the players first, then the moves, the clock and the help. */
  .side { display: contents; }
  .side > .panel-box { width: min(92vw, 34rem); justify-self: center; align-self: auto; }
  .players-box { order: 1; }
  .side-left > :first-child { order: 2; }
  #clock-box { order: 3; }
  .help-box { order: 4; }
}

/* The table: a tilted slab seen in perspective. The board never mirrors in right-to-left languages. */
.scene { position: relative; direction: ltr; container-type: inline-size; width: min(92vw, 74vh, 680px); margin-block: -1.5rem 1.5rem; perspective: 1200px; perspective-origin: 50% 30%; }
.tilt { position: relative; transform: rotateX(var(--tilt)); transform-style: preserve-3d; }
.tilt::before { content: ""; position: absolute; inset: 2cqw; transform: translateZ(-8cqw); background: #000; filter: blur(3.5cqw); opacity: 0.6; }
.face { position: absolute; inset-inline: 0; top: 100%; height: 8cqw; transform-origin: top; transform: rotateX(-90deg); border-radius: 0 0 1cqw 1cqw; background: linear-gradient(var(--face-a), var(--face-b)); }
.board { display: grid; grid-template: repeat(8, 1fr) / repeat(8, 1fr); aspect-ratio: 1; transform-style: preserve-3d; touch-action: none; user-select: none; -webkit-user-select: none; border: 5cqw solid var(--frame); border-radius: 1cqw; background: var(--frame); outline: 0.4cqw solid rgba(255, 184, 74, 0.35); outline-offset: -0.9cqw; }
.coords { position: absolute; inset: 0; transform: translateZ(0.2cqw); pointer-events: none; color: rgba(236, 208, 160, 0.85); font-size: 2.2cqw; font-weight: 700; }
.files, .ranks { position: absolute; display: grid; place-items: center; }
.files { left: 5cqw; right: 5cqw; height: 3.4cqw; grid-template-columns: repeat(8, 1fr); }
.files.top { top: 1.5cqw; }
.files.bottom { bottom: 1.5cqw; }
.ranks { top: 5cqw; bottom: 5cqw; width: 3.4cqw; grid-template-rows: repeat(8, 1fr); }
.ranks.left { left: 1.5cqw; }
.ranks.right { right: 1.5cqw; }
.sq { position: relative; display: grid; place-items: center; transform-style: preserve-3d; background: var(--light); cursor: pointer; }
.sq.dark { background: var(--dark); }
.sq.last { background-image: linear-gradient(rgba(255, 184, 74, 0.22), rgba(255, 184, 74, 0.22)); }
.sq.check { background-image: radial-gradient(circle, rgba(255, 70, 70, 0.75) 0%, rgba(255, 70, 70, 0) 70%); }
.sq:focus-visible { outline-offset: -3px; }
.sq.picked { background-image: linear-gradient(rgba(255, 184, 74, 0.35), rgba(255, 184, 74, 0.35)); box-shadow: inset 0 0 0 0.7cqw rgba(255, 184, 74, 0.9); }
.sq.target { box-shadow: inset 0 0 0 0.7cqw rgba(255, 184, 74, 0.9); }
.sq.occupied::before { content: ""; position: absolute; bottom: 10%; width: 64%; height: 24%; border-radius: 50%; background: radial-gradient(closest-side, rgba(0, 0, 0, 0.5), transparent); }

/* Pieces stand upright on the tilted board and cast a shadow on their square. */
/* Pieces are KrinkerLabs' own vector drawings (pieces.ts): ivory and ebony gradients lit from the upper left, a thin rim and a highlight.
   On the tilted board each piece is turned back upright and casts its shadow on the square. */
/* Turn lights stand on the table by the board corners (inside the tilted plane, upright like the pieces): far left for the side at the top, near right for the side at the bottom; green for the side to move. */
.turn-light { position: absolute; z-index: 2; width: 3.4cqw; height: 3.4cqw; transform-origin: 50% 100%; transform: translateZ(0.1cqw) rotateX(calc(var(--tilt) * -1)); border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #9b93ad, #4f4860 70%); box-shadow: inset 0 -2px 3px rgba(0, 0, 0, 0.45), 0 0 0 2px rgba(255, 255, 255, 0.08); transition: background 0.25s, box-shadow 0.25s; }
.turn-light.on { background: radial-gradient(circle at 35% 30%, #c8ffd9, #3ddc84 55%, #14864a); box-shadow: inset 0 -2px 3px rgba(0, 0, 0, 0.3), 0 0 14px 3px rgba(61, 220, 132, 0.65); }
.turn-light.top { top: -5cqw; left: 3cqw; }
.turn-light.bottom { bottom: -6.5cqw; right: 7cqw; }
.piece-defs { position: absolute; width: 0; height: 0; overflow: hidden; }
.piece { display: block; width: 10.6cqw; height: 10.6cqw; transform-origin: 50% 90%; transform: translateZ(0.1cqw) rotateX(calc(var(--tilt) * -1)); filter: drop-shadow(0 0.5cqw 0.35cqw rgba(0, 0, 0, 0.55)); }
.piece svg { display: block; width: 100%; height: 100%; overflow: visible; }
.piece .body { stroke-width: 1.6; stroke-linejoin: round; }
.piece.w .body { fill: url(#ivory); stroke: #34244c; }
.piece.b .body { fill: url(#ebony); stroke: #d6c9f7; stroke-width: 1.3; }
.piece .detail { fill: none; stroke-width: 1.6; stroke-linecap: round; }
.piece.w .detail { stroke: #6e5a3c; }
.piece.b .detail { stroke: #8a77c4; }
.piece .shine { fill: #fff; opacity: 0.55; }
.piece.b .shine { opacity: 0.22; }
.piece .eye { fill: #1b1030; }
.piece.b .eye { fill: #d7cbf5; }
.piece.lifted { opacity: 0.3; }
.ghost { position: fixed; z-index: 30; pointer-events: none; transform: none; translate: -50% -65%; }

/* Menu and dialogs: dense violet middle with edges fading into the background. */
.overlay { position: fixed; inset: 0; z-index: 5; display: grid; place-items: center; padding: 1rem 1rem 7vh; overflow-y: auto; background: radial-gradient(ellipse at center, rgba(10, 6, 18, 0.45), rgba(10, 6, 18, 0.9)); }
.card { position: relative; isolation: isolate; width: min(92vw, 620px); padding: 28px 32px; text-align: center; }
.card > * + * { margin-top: 0.9rem; }
.card::before { content: ""; position: absolute; inset: -56px -72px; z-index: -1; border-radius: 48px; pointer-events: none;
  background: radial-gradient(circle at 16% 10%, rgba(109, 40, 217, 0.5), transparent 55%), radial-gradient(circle at 86% 90%, rgba(76, 29, 149, 0.6), transparent 55%), radial-gradient(ellipse at center, rgba(22, 16, 36, 0.94) 0%, rgba(24, 18, 40, 0.82) 60%, rgba(24, 18, 44, 0.5) 100%);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  -webkit-mask-image: linear-gradient(to right, transparent, #000 10%, #000 90%, transparent), linear-gradient(to bottom, transparent, #000 8%, #000 92%, transparent); -webkit-mask-composite: source-in;
  mask-image: linear-gradient(to right, transparent, #000 10%, #000 90%, transparent), linear-gradient(to bottom, transparent, #000 8%, #000 92%, transparent); mask-composite: intersect; }
.card .mark { font-size: clamp(1.15rem, 4.4vw, 1.9rem); }
.card .go, .card .alt { display: block; margin-inline: auto; width: fit-content; }
.opts { display: grid; gap: 0.7rem; margin-block: 1rem; }
.opt { display: grid; grid-template-columns: 8rem 1fr; gap: 0.6rem; align-items: center; text-align: start; font-size: 0.9rem; }
.choice { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.choice button { padding: 0.3rem 0.85rem; color: var(--muted); font: inherit; font-size: 0.85rem; background: transparent; border: 1px solid var(--line); border-radius: 999px; cursor: pointer; }
.choice button:hover { color: #fff; border-color: var(--brand-400); }
.choice button[aria-pressed="true"] { color: #fff; background: rgba(124, 58, 237, 0.3); border-color: var(--brand-400); }
.swatch { width: 2.4rem; height: 2rem; padding: 0.2rem !important; }
.swatch i { display: block; width: 100%; height: 100%; border-radius: 6px; }
.swatch[data-value="violet"] i { background: linear-gradient(135deg, #c9bb9c 50%, #5b4784 50%); }
.swatch[data-value="wood"] i { background: linear-gradient(135deg, #c9ab80 50%, #7a5538 50%); }
.swatch[data-value="green"] i { background: linear-gradient(135deg, #cfd1b0 50%, #5d8363 50%); }
.swatch[data-value="blue"] i { background: linear-gradient(135deg, #c6cfdc 50%, #506f96 50%); }
.bug { font-size: 0.85rem; opacity: 0.85; }
.promo-row { display: flex; gap: 0.6rem; justify-content: center; }
.piece-choice { width: 4rem; height: 4rem; padding: 0.35rem; border: 2px solid #ffb347; border-radius: 12px; background: var(--light); cursor: pointer; transform: none; filter: none; }
.draw-glyph { display: block; width: 6rem; height: 6rem; margin-inline: auto; padding: 0.8rem; border: 3px solid #ffb347; border-radius: 50%; background: var(--light); transform: none; }
.draw-result { min-height: 1.6rem; font-weight: 700; }

.menu-note { margin: 0; color: var(--warn); font-size: 0.9rem; }
.menu-note:empty { display: none; }
.view-switch { display: flex; align-items: center; gap: 0.5rem; color: var(--muted); font-size: 0.9rem; }
