* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #14121f;
  --bg-card: #1f1c2e;
  --bg-card-2: #282440;
  --fg: #f2eefb;
  --muted: #9d95b8;
  --accent: #ffb454;
  --accent-2: #7c5cff;
  --danger: #ff5470;
  --ok: #3ddc85;
  --radius: 14px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.screen {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 16px 48px;
  min-height: 100%;
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 0.9rem; }

/* ------------------------------------------------------------------ hero */
.hero { text-align: center; padding: 48px 0 24px; }
.hero h1 {
  font-size: 2rem;
  letter-spacing: 0.02em;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.tagline { color: var(--muted); margin-top: 4px; letter-spacing: 0.25em; text-transform: uppercase; font-size: 0.8rem; }

/* ------------------------------------------------------------------ cards */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
}
.card h2 { font-size: 1.2rem; margin-bottom: 6px; }
.card h3 { font-size: 1rem; margin-bottom: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.1em; }

.join-card { display: flex; flex-direction: column; gap: 8px; }
.join-card label { color: var(--muted); font-size: 0.85rem; margin-top: 6px; }

input[type="text"] {
  background: var(--bg-card-2);
  border: 2px solid transparent;
  border-radius: 10px;
  color: var(--fg);
  font-size: 1.3rem;
  padding: 12px 14px;
  outline: none;
  width: 100%;
}
input[type="text"]:focus { border-color: var(--accent-2); }
#inputCode { text-transform: uppercase; letter-spacing: 0.2em; font-weight: 700; text-align: center; }

/* ---------------------------------------------------------------- buttons */
.btn {
  appearance: none;
  border: none;
  border-radius: 12px;
  background: var(--bg-card-2);
  color: var(--fg);
  font-size: 1.05rem;
  font-weight: 600;
  padding: 14px 18px;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.05s ease, filter 0.15s ease;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn-primary { background: linear-gradient(90deg, var(--accent), #ff8c37); color: #201505; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; color: var(--muted); padding: 10px 6px; }
.btn.recording { animation: pulse 1s infinite; background: var(--danger); color: #fff; }
@keyframes pulse { 50% { filter: brightness(1.35); } }

/* ----------------------------------------------------------------- topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0 14px;
  gap: 8px;
}
.room-chip {
  background: var(--bg-card-2);
  border-radius: 8px;
  padding: 6px 12px;
  font-weight: 800;
  letter-spacing: 0.25em;
  color: var(--accent);
}
.you-chip { color: var(--muted); font-size: 0.9rem; max-width: 50%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ------------------------------------------------------------ player list */
.player-list { list-style: none; }
.player-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 2px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  font-size: 1.05rem;
}
.player-list li:last-child { border-bottom: none; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--ok); flex: none; }
.dot.off { background: var(--muted); }

/* -------------------------------------------------------------- line list */
.section-title { color: var(--muted); text-transform: uppercase; letter-spacing: 0.1em; font-size: 0.85rem; margin: 18px 4px 8px; }
.line-list { list-style: none; }
.line-list li {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.line-list li.mine { border-left: 4px solid var(--accent); cursor: pointer; }
.line-list li.mine:active { filter: brightness(1.2); }
.line-main { flex: 1; min-width: 0; }
.line-character { color: var(--accent-2); font-weight: 700; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.06em; }
.line-caption { font-size: 1.05rem; margin-top: 2px; overflow-wrap: anywhere; }
.badge {
  flex: none;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 4px 10px;
  background: var(--bg-card-2);
  color: var(--muted);
  white-space: nowrap;
}
.badge.done { background: rgba(61, 220, 133, 0.15); color: var(--ok); }
.badge.yours { background: rgba(255, 180, 84, 0.15); color: var(--accent); }
.badge.syncing { background: rgba(124, 92, 255, 0.15); color: var(--accent-2); }

.banner {
  background: rgba(61, 220, 133, 0.12);
  color: var(--ok);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
  font-weight: 700;
  margin-bottom: 14px;
}

/* ------------------------------------------------------------ record panel */
.record-panel { text-align: center; }
.record-panel .line-caption { font-size: 1.25rem; margin: 6px 0 10px; }
.rec-controls { display: flex; gap: 8px; justify-content: center; margin: 16px 0 10px; flex-wrap: wrap; }
.wave-canvas {
  width: 100%;
  height: 90px;
  border-radius: 10px;
  background: var(--bg-card-2);
  display: block;
  margin: 6px 0;
}
.rec-progress {
  position: relative;
  height: 10px;
  border-radius: 999px;
  background: var(--bg-card-2);
  overflow: visible;
  margin: 8px 0 4px;
}
.rec-progress-bar {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--ok), var(--accent));
  transition: width 0.1s linear;
}
.rec-progress-bar.over { background: var(--danger); }
.rec-target-mark {
  position: absolute;
  top: -4px;
  width: 3px;
  height: 18px;
  border-radius: 2px;
  background: var(--fg);
  opacity: 0.9;
}
.rec-time {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  font-size: 1.4rem;
}
.rec-time.over { color: var(--danger); }

.level-track, .timer-track {
  height: 10px;
  border-radius: 999px;
  background: var(--bg-card-2);
  overflow: hidden;
  margin: 10px 0;
}
.level-bar {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--ok), var(--accent));
  transition: width 0.08s linear;
}
.timer-bar {
  height: 100%;
  width: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
}
.timer-bar.low { background: var(--danger); }
.timer-text { font-variant-numeric: tabular-nums; font-weight: 800; font-size: 1.5rem; text-align: center; }
#btnSubmit { width: 100%; margin-top: 8px; }

/* ------------------------------------------------------------------ turns */
.turn-card { text-align: center; }
.turn-card h2 { font-size: 1.35rem; margin: 6px 0; }

/* ----------------------------------------------------------------- finale */
.finale { text-align: center; padding-top: 25vh; }
.finale h1 { font-size: 2rem; margin-bottom: 10px; }
.finale .btn { margin-top: 20px; }

.waiting-pulse { text-align: center; color: var(--muted); animation: fade 2s infinite; margin-top: 20px; }
@keyframes fade { 50% { opacity: 0.35; } }

.error { color: var(--danger); font-weight: 600; margin-top: 8px; text-align: center; }

/* ------------------------------------------------------------------ toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  background: #000c;
  color: #fff;
  border-radius: 999px;
  padding: 10px 20px;
  font-size: 0.95rem;
  z-index: 50;
  max-width: 90vw;
  text-align: center;
  backdrop-filter: blur(6px);
}
