:root {
  --bg: #0A0A0A;
  --bg-vignette: #000000;
  --panel: #161213;
  --panel-line: #3B1A22;
  --text: #F7F5F2;
  --text-muted: #9A9490;
  --crimson: #A6192E;
  --crimson-dim: #3A0F16;
  --red: #E0202B;
  --red-dim: #401212;
  --white-accent: #F7F5F2;
  --white-dim: #2A2A2A;

  --font-display: 'Space Grotesk', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;
  --font-body: 'IBM Plex Sans', sans-serif;

  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: radial-gradient(circle at 50% -10%, #1a0d10 0%, var(--bg-vignette) 65%);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
}

body { min-height: 100vh; }

.view { min-height: 100vh; display: flex; justify-content: center; }
.hidden { display: none !important; }

/* ---------- shared field/button primitives ---------- */

.field {
  display: flex; flex-direction: column; gap: 6px;
  margin: 12px 0; font-size: 13px; color: var(--text-muted);
}
.field input, .field select {
  font-family: var(--font-mono); font-size: 15px; color: var(--text);
  background: var(--bg); border: 1px solid var(--panel-line);
  border-radius: 8px; padding: 11px 12px; width: 100%;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--crimson); }
.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text); }
.checkbox-row input { width: auto; }

.btn {
  font-family: var(--font-body); font-weight: 600; font-size: 15px;
  padding: 15px 18px; border-radius: var(--radius); border: 1px solid transparent;
  cursor: pointer; width: 100%;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--crimson); outline-offset: 2px; }
.btn:disabled { opacity: 0.6; cursor: default; }
.btn-primary { background: var(--crimson); color: #FFF; }
.btn-outline { background: transparent; color: var(--text); border-color: var(--panel-line); }
.btn-outline:hover { border-color: var(--crimson); }
.btn-found { background: var(--white-accent); color: #150506; }
.btn-giveup { background: transparent; color: var(--red); border-color: var(--red-dim); }
.btn-small { padding: 12px 14px; font-size: 13px; width: auto; }

.error-text { color: var(--red); font-size: 13px; margin-top: 10px; }

/* ---------- landing / join ---------- */

.landing {
  width: 100%; max-width: 420px; padding: 60px 24px;
  display: flex; flex-direction: column; position: relative;
}
.landing-brand {
  font-family: var(--font-display); font-weight: 700; font-size: 40px;
  letter-spacing: 0.04em; text-align: center; margin-bottom: 4px;
}
.landing-brand.small { font-size: 24px; margin-top: 20px; text-align: left; }
.landing-sub {
  font-family: var(--font-mono); font-size: 12px; letter-spacing: 0.2em;
  color: var(--crimson); text-transform: uppercase; text-align: center; margin-bottom: 40px;
}
.landing-btn { margin-top: 12px; }
.landing-hint { font-size: 12px; color: var(--text-muted); text-align: center; margin-top: 24px; line-height: 1.5; }
.back-btn {
  position: absolute; top: 24px; left: 20px; background: none; border: none;
  color: var(--text); font-size: 22px; cursor: pointer;
}
.howto-link {
  position: absolute; top: 24px; right: 20px;
  font-family: var(--font-mono); font-size: 12px; letter-spacing: 0.03em;
  color: var(--text-muted); text-decoration: none;
}
.howto-link:hover { color: var(--crimson); }

/* ---------- app shell ---------- */

.app {
  width: 100%; max-width: 480px; min-height: 100vh;
  background: var(--bg); border-left: 1px solid var(--panel-line); border-right: 1px solid var(--panel-line);
  padding: env(safe-area-inset-top) 18px 32px; display: flex; flex-direction: column;
}

.topbar { display: flex; align-items: center; justify-content: space-between; padding: 18px 2px 6px; }
.brand {
  font-family: var(--font-display); font-weight: 700; font-size: 20px;
  letter-spacing: 0.04em; display: flex; flex-direction: column; line-height: 1.1;
}
.brand-sub {
  font-family: var(--font-mono); font-size: 14px; font-weight: 700;
  letter-spacing: 0.16em; color: var(--crimson); margin-top: 2px; cursor: pointer;
}
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--panel-line);
  background: var(--panel); color: var(--text); font-size: 17px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}

/* ---------- tabs ---------- */

.tabbar {
  display: flex; background: var(--panel); border: 1px solid var(--panel-line);
  border-radius: var(--radius); padding: 4px; gap: 4px; margin: 10px 2px 14px;
}
.tab-btn {
  flex: 1; border: none; background: transparent; color: var(--text-muted);
  font-family: var(--font-mono); font-weight: 700; font-size: 11px; letter-spacing: 0.06em;
  padding: 10px 4px; border-radius: 7px; cursor: pointer;
}
.tab-btn.is-active { background: var(--crimson-dim); color: var(--crimson); }
.tab-panel { padding: 2px; }

/* ---------- room code card ---------- */

.code-card {
  background: var(--panel); border: 1px solid var(--panel-line); border-radius: var(--radius);
  padding: 16px; text-align: center; margin-bottom: 14px;
}
.code-card-label {
  font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--text-muted); margin-bottom: 8px;
}
.code-card-value {
  font-family: var(--font-mono); font-weight: 700; font-size: clamp(30px, 9vw, 42px);
  letter-spacing: 0.08em; color: var(--text); background: none; border: none; cursor: pointer;
  padding: 4px 0; width: 100%;
}
.code-card-actions { display: flex; gap: 8px; justify-content: center; margin-top: 10px; }
.code-card-actions .btn { flex: 1; max-width: 160px; }

/* ---------- team banner ---------- */

.team-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  border: 1px solid var(--panel-line); border-radius: var(--radius);
  padding: 10px 14px; margin-bottom: 12px; font-size: 13px;
}
.team-banner-name { font-family: var(--font-display); font-weight: 700; font-size: 15px; }
.team-banner-role {
  font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase;
  padding: 4px 9px; border-radius: 999px; background: var(--crimson-dim); color: var(--crimson);
}
.team-banner-muted { color: var(--text-muted); justify-content: center; }

/* ---------- timer tab ---------- */

.round-status-line {
  font-family: var(--font-mono); font-size: 12px; color: var(--text-muted);
  text-align: center; margin-bottom: 10px; letter-spacing: 0.02em;
}
.game-time-line {
  font-family: var(--font-mono); font-size: 11px; color: var(--crimson);
  text-align: center; margin-bottom: 10px; letter-spacing: 0.04em;
}

.gauge-wrap { position: relative; width: min(72vw, 260px); aspect-ratio: 1 / 1; margin: 6px auto 20px; }
.gauge { width: 100%; height: 100%; transform: rotate(-90deg); }
.gauge-track { fill: none; stroke: var(--panel-line); stroke-width: 14; }
.gauge-progress {
  fill: none; stroke: var(--crimson); stroke-width: 14; stroke-linecap: round;
  transition: stroke-dashoffset 0.25s linear, stroke 0.3s ease;
}
.gauge-center {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center;
}
.clock-digits {
  font-family: var(--font-mono); font-weight: 700; font-size: clamp(34px, 11vw, 48px);
  font-variant-numeric: tabular-nums;
}
.clock-label {
  font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--text-muted); margin-top: 6px;
}

.action-area { display: flex; flex-direction: column; gap: 10px; }
.action-row { display: flex; gap: 10px; }
.action-row .btn { flex: 1; }
.waiting-note {
  text-align: center; color: var(--text-muted); font-size: 13px;
  padding: 14px; border: 1px dashed var(--panel-line); border-radius: var(--radius);
}

/* ---------- pairing cards (concurrent rounds) ---------- */

.pairing-cards { display: flex; flex-direction: column; gap: 12px; }
.pairing-card {
  background: var(--panel); border: 1px solid var(--panel-line); border-radius: var(--radius);
  padding: 14px; border-left: 3px solid var(--panel-line);
}
.pairing-card.phase-dropping { border-left-color: var(--crimson); }
.pairing-card.phase-hunting { border-left-color: var(--red); }
.pairing-card.phase-returning { border-left-color: var(--white-accent); }
.pc-header { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.pc-title { font-family: var(--font-display); font-weight: 700; font-size: 16px; }
.pc-role {
  font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--text-muted); white-space: nowrap;
}
.pc-meta { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.pc-clock {
  font-family: var(--font-mono); font-weight: 700; font-size: 30px; text-align: center;
  margin: 10px 0; font-variant-numeric: tabular-nums;
}
.pc-body .btn { width: 100%; }

/* ---------- updates / log list ---------- */

.log-list { display: flex; flex-direction: column; gap: 8px; }
.log-row {
  background: var(--panel); border: 1px solid var(--panel-line); border-radius: 8px;
  padding: 11px 13px; font-size: 13px;
}
.log-row .lt { display: block; color: var(--text-muted); font-family: var(--font-mono); font-size: 10px; margin-bottom: 4px; }
.log-photo-row { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.log-thumb-btn { padding: 0; border: none; background: none; cursor: pointer; line-height: 0; }
.log-thumb { width: 44px; height: 44px; border-radius: 6px; object-fit: cover; border: 1px solid var(--panel-line); }
.empty-note { color: var(--text-muted); font-size: 13px; text-align: center; padding: 20px 0; }

/* ---------- leaderboard ---------- */

.leaderboard-list { display: flex; flex-direction: column; gap: 10px; }
.lb-card { background: var(--panel); border: 1px solid var(--panel-line); border-radius: var(--radius); padding: 14px; }
.lb-header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.lb-name { font-family: var(--font-display); font-weight: 700; font-size: 16px; }
.lb-score { font-family: var(--font-mono); color: var(--crimson); font-size: 14px; }
.lb-rounds { display: flex; flex-direction: column; gap: 6px; }
.lb-round-row {
  display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-muted);
  font-family: var(--font-mono);
}
.lb-round-row .oc-found { color: var(--white-accent); }
.lb-round-row .oc-gaveup { color: var(--red); }
.lb-thumb-btn { padding: 0; border: none; background: none; cursor: pointer; line-height: 0; }
.lb-thumb { width: 34px; height: 34px; border-radius: 6px; object-fit: cover; border: 1px solid var(--panel-line); }
.lb-dl-btn {
  border: 1px solid var(--panel-line); background: none; color: var(--text-muted);
  border-radius: 6px; width: 22px; height: 22px; cursor: pointer; font-size: 12px; line-height: 1;
  display: flex; align-items: center; justify-content: center; padding: 0;
}
.lb-dl-btn:hover { border-color: var(--crimson); color: var(--crimson); }

/* ---------- hunting chart ---------- */

.chart-table { margin-bottom: 12px; }
.chart-row {
  display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; align-items: center; margin-bottom: 8px;
}
.chart-head {
  font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--text-muted);
}
.chart-team-name { font-size: 13px; font-weight: 600; }
.chart-row select {
  font-family: var(--font-mono); font-size: 12px; background: var(--bg); color: var(--text);
  border: 1px solid var(--panel-line); border-radius: 6px; padding: 8px 6px; width: 100%;
}
.chart-row select:disabled { opacity: 0.5; }

/* ---------- manage tab ---------- */

.manage-block {
  border-top: 1px solid var(--panel-line); padding: 16px 2px;
}
.manage-block:first-child { border-top: none; }
.manage-title {
  font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--text-muted); margin-bottom: 10px;
}
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.team-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.team-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.team-role-select {
  font-family: var(--font-mono); font-size: 11px; background: var(--bg); color: var(--text);
  border: 1px solid var(--panel-line); border-radius: 6px; padding: 5px 6px;
}
.chip {
  font-family: var(--font-mono); font-size: 12px; padding: 6px 12px;
  border-radius: 999px; border: 1px solid var(--panel-line); color: var(--text);
}
.inline-form { display: flex; gap: 8px; margin-bottom: 12px; }
.inline-form input { flex: 1; }
.inline-form select {
  font-family: var(--font-mono); font-size: 12px; background: var(--bg); color: var(--text);
  border: 1px solid var(--panel-line); border-radius: 8px; padding: 0 8px;
}
.roster-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.roster-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--panel); border: 1px solid var(--panel-line); border-radius: 8px; padding: 9px 11px;
}
.roster-row .pname { font-size: 13px; }
.roster-row select { font-family: var(--font-mono); font-size: 12px; background: var(--bg); color: var(--text); border: 1px solid var(--panel-line); border-radius: 6px; padding: 6px; }

/* ---------- photo overlay ---------- */

.photo-overlay {
  position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, 0.86);
  display: flex; align-items: center; justify-content: center; padding: 24px;
  backdrop-filter: blur(6px);
}
.photo-overlay-card {
  position: relative; width: 100%; max-width: 420px; background: var(--panel);
  border: 1px solid var(--crimson); border-radius: var(--radius); padding: 18px;
  display: flex; flex-direction: column; gap: 12px; align-items: center;
}
.photo-overlay-card img { width: 100%; border-radius: 8px; max-height: 60vh; object-fit: contain; background: #000; }
.photo-overlay-caption { font-family: var(--font-display); font-weight: 700; font-size: 15px; text-align: center; }
.photo-overlay-close {
  position: absolute; top: -14px; right: -14px; width: 34px; height: 34px; border-radius: 50%;
  background: var(--crimson); color: #fff; border: 2px solid var(--bg); font-size: 18px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.photo-overlay-card .btn { width: 100%; }

/* ---------- toast ---------- */

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(10px);
  background: var(--panel); border: 1px solid var(--crimson-dim); color: var(--text);
  font-size: 13px; padding: 11px 18px; border-radius: 999px; opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease; z-index: 30; max-width: 88vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (prefers-reduced-motion: reduce) {
  .gauge-progress, .toast { transition: none !important; }
}
