/* ---- Design tokens ---------------------------------------------------- */
:root {
  --bg: #14101f;
  --bg-2: #1f1830;
  --panel: #271e3d;
  --panel-2: #2f2548;
  --text: #f4f1fb;
  --muted: #b3a8cc;
  --accent: #8E44AD;
  --accent-2: #E84393;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);

  /* Kept in sync with COLOR_HEX in shared/constants.js. Hues spread around the
     wheel so adjacent categories never look alike. */
  --c-yellow: #FFC400;
  --c-pink: #FF3D8B;
  --c-turquoise: #00C2D1;
  --c-green: #34C759;
  --c-violet: #8B5CF6;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: radial-gradient(1200px 600px at 50% -10%, var(--bg-2), var(--bg));
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

a { color: var(--accent-2); }

.wrap {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px 16px 64px;
}

header.app {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 4px 20px;
}
header.app h1 {
  font-size: 1.25rem;
  margin: 0;
  letter-spacing: 0.3px;
}
header.app .sub { color: var(--muted); font-size: 0.85rem; }

/* ---- Panels & layout -------------------------------------------------- */
.panel {
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}
.panel h2 { margin: 0 0 12px; font-size: 1.05rem; }
.row { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-start; }
.col { flex: 1 1 320px; min-width: 0; }
.center { text-align: center; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* ---- Buttons & inputs ------------------------------------------------- */
button, .btn {
  font: inherit;
  cursor: pointer;
  border: none;
  border-radius: 12px;
  padding: 12px 18px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  transition: transform 0.06s ease, filter 0.15s ease;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation; /* no double-tap zoom / 300ms delay on mobile */
}
button:hover, .btn:hover { filter: brightness(1.08); }
button:active, .btn:active { transform: translateY(1px); }
button.secondary { background: var(--panel-2); border: 1px solid rgba(255,255,255,0.12); }
button.ghost { background: transparent; border: 1px solid rgba(255,255,255,0.18); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.big { padding: 16px 26px; font-size: 1.05rem; }

input[type=text] {
  font: inherit;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.16);
  background: rgba(0,0,0,0.25);
  color: var(--text);
  width: 100%;
}
label.field { display: block; margin-bottom: 12px; }
label.field span { display: block; margin-bottom: 6px; color: var(--muted); font-size: 0.85rem; }

.btn-group { display: flex; flex-wrap: wrap; gap: 10px; }

/* ---- Room code + QR --------------------------------------------------- */
.roomcode {
  font-size: 2.6rem;
  font-weight: 800;
  letter-spacing: 6px;
  background: rgba(0,0,0,0.3);
  border-radius: 12px;
  padding: 10px 18px;
  display: inline-block;
}
.qr img { width: 200px; height: 200px; border-radius: 12px; background: #fff; padding: 8px; }

/* ---- Wheel ------------------------------------------------------------ */
.wheel-box { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.wheel-stage { position: relative; width: 320px; max-width: 84vw; aspect-ratio: 1; }
.wheel-stage svg { width: 100%; height: 100%; display: block; }
.wheel-rotor {
  transition: transform 4s cubic-bezier(0.17, 0.67, 0.12, 0.99);
  /* For SVG groups, anchor the rotation to the viewBox center reliably.
     Without transform-box the origin resolves against the element bbox and
     the wheel lands on the wrong segment. */
  transform-box: view-box;
  transform-origin: 150px 150px; /* center of the 300x300 viewBox */
}
.wheel-pointer {
  position: absolute; top: -6px; left: 50%; transform: translateX(-50%);
  width: 0; height: 0; border-left: 16px solid transparent; border-right: 16px solid transparent;
  border-top: 26px solid #fff; filter: drop-shadow(0 2px 3px rgba(0,0,0,0.5)); z-index: 2;
}
.spin-result {
  font-size: 1.1rem; font-weight: 700; min-height: 1.6em;
  display: flex; align-items: center; gap: 10px;
}
.swatch { width: 18px; height: 18px; border-radius: 5px; display: inline-block; border: 1px solid rgba(255,255,255,0.4); }

/* ---- Turn indicator --------------------------------------------------- */
.turn-info {
  display: none;
  margin-top: 8px;
  padding: 8px 14px;
  border-radius: 999px;
  text-align: center;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.18);
}
.turn-info.show { display: inline-block; }

/* ---- Matchball banner ------------------------------------------------- */
.matchball {
  display: none;
  margin-top: 10px;
  padding: 10px 14px;
  border-radius: 12px;
  text-align: center;
  font-weight: 700;
  color: #1a1306;
  background: linear-gradient(90deg, #FFC400, #ffe680);
  box-shadow: 0 0 0 2px rgba(255, 196, 0, 0.4);
  animation: mbpulse 1.1s ease-in-out infinite alternate;
}
.matchball.show { display: block; }
@keyframes mbpulse {
  from { box-shadow: 0 0 0 2px rgba(255, 196, 0, 0.35); }
  to { box-shadow: 0 0 16px 3px rgba(255, 196, 0, 0.8); }
}

/* ---- Legend ----------------------------------------------------------- */
.legend { display: flex; flex-wrap: wrap; gap: 8px 16px; justify-content: center; }
.legend .item { display: flex; align-items: center; gap: 7px; font-size: 0.85rem; color: var(--muted); }

/* ---- Bingo card ------------------------------------------------------- */
.card-grid {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px;
  width: 100%; max-width: 460px; margin: 0 auto;
}
.card-grid.mini { max-width: 200px; gap: 3px; }
.cell {
  aspect-ratio: 1; border-radius: 10px; position: relative;
  border: 2px solid rgba(0,0,0,0.25); cursor: default;
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.08s ease, box-shadow 0.15s ease;
  user-select: none; -webkit-user-select: none; touch-action: manipulation;
}
.card-grid.interactive .cell { cursor: pointer; }
.card-grid.interactive .cell:hover { box-shadow: 0 0 0 3px rgba(255,255,255,0.35); }
.cell.marked::after {
  content: "✓"; color: #fff; font-weight: 900; font-size: 1.4rem;
  text-shadow: 0 1px 2px rgba(0,0,0,0.6);
}
.card-grid.mini .cell.marked::after { font-size: 0.8rem; }
.cell.marked { filter: saturate(1.1); }
.cell.marked::before {
  content: ""; position: absolute; inset: 0; border-radius: 8px;
  background: rgba(0,0,0,0.32);
}
.cell.win { animation: winpulse 0.9s ease-in-out infinite alternate; }
@keyframes winpulse {
  from { box-shadow: 0 0 0 2px rgba(255,255,255,0.5); }
  to { box-shadow: 0 0 14px 4px rgba(255,255,255,0.9); }
}

.cell-yellow { background: var(--c-yellow); }
.cell-pink { background: var(--c-pink); }
.cell-turquoise { background: var(--c-turquoise); }
.cell-green { background: var(--c-green); }
.cell-violet { background: var(--c-violet); }

/* ---- Player list / all cards ----------------------------------------- */
.players { display: flex; flex-wrap: wrap; gap: 18px; }
.player-card { background: rgba(0,0,0,0.18); border-radius: 14px; padding: 12px; }
.player-card .name { display: flex; align-items: center; gap: 8px; font-weight: 700; margin-bottom: 8px; }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.badge { font-size: 0.72rem; color: var(--muted); background: rgba(255,255,255,0.08); padding: 2px 7px; border-radius: 999px; }

/* ---- Tabs ------------------------------------------------------------- */
.tabs { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.tabs button { background: var(--panel-2); }
.tabs button.active { background: var(--accent); }

/* ---- Highscore -------------------------------------------------------- */
.highscore { display: flex; flex-direction: column; gap: 6px; }
.hs-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; border-radius: 12px;
  background: rgba(0, 0, 0, 0.18);
}
.hs-row.leader { background: linear-gradient(90deg, rgba(255,196,0,0.25), rgba(0,0,0,0.18)); }
.hs-rank { width: 28px; text-align: center; font-size: 1.1rem; }
.hs-name { flex: 1; font-weight: 700; }
.hs-pts { font-weight: 800; font-size: 1.15rem; min-width: 2ch; text-align: right; }

/* ---- History ---------------------------------------------------------- */
.history .round { margin-bottom: 10px; }
.history .round h4 { margin: 0 0 4px; font-size: 0.9rem; }
.history .ev { font-size: 0.82rem; color: var(--muted); padding: 2px 0; }

/* ---- Toast ------------------------------------------------------------ */
#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: #000; color: #fff; padding: 12px 18px; border-radius: 12px;
  box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: all 0.25s ease;
  z-index: 50; max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.win { background: linear-gradient(90deg, var(--c-pink), var(--c-violet)); font-weight: 800; }

/* ---- Win mode switch -------------------------------------------------- */
.modes { display: flex; flex-direction: column; gap: 8px; }
.modes label { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.modes small { color: var(--muted); display: block; }

/* ---- Override toggle -------------------------------------------------- */
.override-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.override-bar.active { outline: 2px dashed var(--c-pink); outline-offset: 6px; border-radius: 10px; padding: 8px; }

/* ---- Ready bar (spin-lock gate) --------------------------------------- */
.ready-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-top: 10px;
}

/* ---- Ready/waiting overview panel (always visible, both screens) ------ */
.ready-overview {
  margin-top: 10px;
  font-size: 0.84rem;
}
.ready-overview:empty { display: none; }
.ro-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 0;
  line-height: 1.3;
}
.ro-row.ro-current-turn { font-weight: 700; }
.ro-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ro-status { font-size: 0.8rem; color: var(--muted); white-space: nowrap; }
.ro-status.ready { color: #34C759; }
.ro-status.waiting { color: var(--muted); }
.ro-status.absent { color: #666; }
.ro-turn {
  font-size: 0.72rem;
  background: var(--accent);
  color: #fff;
  border-radius: 6px;
  padding: 1px 7px;
  font-weight: 700;
  white-space: nowrap;
}

/* ---- Host kick-list (one row per non-host player) --------------------- */
.kick-list:empty { display: none; }
.kick-list { margin-top: 8px; }
.kick-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
}
.kick-name { flex: 1; font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kick-btn { font-size: 0.75rem; padding: 2px 10px; }

/* ---- Spin-audit stamps (per-cell, full card only) --------------------- */
.cell-stamp {
  position: absolute; bottom: 2px; right: 3px;
  font-size: 0.48rem; line-height: 1;
  background: rgba(0,0,0,0.55); color: #fff;
  border-radius: 3px; padding: 1px 3px;
  pointer-events: none; z-index: 2;
}
.cell-override {
  position: absolute; top: 2px; right: 3px;
  font-size: 0.48rem; line-height: 1;
  background: rgba(232,67,147,0.8); color: #fff;
  border-radius: 3px; padding: 1px 3px;
  pointer-events: none; z-index: 2;
}
/* Hide stamps on mini cards to save space */
.card-grid.mini .cell-stamp,
.card-grid.mini .cell-override { display: none; }

/* ---- Override-depth select -------------------------------------------- */
#overrideDepthBar select {
  font: inherit; padding: 6px 10px; border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.16);
  background: rgba(0,0,0,0.25); color: var(--text);
}

/* ---- Intermission screen (between rounds) ------------------------------ */
.intermission {
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-left: 3px solid var(--accent-2);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}
.intermission h2 { margin: 0 0 14px; color: var(--accent-2); font-size: 1.05rem; }
.mode-vote { margin-bottom: 14px; }
.mode-vote p { margin: 0 0 8px; color: var(--muted); font-size: 0.9rem; }
#modeTally { display: block; font-size: 0.82rem; color: var(--muted); margin-top: 6px; }
.intermission-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
#startInfo { color: var(--muted); font-size: 0.88rem; }
