/* Streamy — widget styles.
   Self-contained: no external fonts, images, or CDNs (CSP-safe).
   Dark by default, light-scheme aware. */

:root {
  --bg: #0f1115;
  --bg-elev: #151922;
  --bg-hover: #1a1f2a;
  --border: #232a37;
  --text: #e9ecf2;
  --text-dim: #8b93a4;
  --accent: #e8a44d;
  --accent-strong: #f6bd6a;
  --accent-ink: #1c1408;
  --wave-base: #3a4252;
  --playhead: #ffd58f;
  --error: #ef5f66;
  --radius: 10px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f5f8;
    --bg-elev: #ffffff;
    --bg-hover: #e9ecf2;
    --border: #d9dee7;
    --text: #191d25;
    --text-dim: #5f6878;
    --accent: #b97a17;
    --accent-strong: #935f0b;
    --accent-ink: #ffffff;
    --wave-base: #c4cbd8;
    --playhead: #7a4f06;
    --error: #c3343b;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.app { height: 100%; display: flex; flex-direction: column; }

/* ---------------------------------------------------------------- header */

.head {
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.select-wrap { position: relative; }

/* Single-reel embed (?playlist=…): hide the switcher, show a static title. */
.pl-title {
  margin: 0 2px;
  font-size: 15px;
  font-weight: 650;
  letter-spacing: .01em;
  line-height: 1.35;
}
body.single .select-wrap { display: none; }

/* Forced color scheme via ?theme=light|dark (overrides prefers-color-scheme
   so an embed matches its host page regardless of the viewer's OS setting). */
:root[data-theme="light"] {
  --bg: #f4f5f8; --bg-elev: #ffffff; --bg-hover: #e9ecf2; --border: #d9dee7;
  --text: #191d25; --text-dim: #5f6878; --accent: #b97a17; --accent-strong: #935f0b;
  --accent-ink: #ffffff; --wave-base: #c4cbd8; --playhead: #7a4f06; --error: #c3343b;
}
:root[data-theme="dark"] {
  --bg: #0f1115; --bg-elev: #151922; --bg-hover: #1a1f2a; --border: #232a37;
  --text: #e9ecf2; --text-dim: #8b93a4; --accent: #e8a44d; --accent-strong: #f6bd6a;
  --accent-ink: #1c1408; --wave-base: #3a4252; --playhead: #ffd58f; --error: #ef5f66;
}

/* Bare embed (?bare=1): transparent ground, no chrome — just the play button
   and waveform. For dropping a single reel onto a minimal/light page. */
body.bare { background: transparent; }
body.bare .head { display: none; }
body.bare .tracks-wrap { overflow: hidden; }
body.bare .tracks { padding: 0; }
body.bare .track,
body.bare .track:hover,
body.bare .track.active {
  background: transparent;
  box-shadow: none;
  padding: 6px 4px;
  margin: 0;
}
body.bare .track .meta { display: none; }
body.bare .btn-play { background: transparent; border-color: var(--border); }
body.bare canvas.wave { height: 56px; }

#playlist-select {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  background: var(--bg-elev);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 36px 9px 12px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: .01em;
  cursor: pointer;
  transition: border-color .15s ease;
}
#playlist-select:hover:not(:disabled) { border-color: var(--text-dim); }
#playlist-select:disabled { opacity: .55; cursor: default; }
#playlist-select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.select-wrap::after {
  content: "";
  position: absolute;
  right: 14px;
  top: 50%;
  width: 7px;
  height: 7px;
  border-right: 2px solid var(--text-dim);
  border-bottom: 2px solid var(--text-dim);
  transform: translateY(-65%) rotate(45deg);
  pointer-events: none;
}

.pl-desc {
  margin: 10px 2px 0;
  color: var(--text-dim);
  font-size: 12.5px;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.pl-meta {
  margin: 7px 2px 0;
  color: var(--text-dim);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------------- status */

.status { padding: 14px 16px; color: var(--text-dim); font-size: 13px; }
.status.error { color: var(--error); }
.status .retry {
  margin-left: 8px;
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 3px 10px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.status .retry:hover { border-color: var(--text-dim); }

/* ------------------------------------------------------------------ gate */

.gate {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 28px 20px;
}
.gate-lock { width: 30px; height: 30px; color: var(--text-dim); margin-bottom: 10px; }
.gate-heading { margin: 0; font-size: 15px; font-weight: 650; }
.gate-sub { margin: 4px 0 16px; color: var(--text-dim); font-size: 12.5px; }
.gate-form { display: flex; gap: 8px; width: 100%; max-width: 320px; }
.gate-form input {
  flex: 1;
  min-width: 0;
  background: var(--bg-elev);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  font: inherit;
  font-size: 13.5px;
}
.gate-form input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.gate-form button {
  background: var(--accent);
  color: var(--accent-ink);
  border: 0;
  border-radius: 8px;
  padding: 9px 16px;
  font: inherit;
  font-size: 13.5px;
  font-weight: 650;
  cursor: pointer;
  transition: background .15s ease;
}
.gate-form button:hover:not(:disabled) { background: var(--accent-strong); }
.gate-form button:disabled { opacity: .6; cursor: default; }
.gate-error { margin: 12px 0 0; color: var(--error); font-size: 12.5px; }

/* ---------------------------------------------------------------- tracks */

.tracks-wrap {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.tracks-wrap::-webkit-scrollbar { width: 8px; }
.tracks-wrap::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.tracks { list-style: none; margin: 0; padding: 8px 10px 16px; }

.track {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border-radius: var(--radius);
  transition: background .12s ease;
}
.track + .track { margin-top: 2px; }
.track:hover { background: var(--bg-hover); }
.track.active { background: var(--bg-elev); box-shadow: inset 0 0 0 1px var(--border); }

.btn-play {
  position: relative;
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
  transition: background .15s ease, color .15s ease, border-color .15s ease, transform .08s ease;
}
.btn-play:hover { border-color: var(--text-dim); }
.btn-play:active { transform: scale(.94); }
.btn-play:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.track.active .btn-play { background: var(--accent); border-color: transparent; color: var(--accent-ink); }

.btn-play .ic { width: 15px; height: 15px; fill: currentColor; }
.btn-play .ic-play { margin-left: 2px; }
.track:not(.playing) .ic-pause { display: none; }
.track.playing .ic-play { display: none; }

.track.buffering .ic { opacity: 0; }
.track.buffering .btn-play::after {
  content: "";
  position: absolute;
  inset: 9px;
  border-radius: 50%;
  border: 2px solid transparent;
  border-top-color: currentColor;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.body { flex: 1; min-width: 0; }

.meta { display: flex; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.num {
  color: var(--text-dim);
  font-size: 10.5px;
  font-variant-numeric: tabular-nums;
  letter-spacing: .04em;
}
.title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: .01em;
}
.time { color: var(--text-dim); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.track.active .time { color: var(--accent-strong); }

canvas.wave {
  display: block;
  width: 100%;
  height: 46px;
  cursor: pointer;
  border-radius: 4px;
  touch-action: pan-y; /* vertical scroll still works; horizontal drags scrub */
}
canvas.wave:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
canvas.wave.loading {
  background: linear-gradient(90deg, transparent 20%, var(--bg-hover) 50%, transparent 80%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}
@keyframes shimmer {
  from { background-position: 180% 0; }
  to   { background-position: -80% 0; }
}
.no-peaks .wave { opacity: .5; }

.empty { padding: 28px 18px; text-align: center; color: var(--text-dim); font-size: 13px; }
.noscript { padding: 20px; text-align: center; }

/* ------------------------------------------------------------- utilities */

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* --------------------------------------------------------- narrow iframe */

@media (max-width: 420px) {
  .head { padding: 10px 12px 8px; }
  .tracks { padding: 6px 6px 12px; }
  .track { gap: 9px; padding: 8px; }
  .btn-play { width: 31px; height: 31px; }
  .btn-play .ic { width: 13px; height: 13px; }
  canvas.wave { height: 38px; }
  .num { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
