/* ==========================================================================
   Ti Pade Lančut Radio — hand-written stylesheet, no build step.

   Design notes
   - The whole viewport is the player. No card on a gradient.
   - The album art bleeds into a blurred ambient backdrop behind everything.
   - A 2px hairline at the very top edge of the page is the track progress.
   - One large play/pause control; everything else whispers.
   - "Dim" graphite by default. Near-black dark and a light theme are available
     from the switch in the top bar (stored as data-theme on <html>).
   ========================================================================== */

:root {
  color-scheme: dark;

  --bg: #191a1e;
  --fg: #ececef;
  --fg-2: color-mix(in srgb, var(--fg) 64%, transparent);
  --fg-3: color-mix(in srgb, var(--fg) 40%, transparent);
  --line: color-mix(in srgb, var(--fg) 10%, transparent);
  --glass: color-mix(in srgb, var(--fg) 6%, transparent);
  --glass-strong: color-mix(in srgb, var(--fg) 12%, transparent);
  --veil: color-mix(in srgb, var(--bg) 68%, transparent);

  --accent: var(--fg);          /* replaced at runtime with the album's colour */
  --live: #34d399;
  --warn: #fbbf24;

  --shadow: 0 30px 60px -20px rgb(0 0 0 / 0.55);
  --radius: 20px;
  --pad: clamp(20px, 4vw, 48px);
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);

  --font: "Bricolage Grotesque", "SF Pro Display", -apple-system, BlinkMacSystemFont,
    "Segoe UI Variable", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "DM Mono", ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

/* Themes. The bare :root above is the default (dim); these are the switch's
   positions. Every token they touch is declared above first. */

:root[data-theme="dim"] {
  color-scheme: dark;
  --bg: #191a1e;
  --fg: #ececef;
  --veil: color-mix(in srgb, var(--bg) 68%, transparent);
  --shadow: 0 30px 60px -20px rgb(0 0 0 / 0.55);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f7f7f8;
  --fg: #101014;
  --veil: color-mix(in srgb, var(--bg) 78%, transparent);
  --shadow: 0 30px 60px -24px rgb(0 0 0 / 0.35);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0a0a0c;
  --fg: #f5f5f6;
  --veil: color-mix(in srgb, var(--bg) 72%, transparent);
  --shadow: 0 30px 60px -20px rgb(0 0 0 / 0.7);
}

/* --------------------------------------------------------------------------
   Base
   -------------------------------------------------------------------------- */

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

html {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.4;
  background: var(--bg);
  color: var(--fg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

img {
  display: block;
  max-width: 100%;
}

button {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--fg);
  outline-offset: 4px;
}

[hidden] {
  display: none !important;
}

/* --------------------------------------------------------------------------
   Ambient backdrop
   -------------------------------------------------------------------------- */

.backdrop {
  position: fixed;
  inset: 0;
  z-index: -1;
  background: var(--bg);
  overflow: hidden;
}

.backdrop__layer {
  position: absolute;
  inset: -15%;
  background-position: center;
  background-size: cover;
  filter: blur(70px) saturate(1.5);
  opacity: 0;
  transition: opacity 1.4s var(--ease);
  animation: drift 60s ease-in-out infinite alternate;
  will-change: opacity;
}

.backdrop__layer.is-visible {
  opacity: 1;
}

.backdrop::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(60% 50% at 30% 20%, color-mix(in srgb, var(--fg) 7%, transparent), transparent 70%),
    radial-gradient(50% 45% at 80% 85%, color-mix(in srgb, var(--fg) 4%, transparent), transparent 70%);
}

.backdrop::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--veil);
}

/* --------------------------------------------------------------------------
   Progress hairline
   -------------------------------------------------------------------------- */

.progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  z-index: 10;
  background: var(--line);
}

.progress::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--accent);
  transform-origin: left;
  transform: scaleX(var(--p, 0));
  transition: transform 1s linear;
}

.progress.is-resetting::after {
  transition: none;
}

/* --------------------------------------------------------------------------
   Page grid
   -------------------------------------------------------------------------- */

.app {
  min-height: 100dvh;
  max-width: 1120px;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 32px;
  padding: calc(var(--pad) * 0.75) var(--pad) var(--pad);
  padding-top: max(calc(var(--pad) * 0.75), env(safe-area-inset-top));
  padding-bottom: max(var(--pad), env(safe-area-inset-bottom));
}

/* --------------------------------------------------------------------------
   Top bar
   -------------------------------------------------------------------------- */

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--fg);
  text-decoration: none;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  border-radius: 8px;
}

.brand__mark {
  height: 15px;
  width: auto;
  aspect-ratio: 512 / 288;
  color: var(--fg);
  opacity: 0.92;
}

.status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--glass);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg-2);
  white-space: nowrap;
}

.status__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--fg-3);
  transition: background 0.4s;
}

.status[data-state="live"] .status__dot {
  background: var(--live);
  animation: pulse 2.2s var(--ease) infinite;
}

.status[data-state="offline"] .status__dot {
  background: var(--warn);
}

.status__listeners {
  color: var(--fg-3);
  letter-spacing: 0;
  text-transform: none;
  font-variant-numeric: tabular-nums;
}

.status__listeners::before {
  content: "·";
  margin-right: 8px;
}

.top__actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.theme-btn {
  width: 34px;
  height: 34px;
}

.theme-btn svg {
  width: 16px;
  height: 16px;
}

.theme-btn .theme-btn__half {
  fill: currentColor;
  stroke: none;
  transform-origin: center;
  transition: transform 0.5s var(--ease), opacity 0.3s;
}

:root[data-theme="dim"] .theme-btn .theme-btn__half {
  opacity: 0.45;
}

:root[data-theme="light"] .theme-btn .theme-btn__half {
  transform: rotate(180deg);
}

/* --------------------------------------------------------------------------
   Stage: art + now playing + controls
   -------------------------------------------------------------------------- */

.stage {
  align-self: center;
  width: 100%;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: clamp(28px, 5vw, 64px);
}

.art {
  --size: clamp(160px, 28vw, 300px);
  position: relative;
  width: var(--size);
  aspect-ratio: 1;
  margin: 0;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--glass);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: box-shadow 0.8s var(--ease), transform 0.8s var(--ease);
}

.app[data-playing="true"] .art {
  box-shadow: var(--shadow),
    0 0 90px -20px color-mix(in srgb, var(--accent) 55%, transparent);
}

.art__placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
}

.art__placeholder-mark {
  width: 42%;
  height: auto;
  aspect-ratio: 512 / 288;
  color: var(--fg);
  opacity: 0.14;
}

.art__img {
  position: relative;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.8s var(--ease);
}

.art__img.is-loaded {
  opacity: 1;
}

/* Tiny spectrum pill, visible while the stream plays. By default the bars
   follow a rhythm; with AUDIO_REACTIVE on, the script drives them from the
   audio and the keyframes are switched off. */

.art__eq {
  position: absolute;
  left: 12px;
  bottom: 12px;
  padding: 7px 8px;
  border-radius: 999px;
  background: rgb(0 0 0 / 0.38);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.4s, transform 0.4s var(--ease);
}

.app[data-playing="true"] .art__eq {
  opacity: 1;
  transform: none;
}

.art__eq svg {
  display: block;
  width: 46px;
  height: 14px;
}

.art__eq rect {
  fill: #fff;
  transform-box: fill-box;
  transform-origin: 50% 100%;
  transform: scaleY(0.3);
  animation: eq var(--d, 1s) ease-in-out var(--o, 0s) infinite alternate;
  animation-play-state: paused;
}

.app[data-playing="true"] .art__eq rect {
  animation-play-state: running;
}

.art__eq.is-reactive rect {
  animation: none;
  transition: transform 70ms linear;
}


.stage__body {
  min-width: 0;
}

.eyebrow {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 14px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--fg-3);
}

.eyebrow__time {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0;
  text-transform: none;
  font-variant-numeric: tabular-nums;
}

.eyebrow__sep {
  margin: 0 5px;
  opacity: 0.5;
}

.title {
  margin: 0;
  font-size: clamp(1.9rem, 5.2vw, 3.6rem);
  font-weight: 600;
  font-variation-settings: "opsz" 96;
  letter-spacing: -0.02em;
  line-height: 1.02;
  text-wrap: balance;
  overflow-wrap: anywhere;
  transition: color 0.6s;
}

.title.is-pending {
  color: var(--fg-3);
  font-weight: 500;
}

.artist {
  margin: 10px 0 0;
  font-size: clamp(1.05rem, 2vw, 1.35rem);
  font-weight: 400;
  letter-spacing: -0.01em;
  color: var(--fg-2);
  overflow-wrap: anywhere;
}

.artist:empty {
  display: none;
}

/* Controls ---------------------------------------------------------------- */

.controls {
  display: flex;
  align-items: center;
  gap: 22px;
  margin-top: 36px;
}

.play {
  position: relative;
  width: 72px;
  height: 72px;
  flex: none;
  border: 0;
  border-radius: 50%;
  background: var(--fg);
  color: var(--bg);
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 12px 30px -12px rgb(0 0 0 / 0.6);
  transition: transform 0.25s var(--ease), opacity 0.2s;
}

.play:hover {
  transform: scale(1.05);
}

.play:active {
  transform: scale(0.96);
}

.play__icon {
  display: none;
  width: 26px;
  height: 26px;
  fill: currentColor;
}

.play__icon--play {
  margin-left: 3px; /* optical centring of the triangle */
}

.play[data-state="idle"] .play__icon--play,
.play[data-state="error"] .play__icon--play,
.play[data-state="playing"] .play__icon--pause,
.play[data-state="loading"] .play__icon--pause {
  display: block;
}

.play[data-state="loading"]::before {
  content: "";
  position: absolute;
  inset: -5px;
  border-radius: 50%;
  border: 2px solid transparent;
  border-top-color: var(--fg);
  animation: spin 0.9s linear infinite;
}

.volume {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  flex: none;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--glass);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.2s;
}

.icon-btn:hover {
  background: var(--glass-strong);
}

.icon-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-btn svg path:first-child {
  fill: currentColor;
}

.volume__x {
  display: none;
}

.icon-btn[data-muted="true"] .volume__wave {
  display: none;
}

.icon-btn[data-muted="true"] .volume__x {
  display: block;
}

.range {
  --v: 85%;
  -webkit-appearance: none;
  appearance: none;
  width: 128px;
  height: 20px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}

.range::-webkit-slider-runnable-track {
  height: 2px;
  border-radius: 2px;
  background:
    linear-gradient(var(--accent), var(--accent)) 0 0 / var(--v) 100% no-repeat,
    var(--line);
}

.range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  margin-top: -5px;
  border: 0;
  border-radius: 50%;
  background: var(--fg);
  transition: transform 0.2s var(--ease);
}

.range:hover::-webkit-slider-thumb,
.range:active::-webkit-slider-thumb {
  transform: scale(1.3);
}

.range::-moz-range-track {
  height: 2px;
  border-radius: 2px;
  background: var(--line);
}

.range::-moz-range-progress {
  height: 2px;
  border-radius: 2px;
  background: var(--accent);
}

.range::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border: 0;
  border-radius: 50%;
  background: var(--fg);
}

/* --------------------------------------------------------------------------
   Recently played
   Five equal columns on wide screens, a compact vertical list below that.
   -------------------------------------------------------------------------- */

.history {
  display: grid;
  gap: 14px;
}

.history__label {
  margin: 0;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--fg-3);
}

.history__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}

.history__item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  padding: 8px 12px 8px 8px;
  cursor: default;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--glass);
  transition: background 0.25s, border-color 0.25s, transform 0.35s var(--ease);
  animation: rise 0.6s var(--ease) both;
  animation-delay: calc(var(--i, 0) * 50ms);
}

.history__item:hover {
  z-index: 2;
  background: var(--glass-strong);
  border-color: color-mix(in srgb, var(--fg) 18%, transparent);
  transform: translateY(-2px);
}

/* Tooltip with the untruncated title and artist */

.history__item::after {
  content: attr(data-tip);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 10px);
  transform: translate(-50%, 4px);
  width: max-content;
  max-width: min(300px, 80vw);
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 94%, var(--fg));
  color: var(--fg);
  font-size: 12.5px;
  line-height: 1.35;
  white-space: normal;
  text-align: center;
  box-shadow: 0 12px 30px -12px rgb(0 0 0 / 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.25s var(--ease);
}

.history__item:hover::after {
  opacity: 1;
  transform: translate(-50%, 0);
  transition-delay: 0.35s;
}

.history__item:first-child::after {
  left: 0;
  transform: translate(0, 4px);
}

.history__item:first-child:hover::after {
  transform: translate(0, 0);
}

.history__item:last-child::after {
  left: auto;
  right: 0;
  transform: translate(0, 4px);
}

.history__item:last-child:hover::after {
  transform: translate(0, 0);
}

.history__empty {
  font-size: 13px;
  color: var(--fg-3);
}

.history__thumb {
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: 9px;
  object-fit: cover;
  background: var(--glass-strong);
  transition: transform 0.35s var(--ease);
}

.history__item:hover .history__thumb {
  transform: scale(1.06);
}

.history__text {
  min-width: 0;
  flex: 1;
  display: grid;
  gap: 2px;
}

.history__title {
  font-size: 13.5px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history__sub {
  font-size: 12px;
  color: var(--fg-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 960px) {
  .history__list {
    grid-template-columns: 1fr;
    gap: 6px;
    max-width: 560px;
  }

  .history__item::after,
  .history__item:last-child::after {
    left: 0;
    right: auto;
    transform: translate(0, 4px);
    text-align: left;
  }

  .history__item:hover::after,
  .history__item:last-child:hover::after {
    transform: translate(0, 0);
  }

  .history__item {
    padding: 6px 12px 6px 6px;
  }

  .history__thumb {
    width: 36px;
    height: 36px;
  }
}

/* Skeleton while the first payload is in flight */

.is-skeleton .history__title,
.is-skeleton .history__sub {
  display: block;
  height: 10px;
  border-radius: 5px;
  background: linear-gradient(90deg, var(--glass), var(--glass-strong), var(--glass));
  background-size: 200% 100%;
  animation: shimmer 1.6s linear infinite;
}

.is-skeleton .history__title {
  width: 70%;
}

.is-skeleton .history__sub {
  width: 45%;
}

/* --------------------------------------------------------------------------
   Toast
   -------------------------------------------------------------------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 20;
  max-width: min(90vw, 420px);
  padding: 10px 16px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  font-size: 13px;
  color: var(--fg-2);
  text-align: center;
  animation: toast-in 0.4s var(--ease) both;
}

/* --------------------------------------------------------------------------
   Error page
   -------------------------------------------------------------------------- */

.app--error {
  grid-template-rows: auto 1fr;
}

.error {
  align-self: center;
  justify-self: center;
  text-align: center;
  max-width: 560px;
}

.error .eyebrow {
  justify-content: center;
  font-family: var(--mono);
}

.error .artist {
  margin-top: 14px;
}

.btn {
  display: inline-block;
  margin-top: 32px;
  padding: 12px 22px;
  border-radius: 999px;
  background: var(--fg);
  color: var(--bg);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  transition: transform 0.25s var(--ease);
}

.btn:hover {
  transform: scale(1.04);
}

.stack {
  margin-top: 40px;
  padding: 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--glass);
  font-family: var(--mono);
  font-size: 12px;
  text-align: left;
  color: var(--fg-3);
  overflow-x: auto;
}

/* --------------------------------------------------------------------------
   Small screens
   -------------------------------------------------------------------------- */

@media (max-width: 720px) {
  .stage {
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: center;
    gap: 28px;
  }

  .art {
    --size: min(62vw, 280px);
  }

  .stage__body {
    width: 100%;
  }

  .eyebrow,
  .controls {
    justify-content: center;
  }

  .controls {
    margin-top: 28px;
  }

  .status__listeners {
    display: none;
  }
}

@media (max-height: 640px) and (min-width: 721px) {
  .art {
    --size: clamp(140px, 24vh, 220px);
  }
}

/* --------------------------------------------------------------------------
   Keyframes & motion preferences
   -------------------------------------------------------------------------- */

@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 color-mix(in srgb, var(--live) 55%, transparent); }
  70%  { box-shadow: 0 0 0 8px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

@keyframes eq {
  from { transform: scaleY(0.2); }
  to   { transform: scaleY(1); }
}

@keyframes shimmer {
  from { background-position: 200% 0; }
  to   { background-position: -200% 0; }
}

@keyframes drift {
  from { transform: scale(1.05) translate(-2%, -2%); }
  to   { transform: scale(1.15) translate(2%, 3%); }
}

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