/* ==========================================================================
   THE TWISTED SACK — styles
   "medical-alert arcade": dark navy base, hot orange-red + caution yellow
   accents, tasteful torsion/swirl motif. Two layouts: HOST (big/TV) and
   PLAYER (compact/phone).
   ========================================================================== */

:root {
  --ink: #0B1220;
  --surface: #12203A;
  --surface-2: #1A2C4D;
  --accent: #FF5A36;
  --accent-2: #FFC53D;
  --good: #37D67A;
  --bad: #FF4D6D;
  --text: #EDEFF7;
  --muted: #93A0C2;

  --font-display: "Bungee", "Arial Black", "Impact", system-ui, sans-serif;
  --font-body: "Manrope", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "Space Mono", "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;

  --radius: 14px;
  --radius-lg: 22px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--ink);
  color: var(--text);
  min-height: 100%;
  overflow-x: hidden;
}

body {
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.4;
}

.root {
  min-height: 100vh;
  width: 100%;
  position: relative;
  z-index: 1;
}

h1, h2, h3 { margin: 0 0 0.4em; }

button {
  font-family: inherit;
  cursor: pointer;
}

input {
  font-family: inherit;
}

a, .link-btn {
  color: var(--muted);
  text-decoration: underline;
  background: none;
  border: none;
  padding: 0;
  font-size: 0.85rem;
}

a:hover, .link-btn:hover { color: var(--text); }

.tabular { font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------------- */
/* Connection banner                                                       */
/* ---------------------------------------------------------------------- */
.conn-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 999;
  background: var(--accent-2);
  color: #1a1300;
  text-align: center;
  font-weight: 700;
  font-size: 0.85rem;
  padding: 6px 10px;
  letter-spacing: 0.02em;
}

/* ---------------------------------------------------------------------- */
/* Swirl / torsion motif                                                   */
/* ---------------------------------------------------------------------- */
/* A single persistent element living outside #root (see index.html) so it
   never gets torn down and recreated by a poll-driven re-render — that used
   to snap its rotation back to 0 every ~1.5s and looked like a stutter.
   Its visibility is toggled via the [hidden] attribute, never recreated. */
.swirl {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    conic-gradient(from 0deg at 50% 50%,
      rgba(255,90,54,0.22), rgba(255,197,61,0.14), transparent 40%,
      rgba(255,90,54,0.12), transparent 70%);
  filter: blur(2px);
  animation: swirl-spin 40s linear infinite;
  opacity: 0.8;
}

.swirl[hidden] { display: none; }

@keyframes swirl-spin {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .swirl { animation: none; }
}

/* ---------------------------------------------------------------------- */
/* Reusable pieces                                                         */
/* ---------------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
}

.pill {
  display: inline-block;
  padding: 0.15em 0.7em;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.8em;
  font-weight: 700;
}

.blank {
  display: inline-block;
  background: var(--accent-2);
  color: #1a1300;
  font-weight: 800;
  padding: 0.05em 0.5em;
  border-radius: 6px;
  margin: 0 0.1em;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
  border: none;
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  font-weight: 700;
  font-size: 1rem;
  padding: 0.9em 1.3em;
  min-height: 44px;
  transition: transform 0.08s ease, filter 0.15s ease, opacity 0.15s ease;
}

.btn:active { transform: scale(0.97); }

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: var(--accent);
  color: #1a0800;
}

.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }

.btn-accent2 {
  background: var(--accent-2);
  color: #1a1300;
}

.btn-good {
  background: var(--good);
  color: #06210f;
}

.btn-block { width: 100%; }

.btn-huge {
  font-size: 1.3rem;
  padding: 1.1em 1.5em;
}

.reset-link {
  position: fixed;
  bottom: 10px;
  right: 12px;
  z-index: 50;
  font-size: 0.75rem;
  opacity: 0.6;
}

.reset-link:hover { opacity: 1; }

.reset-link.top {
  top: 10px;
  bottom: auto;
}

.mute-btn {
  position: fixed;
  top: 10px;
  left: 12px;
  z-index: 50;
  font-size: 1.3rem;
  line-height: 1;
  opacity: 0.7;
  text-decoration: none;
}

.mute-btn:hover { opacity: 1; }

.center-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.error-box {
  border: 2px dashed var(--bad);
  color: var(--bad);
  border-radius: var(--radius);
  padding: 1em;
  font-weight: 700;
}

/* ---------------------------------------------------------------------- */
/* Landing screen                                                          */
/* ---------------------------------------------------------------------- */
.landing {
  position: relative;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1.25rem;
  gap: 1.75rem;
  overflow: hidden;
}

.landing-title {
  position: relative;
  z-index: 1;
  font-family: var(--font-display);
  font-size: clamp(2.4rem, 9vw, 5rem);
  line-height: 1.05;
  text-align: center;
  color: var(--text);
  text-shadow: 0 0 30px rgba(255,90,54,0.45);
  letter-spacing: 0.01em;
}

.landing-title .accent { color: var(--accent); }

.landing-sub {
  position: relative;
  z-index: 1;
  color: var(--muted);
  font-weight: 600;
  text-align: center;
  max-width: 32em;
}

.landing-actions {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: 100%;
  max-width: 420px;
}

.landing-actions .btn {
  font-size: 1.15rem;
  padding: 1.1em 1.2em;
}

.join-form {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  width: 100%;
  max-width: 420px;
}

.field-label {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.3em;
  display: block;
}

.field-input {
  width: 100%;
  background: var(--surface-2);
  border: 2px solid transparent;
  border-radius: var(--radius);
  color: var(--text);
  padding: 0.85em 1em;
  font-size: 1.1rem;
  min-height: 44px;
}

.field-input:focus {
  outline: none;
  border-color: var(--accent);
}

.field-input.code-input {
  font-family: var(--font-mono);
  letter-spacing: 0.3em;
  text-transform: uppercase;
  text-align: center;
  font-size: 1.4rem;
}

.form-error {
  color: var(--bad);
  font-weight: 700;
  font-size: 0.9rem;
  min-height: 1.2em;
}

/* ---------------------------------------------------------------------- */
/* HOST layout (big screen)                                                */
/* ---------------------------------------------------------------------- */
.host-view {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 2.5vh 4vw 0;
  position: relative;
}

.host-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.75rem;
  text-align: center;
  padding-bottom: 8rem;
  position: relative;
  z-index: 1;
}

.host-eyebrow {
  font-family: var(--font-mono);
  color: var(--accent-2);
  letter-spacing: 0.25em;
  text-transform: uppercase;
  font-size: clamp(0.85rem, 1.6vw, 1.1rem);
  font-weight: 700;
}

.host-headline {
  font-family: var(--font-display);
  font-size: clamp(1.8rem, 5vw, 3.6rem);
  line-height: 1.15;
  max-width: 90vw;
}

.host-prompt {
  font-family: var(--font-display);
  font-size: clamp(1.6rem, 4.2vw, 3rem);
  line-height: 1.2;
  max-width: 85vw;
}

.host-subtext {
  font-size: clamp(1rem, 2vw, 1.4rem);
  color: var(--muted);
  font-weight: 600;
  max-width: 60em;
}

.room-code-display {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: clamp(2.5rem, 10vw, 6rem);
  letter-spacing: 0.15em;
  color: var(--accent-2);
  background: var(--surface);
  border: 3px solid var(--accent-2);
  border-radius: var(--radius-lg);
  padding: 0.2em 0.5em;
  display: inline-block;
}

.room-url {
  font-family: var(--font-mono);
  font-size: clamp(1rem, 2.4vw, 1.6rem);
  color: var(--muted);
}

.player-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  justify-content: center;
  max-width: 80vw;
}

.player-chip {
  background: var(--surface-2);
  border-radius: 999px;
  padding: 0.5em 1.1em;
  font-weight: 700;
  font-size: 1.1rem;
}

.count-readout {
  font-family: var(--font-mono);
  font-size: clamp(1.2rem, 3vw, 2rem);
  color: var(--text);
  font-weight: 700;
}

.count-readout .of { color: var(--muted); font-weight: 400; }

.host-btn-row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  justify-content: center;
  position: relative;
  z-index: 1;
}

.choices-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
  width: 100%;
  max-width: 1100px;
}

.choice-card {
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 1em 1.2em;
  font-size: 1.3rem;
  font-weight: 700;
  text-align: left;
  position: relative;
}

.choice-card.is-winner {
  outline: 3px solid var(--good);
  box-shadow: 0 0 24px rgba(55,214,122,0.35);
}

.choice-card.is-correct {
  outline: 3px solid var(--good);
}

.choice-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75em;
  margin-top: 0.5em;
  font-size: 0.9rem;
  color: var(--muted);
  font-weight: 600;
}

.vote-bar-track {
  width: 100%;
  height: 10px;
  background: rgba(255,255,255,0.08);
  border-radius: 6px;
  overflow: hidden;
  margin-top: 0.5em;
}

.vote-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 6px;
  transition: width 0.4s ease;
}

.vote-bar-fill.is-good { background: var(--good); }

.vote-count-badge {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--accent-2);
}

.author-tag {
  color: var(--accent-2);
  font-weight: 700;
}

.voter-names {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 0.35em;
}

/* Scoreboard strip (host, persistent) */
.scoreboard-strip {
  position: sticky;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(to top, rgba(11,18,32,0.98), rgba(11,18,32,0.85));
  border-top: 1px solid rgba(255,255,255,0.08);
  padding: 0.6rem 1rem calc(0.6rem + env(safe-area-inset-bottom, 0px));
  display: flex;
  gap: 0.6rem;
  overflow-x: auto;
  z-index: 5;
}

.scoreboard-strip .sb-item {
  flex: 0 0 auto;
  background: var(--surface);
  border-radius: 999px;
  padding: 0.4em 0.9em;
  font-size: 0.85rem;
  font-weight: 700;
  white-space: nowrap;
  color: var(--muted);
  display: flex;
  gap: 0.4em;
  align-items: baseline;
}

.scoreboard-strip .sb-item .sb-score {
  color: var(--accent-2);
  font-family: var(--font-mono);
}

.scoreboard-strip .sb-item.is-leader .sb-score { color: var(--good); }

/* Leaderboard (gameover) */
.leaderboard {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  width: 100%;
  max-width: 640px;
}

.lb-row {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 0.75em 1.1em;
  font-size: 1.2rem;
  font-weight: 700;
}

.lb-row.is-champion {
  background: linear-gradient(90deg, rgba(255,197,61,0.25), rgba(255,90,54,0.15));
  outline: 2px solid var(--accent-2);
  font-size: 1.5rem;
}

.lb-rank {
  font-family: var(--font-mono);
  color: var(--muted);
  width: 2em;
}

.lb-name { flex: 1; text-align: left; }

.lb-score {
  font-family: var(--font-mono);
  color: var(--accent-2);
}

.champion-banner {
  font-family: var(--font-display);
  font-size: clamp(1.4rem, 4vw, 2.4rem);
  color: var(--accent-2);
  text-shadow: 0 0 20px rgba(255,197,61,0.5);
}

.confetti-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}

.confetti-piece {
  position: absolute;
  top: -10%;
  width: 10px;
  height: 16px;
  opacity: 0.9;
  animation: confetti-fall 3.2s linear infinite;
}

@keyframes confetti-fall {
  to { transform: translateY(115vh) rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .confetti-piece { animation: none; top: 20%; opacity: 0.5; }
}

/* ---------------------------------------------------------------------- */
/* PLAYER layout (phone)                                                   */
/* ---------------------------------------------------------------------- */
.player-view {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.player-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.7rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  position: sticky;
  top: 0;
  z-index: 4;
}

.player-topbar .who {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text);
}

.player-topbar .who .muted { color: var(--muted); font-weight: 500; }

.player-topbar .score-chip {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--accent-2);
  background: var(--surface-2);
  border-radius: 999px;
  padding: 0.3em 0.8em;
  font-size: 0.95rem;
}

.player-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 1rem 1rem 1.25rem;
  gap: 1rem;
}

.player-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  justify-content: center;
}

.player-eyebrow {
  font-family: var(--font-mono);
  color: var(--accent-2);
  text-transform: uppercase;
  letter-spacing: 0.15em;
  font-size: 0.75rem;
  font-weight: 700;
}

.player-prompt {
  font-size: 1.3rem;
  font-weight: 800;
  line-height: 1.35;
}

.player-actions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: auto;
  padding-top: 0.5rem;
}

.choice-btn {
  display: block;
  width: 100%;
  background: var(--surface-2);
  color: var(--text);
  border: 2px solid transparent;
  border-radius: var(--radius);
  padding: 1em 1.1em;
  font-size: 1.05rem;
  font-weight: 700;
  text-align: left;
  min-height: 48px;
}

.choice-btn:active { border-color: var(--accent); }

.choice-btn:disabled { opacity: 0.5; }

.option-letter {
  display: inline-block;
  width: 1.6em;
  height: 1.6em;
  line-height: 1.6em;
  text-align: center;
  border-radius: 50%;
  background: var(--surface);
  margin-right: 0.6em;
  font-family: var(--font-mono);
  color: var(--accent-2);
}

.choice-btn.is-correct {
  background: rgba(55,214,122,0.18);
  border-color: var(--good);
}

.choice-btn.is-mine-wrong {
  background: rgba(255,77,109,0.18);
  border-color: var(--bad);
}

.status-note {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.95rem;
  text-align: center;
}

.status-note.locked {
  color: var(--good);
}

.big-wait {
  font-size: 1.4rem;
  font-weight: 800;
  text-align: center;
  line-height: 1.4;
}

textarea.field-input {
  resize: none;
  min-height: 5.5em;
  font-size: 1.05rem;
}

.char-count {
  text-align: right;
  color: var(--muted);
  font-size: 0.75rem;
}

.twist-ready-badge {
  font-family: var(--font-display);
  font-size: clamp(1.6rem, 8vw, 2.6rem);
  text-align: center;
  color: var(--accent-2);
}

.twist-go-btn {
  display: block;
  width: 100%;
  min-height: 220px;
  border-radius: var(--radius-lg);
  background: var(--accent);
  color: #1a0800;
  font-family: var(--font-display);
  font-size: clamp(1.6rem, 8vw, 2.8rem);
  border: none;
  animation: pulse-go 0.7s ease-in-out infinite alternate;
}

@keyframes pulse-go {
  from { transform: scale(1); }
  to { transform: scale(1.03); }
}

@media (prefers-reduced-motion: reduce) {
  .twist-go-btn { animation: none; }
}

.twist-go-btn:disabled {
  opacity: 0.5;
  animation: none;
}

.fastest-callout {
  font-family: var(--font-display);
  font-size: clamp(1.3rem, 6vw, 2rem);
  color: var(--accent-2);
  text-align: center;
}

.my-time {
  font-family: var(--font-mono);
  color: var(--muted);
  text-align: center;
}

/* Player: fact/blank display */
.fact-text {
  font-size: 1.2rem;
  font-weight: 700;
  line-height: 1.45;
}

/* Loading spinner-ish, minimal */
.loading-note {
  text-align: center;
  color: var(--muted);
  padding: 3rem 1rem;
}

.footnote {
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  padding: 0.5rem 1rem 1rem;
}

@media (min-width: 700px) {
  .player-view {
    max-width: 480px;
    margin: 0 auto;
    box-shadow: 0 0 0 1px rgba(255,255,255,0.05);
    min-height: 100vh;
  }
}
