/* Riffdle */

:root {
  --bg:      #ffffff;
  --surface: #f3f3f1;
  --line:    #e4e4e0;
  --text:    #141414;
  --muted:   #6e6e6a;
  --faint:   #a3a39e;

  --drums:  #e2482a;
  --bass:   #2f62d0;
  --melody: #d39a0b;
  --vocals: #2e8b57;
  --bad:    #d23b25;
  --good:   #2e8b57;

  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:      #121212;
    --surface: #1e1e1e;
    --line:    #2c2c2c;
    --text:    #f2f2f0;
    --muted:   #9c9c97;
    --faint:   #66665f;
  }
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { height: 100%; }
body {
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
:focus-visible { outline: 2px solid var(--bass); outline-offset: 2px; }

.hidden { display: none !important; }
.screen { display: none; }
.screen.active { display: block; }

.page, #screen-game {
  max-width: 560px;
  margin: 0 auto;
  padding: 2rem 1rem 3rem;
}

h2 {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 0.6rem;
}

/* ── Controls ─────────────────────────────────────────────────── */
button {
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--bg);
  background: var(--text);
  border: none;
  border-radius: var(--radius);
  padding: 0.7rem 1.1rem;
  cursor: pointer;
  transition: opacity 0.15s ease, background 0.15s ease;
}
button:hover:not(:disabled) { opacity: 0.85; }
button:disabled { opacity: 0.35; cursor: default; }

.btn-secondary { background: var(--surface); color: var(--text); }
.btn-secondary:hover:not(:disabled) { opacity: 1; background: var(--line); }

.btn-text {
  background: none;
  color: var(--muted);
  padding: 0.3rem 0;
  font-weight: 500;
}
.btn-text:hover:not(:disabled) { opacity: 1; color: var(--text); }

.btn-wide { width: 100%; }
.btn-icon { display: inline-flex; align-items: center; justify-content: center; gap: 0.45rem; }
.btn-ico { width: 16px; height: 16px; flex-shrink: 0; }

input[type="text"],
input[type="number"] {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.65rem 0.8rem;
  width: 100%;
  min-width: 0;
}
input::placeholder { color: var(--faint); }
input:focus { outline: none; border-color: var(--text); }

.error-msg { color: var(--bad); font-size: 0.9rem; margin-top: 0.6rem; }

.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.5rem; }
.chip {
  background: var(--surface);
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 500;
  padding: 0.35rem 0.8rem;
  border-radius: 999px;
}
.chip:hover:not(:disabled):not(.active) { opacity: 1; background: var(--line); }
.chip.active { background: var(--text); color: var(--bg); }

.field { margin-bottom: 1rem; }
.field label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 0.3rem; }
.field-row { display: flex; gap: 1rem; }
.field-row .field { flex: 1; }

.block { margin-top: 2rem; }

/* ── Landing ──────────────────────────────────────────────────── */
.masthead { margin-bottom: 1.5rem; }
.logo {
  font-size: 2.6rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1;
}
.intro { color: var(--muted); margin-top: 0.5rem; }
.whats-new { font-size: 0.8rem; color: var(--muted); margin-top: 0.6rem; }
.new-tag { font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--bg); background: var(--good); border-radius: 4px; padding: 0.1rem 0.35rem; margin-right: 0.3rem; vertical-align: 1px; }

.btn-daily {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.1rem;
  padding: 1.1rem;
  font-size: 1.15rem;
}
.btn-daily-sub { font-size: 0.85rem; font-weight: 400; opacity: 0.7; }
.btn-daily-sub:empty { display: none; }
.btn-daily.played { background: var(--surface); color: var(--text); }

.streak { text-align: center; font-size: 0.9rem; color: var(--muted); margin-top: 0.6rem; }
.streak #streak-count { color: var(--drums); font-weight: 700; }

.url-form { display: flex; gap: 0.5rem; }
.url-form input { flex: 1; }
.url-form button { flex-shrink: 0; }

.search-results {
  margin-top: 0.5rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.search-card {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 0.7rem;
  cursor: pointer;
  border-bottom: 1px solid var(--line);
}
.search-card:last-child { border-bottom: none; }
.search-card:hover { background: var(--surface); }
.search-thumb { width: 64px; height: 36px; object-fit: cover; border-radius: 4px; flex-shrink: 0; }
.search-meta { display: flex; flex-direction: column; min-width: 0; }
.search-title, .search-artist { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-title { font-weight: 600; font-size: 0.95rem; }
.search-artist { color: var(--muted); font-size: 0.85rem; }
.no-results { padding: 0.8rem; color: var(--muted); font-size: 0.9rem; }

.request-section { margin-top: 0.5rem; }
.request-toggle { background: none; color: var(--muted); padding: 0.2rem 0; font-weight: 400; font-size: 0.85rem; text-decoration: underline; text-underline-offset: 2px; }
.request-toggle:hover:not(:disabled) { opacity: 1; color: var(--text); }
.request-form { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.5rem; }
.request-form .contact-input { flex-basis: 100%; }
.contact-input { font-size: 0.85rem; }
.request-form input { flex: 1; }
.request-msg { font-size: 0.9rem; color: var(--good); margin-top: 0.5rem; }
.request-msg.error { color: var(--bad); }

.feedback-section { margin-top: 1.5rem; }
.feedback-email { font-size: 0.8rem; color: var(--faint); margin-top: 0.3rem; }
.feedback-email a, .site-about-body a { color: var(--muted); }
.feedback-form { display: flex; flex-direction: column; align-items: flex-start; gap: 0.5rem; margin-top: 0.5rem; }
.feedback-form textarea {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.65rem 0.8rem;
  width: 100%;
  resize: vertical;
}
.feedback-form textarea::placeholder { color: var(--faint); }
.feedback-form textarea:focus { outline: none; border-color: var(--text); }

#btn-random { margin-top: 0.4rem; }

.site-about { margin-top: 3rem; font-size: 0.9rem; color: var(--muted); }
.site-about summary { cursor: pointer; }
.site-about-body { margin-top: 0.8rem; }
.site-about-body h3 { font-size: 0.9rem; color: var(--text); margin: 1rem 0 0.2rem; }
.site-footer { margin-top: 2.5rem; padding-top: 1rem; border-top: 1px solid var(--line); font-size: 0.75rem; color: var(--faint); line-height: 1.5; }
.site-footer a { color: var(--muted); }

/* ── Page titles (multiplayer, lobby) ─────────────────────────── */
.page > .btn-text:first-child { margin-bottom: 1rem; }
.page-title { font-size: 1.7rem; font-weight: 800; letter-spacing: -0.02em; margin-bottom: 1.5rem; }
.mp-code-input { text-transform: uppercase; letter-spacing: 0.15em; font-weight: 600; }
.mp-len-input { max-width: 7rem; }
#btn-create-room { margin-top: 0.6rem; }

.lobby-code-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.lobby-code-label { display: block; font-size: 0.85rem; color: var(--muted); }
.lobby-code-value { font-size: 3rem; font-weight: 800; letter-spacing: 0.08em; line-height: 1.1; }
.lobby-players { list-style: none; }
.lobby-players li { padding: 0.45rem 0; border-bottom: 1px solid var(--line); }
.lobby-players li:last-child { border-bottom: none; }
.lobby-players:empty::before { content: "Waiting for players…"; color: var(--muted); }
.lobby-summary { list-style: none; }
.lobby-summary li { display: flex; justify-content: space-between; padding: 0.35rem 0; color: var(--muted); }
.lobby-summary strong { color: var(--text); }
.lobby-wait { color: var(--muted); text-align: center; margin-top: 1.5rem; }
#btn-start-game { margin-top: 2rem; }
.crown-ico { width: 13px; height: 13px; vertical-align: -1px; margin-right: 0.25rem; color: var(--melody); }

/* ── Loading ──────────────────────────────────────────────────── */
.loading-box { text-align: center; padding: 30vh 1rem 0; color: var(--muted); }
.spinner {
  width: 28px; height: 28px; margin: 0 auto 1rem;
  border: 3px solid var(--line);
  border-top-color: var(--text);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Game ─────────────────────────────────────────────────────── */
#screen-game { padding-top: 1rem; }
.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.2rem;
}
.logo-sm { font-weight: 800; font-size: 1.2rem; letter-spacing: -0.02em; cursor: pointer; }
#score-display { font-weight: 600; font-variant-numeric: tabular-nums; }
.challenge-note { font-size: 0.9rem; color: var(--muted); margin-bottom: 1rem; }

.stems-panel { margin-bottom: 1rem; }
.stem-card {
  --stem: var(--faint);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  height: 52px;
  padding: 0 0.85rem;
  margin-bottom: 0.4rem;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--faint);
  transition: color 0.3s ease;
}
#stem-drums  { --c: var(--drums); }
#stem-bass   { --c: var(--bass); }
#stem-melody { --c: var(--melody); }
#stem-vocals { --c: var(--vocals); }
.stem-card.unlocked { --stem: var(--c); color: var(--text); }
.stem-icon { width: 22px; height: 22px; flex-shrink: 0; }
.stem-icon svg { width: 100%; height: 100%; }
.stem-card.unlocked .stem-icon { color: var(--stem); }
.stem-label { width: 4.5rem; font-weight: 600; font-size: 0.95rem; }

.stem-lane { position: relative; flex: 1; min-width: 0; height: 22px; }
.stem-eq {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: space-between; gap: 2px;
  opacity: 0;
  transition: opacity 0.3s ease;
}
.stem-card.unlocked .stem-eq { opacity: 1; }
.stem-eq span {
  flex: 1 1 0;
  max-width: 3px;
  height: 100%;
  border-radius: 2px;
  background: var(--stem);
  transform: scaleY(0.15);
}
body:has(#btn-play-all.playing) .stem-card.unlocked .stem-eq span { animation: eq 0.8s ease-in-out infinite; }
body:has(#btn-play-all.playing) .stem-card.unlocked .stem-eq span:nth-child(4n+1) { animation-duration: 0.82s; }
body:has(#btn-play-all.playing) .stem-card.unlocked .stem-eq span:nth-child(4n+2) { animation-duration: 0.66s; animation-delay: 0.12s; }
body:has(#btn-play-all.playing) .stem-card.unlocked .stem-eq span:nth-child(4n+3) { animation-duration: 0.94s; animation-delay: 0.22s; }
body:has(#btn-play-all.playing) .stem-card.unlocked .stem-eq span:nth-child(4n+4) { animation-duration: 0.74s; animation-delay: 0.05s; }
@keyframes eq { 0%, 100% { transform: scaleY(0.15); } 50% { transform: scaleY(1); } }

.stem-state { position: relative; width: 18px; height: 18px; flex-shrink: 0; }
.stem-state svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.stem-live { display: none; color: var(--stem); }
.stem-card.unlocked .stem-lock { display: none; }
.stem-card.unlocked .stem-live { display: block; }

.master-player { display: flex; align-items: center; gap: 0.9rem; margin-bottom: 1rem; }
.btn-play-all {
  width: 48px; height: 48px;
  border-radius: 50%;
  padding: 0;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.btn-play-all svg { width: 20px; height: 20px; }
.btn-play-all .ico-pause { display: none; }
.btn-play-all.playing .ico-play { display: none; }
.btn-play-all.playing .ico-pause { display: block; }
.master-seek-wrap { flex: 1; min-width: 0; }

#seek-bar {
  --seek: 0%;
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 20px;
  background: transparent;
  cursor: pointer;
}
#seek-bar::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(to right, var(--text) var(--seek), var(--line) var(--seek));
}
#seek-bar::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  margin-top: -5px;
  border-radius: 50%;
  background: var(--text);
}
#seek-bar::-moz-range-track { height: 4px; border-radius: 2px; background: var(--line); }
#seek-bar::-moz-range-progress { height: 4px; border-radius: 2px; background: var(--text); }
#seek-bar::-moz-range-thumb { width: 14px; height: 14px; border: none; border-radius: 50%; background: var(--text); }
#seek-bar:disabled { opacity: 0.4; cursor: default; }
.time-row { display: flex; justify-content: space-between; font-size: 0.8rem; color: var(--muted); font-variant-numeric: tabular-nums; }

.reveal-row { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 1rem; }
.btn-hint { margin-left: auto; }
#btn-mp-skip { display: none; }
body.mp #btn-mp-skip { display: inline-block; }
#btn-mp-skip.voted { background: var(--text); color: var(--bg); }

.guess-form { display: flex; gap: 0.5rem; }
#guess-input { flex: 1; }
.btn-skip { background: var(--surface); color: var(--text); }
.btn-skip:hover:not(:disabled) { opacity: 1; background: var(--line); }

.hint-list:not(:empty) { margin-bottom: 0.75rem; }
.hint-box {
  display: flex; align-items: center; gap: 0.5rem;
  font-size: 0.9rem;
  padding: 0.5rem 0.75rem;
  margin-bottom: 0.35rem;
  border-radius: var(--radius);
  background: var(--surface);
}
.hint-ico { width: 15px; height: 15px; flex-shrink: 0; color: var(--muted); }
.hint-text { flex: 1; }
.hint-cost { color: var(--muted); }
.hint-free { color: var(--muted); }

.artist-bonus { display: flex; align-items: center; gap: 0.4rem; margin-top: 0.75rem; font-size: 0.9rem; color: var(--good); }
.artist-bonus svg { width: 15px; height: 15px; }

#guess-log { margin-top: 1rem; }
.guess-entry {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.95rem;
}
.guess-badge { width: 1.2em; text-align: center; font-weight: 700; }
.guess-entry.correct .guess-badge { color: var(--good); }
.guess-entry.artist  .guess-badge { color: var(--melody); }
.guess-entry.wrong   .guess-badge { color: var(--bad); }
.guess-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.guess-entry.wrong .guess-text { color: var(--muted); }
.guess-hint { font-size: 0.8rem; color: var(--muted); }
.guess-pts { font-weight: 600; color: var(--good); }

/* ── Multiplayer HUD ──────────────────────────────────────────── */
.mp-hud { display: none; }
body.mp .mp-hud { display: block; margin-bottom: 1rem; }
body.mp #challenge-note,
body.mp #btn-hint,
body.mp #hint-list { display: none; }
body.mp #btn-next-stem, body.mp #btn-skip { display: none !important; }

.btn-mp-abort { float: right; }
.mp-round-badge { font-size: 0.9rem; color: var(--muted); }
.mp-timer { font-size: 1.1rem; margin: 0.2rem 0 0.6rem; }
.mp-timer.last-call { color: var(--bad); font-weight: 700; }
.mp-skip-status { font-size: 0.85rem; color: var(--muted); margin-bottom: 0.6rem; }
.mp-hud-cols { display: flex; gap: 1.5rem; }
.mp-scoreboard, .mp-feed-wrap { flex: 1; min-width: 0; }
.mp-scoreboard ol { list-style: none; }
.mp-scoreboard li { display: flex; justify-content: space-between; gap: 0.5rem; padding: 0.2rem 0; font-size: 0.9rem; }
.mp-score-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mp-score-pts { font-weight: 600; font-variant-numeric: tabular-nums; }
.mp-hud .streak-badge, .leaderboard .streak-badge, .feed-streak { color: var(--drums); font-weight: 600; font-size: 0.85em; }
.mp-feed { max-height: 7.5rem; overflow-y: auto; font-size: 0.85rem; color: var(--muted); }
.mp-feed-wrap:has(.mp-feed:empty) { display: none; }
.mp-feed > div { padding: 0.15rem 0; }
.feed-you { color: var(--text); font-weight: 600; }

/* ── Results ──────────────────────────────────────────────────── */
.result-label { font-size: 0.9rem; font-weight: 500; color: var(--muted); margin-bottom: 0.3rem; }
.result-label:empty { display: none; }
.answer-title { font-size: 2rem; font-weight: 800; letter-spacing: -0.02em; line-height: 1.15; margin-top: 1rem; }
.answer-artist { font-size: 1.1rem; color: var(--muted); margin-top: 0.15rem; }
.result-listen { margin-top: 1rem; max-width: 560px; }
.yt-embed { aspect-ratio: 16 / 9; border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.yt-embed iframe { width: 100%; height: 100%; border: 0; display: block; }
.yt-link { display: inline-block; margin-top: 0.5rem; font-size: 0.85rem; color: var(--muted); }
.yt-link:hover { color: var(--text); }
.final-score { margin-top: 1.5rem; font-size: 1.05rem; color: var(--muted); }
.final-score strong { color: var(--text); font-size: 1.4rem; }

.daily-grid { font-size: 1.6rem; letter-spacing: 0.1em; margin-top: 1rem; }
.daily-grid-sub { font-size: 0.9rem; letter-spacing: 0; color: var(--muted); margin-top: 0.2rem; }
.result-stats { font-size: 0.9rem; color: var(--muted); margin-top: 0.75rem; }
.result-hints { font-size: 0.9rem; color: var(--muted); margin-top: 0.75rem; }
.rh-head { color: var(--text); }

.result-actions, .daily-result { margin-top: 2rem; display: flex; flex-direction: column; gap: 0.5rem; }
.daily-result { margin-top: 1rem; }
.daily-result .daily-grid { margin-top: 0; }
.daily-streak { font-size: 0.95rem; color: var(--muted); }
.daily-streak #streak-current-big { color: var(--drums); font-weight: 700; }
.daily-countdown { text-align: center; font-size: 0.9rem; color: var(--muted); margin-top: 0.5rem; }
#btn-daily-home { align-self: center; }

.leaderboard { margin-top: 2rem; }
.leaderboard ol { list-style: none; }
.leaderboard li {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--line);
}
.lb-rank { min-width: 1.6em; color: var(--muted); }
.lb-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-score { font-weight: 600; font-variant-numeric: tabular-nums; }
#mp-result-round { color: var(--muted); font-size: 0.9rem; }
#btn-mp-play-again { margin-top: 1.5rem; }
#btn-mp-leave-result { display: block; margin: 1rem auto 0; }

/* ── Toast + modal ────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: var(--text);
  color: var(--bg);
  font-size: 0.9rem;
  padding: 0.6rem 1rem;
  border-radius: var(--radius);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 200;
  max-width: min(90vw, 420px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 300;
  padding: 1rem;
}
.modal-card {
  background: var(--bg);
  border-radius: 14px;
  padding: 1.25rem;
  max-width: 340px;
  width: 100%;
}
#hint-confirm-text { margin-bottom: 1rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; }

/* ── Small screens ────────────────────────────────────────────── */
@media (max-width: 480px) {
  .logo { font-size: 2.2rem; }
  .stem-label { width: 4rem; }
  .mp-hud-cols { flex-direction: column; gap: 0.75rem; }
  .lobby-code-value { font-size: 2.4rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
