@import url('../fonts/fonts.css');

/* ------------------------------------------------------------------ tokens */
:root {
  /* Shell: copper-spire verdigris at dusk */
  --spire-950: #0b2421;
  --spire-900: #10302c;
  --spire-800: #163f3a;
  --spire-700: #1d4f49;
  --spire-600: #286159;
  --spire-500: #357569;
  --spire-300: #93c6b8;
  --spire-200: #bfe0d6;
  --chalk: #f7f2e8;
  --chalk-dim: #d8e6df;

  /* Square: limestone (paas) and mortar */
  --paas: #ebe5d7;
  --paas-deep: #ddd5c3;
  --mortar: #c4b99f;
  --umber: #2a1a0e;
  --umber-soft: #5a4636;

  /* Glazed stove tile (kahhel) */
  --glaze-hi: #fff1b8;
  --glaze: #ffd66b;
  --glaze-lo: #f2bd45;
  --glaze-edge: #c98d1f;

  /* Façade-painted premium squares */
  --prem-l2: #a9d4e8;
  --prem-l3: #2c6ba0;
  --prem-w2: #f5aa98;
  --prem-w3: #ae3823;
  --prem-st: #f5b82e;

  /* Actions and states */
  --ochre: #f7bf34;
  --ochre-hi: #ffd35e;
  --ochre-ink: #2a1a0e;
  --roos: #ef4f86;          /* reserved: your unplayed tiles + preview only */
  --roos-ink: #b81d58;      /* roos as text on limestone */
  --roos-soft: rgba(239, 79, 134, 0.18);
  --ok: #62d39f;
  --warn: #ffb347;
  --bad: #ff8a73;           /* error text on the dark shell */
  --bad-ink: #a32b17;       /* error text on limestone */

  /* Player façades */
  --p1: #f4935a;
  --p2: #63c7a0;
  --p3: #79afe2;
  --p4: #bba2e6;

  /* Type */
  --f-display: 'Bricolage Grotesque', 'Atkinson Hyperlegible Next', system-ui, sans-serif;
  --f-ui: 'Atkinson Hyperlegible Next', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --t-xs: 0.8125rem;
  --t-sm: 0.9375rem;
  --t-md: 1.0625rem;
  --t-lg: 1.3125rem;
  --t-xl: 1.75rem;
  --t-2xl: 2.5rem;
  --t-3xl: clamp(3rem, 7vw, 5.5rem);

  /* Space, radius, depth */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px;
  --r-sm: 8px; --r-md: 12px; --r-lg: 16px; --r-pill: 999px;
  --lift-1: 0 2px 6px rgba(5, 20, 18, 0.28);
  --lift-2: 0 8px 24px rgba(5, 20, 18, 0.35);
  --lift-3: 0 18px 48px rgba(5, 20, 18, 0.45);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --tap: 48px;

  color-scheme: dark;
}

/* ------------------------------------------------------------------ base */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--f-ui);
  font-size: var(--t-md);
  line-height: 1.5;
  color: var(--chalk);
  background: linear-gradient(180deg, #1c4a44 0, var(--spire-800) 420px) var(--spire-800);
  background-attachment: fixed;
  caret-color: var(--roos);
  -webkit-font-smoothing: antialiased;
  overflow-x: clip;
}

.brand { display: flex; align-items: center; gap: var(--s2); color: var(--chalk); text-decoration: none; }
.brand:hover { color: var(--chalk); }
.brand__mark { display: flex; gap: 3px; }
.brand__mark .tile { --tile-size: 30px; }
.brand__name { font-family: var(--f-display); font-weight: 800; font-size: 1.5rem; letter-spacing: -0.03em; }
::selection { background: var(--ochre); color: var(--ochre-ink); }
h1, h2, h3 { font-family: var(--f-display); line-height: 1.1; margin: 0; letter-spacing: -0.02em; text-wrap: balance; }
p { margin: 0; text-wrap: pretty; }
a { color: var(--ochre-hi); text-underline-offset: 3px; text-decoration-thickness: 1.5px; }
a:hover { color: #fff; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--ochre); outline-offset: 3px; border-radius: 6px; }
.icon { flex: none; display: block; }
.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
[hidden] { display: none !important; }

* { scrollbar-width: thin; scrollbar-color: var(--spire-500) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--spire-500); border-radius: 10px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ------------------------------------------------------------------ buttons */
.btn {
  --btn-bg: var(--spire-600);
  --btn-fg: var(--chalk);
  --btn-bg-hover: var(--spire-500);
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: var(--tap);
  padding: 0 var(--s5);
  border: 0;
  border-radius: var(--r-md);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-weight: 700;
  font-size: var(--t-md);
  line-height: 1.1;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color 160ms var(--ease-out), transform 160ms var(--ease-out), box-shadow 160ms var(--ease-out);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.btn:hover:not(:disabled) { background: var(--btn-bg-hover); }
.btn:active:not(:disabled) { transform: translateY(1px) scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn--primary:disabled { opacity: 1; background: var(--spire-700); color: var(--spire-300); box-shadow: inset 0 0 0 2px var(--spire-600); }
.btn--primary {
  --btn-bg: var(--ochre);
  --btn-bg-hover: var(--ochre-hi);
  --btn-fg: var(--ochre-ink);
  background-image: linear-gradient(180deg, rgba(255, 255, 255, 0.18), rgba(140, 80, 0, 0.12));
  box-shadow: var(--lift-1);
}
.btn--big { min-height: 60px; padding: 0 var(--s6); font-size: var(--t-lg); border-radius: var(--r-lg); }
.btn--ghost { --btn-bg: transparent; --btn-bg-hover: rgba(255, 255, 255, 0.08); --btn-fg: var(--chalk); box-shadow: inset 0 0 0 2px var(--spire-500); }
.btn--quiet { --btn-bg: transparent; --btn-bg-hover: rgba(255, 255, 255, 0.08); padding: 0 var(--s3); }
.btn--icon { padding: 0; width: var(--tap); }
.btn--yes { --btn-bg: var(--ok); --btn-bg-hover: #86e4b8; --btn-fg: #08291c; }
.btn--no { --btn-bg: var(--bad); --btn-bg-hover: #ffa794; --btn-fg: #3a0d05; }
.btn--danger { --btn-bg: transparent; --btn-bg-hover: rgba(255, 138, 115, 0.12); --btn-fg: var(--bad); box-shadow: inset 0 0 0 2px rgba(255, 138, 115, 0.55); }

/* ------------------------------------------------------------------ inputs */
.field { display: grid; gap: var(--s2); }
.field__label { font-weight: 700; font-size: var(--t-sm); color: var(--chalk-dim); }
.input {
  min-height: 56px;
  width: 100%;
  padding: 0 var(--s4);
  border-radius: var(--r-md);
  border: 2px solid var(--spire-500);
  background: var(--spire-900);
  color: var(--chalk);
  font-size: var(--t-lg);
  transition: border-color 160ms var(--ease-out), background-color 160ms;
}
.input::placeholder { color: var(--spire-300); opacity: 1; }
.input:focus { outline: none; border-color: var(--ochre); background: var(--spire-950); }
.input--code { font-family: var(--f-display); font-weight: 800; letter-spacing: 0.18em; text-transform: uppercase; }

.switch { display: flex; align-items: center; gap: var(--s3); cursor: pointer; min-height: var(--tap); }
.switch input { appearance: none; -webkit-appearance: none; margin: 0; flex: none; width: 56px; height: 32px; border-radius: var(--r-pill); background: var(--spire-900); box-shadow: inset 0 0 0 2px var(--spire-500); position: relative; cursor: pointer; transition: background-color 180ms var(--ease-out); }
.switch input::after { content: ''; position: absolute; top: 4px; left: 4px; width: 24px; height: 24px; border-radius: 50%; background: var(--chalk-dim); transition: transform 220ms var(--ease-spring), background-color 180ms; }
.switch input:checked { background: var(--ochre); box-shadow: none; }
.switch input:checked::after { transform: translateX(24px); background: var(--ochre-ink); }
.switch input:disabled { opacity: 0.5; cursor: not-allowed; }
.select {
  min-height: var(--tap); padding: 0 40px 0 var(--s3); border-radius: var(--r-md);
  border: 2px solid var(--spire-500); background: var(--spire-900); color: var(--chalk);
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%23f7f2e8' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
}
.select:disabled { opacity: 0.55; }

/* ------------------------------------------------------------------ tile */
.tile {
  --tile-size: 48px;
  position: relative;
  display: inline-grid;
  place-items: center;
  width: var(--tile-size);
  height: var(--tile-size);
  border-radius: calc(var(--tile-size) * 0.16);
  background:
    radial-gradient(120% 90% at 30% 15%, var(--glaze-hi) 0%, transparent 55%),
    linear-gradient(180deg, var(--glaze) 0%, var(--glaze-lo) 100%);
  box-shadow:
    inset 0 calc(var(--tile-size) * -0.07) 0 var(--glaze-edge),
    inset 0 1px 0 rgba(255, 255, 255, 0.75),
    0 2px 5px rgba(42, 26, 14, 0.35);
  color: var(--umber);
  user-select: none;
  -webkit-user-select: none;
}
.tile__letter {
  font-family: var(--f-display);
  font-weight: 800;
  font-size: calc(var(--tile-size) * 0.56);
  line-height: 1;
  margin-top: calc(var(--tile-size) * -0.06);
  font-variation-settings: 'opsz' 48;
}
.tile__value {
  position: absolute;
  right: calc(var(--tile-size) * 0.09);
  bottom: calc(var(--tile-size) * 0.1);
  font-family: var(--f-ui);
  font-weight: 800;
  font-size: calc(var(--tile-size) * 0.22);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.tile--blank .tile__letter { color: var(--roos-ink); }
.tile--blank:not(.has-letter) .tile__letter::before { content: '?'; color: rgba(90, 70, 54, 0.45); }
.tile--blank::after {
  content: ''; position: absolute; inset: calc(var(--tile-size) * 0.1);
  border-radius: calc(var(--tile-size) * 0.1);
  border: 2px dashed rgba(90, 70, 54, 0.45);
  pointer-events: none;
}
.tile--blank.has-letter::after { display: none; }

/* ------------------------------------------------------------------ toast */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 90;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  max-width: min(92vw, 520px);
  padding: var(--s3) var(--s5); border-radius: var(--r-md);
  background: var(--chalk); color: var(--umber); font-weight: 700;
  box-shadow: var(--lift-2);
  transition: transform 260ms var(--ease-out), opacity 200ms;
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }
.toast[data-tone='bad'] { background: #ffe1d9; color: var(--bad-ink); }
.toast[data-tone='ok'] { background: #d9f6e8; color: #0e4a2f; }

/* ------------------------------------------------------------------ house row (signature) */
.houses {
  display: flex; align-items: flex-end; justify-content: center;
  gap: var(--s3);
  padding: var(--s3) var(--s2) 0;
  min-height: 150px;
  border-bottom: 3px solid var(--mortar);
  background: linear-gradient(180deg, transparent 0%, transparent 80%, rgba(196, 185, 159, 0.12) 100%);
}
.house {
  --c: var(--p1);
  --h: 1;
  position: relative;
  flex: 1 1 0;
  max-width: 108px;
  min-width: 64px;
  display: flex; flex-direction: column; align-items: center;
  color: var(--umber);
  transition: transform 420ms var(--ease-spring);
}
.house[data-seat='1'] { --c: var(--p2); }
.house[data-seat='2'] { --c: var(--p3); }
.house[data-seat='3'] { --c: var(--p4); }
.house__art { width: 100%; }
.house__shape { width: 100%; height: auto; display: block; overflow: visible; }
.house__body { fill: var(--c); }
.house__trim { fill: rgba(42, 26, 14, 0.18); }
.house__win { fill: #2c3c3a; transition: fill 300ms; }
.house__door { fill: rgba(42, 26, 14, 0.55); }
.house__name {
  margin-top: var(--s2);
  max-width: 100%;
  font-weight: 700; font-size: var(--t-sm); color: var(--chalk);
  line-height: 1.15; text-align: center;
}
/* names wrap onto a second line before they are cut */
.house__name .nm {
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2;
  overflow: hidden; overflow-wrap: break-word;
}
.house__art { position: relative; }
.house__crown {
  position: absolute; left: -2px; top: 2px; z-index: 1;
  display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%;
  background: var(--spire-950); color: var(--ochre);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}
.house__crown .icon { width: 16px; height: 16px; }
.house__score { display: none; }
.house__meta { font-size: var(--t-xs); color: var(--spire-200); min-height: 1.2em; white-space: nowrap; }
.house__art { transition: transform 420ms var(--ease-spring); }
.house.is-turn .house__art { transform: translateY(-8px); }
.house.is-turn .house__win { fill: #ffe27a; filter: drop-shadow(0 0 6px rgba(255, 214, 90, 0.9)); }
.house.is-turn .house__flag { opacity: 1; transform: scaleX(1); }
.house__flag { opacity: 0; transform-origin: left center; transform: scaleX(0.2); transition: opacity 260ms, transform 420ms var(--ease-spring); fill: var(--roos); }
.house.is-offline .house__body { fill: #7d8c88; }
.house.is-offline .house__name { color: var(--spire-300); }
.house.is-me .house__name .nm { text-decoration: underline; text-decoration-color: var(--c); text-decoration-thickness: 3px; text-underline-offset: 4px; }
.house.is-winner .house__win { fill: #ffe27a; }
.house.is-empty .house__body { fill: transparent; stroke: var(--spire-500); stroke-width: 2; stroke-dasharray: 5 5; }
.house.is-empty .house__win, .house.is-empty .house__door, .house.is-empty .house__trim { fill: transparent; }
.house.is-empty .house__name { color: var(--spire-300); font-weight: 400; }
@keyframes house-bump { 0% { transform: translateY(0) scale(1); } 40% { transform: translateY(-14px) scale(1.07); } 100% { transform: translateY(0) scale(1); } }
.house.bump .house__shape { animation: house-bump 600ms var(--ease-spring); transform-origin: 50% 100%; }

/* ------------------------------------------------------------------ board */
.board-wrap { position: relative; width: 100%; display: grid; justify-items: center; }
.board {
  --n: 15;
  --gap: 2px;
  position: relative;
  container-type: inline-size;
  width: min(100%, var(--board-max, 640px));
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  grid-template-rows: repeat(var(--n), 1fr);
  gap: var(--gap);
  padding: var(--gap);
  border-radius: var(--r-md);
  background: var(--mortar);
  box-shadow: 0 0 0 6px var(--paas-deep), 0 0 0 8px rgba(42, 26, 14, 0.25), var(--lift-3);
  touch-action: manipulation;
}
.cell {
  position: relative;
  display: grid; place-items: center;
  min-width: 0; min-height: 0;
  padding: 0; border: 0;
  border-radius: 3px;
  background: var(--paas);
  color: var(--umber);
  font-family: var(--f-ui);
  -webkit-tap-highlight-color: transparent;
  cursor: default;
}
.cell.is-target { cursor: pointer; }
.cell.is-target:hover { background: #fff8e8; }
.cell__prem { display: grid; place-items: center; line-height: 0.95; text-align: center; pointer-events: none; }
.cell__mul { font-family: var(--f-display); font-weight: 800; font-size: clamp(9px, 2.6cqi, 17px); letter-spacing: -0.02em; }
.cell__kind { font-weight: 700; font-size: clamp(9px, 1.45cqi, 11px); text-transform: uppercase; letter-spacing: 0.04em; }
.cell__short { display: none; font-family: var(--f-display); font-weight: 800; font-size: clamp(8px, 3.3cqi, 16px); letter-spacing: -0.02em; }
/* Below ~620px the TÄHT/SÕNA label would be under 9px: show 2T / 3S instead
   (key in Reeglid). The frame on word squares tells the kinds apart without colour. */
@container (max-width: 620px) { .cell__mul, .cell__kind { display: none; } .cell__short { display: block; } }
.cell--L2 { background: var(--prem-l2); }
.cell--L3 { background: var(--prem-l3); color: #fff; }
.cell--W2, .cell--W3 { --frame: clamp(1.5px, 0.75cqi, 4px); --line: clamp(1px, 0.3cqi, 1.5px); }
.cell--W2 { background: var(--prem-w2); box-shadow: inset 0 0 0 var(--frame) var(--prem-w2), inset 0 0 0 calc(var(--frame) + var(--line)) rgba(42, 26, 14, 0.5); }
.cell--W3 { background: var(--prem-w3); color: #fff; box-shadow: inset 0 0 0 var(--frame) var(--prem-w3), inset 0 0 0 calc(var(--frame) + var(--line)) rgba(255, 255, 255, 0.7); }
.cell--ST { background: var(--prem-st); }
.cell--ST .icon { width: 64%; height: 64%; color: var(--umber); }
.cell.is-drop { background: #fff3c9; box-shadow: inset 0 0 0 3px var(--roos); }
.cell.is-selectable-target { box-shadow: inset 0 0 0 2px rgba(239, 79, 134, 0.35); }

.cell > .tile {
  --tile-size: 100%;
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  border-radius: 4px;
  box-shadow: inset 0 -2px 0 var(--glaze-edge), inset 0 1px 0 rgba(255, 255, 255, 0.7), 0 1px 2px rgba(42, 26, 14, 0.4);
}
.cell > .tile .tile__letter { font-size: clamp(11px, 4.1cqi, 30px); margin-top: -6%; }
.cell > .tile .tile__value { font-size: clamp(6px, 1.5cqi, 11px); right: 7%; bottom: 6%; }
.cell > .tile.is-last { box-shadow: inset 0 -2px 0 var(--glaze-edge), 0 0 0 3px var(--last-c, var(--p1)); z-index: 1; }
.cell > .tile.is-pending {
  background: linear-gradient(180deg, #fff3c2 0%, var(--glaze) 100%);
  box-shadow: inset 0 -2px 0 var(--glaze-edge), 0 0 0 3px var(--roos), 0 6px 14px rgba(42, 26, 14, 0.4);
  z-index: 2; cursor: grab; transform: translateY(-1px);
  touch-action: none;
}
.cell > .tile.is-ghost { opacity: 0.62; box-shadow: 0 0 0 2px var(--ghost-c, var(--spire-300)); animation: ghost-breathe 1.4s ease-in-out infinite; }
@keyframes ghost-breathe { 50% { opacity: 0.85; } }
.cell > .tile.is-placed-anim { animation: tile-land 380ms var(--ease-spring); }
@keyframes tile-land { 0% { transform: scale(1.35) translateY(-8%); } 100% { transform: none; } }

.board__score-pop {
  position: absolute; z-index: 5; pointer-events: none;
  transform: translate(-50%, -50%);
  padding: 6px 14px; border-radius: var(--r-pill);
  background: var(--umber); color: var(--glaze);
  font-family: var(--f-display); font-weight: 800; font-size: 1.6rem; white-space: nowrap;
  box-shadow: var(--lift-2);
  animation: score-pop 1600ms var(--ease-out) forwards;
}
@keyframes score-pop {
  0% { opacity: 0; transform: translate(-50%, -20%) scale(0.6); }
  18% { opacity: 1; transform: translate(-50%, -70%) scale(1.12); }
  30% { transform: translate(-50%, -80%) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -160%) scale(1); }
}

/* ------------------------------------------------------------------ rack + actions */
.tray { display: grid; gap: var(--s3); justify-items: center; width: 100%; }
.tray__rackrow, .tray__actrow { display: flex; align-items: center; justify-content: center; gap: var(--s3); width: 100%; }
.tray__risky { display: flex; gap: var(--s2); margin-left: var(--s3); padding-left: var(--s4); border-left: 2px solid var(--spire-600); }
.tray__rackrow .btn--icon { flex: none; }
.btn .btn__lbl { line-height: 1.1; }
.rack {
  --slot: clamp(40px, 11.5vw, 60px);
  display: flex; justify-content: center; align-items: center; gap: clamp(4px, 1.2vw, 10px);
  min-height: calc(var(--slot) + 26px);
  min-width: calc(var(--slot) * 7 + clamp(4px, 1.2vw, 10px) * 6 + clamp(10px, 2vw, 18px) * 2);
  padding: 12px clamp(10px, 2vw, 18px) 14px;
  border-radius: var(--r-lg);
  background: linear-gradient(180deg, #6b4a2c 0%, #553a22 100%);
  background-image: linear-gradient(180deg, #6b4a2c 0%, #553a22 82%, #3c2816 100%);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.12), var(--lift-2);
  touch-action: none;
}
.rack.is-empty::before { content: 'Riiul on tühi'; color: #e8d4b8; font-weight: 700; }
.rack.is-readonly { touch-action: auto; }
.rack .tile {
  --tile-size: var(--slot);
  cursor: grab;
  transition: transform 220ms var(--ease-spring), box-shadow 200ms, opacity 160ms;
  touch-action: none;
}
.rack .tile:hover { transform: translateY(-3px); }
.rack .tile.is-selected {
  transform: translateY(-10px);
  box-shadow: inset 0 calc(var(--tile-size) * -0.07) 0 var(--glaze-edge), 0 0 0 3px var(--roos), 0 10px 18px rgba(0, 0, 0, 0.4);
}
.rack .tile.is-marked { transform: translateY(-6px) rotate(-4deg); box-shadow: inset 0 calc(var(--tile-size) * -0.07) 0 var(--glaze-edge), 0 0 0 3px var(--chalk), 0 8px 14px rgba(0, 0, 0, 0.4); }
.rack .tile.is-away { opacity: 0.25; transform: scale(0.9); }
.rack .tile.is-drop-before { box-shadow: -8px 0 0 -3px var(--roos), inset 0 calc(var(--tile-size) * -0.07) 0 var(--glaze-edge); }
.rack-slot-gap { width: 0; transition: width 160ms var(--ease-out); }
.drag-ghost {
  position: fixed; z-index: 100; pointer-events: none; left: 0; top: 0;
  transform: translate(-50%, -60%) rotate(-4deg) scale(1.1);
  filter: drop-shadow(0 14px 18px rgba(0, 0, 0, 0.45));
}
.drag-ghost .tile { --tile-size: var(--ghost-size, 56px); }

.preview {
  display: inline-flex; align-items: center; gap: var(--s2);
  min-height: 40px; padding: 0 var(--s4);
  border-radius: var(--r-pill);
  font-weight: 700;
  background: var(--spire-900);
  color: var(--chalk-dim);
  box-shadow: inset 0 0 0 2px var(--spire-600);
  max-width: 100%;
}
.preview.is-good { background: var(--roos); color: #fff; box-shadow: none; }
.preview.is-hint { color: #ffd9b8; box-shadow: inset 0 0 0 2px rgba(255, 179, 71, 0.5); }
.preview__score { font-family: var(--f-display); font-weight: 800; font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.preview__words { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview.bump { animation: pill-bump 300ms var(--ease-spring); }
@keyframes pill-bump { 40% { transform: scale(1.08); } }

/* ------------------------------------------------------------------ turn band */
.turnband {
  display: flex; align-items: center; justify-content: center; gap: var(--s3);
  width: 100%;
  min-height: 56px;
  padding: 0 var(--s4);
  text-align: center;
}
.turnband__text { font-family: var(--f-display); font-weight: 800; font-size: clamp(1.4rem, 2.6vw, 2.1rem); letter-spacing: -0.025em; line-height: 1.05; }
.turnband__sub { font-size: var(--t-sm); color: var(--spire-200); }
.turnband__dot { width: 18px; height: 18px; border-radius: 50%; background: var(--c, var(--chalk)); flex: none; box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.15); }
.turnband.is-mine .turnband__text { color: var(--ochre-hi); }
.turnband__score {
  display: inline-block; padding: 0 12px; border-radius: var(--r-pill);
  background: var(--roos); color: #fff; font-variant-numeric: tabular-nums;
}
.turnband.is-preview .turnband__text { color: var(--chalk); }
.turnband__words { letter-spacing: 0.02em; overflow-wrap: anywhere; }
.turnband__warn { color: #ffd9b8; font-weight: 700; }
.turnband.is-mine .turnband__dot { background: var(--roos); animation: dot-pulse 1.6s ease-in-out infinite; }
@keyframes dot-pulse { 50% { box-shadow: 0 0 0 8px rgba(239, 79, 134, 0.18); } }
.turnband__timer { font-family: var(--f-display); font-weight: 800; font-variant-numeric: tabular-nums; padding: 4px 12px; border-radius: var(--r-pill); background: var(--spire-900); font-size: var(--t-lg); }
.turnband__timer.is-low { background: var(--bad); color: #3a0d05; }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, 0.25); border-top-color: var(--ochre); animation: spin 0.9s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.turnband.is-enter { animation: band-in 420ms var(--ease-out); }
@keyframes band-in { from { opacity: 0; transform: translateY(-10px); } }

/* ------------------------------------------------------------------ notices (rejection stamp, hints) */
.notice-host {
  position: absolute; z-index: 6; top: 10%; left: 50%; transform: translateX(-50%);
  width: min(92%, 600px);
  display: grid; justify-items: stretch;
}
.notice-host:empty { display: none; }
.notice {
  position: relative;
  width: 100%;
  padding: var(--s4) var(--s5);
  padding-right: 56px;
  border-radius: var(--r-lg);
  background: var(--paas);
  color: var(--umber);
  box-shadow: var(--lift-2);
  animation: notice-in 360ms var(--ease-out);
}
@keyframes notice-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
.notice__close { position: absolute; top: 6px; right: 6px; --btn-fg: var(--umber); --btn-bg-hover: rgba(42, 26, 14, 0.08); }
.notice__title { font-family: var(--f-display); font-weight: 800; font-size: var(--t-lg); margin-bottom: var(--s1); }
.notice__words { list-style: none; margin: var(--s2) 0 0; padding: 0; display: grid; gap: var(--s2); }
.notice__words li { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--s1) var(--s3); }
.notice__word { font-family: var(--f-display); font-weight: 800; font-size: var(--t-lg); text-decoration: line-through; text-decoration-color: var(--bad-ink); text-decoration-thickness: 3px; letter-spacing: 0.04em; }
.notice__why { color: var(--umber-soft); }
.notice a { color: var(--prem-l3); font-weight: 700; display: inline-flex; align-items: center; gap: 4px; }
.notice a:hover { color: var(--umber); }
.notice__stamp {
  position: absolute; right: 64px; top: 10px;
  padding: 2px 10px;
  border: 3px solid var(--bad-ink); border-radius: 6px;
  color: var(--bad-ink);
  font-family: var(--f-display); font-weight: 800; font-size: var(--t-md); letter-spacing: 0.08em;
  transform: rotate(-7deg);
  opacity: 0.85;
  animation: stamp 420ms var(--ease-spring);
}
@keyframes stamp { 0% { transform: rotate(-7deg) scale(2.2); opacity: 0; } 100% { transform: rotate(-7deg) scale(1); opacity: 0.85; } }
.notice--hint { background: #fff1d6; }
.notice--soft { background: var(--spire-700); color: var(--chalk); box-shadow: none; }
.notice--soft .notice__close { --btn-fg: var(--chalk); }

/* ------------------------------------------------------------------ panels, tabs, chat, log */
.panel { display: flex; flex-direction: column; min-height: 0; background: var(--spire-900); border-radius: var(--r-lg); overflow: hidden; }
.panel__head { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); padding: var(--s3) var(--s4); }
.panel__title { font-family: var(--f-display); font-weight: 800; font-size: var(--t-lg); }
.tabs { display: flex; gap: var(--s1); padding: var(--s2); background: var(--spire-950); }
.tab {
  flex: 1; position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: 44px; border: 0; border-radius: var(--r-md);
  background: transparent; color: var(--spire-200); font-weight: 700;
}
.tab[aria-selected='true'] { background: var(--spire-700); color: var(--chalk); }
.tab:hover:not([aria-selected='true']) { color: var(--chalk); background: rgba(255, 255, 255, 0.05); }
.badge {
  min-width: 22px; height: 22px; padding: 0 6px; border-radius: var(--r-pill);
  background: var(--roos); color: #fff; font-size: var(--t-xs); font-weight: 800;
  display: inline-grid; place-items: center; line-height: 1;
}
.tabpanel { flex: 1; min-height: 0; display: flex; flex-direction: column; }

.chat { flex: 1; min-height: 0; overflow-y: auto; padding: var(--s3) var(--s4); display: flex; flex-direction: column; gap: var(--s2); overscroll-behavior: contain; }
.msg { max-width: 92%; align-self: flex-start; }
.msg__who { font-size: var(--t-xs); font-weight: 700; color: var(--c, var(--spire-200)); margin-bottom: 2px; display: flex; gap: var(--s2); }
.msg__who time { color: var(--spire-300); font-weight: 400; }
.msg__text { display: inline-block; padding: var(--s2) var(--s3); border-radius: 4px 14px 14px 14px; background: var(--spire-700); overflow-wrap: anywhere; white-space: pre-wrap; }
.msg.is-me { align-self: flex-end; text-align: right; }
.msg.is-me .msg__who { justify-content: flex-end; }
.msg.is-me .msg__text { background: var(--chalk); color: var(--umber); border-radius: 14px 4px 14px 14px; text-align: left; }
.msg--sys { align-self: center; max-width: 100%; text-align: center; font-size: var(--t-xs); color: var(--spire-300); padding: 0 var(--s3); line-height: 1.35; }
.msg--sys.is-move { color: var(--chalk-dim); font-weight: 600; }
.msg__dot { display: inline-block; width: 8px; height: 8px; margin-right: 6px; border-radius: 50%; background: var(--c, var(--spire-300)); vertical-align: 1px; }
.chat__empty { margin-top: auto; text-align: center; color: var(--spire-200); padding: var(--s4) var(--s3) var(--s2); }
.chat-form { display: flex; gap: var(--s2); padding: var(--s3); border-top: 2px solid var(--spire-800); }
.chat-form .input { min-height: var(--tap); font-size: var(--t-md); flex: 1 1 0; min-width: 0; width: auto; }

.log { list-style: none; margin: 0; padding: var(--s2) var(--s3); overflow-y: auto; flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 2px; }
.log__item { display: grid; grid-template-columns: 28px 1fr auto; align-items: start; gap: var(--s2); padding: var(--s2); border-radius: var(--r-sm); }
.log__item:nth-child(odd) { background: rgba(255, 255, 255, 0.03); }
.log__n { font-size: var(--t-xs); color: var(--spire-300); padding-top: 3px; font-variant-numeric: tabular-nums; }
.log__who { font-weight: 700; display: flex; align-items: center; gap: 6px; }
.log__dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); flex: none; }
.log__words { font-family: var(--f-display); font-weight: 800; letter-spacing: 0.03em; overflow-wrap: anywhere; }
.log__words small { font-family: var(--f-ui); font-weight: 400; letter-spacing: 0; color: var(--spire-200); }
.log__score { font-family: var(--f-display); font-weight: 800; font-size: var(--t-lg); font-variant-numeric: tabular-nums; }
.log__item.is-quiet .log__score { color: var(--spire-300); }
.log__bingo { display: inline-block; margin-left: 6px; padding: 0 8px; border-radius: var(--r-pill); background: var(--roos); color: #fff; font-family: var(--f-ui); font-size: var(--t-xs); letter-spacing: 0.02em; vertical-align: 2px; }
.log__empty { margin: auto; color: var(--spire-300); padding: var(--s5); text-align: center; }

/* ------------------------------------------------------------------ video */
.video { display: flex; flex-direction: column; gap: var(--s3); padding: var(--s3); }
.video__grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 128px), 1fr)); gap: var(--s2); }
.vtile { position: relative; aspect-ratio: 4 / 3; border-radius: var(--r-md); overflow: hidden; background: var(--spire-950); box-shadow: 0 0 0 3px var(--c, var(--spire-600)); }
.vtile video { width: 100%; height: 100%; object-fit: cover; display: block; background: #000; }
.vtile.is-me video { transform: scaleX(-1); }
.vtile__name { position: absolute; left: 6px; bottom: 6px; max-width: calc(100% - 12px); padding: 2px 8px; border-radius: var(--r-pill); background: rgba(11, 36, 33, 0.82); font-size: var(--t-xs); font-weight: 700; display: flex; align-items: center; gap: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vtile__name .icon { color: var(--bad); }
.vtile__off { position: absolute; inset: 0; display: grid; place-items: center; font-family: var(--f-display); font-weight: 800; font-size: 2rem; color: var(--umber); background: var(--c, var(--spire-600)); }
.vtile.is-speaking { box-shadow: 0 0 0 3px var(--ochre); }
.video__bar { display: flex; flex-wrap: wrap; gap: var(--s2); }
.video__bar .btn { flex: 1 1 auto; }
.video__bar.in-call { display: grid; grid-template-columns: repeat(auto-fit, minmax(80px, 1fr)); }
.video__bar.in-call .btn { flex-direction: column; gap: 2px; min-height: 60px; padding: 0 var(--s2); font-size: var(--t-sm); white-space: normal; text-align: center; }
.video__bar .btn.is-off { --btn-bg: var(--bad); --btn-fg: #3a0d05; --btn-bg-hover: #ffa794; }
.video__note { font-size: var(--t-sm); color: var(--spire-200); }
.video__note.is-bad { color: #ffd2c7; }

/* ------------------------------------------------------------------ dialogs */
dialog {
  border: 0; padding: 0; border-radius: var(--r-lg);
  background: var(--paas); color: var(--umber);
  box-shadow: var(--lift-3);
  max-width: min(94vw, 560px);
  width: 100%;
}
dialog::backdrop { background: rgba(6, 22, 20, 0.62); backdrop-filter: blur(3px); }
dialog[open] { animation: dlg-in 320ms var(--ease-out); }
@keyframes dlg-in { from { opacity: 0; transform: translateY(16px) scale(0.97); } }
.dlg { padding: var(--s5); display: grid; gap: var(--s4); }
.dlg h2 { font-size: var(--t-xl); }
.dlg p { color: var(--umber-soft); }
.dlg .btn--ghost { --btn-fg: var(--umber); box-shadow: inset 0 0 0 2px var(--mortar); --btn-bg-hover: rgba(42, 26, 14, 0.06); }
.dlg .btn--quiet { --btn-fg: var(--umber); --btn-bg-hover: rgba(42, 26, 14, 0.06); }
.dlg__row { display: flex; flex-wrap: wrap; gap: var(--s2); justify-content: flex-end; }
.dlg a { color: var(--prem-l3); font-weight: 700; }
.letters { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: var(--s2); }
.letters button { border: 0; padding: 0; background: none; border-radius: 10px; }
.letters .tile { --tile-size: 52px; transition: transform 160ms var(--ease-spring); }
.letters button:hover .tile, .letters button:focus-visible .tile { transform: translateY(-3px) scale(1.06); }
.vote-words { list-style: none; padding: 0; margin: 0; display: grid; gap: var(--s2); }
.vote-words li { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s2); padding: var(--s3) var(--s4); background: #fff; border-radius: var(--r-md); }
.vote-words b { font-family: var(--f-display); font-size: var(--t-xl); letter-spacing: 0.05em; }
.vote-meter { height: 8px; border-radius: 8px; background: var(--paas-deep); overflow: hidden; }
.vote-meter > i { display: block; height: 100%; background: var(--prem-l3); width: 100%; transform-origin: left; }
.vote-btns { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); }
.vote-btns .btn { min-height: 64px; font-size: var(--t-xl); }

.rules { display: grid; gap: var(--s4); max-height: min(70vh, 640px); overflow-y: auto; }
.rules ul { margin: 0; padding-left: 1.2em; display: grid; gap: var(--s1); }
.legend { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s3); }
.legend li { display: flex; align-items: center; gap: var(--s3); font-weight: 700; }
.legend .sw { width: 34px; height: 34px; border-radius: 6px; display: grid; place-items: center; font-family: var(--f-display); font-weight: 800; font-size: 0.95rem; flex: none; }
.legend .sw--frame { outline: 1.5px solid currentColor; outline-offset: -5px; opacity: 1; }
.legend small { display: block; font-weight: 400; color: var(--umber-soft); }
.values { display: flex; flex-wrap: wrap; gap: 6px; }
.values .tile { --tile-size: 38px; }

/* ------------------------------------------------------------------ results */
.results { display: grid; gap: var(--s4); }
.results__crown { display: flex; align-items: center; gap: var(--s3); }
.results__crown .icon { color: var(--glaze-edge); }
.results__table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.results__table th { text-align: left; font-size: var(--t-xs); text-transform: uppercase; letter-spacing: 0.06em; color: var(--umber-soft); padding: var(--s2); }
.results__table td { padding: var(--s3) var(--s2); border-top: 2px solid var(--paas-deep); }
.results__table td.num, .results__table th.num { text-align: right; }
.results__table tr.is-win td { font-weight: 800; }
.results__table .big { font-family: var(--f-display); font-weight: 800; font-size: var(--t-xl); }
.results__name { display: flex; align-items: center; gap: var(--s2); font-weight: 700; }
.results__name i { width: 14px; height: 14px; border-radius: 4px; background: var(--c); flex: none; }

.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 120; overflow: hidden; }
.confetti i { position: absolute; top: -20px; width: 14px; height: 14px; border-radius: 3px; animation: fall var(--dur, 2.4s) var(--ease-out) forwards; }
@keyframes fall {
  0% { transform: translate3d(0, 0, 0) rotate(0); opacity: 1; }
  100% { transform: translate3d(var(--dx, 0), 105vh, 0) rotate(var(--rot, 540deg)); opacity: 0.9; }
}
.bingo-burst {
  position: fixed; left: 50%; top: 40%; z-index: 121; pointer-events: none;
  transform: translate(-50%, -50%);
  font-family: var(--f-display); font-weight: 800; font-size: clamp(3rem, 12vw, 7rem);
  color: var(--glaze); letter-spacing: -0.03em; text-shadow: 0 6px 0 var(--glaze-edge), 0 18px 40px rgba(0, 0, 0, 0.5);
  animation: bingo 1800ms var(--ease-out) forwards;
  white-space: nowrap;
}
@keyframes bingo { 0% { opacity: 0; transform: translate(-50%, -50%) scale(0.3) rotate(-8deg); } 25% { opacity: 1; transform: translate(-50%, -50%) scale(1.1) rotate(2deg); } 40% { transform: translate(-50%, -50%) scale(1) rotate(0); } 80% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -60%) scale(1); } }

/* ------------------------------------------------------------------ reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
  .confetti, .bingo-burst { display: none; }
}
