* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: linear-gradient(160deg, #0e0b1f 0%, #1a1340 55%, #2a1a5e 100%);
  background-attachment: fixed;
  color: #fff;
  min-height: 100vh;
}
.wrap { max-width: 480px; margin: 0 auto; padding: 24px 16px; }
.wrap.wide { max-width: 900px; }
h1 { font-size: 1.7rem; margin-bottom: 4px; }
h2 { font-size: 1.3rem; margin: 0 0 12px; }
h3 { font-size: 1.05rem; }
.sub { opacity: 0.75; font-size: 0.95rem; margin-bottom: 24px; }
.btn {
  display: block; width: 100%; padding: 14px; margin: 8px 0;
  background: #6ee7ff; color: #0e0b1f; border: none; border-radius: 12px;
  font-size: 1rem; font-weight: 700; cursor: pointer;
  box-shadow: 0 3px 0 rgba(0,0,0,0.25); transition: transform 0.08s;
}
.btn:active { transform: translateY(2px); box-shadow: none; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.secondary { background: transparent; border: 2px solid #6ee7ff; color: #6ee7ff; box-shadow: none; }
.btn.danger { background: #ff5b6e; color: #fff; }
.btn.small { width: auto; padding: 8px 14px; font-size: 0.85rem; display: inline-block; }
input[type=text], textarea, select {
  width: 100%; padding: 12px; border-radius: 10px; border: none;
  font-size: 1rem; margin: 6px 0 14px; font-family: inherit;
}
textarea { min-height: 90px; resize: vertical; line-height: 1.4; }
.panel { background: rgba(255,255,255,0.08); border-radius: 14px; padding: 16px; margin: 14px 0; backdrop-filter: blur(4px); }
.center { text-align: center; }
.status { font-size: 0.85rem; opacity: 0.75; margin-bottom: 10px; }
a.link { color: #6ee7ff; }
.qr-box { background: #fff; padding: 16px; border-radius: 12px; display: inline-block; margin: 12px 0; }

/* setup controls */
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.chip {
  padding: 8px 14px; border-radius: 999px; border: 2px solid rgba(255,255,255,0.3);
  background: transparent; color: #fff; font-size: 0.85rem; font-weight: 600; cursor: pointer;
}
.chip.on { background: #6ee7ff; border-color: #6ee7ff; color: #0e0b1f; }

/* countdown ring (big, host + player) */
.countdown {
  font-size: clamp(6rem, 22vw, 12rem); font-weight: 900; text-align: center;
  color: #6ee7ff; line-height: 1; margin: 24px 0 12px;
  text-shadow: 0 4px 30px rgba(110,231,255,0.4);
}
.countdown.go { color: #2ec27e; }

/* the typing passage display */
.passage {
  font-family: 'SF Mono', Menlo, Monaco, Consolas, monospace;
  font-size: clamp(1rem, 2.6vw, 1.3rem); line-height: 1.7;
  background: rgba(0,0,0,0.35); padding: 18px 20px; border-radius: 10px;
  white-space: pre-wrap; word-break: break-word; margin: 14px 0;
  letter-spacing: 0.01em;
}
.passage .ch { display: inline; }
.passage .ok { color: #2ec27e; }
.passage .bad { color: #ff5b6e; text-decoration: underline; }
.passage .cur { background: rgba(110,231,255,0.35); border-radius: 2px; }

/* player typing input */
#typingInput {
  font-family: 'SF Mono', Menlo, Monaco, Consolas, monospace;
  font-size: clamp(1rem, 2.6vw, 1.3rem); line-height: 1.7;
  background: rgba(0,0,0,0.35); padding: 18px 20px; border-radius: 10px;
  min-height: 1.7em; resize: none; color: #fff;
}
#typingInput:focus { outline: 2px solid #6ee7ff; }

/* live stats pill row */
.stat-row {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 8px; margin: 14px 0;
}
.stat-card {
  background: rgba(0,0,0,0.3); padding: 10px; border-radius: 10px; text-align: center;
}
.stat-card .lbl { font-size: 0.7rem; opacity: 0.7; text-transform: uppercase; letter-spacing: 0.05em; }
.stat-card .val { font-size: 1.4rem; font-weight: 800; color: #6ee7ff; }

/* timer */
.timer { font-size: 2.4rem; font-weight: 800; color: #6ee7ff; margin: 6px 0; }
.timer.urgent { color: #ff5b6e; animation: blink 0.6s infinite; }
@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }

/* player scoreboard */
.score-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.score-card {
  background: rgba(0,0,0,0.3); border-radius: 10px; padding: 10px; text-align: center;
  border: 2px solid transparent; transition: border-color 0.2s, background 0.2s;
}
.score-card .name { font-weight: 700; font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.score-card .wpm { font-size: 1.3rem; font-weight: 800; color: #6ee7ff; }
.score-card .acc { font-size: 0.75rem; opacity: 0.7; margin-top: 2px; }
.score-card.typing { border-color: #6ee7ff; background: rgba(110,231,255,0.1); }
.score-card.done { border-color: #2ec27e; }

/* podium */
.podium { font-size: 1.15rem; line-height: 2; text-align: center; }
.podium .rank { font-weight: 700; }
.podium .stat { font-size: 0.9rem; opacity: 0.8; }
.podium .p1 { font-size: 1.4rem; color: #ffd93d; }
.podium .p2 { font-size: 1.2rem; color: #d0d0d0; }
.podium .p3 { font-size: 1.1rem; color: #cd7f32; }

/* leaderboard / table view */
.leaderboard { width: 100%; border-collapse: collapse; margin: 14px 0; }
.leaderboard th, .leaderboard td {
  padding: 8px 6px; text-align: right; font-size: 0.95rem;
}
.leaderboard th { opacity: 0.7; font-weight: 600; border-bottom: 1px solid rgba(255,255,255,0.2); }
.leaderboard td.name-cell { text-align: left; font-weight: 700; }
.leaderboard tr.me td { background: rgba(110,231,255,0.15); }
.leaderboard tr.p1 td.name-cell::before { content: "🏆 "; }
.leaderboard tr.p2 td.name-cell::before { content: "🥈 "; }
.leaderboard tr.p3 td.name-cell::before { content: "🥉 "; }

/* host current text preview during race */
.live-stats {
  display: flex; gap: 16px; flex-wrap: wrap; justify-content: center;
  font-size: 0.9rem; opacity: 0.85; margin: 8px 0;
}
.live-stats span strong { color: #6ee7ff; }

/* status bar at top of player typing screen */
.pillbar { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin: 10px 0; }
.pill {
  padding: 6px 12px; border-radius: 999px; background: rgba(110,231,255,0.15);
  border: 1px solid rgba(110,231,255,0.4); font-size: 0.85rem; font-weight: 700;
}
.pill .v { color: #6ee7ff; margin-left: 4px; }

/* misc */
.action-row { display: flex; gap: 8px; align-items: center; margin: 8px 0; }
.action-row input { flex: 1; margin: 0; }
.log { font-size: 0.8rem; opacity: 0.7; max-height: 80px; overflow-y: auto; }