/* Shared shell for all four views. Dark by default: the board view lives on a
   projector, and phones in a dim hall are easier on the eyes this way. */
:root {
  --bg: #0b1020;
  --bg-soft: #151b32;
  --bg-lift: #1e2643;
  --line: #2b3457;
  --text: #eef1fb;
  --muted: #98a2c7;
  --accent: #6ee7ff;
  --gold: #fbbf24;
  --danger: #f87171;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  /* dvh so the tap area still fills the screen when mobile browser chrome
     shows and hides; vh is the fallback for older engines. */
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  /* Fast repeated tapping must not select text, zoom, or bounce the page. */
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

body { display: flex; flex-direction: column; }

h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: -0.01em; }
a { color: var(--accent); }

.muted { color: var(--muted); }
.center { text-align: center; }
.hidden { display: none !important; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-soft);
}
.topbar h1 { font-size: 17px; }
.topbar nav { display: flex; gap: 14px; font-size: 14px; }

.wrap { width: min(1100px, 100%); margin: 0 auto; padding: 20px 16px 40px; }

button {
  font: inherit;
  font-weight: 600;
  color: var(--text);
  background: var(--bg-lift);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 18px;
  cursor: pointer;
  transition: transform 0.08s ease, filter 0.15s ease;
}
button:hover { filter: brightness(1.15); }
button:active { transform: scale(0.97); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.primary { background: linear-gradient(135deg, #22d3ee, #3b82f6); border-color: transparent; color: #04121f; }
button.danger { background: #3b1620; border-color: #7f2233; color: #fecdd3; }

input, select {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
}

.card {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

/* ------------------------------------------------------- connection state */
.conn {
  position: fixed;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  z-index: 50;
  padding: 8px 16px;
  border-radius: 999px;
  background: #3b1620;
  border: 1px solid #7f2233;
  color: #fecdd3;
  font-size: 13px;
  font-weight: 600;
}

/* ------------------------------------------------------------- team grid */
.team-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}
.team-pick {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 16px 10px;
  background: var(--bg-soft);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
}
.team-pick img { width: 84px; height: 84px; object-fit: contain; pointer-events: none; }
.team-pick .label { font-size: 14px; font-weight: 700; text-align: center; line-height: 1.25; }
.team-pick:hover { border-color: var(--accent); }

/* --------------------------------------------------------------- tap view */
#tap-view { flex: 1; display: flex; flex-direction: column; }


.status-banner {
  padding: 14px 16px;
  text-align: center;
  font-size: 18px;
  font-weight: 700;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--line);
}
.status-banner.go { background: #06301f; color: #6ee7b7; }
.status-banner.win { background: #3a2c05; color: var(--gold); }

.tap-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 24px 16px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.tap-area .logo {
  width: min(56vw, 260px);
  height: min(56vw, 260px);
  object-fit: contain;
  will-change: transform;
  pointer-events: none;
}
.tap-area .hint { font-size: 22px; font-weight: 800; letter-spacing: 0.08em; }

.tap-area.disabled { opacity: 0.55; cursor: default; }

.progress-strip { padding: 14px 16px 22px; background: var(--bg-soft); border-top: 1px solid var(--line); }
.bar {
  position: relative;
  height: 14px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--line);
  overflow: hidden;
}
.bar > span {
  position: absolute;
  inset: 0 auto 0 0;
  width: 100%;
  border-radius: 999px;
  transform-origin: left center;
  transform: scaleX(0);
}
.strip-meta { display: flex; justify-content: space-between; font-size: 13px; margin-top: 8px; }

/* ------------------------------------------------------------ board view */
body.board { overflow: hidden; height: 100vh; }
.board-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  /* Extra right padding keeps the clock clear of the fixed sound toggle. */
  padding: 16px 80px 16px 28px;
  gap: 24px;
}
.board-head h1 { font-size: clamp(20px, 2.4vw, 34px); }
.board-clock { font-size: clamp(18px, 2vw, 28px); font-weight: 800; font-variant-numeric: tabular-nums; color: var(--accent); }

.track { position: relative; flex: 1; padding: 0 24px 18px; display: flex; flex-direction: column; gap: 6px; }
.lane {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 0;
}
.lane + .lane { border-top: 1px dashed rgba(255, 255, 255, 0.07); }

/* Fixed-width gutters keep every lane's runnable track identical, so a team
   with a long name doesn't get a shorter race than one with a short name. */
.lane .rank {
  flex: 0 0 auto;
  width: clamp(26px, 3vw, 44px);
  text-align: center;
  font-size: clamp(14px, 1.6vw, 26px);
  font-weight: 800;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.lane .lane-track {
  position: relative;
  flex: 1 1 auto;
  height: 100%;
  min-width: 0;
  border-radius: 10px;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.045), rgba(255, 255, 255, 0.01));
}
.lane .lane-label {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: clamp(11px, 1.15vw, 17px);
  font-weight: 800;
  letter-spacing: 0.02em;
  opacity: 0.32;
  white-space: nowrap;
  pointer-events: none;
}
.lane .runner {
  position: absolute;
  left: 0;
  top: 50%;
  will-change: transform;
  transform: translate3d(0, -50%, 0);
}
.lane .runner-body {
  position: relative;
  transform-origin: 50% 100%;
  will-change: transform;
}
.lane .runner img {
  display: block;
  height: min(7.4vh, 76px);
  width: min(7.4vh, 76px);
  object-fit: contain;
  filter: drop-shadow(0 3px 8px rgba(0, 0, 0, 0.55));
}
.lane.leader .runner img { filter: drop-shadow(0 0 12px currentColor) drop-shadow(0 3px 8px rgba(0,0,0,0.55)); }

/* Only the current leader is crowned; it appears and disappears with the lead. */
.lane .crown {
  position: absolute;
  left: 50%;
  top: -0.7em;
  font-size: min(3.4vh, 34px);
  line-height: 1;
  opacity: 0;
  transform: translate(-50%, 6px) scale(0.5) rotate(-12deg);
  transition: opacity 0.25s ease, transform 0.35s cubic-bezier(0.2, 1.6, 0.4, 1);
  pointer-events: none;
}
.lane.leader .crown { opacity: 1; transform: translate(-50%, 0) scale(1) rotate(-12deg); }

/* Speed trail behind a runner that is actually moving. Width, position and
   opacity are all set from the frame loop; this is just the look. */
.lane .trail {
  position: absolute;
  top: 50%;
  height: min(4.4vh, 44px);
  transform: translateY(-50%);
  border-radius: 999px;
  background: linear-gradient(90deg, transparent, color-mix(in srgb, currentColor 55%, transparent));
  opacity: 0;
  pointer-events: none;
  filter: blur(3px);
}

.finish-line {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 8px;
  border-radius: 3px;
  background: repeating-linear-gradient(45deg, #fff 0 7px, #1b1b1b 7px 14px);
  opacity: 0.9;
  pointer-events: none;
}

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  background: rgba(6, 9, 20, 0.93);
  z-index: 20;
  text-align: center;
  padding: 24px;
}
.overlay .count { font-size: clamp(80px, 22vw, 260px); font-weight: 900; line-height: 1; color: var(--accent); }
.overlay .winner-logo { width: min(38vh, 320px); height: min(38vh, 320px); object-fit: contain; }
.overlay h2 { font-size: clamp(26px, 5vw, 64px); }
.overlay .qr { width: min(30vh, 260px); border-radius: 12px; background: #fff; padding: 10px; }
.overlay .join-url { font-size: clamp(16px, 2.2vw, 30px); font-weight: 700; color: var(--accent); word-break: break-all; }
.overlay .join-instructions { font-size: clamp(14px, 1.6vw, 20px); color: var(--muted); max-width: 46ch; margin: 0; }

.lobby-team-counts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 10px;
  width: min(1300px, 96vw);
}
.lobby-team-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-left-width: 4px;
  border-radius: 10px;
}
.lobby-team-chip-logo { width: 28px; height: 28px; object-fit: contain; flex: 0 0 auto; }
.lobby-team-chip-label {
  flex: 1 1 auto;
  min-width: 0;
  text-align: left;
  font-size: 14px;
  font-weight: 700;
  white-space: normal;
  line-height: 1.2;
}
.lobby-team-chip-count {
  flex: 0 0 auto;
  font-size: 20px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------ tables */
table { width: 100%; border-collapse: collapse; font-size: 15px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: rgba(255, 255, 255, 0.03); }
.team-cell { display: flex; align-items: center; gap: 10px; }
.team-cell img { width: 28px; height: 28px; object-fit: contain; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 18px; }
.stack { display: flex; flex-direction: column; gap: 18px; }
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.pill { padding: 4px 10px; border-radius: 999px; background: var(--bg-lift); font-size: 12px; font-weight: 700; }
.pill.live { background: #7f1d1d; color: #fecaca; animation: pulse 1.1s ease-in-out infinite; }

/* ============================================================== the fun bits
   Everything below is decoration driven by public/fx.js. It is deliberately
   all in one block: if the playfulness ever needs to go, this is the seam. */

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}
@keyframes wiggle {
  0%, 100% { transform: rotate(-1.5deg); }
  50% { transform: rotate(1.5deg); }
}
@keyframes shine {
  0% { transform: translateX(-120%); }
  100% { transform: translateX(320%); }
}
@keyframes float-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

/* ------------------------------------------------------- sound / haptics */
/* Bottom right on the phone views: the top right is where the pick heading
   and the status banner already live, and on a 390px screen they run straight
   underneath a fixed button. Bottom right is empty on every one of them —
   the "Change team" button is bottom left and the reconnect pill is centred. */
.fx-toggles {
  position: fixed;
  right: 10px;
  bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  z-index: 60;
  display: flex;
  gap: 8px;
}
/* The board is the exception: its bottom right is the last lane's score, and
   its top right has room next to the clock (see .board-head's padding). */
body.board .fx-toggles { top: 14px; bottom: auto; }
.fx-toggle {
  width: 42px;
  height: 42px;
  padding: 0;
  display: grid;
  place-items: center;
  font-size: 19px;
  line-height: 1;
  border-radius: 999px;
  background: rgba(30, 38, 67, 0.85);
  backdrop-filter: blur(6px);
}
.fx-toggle.off { opacity: 0.45; }
/* ------------------------------------------------- particles and flashes */
.float {
  position: absolute;
  z-index: 5;
  font-weight: 900;
  pointer-events: none;
  white-space: nowrap;
  transform: translate(-50%, -50%);
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.6);
}
.float.plus-one { font-size: 30px; }
.float.lane-shout { font-size: clamp(14px, 1.5vw, 22px); letter-spacing: 0.08em; }

.ripple {
  position: absolute;
  z-index: 4;
  border-radius: 50%;
  border: 3px solid currentColor;
  pointer-events: none;
  transform: translate(-50%, -50%);
}

.screen-flash {
  position: fixed;
  inset: 0;
  z-index: 90;
  opacity: 0;
  pointer-events: none;
  mix-blend-mode: screen;
}

.title-pop { animation: float-bob 3.2s ease-in-out infinite; }

/* ------------------------------------------------------- player tap view */
/* Cards glow in their own colour on hover rather than a single accent, so the
   grid reads as twelve teams and not twelve identical buttons. */
.team-pick { transition: border-color 0.2s ease, box-shadow 0.2s ease; will-change: transform; }
.team-pick:hover {
  border-color: var(--team, var(--accent));
  box-shadow: 0 0 0 1px var(--team, var(--accent)), 0 10px 30px -10px var(--team, var(--accent));
}

.combo {
  position: absolute;
  top: 14px;
  right: 18px;
  z-index: 6;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
  color: var(--team, var(--accent));
  pointer-events: none;
}
.combo span { font-size: 40px; font-weight: 900; font-variant-numeric: tabular-nums; }
.combo small { font-size: 11px; letter-spacing: 0.22em; opacity: 0.7; text-transform: uppercase; }
.combo.hot { color: var(--gold); animation: wiggle 0.28s ease-in-out infinite; }
.combo.hot span { text-shadow: 0 0 22px currentColor; }

.tap-overlay {
  position: absolute;
  inset: 0;
  z-index: 7;
  display: grid;
  place-items: center;
  pointer-events: none;
}
.tap-overlay > div {
  font-size: clamp(30px, 10vw, 62px);
  font-weight: 900;
  letter-spacing: 0.02em;
  color: var(--gold);
  text-shadow: 0 4px 30px rgba(0, 0, 0, 0.8);
}

/* A moving sheen on the progress bar: a filling bar that also shimmers reads
   as "live" even when your own team has stalled. */
.bar::after {
  content: '';
  position: absolute;
  inset: 0;
  width: 30%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.5), transparent);
  animation: shine 2.2s linear infinite;
  pointer-events: none;
}

/* --------------------------------------------------------- board podium */
.winner-crown { font-size: clamp(36px, 6vw, 72px); animation: float-bob 2.4s ease-in-out infinite; }

.podium {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(560px, 90vw);
}
.podium-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 18px;
  border-radius: 12px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-left: 5px solid var(--team);
}
.podium-row:first-child { background: color-mix(in srgb, var(--team) 18%, var(--bg-soft)); }
.podium .medal { font-size: clamp(20px, 2.4vw, 30px); }
.podium .podium-name { flex: 1; text-align: left; font-weight: 700; font-size: clamp(15px, 1.7vw, 22px); color: var(--team); }

/* ---------------------------------------------------------- host + history */
tbody tr.leading td { background: rgba(251, 191, 36, 0.08); }
tbody tr.champion td { background: rgba(251, 191, 36, 0.12); font-weight: 700; }
tbody tr.champion td:first-child::before { content: '👑 '; }
#live-rows tr { will-change: transform; }

/* ----------------------------------------------------------- reduced motion
   fx.js already skips its own animations; this stops the purely-CSS loops,
   which it has no hand in. */
@media (prefers-reduced-motion: reduce) {
  .title-pop,
  .winner-crown,
  .combo.hot,
  .pill.live,
  .bar::after { animation: none; }
  .lane .crown { transition: none; }
}
