/* ===========================================================================
   FMSS design tokens + shared primitives
   Extracted from fmss-contracts/public/css/styles.css (the FMSS brand block at
   its foot, which supersedes that file's generic indigo/green defaults).

   Dark-first, unlike contracts. Two reasons: FMSS identity is dark, and the
   Main Display is projected into a darkened hall where a light ground would be
   blinding. Light exists as an opt-in for the Master working in a lit room.

   RULE: never write a raw colour below the token block. scripts/check-ui-tokens.js
   fails the build on hardcoded colours, undefined var(--x), and phantom classes.
   =========================================================================== */

:root {
  /* Surfaces — the marketing-site palette. */
  --bg-main: #0A0A0A;
  --bg-card: #121212;
  --bg-inset: #161616;
  --bg-subtle: #1c1c1c;
  --border-color: #222222;
  --border-strong: #333333;

  /* Text */
  --text-main: #FFFFFF;
  --text-muted: #E0E0E0;
  --text-faint: #999999;

  /* Gold — the FMSS accent, in every theme. */
  --sport: #FFD700;
  --sport-deep: #FFC700;
  --sport-ring: rgba(255, 215, 0, 0.22);
  --sport-grad: linear-gradient(135deg, #FFD700 0%, #FFC700 100%);
  --sport-glow: rgba(255, 215, 0, 0.45);
  --accent: #FFD700;
  --accent-hover: #FFC700;
  /* Text sitting ON a dark surface, tinted gold. Raw #FFD700 as body text
     measures ~1.5:1 on light surfaces, so it is mixed toward the ground. */
  --sport-soft: color-mix(in srgb, var(--sport) 12%, var(--bg-card));
  --sport-on-soft: color-mix(in srgb, var(--sport) 72%, white);
  /* Foreground for text ON a solid gold fill — gold is bright in every theme,
     so this stays near-black and is NOT redefined per theme. */
  --on-sport: #0A0A0A;

  /* Semantic */
  --danger: #dc2626;
  --on-danger: #fff7f7;
  --warning: #d97706;
  --success: #16a34a;
  --focus: rgba(255, 215, 0, 0.30);

  /* Chrome */
  --topbar-bg: rgba(10, 10, 10, 0.85);
  --toast-bg: #1a1a1a;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 18px 44px rgba(0, 0, 0, 0.55);
  --radius: 14px;

  /* Type scale multiplier. The Main Display overrides this in display.css —
     everything below sizes off it so one number rescales a whole view. */
  --scale: 1;

  /* Real team colours are domain data: they arrive from the DB and are set per
     element as an inline --team-color. This declares the unset default so the
     token linter can see it and so an un-themed team still renders. */
  --team-default: #999999;
  --team-color: var(--team-default);
}

/* Opt-in light theme — token values only, no structural changes. */
:root[data-theme="light"] {
  --bg-main: #f7f8fb;
  --bg-card: #ffffff;
  --bg-inset: #f8fafc;
  --bg-subtle: #f1f3f9;
  --border-color: #e8eaf1;
  --border-strong: #d6d9e4;
  --text-main: #161a26;
  --text-muted: #5b6275;
  --text-faint: #6b7280;
  --sport-soft: color-mix(in srgb, var(--sport) 10%, var(--bg-card));
  --sport-on-soft: color-mix(in srgb, var(--sport) 32%, var(--text-main));
  --topbar-bg: rgba(255, 255, 255, 0.85);
  --toast-bg: #1f2433;
  --shadow-sm: 0 1px 2px rgba(20, 26, 38, 0.04), 0 1px 3px rgba(20, 26, 38, 0.06);
  --shadow-md: 0 4px 12px rgba(20, 26, 38, 0.07), 0 2px 4px rgba(20, 26, 38, 0.04);
  --shadow-lg: 0 18px 44px rgba(20, 26, 38, 0.14);
}

/* ===== Base ===== */

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-font-smoothing: antialiased; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-main);
  background-image: linear-gradient(135deg, #0A0A0A 0%, #050505 100%);
  color: var(--text-main);
  line-height: 1.55;
  font-size: calc(15px * var(--scale));
  min-height: 100vh;
}
:root[data-theme="light"] body { background-image: none; }

input, select, textarea, button { font-family: inherit; }
[hidden] { display: none !important; }

/* Oswald carries the display voice — wordmark, titles, scores, timers. */
.brand-name, .page-title, .card-title, .display-title, .kpi .v,
.score-value, .timer-value, .mini-h, h1, h2, h3 {
  font-family: 'Oswald', 'Inter', sans-serif;
  letter-spacing: 0.02em;
}

h1 { font-size: calc(1.35rem * var(--scale)); font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: calc(1.14rem * var(--scale)); font-weight: 700; }
h3 { font-size: calc(1.04rem * var(--scale)); font-weight: 700; }

/* ===== Brand wordmark ===== */

.brand { display: flex; align-items: center; gap: 0.7rem; }
.brand-logo { width: 42px; height: 42px; object-fit: contain;
  filter: drop-shadow(0 0 8px var(--sport-ring)); }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name {
  font-size: calc(1.08rem * var(--scale));
  color: var(--sport);
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-shadow: 0 0 18px var(--sport-glow);
}
.brand-tag {
  font-size: calc(0.64rem * var(--scale));
  color: var(--sport); opacity: 0.75;
  text-transform: uppercase; letter-spacing: 0.12em; font-weight: 600;
}

/* ===== Layout ===== */

.wrap { width: 100%; max-width: 1180px; margin: 0 auto; padding: 2rem;
  display: flex; flex-direction: column; gap: 1.5rem; }

.topbar { display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: 0.85rem 2rem; border-bottom: 1px solid var(--border-color);
  position: sticky; top: 0; z-index: 10;
  background: var(--topbar-bg); backdrop-filter: saturate(180%) blur(10px); }
.topbar::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px;
  height: 2px; background: var(--sport-grad); opacity: 0.9; }
.topbar-titles { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.page-title { font-size: calc(1.14rem * var(--scale)); font-weight: 700; }
.page-context { font-size: calc(0.74rem * var(--scale)); color: var(--text-faint);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right { display: flex; align-items: center; gap: 0.75rem; }

/* ===== Card ===== */

.card { position: relative; background: var(--bg-card);
  border: 1px solid var(--border-color); border-radius: var(--radius);
  padding: 1.75rem; display: flex; flex-direction: column; gap: 1.5rem;
  box-shadow: var(--shadow-sm); }
.card-header { display: flex; justify-content: space-between; align-items: center;
  gap: 0.5rem; flex-wrap: wrap;
  padding-bottom: 1rem; border-bottom: 1px solid var(--border-color); }
.card-title { font-size: calc(1.04rem * var(--scale)); font-weight: 700;
  display: flex; align-items: center; gap: 0.55rem; }
.card-title::before { content: ""; width: 4px; height: 18px; border-radius: 3px;
  background: var(--sport-grad); flex: none; }
.card-sub { font-size: calc(0.78rem * var(--scale)); color: var(--text-faint); font-weight: 500; }

/* ===== Buttons ===== */

.btn { background: var(--sport); color: var(--on-sport);
  padding: 0.58rem 1.15rem; border: none; border-radius: 9px;
  font-weight: 700; font-size: calc(0.88rem * var(--scale)); cursor: pointer;
  box-shadow: 0 4px 12px var(--sport-ring);
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  transition: transform 0.14s, box-shadow 0.14s, background 0.14s; }
.btn:hover { background: var(--sport-deep); transform: translateY(-1px);
  box-shadow: 0 6px 18px var(--sport-ring); }
.btn:active { transform: translateY(0); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--focus); }
.btn:disabled, .btn.loading { opacity: 0.65; cursor: not-allowed; pointer-events: none; }

.btn-secondary { background: var(--bg-card); border: 1px solid var(--border-strong);
  color: var(--text-main); box-shadow: var(--shadow-sm); font-weight: 600; }
.btn-secondary:hover { background: var(--sport-soft); border-color: var(--sport-ring);
  color: var(--sport-on-soft); }
.btn-danger { background: var(--bg-card); border: 1px solid var(--border-strong);
  color: var(--text-muted); box-shadow: none; font-weight: 600; }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 12%, var(--bg-card));
  border-color: var(--danger); color: var(--danger); }
.btn-sm { padding: 0.38rem 0.75rem; font-size: calc(0.8rem * var(--scale)); }
.btn-lg { padding: 0.9rem 1.8rem; font-size: calc(1.05rem * var(--scale)); border-radius: 12px; }
.full-w { width: 100%; }

/* ===== Forms ===== */

label { font-size: calc(0.78rem * var(--scale)); color: var(--text-muted); font-weight: 600; }
.form-group { display: flex; flex-direction: column; gap: 0.4rem; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1.1rem; }

input, select, textarea {
  background: var(--bg-inset); border: 1px solid var(--border-strong);
  color: var(--text-main); padding: 0.58rem 0.72rem; border-radius: 9px;
  font-size: calc(0.9rem * var(--scale)); width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s; }
input::placeholder, textarea::placeholder { color: var(--text-faint); }
input:focus, select:focus, textarea:focus { border-color: var(--sport); outline: none;
  background: var(--bg-card); box-shadow: 0 0 0 3px var(--sport-ring); }
input.error, select.error, textarea.error { border-color: var(--danger);
  background: color-mix(in srgb, var(--danger) 8%, var(--bg-card)); }

.form-error { font-size: calc(0.75rem * var(--scale)); color: var(--danger);
  margin-top: 0.3rem; font-weight: 500; min-height: 1rem; }

/* The join-code field: read aloud to a room, typed on a phone. Wide tracking
   and a monospace-ish feel make a mistyped character obvious. */
.code-input { font-family: 'Oswald', sans-serif; font-size: calc(1.6rem * var(--scale));
  font-weight: 600; letter-spacing: 0.3em; text-align: center; text-transform: uppercase;
  padding: 0.7rem 0.5rem; }

/* ===== Tags & pills ===== */

.tag { display: inline-flex; padding: 0.12rem 0.6rem; border-radius: 9999px;
  font-size: calc(0.72rem * var(--scale)); font-weight: 600;
  border: 1px solid var(--border-strong); color: var(--text-muted); background: var(--bg-inset); }
.tag-live { color: color-mix(in srgb, var(--success) 72%, var(--text-main));
  border-color: color-mix(in srgb, var(--success) 35%, var(--bg-card));
  background: color-mix(in srgb, var(--success) 13%, var(--bg-card)); }
.tag-wait { color: color-mix(in srgb, var(--warning) 72%, var(--text-main));
  border-color: color-mix(in srgb, var(--warning) 35%, var(--bg-card));
  background: color-mix(in srgb, var(--warning) 13%, var(--bg-card)); }
.tag-locked { color: color-mix(in srgb, var(--danger) 72%, var(--text-main));
  border-color: color-mix(in srgb, var(--danger) 35%, var(--bg-card));
  background: color-mix(in srgb, var(--danger) 13%, var(--bg-card)); }
.tag-gold { color: var(--sport-on-soft); border-color: var(--sport-ring);
  background: var(--sport-soft); }

/* Team identity dot — colour comes from the DB via an inline --team-color. */
.team-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%;
  margin-right: 0.4rem; vertical-align: middle;
  background: var(--team-color, var(--team-default)); }

/* ===== Key/value rows ===== */

.mini-h { font-size: calc(0.78rem * var(--scale)); font-weight: 700;
  color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em;
  margin-bottom: 0.7rem; }

.kv { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem;
  padding: 0.5rem 0; border-bottom: 1px solid var(--border-color);
  font-size: calc(0.9rem * var(--scale)); }
.kv:last-child { border-bottom: none; }
.kv .k { display: flex; align-items: center; color: var(--text-muted); min-width: 0; }
.kv .v { font-weight: 700; font-variant-numeric: tabular-nums; }

/* A short code meant to be read aloud and typed in — join codes, PINs. Wide
   tracking so similar-looking characters are unambiguous across a room. */
.pin-chip { display: inline-block; font-family: 'Oswald', sans-serif; font-weight: 600;
  letter-spacing: 0.14em; font-size: calc(1rem * var(--scale));
  color: var(--sport); background: var(--sport-soft);
  border: 1px solid var(--sport-ring); padding: 0.1rem 0.6rem; border-radius: 7px; }

/* ===== Numbers ===== */

.num, .score-value { font-variant-numeric: tabular-nums; white-space: nowrap; }
.score-value { font-weight: 800; letter-spacing: -0.02em; color: var(--sport-on-soft); }
.score-value.up { color: var(--success); }
.score-value.down { color: var(--danger); }

/* ===== Segmented control ===== */

.seg { display: inline-flex; gap: 0.3rem; background: var(--bg-subtle);
  padding: 0.25rem; border-radius: 11px; border: 1px solid var(--border-color); }
.seg button { background: none; border: none; cursor: pointer;
  padding: 0.4rem 0.9rem; border-radius: 8px;
  font-size: calc(0.85rem * var(--scale)); font-weight: 600; color: var(--text-muted); }
.seg button.active { background: var(--bg-card); color: var(--sport-on-soft);
  box-shadow: var(--shadow-sm); }

/* ===== Table ===== */

.table { width: 100%; border-collapse: collapse; text-align: left;
  font-size: calc(0.88rem * var(--scale)); }
.table th { color: var(--text-faint); font-weight: 700;
  font-size: calc(0.7rem * var(--scale)); text-transform: uppercase;
  letter-spacing: 0.06em; padding: 0.6rem 0.8rem;
  border-bottom: 1px solid var(--border-color); }
.table td { padding: 0.85rem 0.8rem; border-bottom: 1px solid var(--border-color);
  vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--sport-soft); }

/* Wide content must scroll inside itself, never the page body. */
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ===== Feedback ===== */

.spinner { display: inline-block; width: 14px; height: 14px;
  border: 2px solid var(--border-strong); border-top-color: var(--sport);
  border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast { position: fixed; bottom: 1.5rem; right: 1.5rem; background: var(--toast-bg);
  color: var(--text-main); padding: 0.75rem 1.15rem; border-radius: 10px;
  font-size: calc(0.85rem * var(--scale)); box-shadow: var(--shadow-lg);
  opacity: 0; transform: translateY(10px); z-index: 50;
  display: flex; align-items: center; gap: 0.6rem; max-width: 400px;
  transition: opacity 0.2s, transform 0.2s; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.err { background: var(--danger); color: var(--on-danger); }

.empty-state { text-align: center; padding: 2.5rem 1.5rem; color: var(--text-faint); }
.empty-state-title { font-size: calc(1rem * var(--scale)); font-weight: 600;
  color: var(--text-muted); margin-bottom: 0.3rem; }
.empty-state-desc { font-size: calc(0.8rem * var(--scale)); line-height: 1.5; }

.muted { color: var(--text-muted); font-size: calc(0.88rem * var(--scale)); }
.hint { font-size: calc(0.8rem * var(--scale)); color: var(--text-faint); }

/* ===== Centred single-panel views (join screen, display standby) ===== */

.centre { min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 2rem; position: relative; overflow: hidden; }
.centre::before { content: ""; position: absolute; inset: -20% -20% auto auto;
  width: 460px; height: 460px; background: var(--sport-grad);
  filter: blur(80px); opacity: 0.12; border-radius: 50%; pointer-events: none; }
.panel { position: relative; width: 100%; max-width: 400px; background: var(--bg-card);
  border: 1px solid var(--border-color); border-radius: 16px; padding: 2.5rem;
  box-shadow: var(--shadow-lg); }
.panel-head { text-align: center; margin-bottom: 1.85rem; }
.panel-logo { width: 76px; height: 76px; object-fit: contain; display: block;
  margin: 0 auto 0.9rem; filter: drop-shadow(0 0 12px var(--sport-glow)); }
.panel-title { font-family: 'Oswald', sans-serif; font-size: calc(1.5rem * var(--scale));
  color: var(--sport); text-transform: uppercase; letter-spacing: 0.16em;
  text-shadow: 0 0 18px var(--sport-glow); }
.panel-sub { color: var(--text-muted); font-size: calc(0.86rem * var(--scale)); margin-top: 0.35rem; }
.stack { display: flex; flex-direction: column; gap: 1rem; }

/* ===== Responsive ===== */

@media (max-width: 820px) {
  .form-row { grid-template-columns: 1fr; }
  .wrap { padding: 1.1rem; gap: 1.1rem; }
  .topbar { padding: 0.7rem 1rem; }
  .card { padding: 1.25rem; gap: 1.1rem; }
  .panel { padding: 1.75rem; }
}
