/* TimeTracks — clean, crisp dark theme.
   Design tokens first; flat surfaces, one accent, generous touch targets. */

:root {
  --bg: #0e1014;
  --surface: #171a21;
  --surface-2: #1f242e;
  --surface-3: #272d3a;
  --border: #272d39;
  --border-strong: #39414f;
  --text: #f2f4f8;
  --text-2: #a3adbd;
  --text-3: #717c8e;
  --accent: #ffcf5c;
  --on-accent: #181102;
  --good: #4ade80;
  --bad: #ff7b72;
  --focus: #8ab4f8;
  --radius: 12px;
  --radius-lg: 16px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, Roboto, "Segoe UI", sans-serif;
  line-height: 1.4;
}

#app {
  max-width: 560px;
  margin: 0 auto;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
}

button { font: inherit; color: inherit; }

/* Visible keyboard focus everywhere; never rely on colour alone. */
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

h1 {
  font-size: 1.7rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  text-align: center;
}

.tagline { text-align: center; color: var(--text-2); margin: 4px 0 16px; font-size: 0.92rem; }

.hidden { display: none !important; }

/* --- Setup panel ----------------------------------------------------------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

label {
  font-weight: 600;
  font-size: 0.95rem;
  margin-top: 10px;
  letter-spacing: -0.01em;
}

.val { color: var(--accent); font-weight: 700; font-variant-numeric: tabular-nums; }

.hint { color: var(--text-2); font-size: 0.84rem; min-height: 1.2em; }

input[type="range"] { width: 100%; accent-color: var(--accent); min-height: 28px; }

input[type="text"] {
  width: 100%;
  padding: 11px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

input[type="text"]:focus-visible { outline-offset: 0; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
  min-height: 40px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: transparent;
  color: var(--text-2);
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.chip:hover { border-color: var(--text-3); color: var(--text); }

.chip.on {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
}

.chip-count {
  margin-left: 6px;
  font-size: 0.78em;
  opacity: 0.7;
  font-variant-numeric: tabular-nums;
}

.chip:disabled { opacity: 0.35; cursor: default; }
.chip:disabled:hover { border-color: var(--border-strong); color: var(--text-2); }

.add-chip { align-self: flex-start; }

/* Player rows */
.p-row { display: flex; gap: 8px; margin-bottom: 6px; }

.p-name { flex: 1; }

.p-del {
  width: 44px;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: transparent;
  color: var(--bad);
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  padding: 0;
}

.p-del:disabled { opacity: 0.3; cursor: default; }

/* Year range: single track, two thumbs, stepper buttons either end */
.yr-row { display: flex; align-items: center; gap: 8px; padding: 16px 0 6px; }

.yr-steppers { display: flex; flex-direction: column; gap: 4px; }

.step {
  min-width: 40px;
  min-height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: transparent;
  color: var(--text);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  padding: 0 8px;
}

.step:hover { background: var(--surface-2); }

.step.wide { min-width: 56px; min-height: 44px; }

.yr-track {
  position: relative;
  flex: 1;
  height: 8px;
  border-radius: 4px;
  background: var(--surface-3);
  touch-action: none;
}

.yr-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  background: var(--accent);
  border-radius: 4px;
}

.yr-thumb {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  min-width: 50px;
  height: 32px;
  border-radius: 999px;
  border: none;
  background: var(--text);
  color: var(--bg);
  font-weight: 700;
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
  cursor: grab;
  touch-action: none;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  padding: 0 8px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.45);
}

/* --- Buttons ----------------------------------------------------------------- */

.big-btn {
  min-height: 50px;
  padding: 13px 28px;
  font-size: 1.02rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: var(--on-accent);
  cursor: pointer;
  transition: transform 0.1s, opacity 0.15s;
}

.big-btn:hover { opacity: 0.92; }
.big-btn:active { transform: scale(0.98); }
.big-btn:disabled { opacity: 0.4; cursor: default; transform: none; }

.big-btn.alt {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border-strong);
}

.text-btn {
  background: none;
  border: none;
  color: var(--text-2);
  cursor: pointer;
  font-size: 0.85rem;
  min-height: 32px;
}

.text-btn:hover { color: var(--text); text-decoration: underline; }

.pool {
  color: var(--text-2);
  font-size: 0.88rem;
  text-align: center;
  margin-top: 6px;
  font-variant-numeric: tabular-nums;
}

/* --- Game: fits the viewport, only the timeline scrolls ----------------------- */

#game {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 26px - env(safe-area-inset-bottom));
  height: calc(100dvh - 26px - env(safe-area-inset-bottom));
  min-height: 430px;
}

.game-head { display: flex; justify-content: center; gap: 8px; align-items: center; flex: 0 0 auto; }

.head-btn {
  min-height: 38px;
  padding: 6px 16px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: transparent;
  color: var(--text-2);
  font-size: 0.86rem;
  font-weight: 500;
  cursor: pointer;
}

.head-btn:hover { color: var(--text); background: var(--surface-2); }

.scores {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 4px 14px;
  margin-top: 6px;
  font-size: 0.88rem;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
  flex: 0 0 auto;
}

.scores .active { color: var(--accent); font-weight: 600; }

.turn {
  text-align: center;
  font-weight: 600;
  font-size: 1rem;
  margin: 6px 0 2px;
  color: var(--text);
  min-height: 1.3em;
  flex: 0 0 auto;
}

#hud-sticky { flex: 0 0 auto; padding: 6px 0 4px; }

.mystery-row { display: flex; gap: 14px; align-items: stretch; }

.mystery-side {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  justify-content: center;
}

.side-controls { display: flex; align-items: center; gap: 10px; }

.mystery-side .big-btn { width: 100%; padding: 11px 16px; font-size: 0.98rem; min-height: 46px; }

/* Flip card */
.card {
  perspective: 1000px;
  width: 140px;
  height: 140px;
  flex: 0 0 auto;
}

.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.6s;
}

.card.flipped .card-inner { transform: rotateY(180deg); }

.card-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 10px;
  overflow: hidden;
}

.card-front { background: var(--surface-2); border: 1px solid var(--border-strong); }

.card-back {
  background: var(--surface-2);
  border: 1px solid var(--accent);
  transform: rotateY(180deg);
  text-align: center;
}

.mystery { font-size: 3rem; font-weight: 700; color: var(--text-3); }

.play-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: var(--on-accent);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  padding: 0;
  transition: transform 0.1s, opacity 0.15s;
}

.play-btn:hover { opacity: 0.92; }
.play-btn:active { transform: scale(0.95); }
.play-btn:disabled { opacity: 0.4; transform: none; }

.play-btn svg, .tl-play svg { display: block; }

.progress-track {
  flex: 1;
  height: 5px;
  border-radius: 3px;
  background: var(--surface-3);
  overflow: hidden;
}

.progress { height: 100%; width: 0; background: var(--accent); transition: width 0.25s linear; }

.cover { width: 34px; height: 34px; border-radius: 8px; object-fit: cover; background: var(--bg); }

.reveal-year {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.reveal-title {
  font-weight: 600;
  font-size: 0.72rem;
  line-height: 1.25;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.reveal-artist {
  color: var(--text-2);
  font-size: 0.68rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.dz-link { color: var(--text-2); font-size: 0.7rem; }

/* Year guess panel */
.guess-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 6px auto 4px;
  max-width: 420px;
  width: 100%;
}

.guess-row { display: flex; align-items: center; justify-content: center; gap: 8px; }

.guess-year {
  min-width: 96px;
  text-align: center;
  font-size: 1.9rem;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

#guess-slider { width: 100%; accent-color: var(--accent); }

.verdict { text-align: center; font-weight: 600; min-height: 1.4em; flex: 0 0 auto; }
.verdict.good { color: var(--good); }
.verdict.bad { color: var(--bad); }

.status { text-align: center; color: var(--text-2); font-size: 0.9rem; min-height: 1.4em; margin: 2px 0; flex: 0 0 auto; }

/* --- Timeline: the one scrollable region while playing ------------------------ */

#timeline-wrap {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.tl-head { display: flex; align-items: center; gap: 10px; margin: 8px 0 4px; flex: 0 0 auto; }

.tl-titles { flex: 0 0 auto; display: flex; flex-direction: column; gap: 1px; }

.tl-head h3 { font-size: 0.95rem; font-weight: 600; color: var(--text-2); }

.tl-order { font-size: 0.7rem; color: var(--text-3); font-weight: 500; }

.tl-progress {
  position: relative;
  flex: 1;
  max-width: 200px;
  height: 6px;
  border-radius: 3px;
  background: var(--surface-3);
  overflow: hidden;
}

.tl-progress-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 0;
  border-radius: 3px;
  background: var(--good);
  transition: width 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.tl-progress-text {
  font-size: 0.82rem;
  color: var(--text-2);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.timeline {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  padding: 2px 2px 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.tl-empty { color: var(--text-3); font-size: 0.9rem; padding: 12px 4px; }

.tl-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  margin: 3px 0;
  flex: 0 0 auto;
}

/* While a timeline card plays as a reminder, its own background fills with the
   playback position — the bar by the mystery card stays the mystery song's.
   The fill is a scaleX() overlay (smooth sub-pixel sweep; a gradient stop
   snaps to whole pixels and judders on narrow elements). */
.tl-card { position: relative; overflow: hidden; }

.tl-card::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.07);
  transform: scaleX(var(--fill-frac, 0));
  transform-origin: left center;
  pointer-events: none;
}

.tl-card.playing:not(.mini) { border-color: var(--border-strong); }

/* Placement ribbon: the timeline collapses to wrapping year badges with slim
   "+" slots between them, so the whole timeline is visible at once — no
   scrolling to find the right gap, even with 20+ cards. */
.timeline.placing {
  flex-direction: row;
  flex-wrap: wrap;
  align-content: flex-start;
  align-items: center;
  gap: 6px;
  padding: 6px 2px 8px;
}

.tl-card.mini {
  min-width: 58px;
  height: 44px;
  padding: 0 8px;
  margin: 0;
  border: none;
  border-radius: 10px;
  font-weight: 700;
  font-size: 0.95rem;
  color: #14213d;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
}

/* Reminder playback sweeps a darkening overlay across the badge (the shared
   .tl-card::after scaleX fill, tinted darker so it reads on bright colours). */
.tl-card.mini::after { background: rgba(0, 0, 0, 0.32); }

/* Several songs share this year — tap the badge repeatedly to hear each. */
.mini-count {
  margin-left: 4px;
  font-size: 0.74em;
  font-weight: 600;
  opacity: 0.75;
}

.tl-card.mini.playing {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.timeline.placing .gap {
  width: 44px;
  min-height: 44px;
  margin: 0;
  flex: 0 0 auto;
  font-size: 1.15rem;
  font-weight: 500;
}

.timeline.placing .gap.wide { flex: 1 1 100%; font-size: 0.9rem; }

.tl-year {
  flex: 0 0 auto;
  min-width: 60px;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1rem;
  color: #14213d;
  border-radius: 9px;
  padding: 0 6px;
  font-variant-numeric: tabular-nums;
}

.tl-info { flex: 1; min-width: 0; }

.tl-title {
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tl-artist {
  font-size: 0.8rem;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tl-play {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.tl-play:hover { color: var(--text); background: var(--surface-2); }
.tl-play:disabled { opacity: 0.4; }

.gap {
  width: 100%;
  min-height: 44px;
  margin: 3px 0;
  border-radius: var(--radius);
  border: 1.5px dashed var(--border-strong);
  background: transparent;
  color: var(--text-2);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
}

.gap:hover, .gap:focus-visible {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(255, 207, 92, 0.08);
}

.gap.drop-hover {
  border-color: var(--good);
  color: var(--good);
  background: rgba(74, 222, 128, 0.1);
}

/* Drag and drop */
.drag-ghost {
  position: fixed;
  z-index: 50;
  transform: translate(-50%, -50%);
  width: 56px;
  height: 56px;
  border-radius: var(--radius);
  background: var(--surface-3);
  border: 1.5px solid var(--accent);
  color: var(--accent);
  font-size: 1.8rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.card.dragging .card-front { opacity: 0.6; }

/* --- History ------------------------------------------------------------------ */

.history { margin-top: 8px; flex: 0 0 auto; }

.history summary {
  cursor: pointer;
  color: var(--text-2);
  font-weight: 600;
  font-size: 0.9rem;
  min-height: 32px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.history ul {
  list-style: none;
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 30vh;
  overflow-y: auto;
}

.history li { font-size: 0.86rem; color: var(--text-2); }

.h-year { color: var(--accent); font-weight: 600; font-variant-numeric: tabular-nums; }
.h-title { font-weight: 600; color: var(--text); }
.h-player { color: var(--text-3); }

/* --- Overlays ------------------------------------------------------------------ */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: rgba(10, 12, 16, 0.94);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 24px;
  text-align: center;
}

.overlay.hidden { display: none; }

.overlay-actions { display: flex; flex-direction: column; gap: 12px; align-items: center; }

.standings-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 1.1rem;
}

.standings-list .rank {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.8em;
  height: 1.8em;
  margin-right: 8px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 0.8em;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.standings-list .winner { color: var(--accent); font-weight: 700; font-size: 1.25rem; }
.standings-list .winner .rank { background: var(--accent); color: var(--on-accent); }

.standings-list .best-row { color: var(--good); font-size: 0.95rem; margin-top: 6px; }

.confirm-msg { font-size: 1.1rem; font-weight: 600; max-width: 320px; }

/* --- Feedback ------------------------------------------------------------------- */

.tl-card.just-won {
  border-color: var(--good);
  animation: card-pop 0.7s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 0 14px rgba(74, 222, 128, 0.45);
}

@keyframes card-pop {
  0% { transform: scale(0.3); }
  60% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

.verdict.good, .verdict.bad { animation: verdict-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1); }

@keyframes verdict-pop {
  0% { transform: scale(0.5); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.card.shake-wrong { animation: card-shake 0.5s; }

@keyframes card-shake {
  15% { transform: translateX(-10px); }
  30% { transform: translateX(9px); }
  45% { transform: translateX(-7px); }
  60% { transform: translateX(5px); }
  75% { transform: translateX(-3px); }
}

.confetti-canvas {
  position: fixed;
  inset: 0;
  z-index: 20;
  pointer-events: none;
}

/* --- Small phones: tighter HUD so card + controls + timeline all fit ------------- */

@media (max-width: 400px) {
  .card { width: 116px; height: 116px; }
  .mystery { font-size: 2.4rem; }
  .mystery-row { gap: 10px; }
  .guess-year { font-size: 1.6rem; min-width: 80px; }
  h1 { font-size: 1.45rem; }
}

@media (max-height: 700px) {
  .turn { margin: 2px 0; }
  .scores { margin-top: 2px; }
  .card { width: 112px; height: 112px; }
  .mystery { font-size: 2.4rem; }
}

/* Respect users who turn animation off. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
