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

:root {
  --bg: #0d0d0d;
  --surface: #1c1c1c;
  --border: #2a2a2a;
  --accent: #e63946;
  --text: #f0ece3;
  --text-dim: #666;
  --success: #2ecc71;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: 0 20px;
}

/* ── Screens ──────────────────────────────────────────────────────────────── */

.screen {
  display: flex;
  flex-direction: column;
  flex: 1;
}

/* ── Home ─────────────────────────────────────────────────────────────────── */

.home {
  padding: 0 0 32px;
  justify-content: space-between;
  overflow: hidden;
}

.home::before {
  content: '';
  position: fixed;
  inset: 0;
  background: url('images/1.webp') center 15% / cover no-repeat;
  opacity: 0.11;
  pointer-events: none;
  z-index: 0;
}

.home-top {
  position: relative;
  z-index: 1;
  padding-top: 48px;
  min-height: 210px;
  display: flex;
  align-items: flex-end;
}

.chains-deco {
  position: absolute;
  right: -24px;
  bottom: -12px;
  height: 200px;
  mix-blend-mode: screen;
  opacity: 0.22;
  pointer-events: none;
  user-select: none;
}

.home-bottom {
  position: relative;
  z-index: 1;
  padding-top: 24px;
  display: flex;
  flex-direction: column;
}

.home-divider {
  width: 36px;
  height: 3px;
  background: var(--accent);
  margin-bottom: 24px;
}

.title {
  font-family: 'Bebas Neue', sans-serif;
  font-size: clamp(4rem, 20vw, 5.5rem);
  font-weight: 400;
  line-height: 0.88;
  letter-spacing: 0.03em;
  color: var(--text);
}

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

.mode-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.mode-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.radio-btn {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.radio-btn.active {
  border-color: var(--accent);
  background: rgba(230, 57, 70, 0.08);
}

.dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--text-dim);
  flex-shrink: 0;
  position: relative;
  transition: border-color 0.15s, background 0.15s;
}

.radio-btn.active .dot {
  border-color: var(--accent);
  background: var(--accent);
}

.score {
  font-size: 0.9rem;
  color: var(--text-dim);
  text-align: center;
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */

.btn-primary {
  width: 100%;
  padding: 18px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: opacity 0.12s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.btn-primary:active {
  opacity: 0.82;
  transform: scale(0.97);
}

.btn-secondary {
  width: 100%;
  padding: 15px;
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 0.95rem;
  cursor: pointer;
  margin-top: 10px;
  -webkit-tap-highlight-color: transparent;
}

.btn-secondary:active { opacity: 0.6; }

.btn-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.1rem;
  cursor: pointer;
  align-self: flex-end;
  padding: 8px;
  line-height: 1;
}

/* ── Playing ──────────────────────────────────────────────────────────────── */

.playing {
  padding: 24px 0 32px;
  align-items: center;
  justify-content: space-between;
}

.waveform {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 80px;
}

.waveform span {
  display: block;
  width: 7px;
  background: var(--accent);
  border-radius: 4px;
  animation: wave 0.9s ease-in-out infinite;
}

.waveform span:nth-child(1) { animation-delay: 0.00s; }
.waveform span:nth-child(2) { animation-delay: 0.18s; }
.waveform span:nth-child(3) { animation-delay: 0.36s; }
.waveform span:nth-child(4) { animation-delay: 0.18s; }
.waveform span:nth-child(5) { animation-delay: 0.00s; }

@keyframes wave {
  0%, 100% { height: 16px; }
  50%       { height: 64px; }
}

.timer {
  font-size: clamp(3.5rem, 15vw, 5rem);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  line-height: 1;
}

.audio-warn {
  font-size: 0.82rem;
  color: var(--accent);
  text-align: center;
}

/* ── Guessing ─────────────────────────────────────────────────────────────── */

.guessing {
  padding-top: 28px;
  overflow: hidden;
}

.guess-header {
  margin-bottom: 16px;
  flex-shrink: 0;
}

.guess-q {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.guess-time {
  font-size: 0.88rem;
  color: var(--text-dim);
}

.search {
  width: 100%;
  padding: 13px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 1rem;
  margin-bottom: 10px;
  outline: none;
  flex-shrink: 0;
  -webkit-appearance: none;
}

.search:focus {
  border-color: var(--accent);
}

.song-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -20px;
  padding: 0 20px;
}

.song-item {
  display: block;
  width: 100%;
  padding: 17px 0;
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-size: 1rem;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.1s;
}

.song-item:active,
.song-item.selected {
  color: var(--accent);
  background: rgba(230, 57, 70, 0.06);
}

/* ── Result ───────────────────────────────────────────────────────────────── */

.result {
  padding: 48px 0 32px;
  align-items: center;
  justify-content: center;
  gap: 14px;
  text-align: center;
}

.result-icon {
  font-size: 5rem;
  line-height: 1;
  font-style: normal;
}

.result-icon.ok   { color: var(--success); }
.result-icon.fail { color: var(--accent); }

.result-msg {
  font-size: 1.6rem;
  font-weight: 800;
}

.result-song, .wrong-answer {
  font-size: 1rem;
  color: var(--text-dim);
}

.result-time {
  font-size: clamp(2.8rem, 12vw, 4rem);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.result .btn-primary {
  margin-top: 16px;
}

.session-score {
  font-size: 0.9rem;
  color: var(--text-dim);
}

.btn-abandon {
  font-size: 0.85rem;
  padding: 10px;
  margin-top: 0;
}

/* ── Top bar ──────────────────────────────────────────────────────────────── */

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  flex-shrink: 0;
}

.round-counter {
  font-size: 0.85rem;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

/* ── Home: nombre ─────────────────────────────────────────────────────────── */

.name-group {
  margin-bottom: 28px;
}

.name-input {
  width: 100%;
  padding: 15px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 1rem;
  outline: none;
  -webkit-appearance: none;
}

.name-input:focus { border-color: var(--accent); }

.field-error {
  font-size: 0.8rem;
  color: var(--accent);
  margin-top: 6px;
}

/* ── Final ────────────────────────────────────────────────────────────────── */

.final {
  padding: 48px 0 32px;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
}

.final-name {
  font-size: 0.85rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.final-score {
  font-size: clamp(5rem, 22vw, 7rem);
  font-weight: 900;
  line-height: 1;
  color: var(--text);
}

.final-of {
  font-size: 0.45em;
  color: var(--text-dim);
}

.final-label {
  font-size: 0.9rem;
  color: var(--text-dim);
  margin-top: -6px;
}

.final-time {
  font-size: 1.3rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.final-pos {
  font-size: 1.1rem;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.final .btn-primary { margin-top: 16px; width: 100%; }
.final .btn-secondary { width: 100%; }

/* ── Ranking ──────────────────────────────────────────────────────────────── */

.ranking {
  padding-top: 0;
  overflow: hidden;
}

.ranking-title {
  font-size: 0.85rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: var(--text-dim);
}

.rank-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  margin: 8px -20px 0;
  padding: 0 20px;
}

.rank-row {
  display: grid;
  grid-template-columns: 2.4rem 1fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.rank-row.me {
  color: var(--accent);
}

.rank-pos {
  font-size: 0.95rem;
  text-align: center;
}

.rank-name {
  font-size: 1rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-pts {
  font-size: 0.95rem;
  font-weight: 700;
  white-space: nowrap;
}

.rank-time {
  font-size: 0.82rem;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.rank-row.me .rank-time { color: inherit; opacity: 0.75; }

.saving {
  align-items: center;
  justify-content: center;
}

.saving-msg {
  color: var(--text-dim);
  font-size: 1rem;
}

.empty-rank {
  padding: 32px 0;
  color: var(--text-dim);
  text-align: center;
  font-size: 0.9rem;
}
