@layer reset, tokens, base, layout, components, states;

/* Manrope (SIL OFL, fonts/OFL-Manrope.txt), self-hosted, variable 200-800 */
@font-face {
  font-family: "Manrope";
  font-style: normal;
  font-display: swap;
  font-weight: 200 800;
  src: url("../fonts/manrope-latin-wght-normal.woff2") format("woff2-variations"),
       url("../fonts/manrope-latin-wght-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Manrope";
  font-style: normal;
  font-display: swap;
  font-weight: 200 800;
  src: url("../fonts/manrope-latin-ext-wght-normal.woff2") format("woff2-variations"),
       url("../fonts/manrope-latin-ext-wght-normal.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  html, body { margin: 0; height: 100%; }
  p, h1 { margin: 0; }
  img, svg { display: block; }
  button, input { font: inherit; color: inherit; }
  [hidden] { display: none !important; }
}

@layer tokens {
  :root {
    --lrp-font: "Manrope", system-ui, -apple-system, "Segoe UI", sans-serif;
    --lrp-text: rgba(255,255,255,.92);
    --lrp-muted: rgba(255,255,255,.72);
    --lrp-line: rgba(255,255,255,.12);
    --lrp-track: rgba(255,255,255,.16);
    --lrp-glass: rgba(12,16,26,.64);
    --lrp-ground: #05070d;
    --lrp-go: #2E9B57;          /* play button while stopped */
    --lrp-go-glow: rgba(46,155,87,.35);
    --lrp-live: #E53935;        /* play button while playing (= site accent) */
    --lrp-live-glow: rgba(229,57,53,.35);
    --lrp-gold: #F2C14E;        /* own rating / hover */
    --lrp-gold-dim: #B8963C;    /* average of other listeners */
    --lrp-star-base: rgba(255,255,255,.20);
    --lrp-warn: #F5B942;

    /* layout variables (stack defaults) */
    --lrp-pad: 20px;
    --lrp-gap: 14px;
    --lrp-radius: 16px;
    --lrp-star: 32px;           /* visible star */
    --lrp-cell: 44px;           /* touch cell, never below 44 px */
    --lrp-star-gap: 0px;
    --lrp-play: 52px;
    --lrp-artist-size: 22px;
    --lrp-title-size: 16px;
    --lrp-logo-w: min(260px, 70vw);
    /* everything in the stack except the cover is about 470 px high */
    --lrp-cover: min(100%, max(150px, calc(100vh - 470px)), 420px);
  }
  @supports (height: 100svh) {
    :root { --lrp-cover: min(100%, max(150px, calc(100svh - 470px)), 420px); }
  }
}

@layer base {
  body.lrp {
    min-height: 100%;
    background: var(--lrp-ground);
    color: var(--lrp-text);
    font-family: var(--lrp-font);
    font-size: 15px;
    line-height: 1.35;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
  }
  /* daily background: site.js sets --daily-bg / --daily-bg-pos on <html> */
  body.lrp::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -2;
    background-image: var(--daily-bg, none);
    background-position: var(--daily-bg-pos, center center);
    background-size: cover;
    background-repeat: no-repeat;
  }
  html.bg-fallback body.lrp::before { background-image: url("/images/background.jpg"); background-position: center; }
  body.lrp::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    background: linear-gradient(180deg, rgba(5,7,13,.30), rgba(5,7,13,.62));
  }
  .lrp-sr {
    position: absolute; width: 1px; height: 1px; overflow: hidden;
    clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
  }
}

@layer layout {
  .lrp-shell {
    min-height: 100vh;
    min-height: 100svh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 14px max(14px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  }
  .lrp-logo-link { display: block; }
  .lrp-logo { width: var(--lrp-logo-w); height: auto; }

  .lrp-card {
    width: 100%;
    max-width: 480px;
    padding: var(--lrp-pad);
    border-radius: var(--lrp-radius);
    background: var(--lrp-glass);
    -webkit-backdrop-filter: blur(18px);
    backdrop-filter: blur(18px);
    border: 1px solid rgba(255,255,255,.10);
    box-shadow: 0 18px 60px rgba(0,0,0,.35);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--lrp-gap);
  }
  .lrp-side {
    width: 100%;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: var(--lrp-gap);
  }
  .lrp-now, .lrp-rating { text-align: center; }
  .lrp-rating { display: flex; flex-direction: column; align-items: center; gap: 2px; }
  .lrp-controls { justify-content: center; }
  .lrp-wide-only { display: none; }

  /* ---------- wide: windows from about 900 x 600 ---------- */
  @media (min-width: 900px) and (min-height: 600px) {
    :root {
      --lrp-pad: 32px;
      --lrp-gap: 22px;
      --lrp-radius: 20px;
      --lrp-star: 44px;
      --lrp-star-gap: 4px;
      --lrp-play: 56px;
      --lrp-artist-size: clamp(26px, 2.2vw, 32px);
      --lrp-title-size: clamp(17px, 1.4vw, 20px);
      --lrp-logo-w: clamp(300px, 26vw, 380px);
      --lrp-cover: min(420px, 36vw, calc(100vh - 230px));
    }
    @supports (height: 100svh) {
      :root { --lrp-cover: min(420px, 36vw, calc(100svh - 230px)); }
    }
    .lrp-shell { gap: 18px; padding: 32px; }
    .lrp-card { max-width: 1060px; flex-direction: row; align-items: center; gap: 40px; }
    .lrp-now, .lrp-rating { text-align: left; }
    .lrp-rating { align-items: flex-start; }
    .lrp-controls { justify-content: flex-start; }
    .lrp-wide-only { display: block; }
    .lrp-side { flex: 1; }
  }

  /* ---------- landscape phones: low and wide ---------- */
  @media (orientation: landscape) and (max-height: 599px) and (min-width: 560px) {
    :root {
      --lrp-pad: 16px;
      --lrp-gap: 8px;
      --lrp-cover: min(40vw, calc(100vh - 64px));
      --lrp-artist-size: 19px;
      --lrp-title-size: 15px;
    }
    @supports (height: 100svh) {
      :root { --lrp-cover: min(40vw, calc(100svh - 64px)); }
    }
    .lrp-shell { padding: 10px; }
    .lrp-logo-link { display: none; }
    .lrp-card { max-width: 900px; flex-direction: row; gap: 20px; }
    .lrp-now, .lrp-rating { text-align: left; }
    .lrp-rating { align-items: flex-start; }
    .lrp-controls { justify-content: flex-start; }
    .lrp-side { flex: 1; }
    .lrp-next { padding-top: 8px; }
  }
}

@layer components {
  /* cover: radius proportional to size, thin light edge, shadow only on the big one */
  .lrp-cover {
    width: var(--lrp-cover);
    height: auto;
    aspect-ratio: 1;
    flex: none;
    object-fit: cover;
    border-radius: 8px;
    background: rgba(255,255,255,.06);
    box-shadow: 0 0 0 1px rgba(255,255,255,.12), 0 12px 32px rgba(0,0,0,.45);
  }

  .lrp-now { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
  .lrp-eyebrow {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--lrp-muted);
  }
  .lrp-artist, .lrp-title {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    overflow-wrap: anywhere;
  }
  .lrp-artist { font-size: var(--lrp-artist-size); font-weight: 600; line-height: 1.2; }
  .lrp-title { font-size: var(--lrp-title-size); font-weight: 400; color: var(--lrp-muted); }

  /* ---------- stars: SVG, half star cut at exactly 50 % ---------- */
  .lrp-stars {
    display: flex;
    gap: var(--lrp-star-gap);
    touch-action: none;           /* swipe across the row = preview */
    user-select: none;
    -webkit-user-select: none;
    cursor: pointer;
    border-radius: 6px;
    outline: none;
  }
  .lrp-stars:focus-visible { box-shadow: 0 0 0 2px #fff; }
  .lrp-star {
    width: var(--lrp-cell);
    height: var(--lrp-cell);
    flex: none;
    display: grid;
    place-items: center;
  }
  .lrp-star-in { position: relative; width: var(--lrp-star); height: var(--lrp-star); pointer-events: none; }
  .lrp-star-in svg { width: var(--lrp-star); height: var(--lrp-star); }
  .lrp-star-base path { fill: var(--lrp-star-base); }
  .lrp-star-fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0; overflow: hidden; }
  .lrp-star-fill path { fill: var(--lrp-gold); }
  .lrp-stars.is-avg .lrp-star-fill path { fill: var(--lrp-gold-dim); }
  .lrp-caption { min-height: 18px; font-size: 13px; line-height: 18px; color: var(--lrp-muted); }
  .lrp-caption.is-warn { color: var(--lrp-warn); }
  .lrp-ts { width: 0; height: 0; overflow: hidden; }

  /* ---------- progress ---------- */
  .lrp-progress { display: flex; flex-direction: column; gap: 6px; width: 100%; }
  .lrp-bar { height: 4px; border-radius: 2px; background: var(--lrp-track); overflow: hidden; }
  .lrp-bar-fill {
    height: 100%;
    width: 100%;
    border-radius: 2px;
    background: rgba(255,255,255,.88);
    transform: scaleX(0);
    transform-origin: left center;
    will-change: transform;
  }
  .lrp-times {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    font-variant-numeric: tabular-nums;
    color: var(--lrp-muted);
  }

  /* ---------- controls ---------- */
  .lrp-controls { display: flex; align-items: center; gap: 24px; }
  .lrp-play {
    width: var(--lrp-play);
    height: var(--lrp-play);
    flex: none;
    border: 0;
    padding: 0;
    border-radius: 50%;
    display: grid;
    place-items: center;
    color: #fff;
    background: var(--lrp-go);
    box-shadow: 0 6px 18px var(--lrp-go-glow);
    cursor: pointer;
    transition: background-color .2s ease, box-shadow .2s ease, filter .2s ease;
  }
  .lrp-play:hover { filter: brightness(1.1); }
  .lrp-play:focus-visible { outline: 2px solid #fff; outline-offset: 3px; }
  .lrp-play svg { width: 22px; height: 22px; }
  .lrp-icon-stop { display: none; }

  .lrp-vol { display: flex; align-items: center; gap: 10px; color: var(--lrp-muted); }
  .lrp-vol svg { width: 20px; height: 20px; }
  .lrp-range {
    -webkit-appearance: none;
    appearance: none;
    width: clamp(110px, 12vw, 160px);
    height: 4px;
    margin: 0;
    border-radius: 2px;
    background: linear-gradient(to right, rgba(255,255,255,.9) var(--lrp-vol, 85%), rgba(255,255,255,.18) var(--lrp-vol, 85%));
    cursor: pointer;
  }
  .lrp-range::-webkit-slider-thumb {
    -webkit-appearance: none; appearance: none;
    width: 16px; height: 16px; border-radius: 50%; border: 0;
    background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.45);
  }
  .lrp-range::-moz-range-thumb {
    width: 16px; height: 16px; border-radius: 50%; border: 0;
    background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.45);
  }
  .lrp-range:focus-visible { outline: 2px solid #fff; outline-offset: 6px; }
  /* touch devices: volume comes from the device buttons */
  html.lrp-touch .lrp-vol { display: none; }

  .lrp-status { font-size: 13px; text-align: center; color: var(--lrp-muted); }
  .lrp-status:empty { display: none; }
  .lrp-status.is-error { color: var(--lrp-warn); }

  /* ---------- up next ---------- */
  .lrp-next {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-top: 14px;
    border-top: 1px solid var(--lrp-line);
  }
  .lrp-next-cover {
    width: 48px; height: 48px; flex: none;
    object-fit: cover;
    border-radius: 4px;
    background: rgba(255,255,255,.06);
    box-shadow: 0 0 0 1px rgba(255,255,255,.12);
  }
  .lrp-next-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
  .lrp-next-line { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .lrp-next-artist { font-weight: 600; }
  .lrp-next-in { flex: none; font-size: 13px; font-variant-numeric: tabular-nums; color: var(--lrp-muted); }
  @media (min-width: 900px) and (min-height: 600px) {
    .lrp-next { padding-top: 18px; gap: 14px; }
    .lrp-next-cover { width: 56px; height: 56px; }
    .lrp-next-line { font-size: 15px; }
    .lrp-times { font-size: 13px; }
  }
}

@layer states {
  /* diagnosis ?lite=1: no blur behind the card */
  /* iOS: no live blur behind the card (shares the GPU process with audio playback) */
  html.lrp-ios .lrp-card { -webkit-backdrop-filter: none; backdrop-filter: none; background: rgba(12,16,26,.84); }
  html.lrp-lite .lrp-card { -webkit-backdrop-filter: none; backdrop-filter: none; background: rgba(12,16,26,.88); }
  /* ?debug=1 on-page log */
  .lrp-debug {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
    max-height: 30vh; overflow: auto; margin: 0; padding: 6px 8px;
    background: rgba(0,0,0,.82); color: #9fe39f;
    font: 10px/1.35 ui-monospace, Menlo, Consolas, monospace; white-space: pre-wrap;
  }

  .lrp-play.is-playing { background: var(--lrp-live); box-shadow: 0 6px 18px var(--lrp-live-glow); }
  .lrp-play.is-playing .lrp-icon-play { display: none; }
  .lrp-play.is-playing .lrp-icon-stop { display: block; }
  .lrp-play.is-busy { opacity: .75; }

  .lrp-stars.is-locked { cursor: default; }
  .lrp-stars.is-off { opacity: .45; cursor: default; }

  @media (prefers-reduced-motion: reduce) {
    .lrp-play { transition: none; }
  }
}
