/* ------------------------------------------------------------------ tokens
   Colors meet WCAG 2.1 AA on the surfaces they're used on:
   - --fg on any surface          ~15:1
   - --fg-dim on card/raised      ~6:1
   - white on --accent-strong     ~5.1:1 (buttons)
   - --accent-text on bg/card     ~5.1:1 (accent-colored text)
   Touch targets follow Apple HIG: 44px minimum with 8px spacing. */
:root {
  --bg: #0e0b16;
  --bg-card: #1a1426;
  --bg-raised: #251c36;
  --fg: #f2eefb;
  --fg-dim: #a596c4;
  --accent: #e4405f;          /* decorative: borders, slider tracks */
  --accent-strong: #d12950;   /* button fills (AA with white text) */
  --accent-strong-2: #a01f3e; /* gradient end */
  --accent-text: #f0566f;     /* accent-colored text on dark surfaces */
  --warn: #f7b32b;
  --green: #3ddc84;
  --red: #ff5470;
  --radius: 14px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  --touch: 44px;              /* HIG minimum touch target */
  --gap-touch: 8px;           /* HIG minimum spacing between targets */
  --space-1: 6px;
  --space-2: 10px;
  --space-3: 16px;
  --space-4: 24px;
}

* { box-sizing: border-box; }

/* Browser chrome + overscroll areas pick up these instead of white. */
html {
  background-color: var(--bg);
  color-scheme: dark;
}

body {
  margin: 0;
  background: radial-gradient(1200px 800px at 80% -10%, #2a1b46 0%, var(--bg) 55%);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  min-height: 100vh;
}

#app { max-width: 640px; margin: 0 auto; padding: var(--space-3) var(--space-3) 140px; }
#players { position: fixed; bottom: 0; right: 0; width: 1px; height: 1px; overflow: hidden; opacity: 0.01; }

h1, h2, h3 { margin: 0.2em 0; }

/* ------------------------------------------------------------- components */

.brand { display: flex; align-items: center; gap: var(--space-2); padding: 8px 0 4px; }
.brand .dial { font-size: 30px; }
.brand h1 { font-size: 24px; letter-spacing: 0.5px; }
.brand h1 a { color: var(--fg); text-decoration: none; }
.brand .live { color: var(--accent-text); }
.tagline { color: var(--fg-dim); margin: 0 0 var(--space-4); }

.card {
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius);
  padding: var(--space-3);
  margin: var(--space-3) 0;
  box-shadow: var(--shadow);
}

input[type='text'] {
  width: 100%;
  min-height: var(--touch);
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: var(--bg-raised);
  color: var(--fg);
  font-size: 16px; /* prevents iOS zoom-on-focus */
  margin: var(--space-1) 0 var(--space-2);
}
input.code-input { text-transform: uppercase; letter-spacing: 4px; font-weight: 700; text-align: center; }

button {
  border: 0;
  border-radius: 10px;
  min-height: var(--touch);
  min-width: var(--touch);
  padding: 10px 18px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  background: var(--bg-raised);
  color: var(--fg);
  transition: transform 0.08s ease, filter 0.15s ease;
  touch-action: manipulation; /* no double-tap zoom on controls */
}
button:hover { filter: brightness(1.15); }
button:active { transform: scale(0.97); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.primary { background: linear-gradient(135deg, var(--accent-strong), var(--accent-strong-2)); color: #fff; }
button.ghost { background: transparent; border: 1px solid rgba(255, 255, 255, 0.25); }
button.wide { width: 100%; }
button.compact { padding: 10px 14px; font-size: 13px; }

/* Visible focus for keyboard users (WCAG 2.4.7) without mouse noise. */
:focus { outline: none; }
:focus-visible { outline: 3px solid var(--warn); outline-offset: 2px; }
input[type='text']:focus-visible { outline: 3px solid var(--accent); outline-offset: 0; }

.row { display: flex; gap: var(--space-2); align-items: center; }
.row.between { justify-content: space-between; }
.muted { color: var(--fg-dim); font-size: 13px; }
.error-text { color: var(--red); font-size: 14px; min-height: 18px; margin: 4px 0; }

.pills { display: flex; flex-wrap: wrap; gap: var(--gap-touch); margin-top: var(--space-1); }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg-raised); border-radius: 999px;
  padding: 6px 12px; font-size: 12px; color: var(--fg-dim);
}
.pill.warn { color: var(--warn); }

/* track rows */
.track { display: flex; gap: var(--space-2); align-items: center; padding: var(--space-2) 0; border-bottom: 1px solid rgba(255,255,255,0.06); }
.track:last-child { border-bottom: 0; }
.track img, .track .art-fallback {
  width: 48px; height: 48px; border-radius: 8px; object-fit: cover; flex-shrink: 0;
  background: var(--bg-raised); display: flex; align-items: center; justify-content: center; font-size: 22px;
}
.track .info { flex: 1; min-width: 0; }
.track .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.track .sub { color: var(--fg-dim); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.track .byline { color: var(--fg-dim); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.track .provider-dot { font-size: 11px; margin-right: 4px; }

/* votes: stacked 44px targets, score between as natural spacing */
.votes { display: flex; flex-direction: column; align-items: center; flex-shrink: 0; }
.votes button {
  background: transparent; min-width: var(--touch); min-height: var(--touch);
  padding: 0; font-size: 18px; line-height: 1; color: var(--fg-dim);
}
.votes button.on-up { color: var(--green); }
.votes button.on-down { color: var(--red); }
.votes .score { font-weight: 700; font-size: 14px; min-width: 20px; text-align: center; }

.now-playing { border: 1px solid rgba(228, 64, 95, 0.4); background: linear-gradient(135deg, #241430, var(--bg-card)); }
.now-playing .eq { color: var(--accent-text); letter-spacing: 2px; font-size: 12px; font-weight: 700; }

/* song progress */
.progress-row { display: flex; align-items: center; gap: var(--space-2); margin-top: var(--space-2); }
.progress-row input[type='range'] { flex: 1; }
.progress-row .time {
  font-size: 12px; color: var(--fg-dim);
  font-variant-numeric: tabular-nums; min-width: 38px; text-align: center;
}
.progress-row.readonly input[type='range'] { accent-color: #8d84a3; pointer-events: none; }

/* range inputs: slim track, HIG-sized hit area and thumb */
input[type='range'] {
  accent-color: var(--accent);
  height: var(--touch);
  margin: 0;
  background: transparent;
  touch-action: manipulation;
}
input[type='range']::-webkit-slider-thumb { width: 24px; height: 24px; }

/* host bar */
.host-bar {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: rgba(16, 12, 26, 0.92); backdrop-filter: blur(12px);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding: var(--space-2) var(--space-3) calc(var(--space-2) + env(safe-area-inset-bottom));
}
.host-bar .inner { max-width: 640px; margin: 0 auto; display: flex; gap: var(--gap-touch); align-items: center; }
.host-bar input[type='range'] { flex: 1; min-width: 70px; }
.host-bar button.icon { font-size: 18px; line-height: 1; padding: 0 14px; }
.host-bar #host-play { font-size: 22px; padding: 0 18px; }

/* modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6);
  display: flex; align-items: flex-end; justify-content: center; z-index: 50;
}
.modal {
  background: var(--bg-card); border-radius: var(--radius) var(--radius) 0 0;
  width: 100%; max-width: 640px; max-height: 88dvh; overflow-y: auto; padding: var(--space-3);
  padding-bottom: calc(var(--space-3) + env(safe-area-inset-bottom));
}

.tabs { display: flex; gap: var(--gap-touch); margin: var(--space-2) 0; }
.tabs button { flex: 1; padding: 10px 6px; font-size: 13px; }
.tabs button.active { background: var(--accent-strong); color: #fff; }

.search-result { cursor: pointer; border-radius: 8px; padding: var(--space-1) var(--space-2); min-height: var(--touch); }
.search-result:hover { background: var(--bg-raised); }

.qr-wrap { display: flex; flex-direction: column; align-items: center; gap: var(--space-2); padding: var(--space-2) 0; }
.qr-wrap .qr-img { background: #fff; padding: 14px; border-radius: 12px; line-height: 0; }
.qr-wrap .code-big { font-size: 34px; font-weight: 800; letter-spacing: 8px; }

/* toasts share the card language: same surface, border, radius, shadow */
.toast {
  position: fixed; top: var(--space-3); left: 50%; transform: translateX(-50%);
  background: var(--bg-card); color: var(--fg);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-left: 3px solid var(--accent);
  padding: 14px 18px; border-radius: var(--radius); box-shadow: var(--shadow);
  z-index: 100; font-size: 14px; line-height: 1.4;
  max-width: min(90vw, 480px);
  animation: toast-in 0.2s ease-out;
}
.toast.error { border-left-color: var(--red); }
.toast.success { border-left-color: var(--green); }
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, -8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

.spin { display: inline-block; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.empty { text-align: center; color: var(--fg-dim); padding: var(--space-4) 0; }
.divider { border: 0; border-top: 1px solid rgba(255,255,255,0.08); margin: var(--space-3) 0; }

.landing-grid { display: grid; grid-template-columns: 1fr; gap: 0; }

/* -------------------------------------------------------------- breakpoints
   <=400px  compact phones: tighter chrome, smaller display text
   <=700px  phones: sheet-style modals (default styles above)
   >700px   tablets+: centered modals, side-by-side landing cards
   >=1024px desktop: wider column */

@media (max-width: 400px) {
  #app { padding: var(--space-2) var(--space-2) 140px; }
  .brand .dial { font-size: 24px; }
  .brand h1 { font-size: 20px; }
  .qr-wrap .code-big { font-size: 28px; letter-spacing: 6px; }
  .host-bar button.icon { padding: 0 10px; }
  .host-bar #host-play { padding: 0 14px; }
}

@media (min-width: 700px) {
  .modal-backdrop { align-items: center; }
  .modal { border-radius: var(--radius); max-height: 85vh; }
  .landing-grid { grid-template-columns: 1fr 1fr; gap: var(--space-3); }
  .landing-grid .card { margin: var(--space-3) 0; }
}

@media (min-width: 1024px) {
  #app { max-width: 720px; }
  .host-bar .inner { max-width: 720px; }
  .modal { max-width: 680px; }
}

/* Respect motion sensitivity (WCAG 2.3.3). */
@media (prefers-reduced-motion: reduce) {
  .spin { animation: none; }
  .toast { animation: none; }
  button { transition: none; }
  button:active { transform: none; }
}
