/* Inter (OFL, fonts/Inter-OFL.txt), self-hosted, subset to Latin + Greek; variable weight 100–900. */
@font-face {
  font-family: "Inter"; font-style: normal; font-weight: 100 900; font-display: swap;
  src: url("../fonts/inter-greek.woff2") format("woff2");
  unicode-range: U+0370-03FF, U+1F00-1FFF;
}
@font-face {
  font-family: "Inter"; font-style: normal; font-weight: 100 900; font-display: swap;
  src: url("../fonts/inter-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2190-2193, U+2212;
}
:root {
  --bg: #1b1410; --bg2: #241a14; --card: #2d2119; --line: #4a3626; --line-strong: #8a6a4a;
  --text: #f3e9d2; --muted: #c4b48c;
  --gold: #e3b23c; --blue: #2e6fb6; --red: #d0544f; --ivory: #f3e9d2; --ebony: #2a2522;
  --radius: 14px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  --serif: var(--font);   /* headings: same family, bolder (no serif any more) */
  --safe-top: env(safe-area-inset-top, 0px); --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px); --safe-left: env(safe-area-inset-left, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body {
  margin: 0; min-height: 100%; color: var(--text); font-family: var(--font);
  background: radial-gradient(1200px 600px at 50% -10%, #3a2718 0%, var(--bg) 60%) var(--bg);
  -webkit-text-size-adjust: 100%;
}
body { padding: 0 var(--safe-right) var(--safe-bottom) var(--safe-left); }

/* visually hidden but available to screen readers */
.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
}

button {
  font: inherit; border: 1px solid var(--line-strong); background: var(--card); color: var(--text);
  padding: 10px 16px; border-radius: 10px; cursor: pointer; min-height: 44px; touch-action: manipulation;
}
button:hover { border-color: var(--gold); }
button:disabled { opacity: .45; cursor: default; border-color: var(--line); }
button.primary { background: var(--gold); color: #1b1410; border-color: var(--gold); font-weight: 700; }
button.ghost { background: transparent; }
input, select {
  font: inherit; background: var(--bg2); color: var(--text); border: 1px solid var(--line-strong);
  border-radius: 10px; padding: 10px 12px; min-height: 44px;
}
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
button.primary:focus-visible { outline-color: var(--text); }
[tabindex="-1"]:focus { outline: none; }
h1, h2, h3 { text-wrap: balance; }
p, li, .msg, .toast { text-wrap: pretty; }

.top {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(10px + var(--safe-top)) 16px 10px; border-bottom: 1px solid var(--line);
  background: rgba(0,0,0,.25); position: sticky; top: 0; z-index: 5; backdrop-filter: blur(6px);
}
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--serif); font-weight: 700; font-size: 1.15rem; letter-spacing: .02em; }
.brand-logo { display: block; height: 30px; width: auto; }
@media (max-width: 440px) { .brand-logo { height: 23px; } }   /* phone header: logo + online + settings + language */
@media (max-width: 360px) { .brand-logo { height: 19px; } }
.top-right { display: flex; align-items: center; gap: 12px; }
.online { color: var(--muted); font-size: .85rem; display: flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #3fbf6a; display: inline-block; box-shadow: 0 0 8px #3fbf6a; }
#lang { padding: 6px 8px; min-height: 36px; }

.screen { max-width: 920px; margin: 0 auto; padding: 16px; }
.hero { text-align: center; padding: 18px 0 8px; }
.hero h1 { font-family: var(--serif); font-weight: 800; letter-spacing: -0.01em; font-size: clamp(2rem, 6vw, 3.2rem); margin: 0; letter-spacing: .02em; }
.tagline { color: var(--muted); margin: 6px 0 0; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; margin: 14px 0; box-shadow: 0 10px 30px rgba(0,0,0,.35);
}
.card.center { text-align: center; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: .9rem; color: var(--muted); flex: 1; margin-bottom: 12px; }
.row { display: flex; gap: 12px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 8px 0; }
.actions button { flex: 1 1 180px; }
.join { display: flex; gap: 10px; margin-top: 8px; }
.join input { flex: 1; min-width: 0; text-transform: uppercase; letter-spacing: .25em; font-weight: 700; text-align: center; }
.msg { color: var(--gold); margin: 10px 0 0; }
.rules h2 { font-family: var(--serif); font-weight: 800; letter-spacing: -0.01em; margin: 0 0 8px; font-size: 1.2rem; }
.rules details { border-top: 1px solid var(--line); padding: 10px 0; }
.rules summary { cursor: pointer; font-weight: 600; min-height: 24px; }
.rules p { color: var(--muted); margin: 8px 0 0; line-height: 1.5; }

.spinner {
  width: 40px; height: 40px; border: 4px solid var(--line); border-top-color: var(--gold);
  border-radius: 50%; margin: 10px auto 16px; animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.code {
  font-size: clamp(2.6rem, 13vw, 3.6rem); letter-spacing: .25em; padding-left: .25em; /* balance the trailing spacing */
  font-weight: 800; font-family: var(--font); font-variant-numeric: tabular-nums lining-nums; /* sans: unambiguous digits */
  margin: 8px 0 14px; color: var(--gold); user-select: all; -webkit-user-select: all; line-height: 1.1;
}
.wait-game { color: var(--muted); margin: -6px 0 14px; }
.share-actions { justify-content: center; }
.share-actions > * { flex: 1 1 160px; }
.btn-link {
  display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 10px 16px;
  border: 1px solid var(--line-strong); border-radius: 10px; background: var(--card); color: var(--text);
  text-decoration: none; touch-action: manipulation;
}
.btn-link:hover { border-color: var(--gold); }
#btnCopy { margin-bottom: 8px; }
.invite-card { max-width: 480px; margin-left: auto; margin-right: auto; }
.invite-card h1 { font-family: var(--serif); font-weight: 800; letter-spacing: -0.01em; font-size: clamp(1.8rem, 6vw, 2.4rem); margin: 4px 0 10px; }
.invite-text { font-size: 1.15rem; line-height: 1.45; margin: 0 0 16px; }
.invite-form { text-align: left; }
.invite-hint { color: var(--muted); line-height: 1.45; margin: -8px 0 16px; }
.field-hint { color: var(--muted); font-size: .9rem; line-height: 1.4; margin: -4px 0 12px; }
.join-label { display: block; margin-top: 16px; font-size: .9rem; color: var(--muted); }

/* game */
#game { padding: 10px 8px; max-width: 980px; }
.hud { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; padding: 4px 6px; }
.player { display: flex; align-items: center; gap: 8px; min-width: 0; }
.player.me { justify-content: flex-end; }
.pname { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pips { color: var(--muted); font-size: .8rem; }
.chip { width: 20px; height: 20px; border-radius: 50%; display: inline-block; border: 2px solid var(--line-strong); flex: none; }
.chip.ivory { background: var(--chip0, var(--ivory)); border-color: var(--chip0-edge, var(--line-strong)); }
.chip.ebony { background: var(--chip1, var(--ebony)); border-color: var(--chip1-edge, var(--line-strong)); }
.chip.turn { box-shadow: 0 0 0 3px var(--gold); }
.score { font-family: var(--font); font-weight: 700; font-variant-numeric: tabular-nums lining-nums; font-size: 1.4rem; display: flex; align-items: center; gap: 10px; }
.score small { color: var(--muted); font-family: var(--font); font-size: .75rem; text-align: center; display: flex; flex-direction: column; }
#gameInfo { max-width: 11em; }   /* "Game 1 · first to 5 · no time limit" wraps instead of squeezing the names */
.status { display: flex; flex-direction: column; gap: 4px; padding: 4px 6px 8px; min-height: 34px; }
#status { font-weight: 600; }
#status[data-hint] { font-weight: 500; font-size: .85rem; color: var(--muted); line-height: 1.5; }
.timer { height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; }
#timerBar { height: 100%; width: 100%; background: var(--gold); transform-origin: left center; transform: scaleX(0); transition: transform .9s linear; }
#timerBar.low { background: var(--red); }
.boardwrap { width: 100%; position: relative; }  /* offsetParent of the canvas: tilt hit testing */
#board.can-roll { cursor: pointer; }
.switch { display: inline-flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; color: var(--text); margin: 0 0 8px; }
.switch.compact { min-height: 36px; margin: 0; font-size: .85rem; color: var(--muted); }
.switch input {
  appearance: none; -webkit-appearance: none; width: 42px; height: 24px; min-height: 0; padding: 0; margin: 0;
  border-radius: 12px; background: var(--bg2); border: 1px solid var(--line-strong); position: relative; cursor: pointer; flex: none;
}
.switch input::before {
  content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%;
  background: var(--muted); transition: transform .15s ease;
}
.switch input:checked { background: var(--gold); border-color: var(--gold); }
.switch input:checked::before { transform: translateX(18px); background: #1b1410; }
#board { display: block; width: 100%; margin: 0 auto; touch-action: manipulation; border-radius: 10px; }
.movelist { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 8px 4px 0; }
.movelist-title { color: var(--muted); font-size: .85rem; margin-right: 4px; }
#moveList { display: flex; flex-wrap: wrap; gap: 6px; }
#moveList .move { min-height: 36px; padding: 6px 10px; font-size: .85rem; font-variant-numeric: tabular-nums; }
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 4px; }
.spacer { flex: 1; }
.dice { display: flex; gap: 6px; min-width: 96px; }
.die {
  width: 42px; height: 42px; background: var(--ivory); border-radius: 9px; display: grid; place-items: center;
  color: #1b1410; font-weight: 800; font-size: 1.3rem; box-shadow: inset 0 -3px 0 rgba(0,0,0,.2); position: relative;
}
.die.used { opacity: .35; text-decoration: line-through; }
.die.opp { background: #5a514b; color: var(--ivory); }
.die.multiplier { background: transparent; color: var(--muted); box-shadow: none; }
.emotes { display: flex; flex-wrap: wrap; gap: 4px; }
.emotes button { padding: 6px 8px; min-height: 36px; font-size: .8rem; }
.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom)); transform: translateX(-50%);
  background: #111; color: var(--text); padding: 10px 16px; border-radius: 10px; border: 1px solid var(--gold);
  z-index: 20; max-width: calc(100vw - 32px); pointer-events: none;
}
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.7); display: grid; place-items: center; z-index: 10;
  padding: calc(16px + var(--safe-top)) calc(16px + var(--safe-right)) calc(16px + var(--safe-bottom)) calc(16px + var(--safe-left));
}
.overlay .card { max-width: 420px; width: 100%; }
.overlay h2 { font-family: var(--serif); font-weight: 800; letter-spacing: -0.01em; font-size: 1.8rem; margin: 0 0 8px; }
/* settings */
.icon-btn {
  display: inline-grid; place-items: center; min-width: 44px; min-height: 44px; padding: 0;
  background: transparent; border-color: var(--line-strong); color: var(--text);
}
.settings-overlay { z-index: 12; align-items: start; overflow-y: auto; }
.overlay .settings-card { max-width: 560px; text-align: left; margin: 0 auto; }
.settings-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 4px; }
.settings-head h2 { margin: 0; }
.opt-group { border: 0; border-top: 1px solid var(--line); margin: 10px 0 0; padding: 10px 0 0; min-width: 0; }
.opt-group legend { color: var(--muted); font-size: .9rem; padding: 0; margin-bottom: 6px; }
.tiles { display: flex; flex-wrap: wrap; gap: 10px; }
.tile { position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; width: 112px; cursor: pointer; font-size: .82rem; text-align: center; }
.tile-input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; pointer-events: none; }
.tile-preview { width: 104px; height: 70px; border-radius: 8px; border: 2px solid transparent; outline-offset: 2px; display: block; }
.tile-input:checked + .tile-preview { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold); }
.tile-input:focus-visible + .tile-preview { outline: 3px solid var(--gold); }
.tile-input:checked ~ .tile-label { color: var(--gold); font-weight: 600; }
.tile-label { line-height: 1.25; }
.opt-switches { border-top: 1px solid var(--line); margin-top: 12px; padding-top: 8px; display: flex; flex-direction: column; }
.opt-switches .switch { margin: 0; }
.switch input:disabled { opacity: .45; cursor: not-allowed; }
.tilt-note { margin: 0 0 4px 52px; }
#board { transform-origin: 50% 50%; }

.bubble {
  position: fixed; top: calc(70px + var(--safe-top)); left: 50%; transform: translateX(-50%);
  background: var(--card); border: 1px solid var(--gold); padding: 8px 14px; border-radius: 20px;
  z-index: 15; animation: pop .25s ease-out; pointer-events: none;
}
@keyframes pop { from { transform: translateX(-50%) scale(.7); opacity: 0; } }

/* accessibility entry point in the lobby, last opponent move, move-list placeholder */
.access-entry { border: 1px solid var(--line-strong); border-radius: 10px; padding: 6px 12px 0; margin-bottom: 14px; }
.access-entry .field-hint { margin: -6px 0 10px 52px; }
.opt-note { margin: -4px 0 8px 52px; }
.last-move { color: var(--muted); font-size: .85rem; min-height: 1.2em; }
.movelist-empty { color: var(--muted); margin: 0; font-size: .95rem; }
.turn-actions { display: contents; }
.card > .switch, .access-entry > .switch { display: flex; width: fit-content; max-width: 100%; }

/* game-end card over the board (between two games); not modal, the page behind stays usable */
.end-card { position: absolute; inset: 0; display: grid; place-items: center; z-index: 4; padding: 8px; pointer-events: none; }
.end-card-inner {
  pointer-events: auto; margin: 0; width: min(100%, 420px); text-align: center; padding: 14px 18px;
  background: rgba(36,26,20,.96); border-color: var(--line-strong); animation: card-in .28s ease-out;
}
.end-card h2 { font-family: var(--serif); font-weight: 800; letter-spacing: -0.01em; font-size: 1.7rem; margin: 0 0 4px; color: var(--text); }
.end-card.won h2 { color: var(--gold); }
.end-card p { margin: 2px 0; line-height: 1.35; }
.end-reason { color: var(--muted); }
.end-score { font-weight: 700; font-size: 1.15rem; font-variant-numeric: tabular-nums lining-nums; margin-top: 6px !important; }
.end-next { margin-top: 8px !important; }
.end-wait { color: var(--muted); font-size: .9rem; min-height: 1.35em; }
.end-timer { height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; margin: 6px auto 4px; max-width: 220px; }
#endTimerBar { height: 100%; width: 100%; background: var(--gold); transform-origin: left center; transition: transform .25s linear; }
#btnContinue { margin-top: 8px; min-width: 160px; }
#btnContinue[aria-disabled="true"] { opacity: .55; cursor: default; }
.result-card h2 { color: var(--gold); }
@keyframes card-in { from { opacity: 0; transform: translateY(8px) scale(.97); } }

@media (max-width: 520px) {
  .tile { width: calc(50% - 5px); }
  .tile-preview { width: 100%; height: auto; aspect-ratio: 104 / 70; }
  .emotes { order: 5; width: 100%; justify-content: center; }
  .score { font-size: 1.2rem; }
  .pips { display: none; }
  .row { flex-direction: column; gap: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
  .spinner { animation: none; border-top-color: var(--gold); }
}

@media (forced-colors: active) {
  .switch input { appearance: auto; -webkit-appearance: auto; width: auto; height: auto; }
  .switch input::before { content: none; }
  .chip.turn { outline: 3px solid CanvasText; }
  #timerBar { background: Highlight; }
}

/* ---------------------------------------------------------------- large controls (html.big-ui)
 * For Voice Control, eye tracking (dwell) and switch access: every target >= 64 x 64 px, >= 12 px apart,
 * a thick focus ring, Roll/Undo always in the same place, the move list keeps its height. */
.big-ui button, .big-ui .btn-link, .big-ui select, .big-ui input:not([type="checkbox"]) { min-height: 64px; font-size: 1.1rem; }
.big-ui button { min-width: 64px; padding: 12px 18px; }
.big-ui .actions, .big-ui .join, .big-ui .controls, .big-ui .share-actions { gap: 12px; }
.big-ui :focus-visible { outline: 5px solid var(--gold); outline-offset: 3px; box-shadow: 0 0 0 10px #000; }
.big-ui button.primary:focus-visible { outline-color: var(--text); }
.big-ui .switch, .big-ui .switch.compact { min-height: 64px; font-size: 1.05rem; color: var(--text); gap: 14px; }
.big-ui .card > .switch { margin-bottom: 12px; }
.big-ui .rules summary { min-height: 64px; display: flex; align-items: center; font-size: 1.1rem; }
.big-ui .switch input { width: 60px; height: 34px; border-radius: 17px; }
.big-ui .switch input::before { width: 28px; height: 28px; }
.big-ui .switch input:checked::before { transform: translateX(26px); }
.big-ui .access-entry .field-hint, .big-ui .opt-note { margin-left: 74px; }
.big-ui .icon-btn { min-width: 64px; min-height: 64px; }
.big-ui #lang { min-height: 64px; }
.big-ui .movelist { display: block; padding: 8px 0 0; }
.big-ui .movelist-title { display: block; font-size: 1rem; margin: 0 0 8px; }
.big-ui #moveList {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px;
  min-height: calc(3 * 64px + 2 * 12px); align-content: start;
}
.big-ui #moveList .move { min-height: 64px; padding: 8px 10px; font-size: 1.3rem; font-weight: 700; }
.big-ui #moveList .move.more { font-size: 1.05rem; font-weight: 600; border-style: dashed; }
.big-ui #moveList:empty { min-height: 0; }    /* no moves: the placeholder below takes the same height */
.big-ui .movelist-empty { min-height: calc(3 * 64px + 2 * 12px); padding: 20px 4px; }
.big-ui .turn-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; width: 100%; }
.big-ui .turn-actions button { min-height: 72px; font-size: 1.3rem; font-weight: 700; }
.big-ui #btnRoll:not(:disabled) { background: var(--gold); color: #1b1410; border-color: var(--gold); }
.big-ui .controls { padding: 16px 0; }
.big-ui .controls .spacer { display: none; }
.big-ui .controls > .ghost { flex: 1 1 140px; }
.big-ui .emotes { width: 100%; gap: 12px; }
.big-ui .emotes button { min-height: 64px; flex: 1 1 140px; font-size: 1rem; }
.big-ui .overlay .card { max-width: 520px; }
.big-ui .overlay .actions button { flex: 1 1 200px; }
.big-ui .last-move { font-size: 1rem; }
.big-ui .end-card-inner { width: min(100%, 520px); padding: 16px 20px; }
.big-ui .end-card h2 { font-size: 2rem; }
.big-ui .end-card p { font-size: 1.1rem; }
.big-ui #btnContinue { min-height: 72px; width: 100%; font-size: 1.3rem; }
.big-ui #status { font-size: 1.15rem; min-height: 1.4em; }     /* one line reserved; rare wraps only shift by a line */
.big-ui .last-move { min-height: 1.4em; }
@media (min-width: 640px) {
  .big-ui #moveList { grid-template-columns: repeat(3, minmax(0, 1fr)); min-height: calc(2 * 64px + 12px); }
  .big-ui .movelist-empty { min-height: calc(2 * 64px + 12px); }
}
/* wide screens: board on the left, moves and actions next to it, so the board stays in view */
@media (min-width: 1000px) {
  .big-ui #game {
    max-width: 1240px; display: grid; grid-template-columns: minmax(0, 1fr) 420px; column-gap: 24px; align-items: start;
    grid-template-areas: "hud hud" "status status" "board moves" "board controls"; grid-template-rows: auto auto auto 1fr;
  }
  .big-ui #game .hud { grid-area: hud; }
  .big-ui #game .status { grid-area: status; }
  .big-ui #game .boardwrap { grid-area: board; }
  .big-ui #game .movelist { grid-area: moves; }
  .big-ui #game .controls { grid-area: controls; }
  .big-ui #moveList { grid-template-columns: repeat(2, minmax(0, 1fr)); min-height: calc(3 * 64px + 2 * 12px); }
  .big-ui .movelist-empty { min-height: calc(3 * 64px + 2 * 12px); }
}
