/* sonora — install / update / offline chrome.
   Loaded after app.css and namespaced .pwa-* so it can borrow the design
   tokens without ever colliding with the app. Every rule has a literal
   fallback, so this file is still correct if the tokens are missing.

   Placement is deliberate: the stack floats in the gap above the player, which
   is 99px on desktop, 94px at tablet width (player row 82px) and 148px on
   mobile (71px player + 67px nav). Nothing here ever covers the mini player,
   the nav or a focused control.

   Weight is deliberate too: every piece of chrome here is one line (a pill, or
   the install row's single 54px band). The install offer used to be a 120px
   card with a big coral tile and two stacked buttons, which made it the
   loudest object on every phone screen; see the install section for what it
   costs the page now, and for the one place the offer reserves its own space. */

.pwa-stack {
  position: fixed;
  left: 0;
  right: 0;
  /* pwa.js measures the real player bar and overrides --pwa-bottom, so a
     redesign of the player (or a new breakpoint) can never make this chrome
     cover it. The calc() below is the no-measurement fallback. */
  bottom: var(--pwa-bottom, calc(99px + env(safe-area-inset-bottom, 0px)));
  z-index: 30; /* base: over the player (20). The update/offline pills lift
                  above the app's overlays in the rule that follows. */
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  /* the app's own screen gutter, plus the landscape notch insets, so the row
     lines up with the page's text column instead of floating at its own 12px */
  padding: 0 calc(var(--gutter, 17px) + var(--sar, 0px)) 0 calc(var(--gutter, 17px) + var(--sal, 0px));
  pointer-events: none;
  font-family: Inter, system-ui, -apple-system, sans-serif;
}

.pwa-stack > * { pointer-events: auto; }

/* The two pills that carry news the user has to act on — "New version
   available · Refresh" and "You're offline" — cannot stay at the base 30.
   Every app overlay is `--z-overlay` (50) with `position: fixed; inset: 0`, and
   `.now-modal` is a full-screen opaque panel on a phone: while the Now Playing
   sheet is open — which is whenever a phone user is actually listening — both
   pills were painted underneath it, invisible, and a thumb where Refresh sits
   hit the scrim and closed the sheet instead of reloading. One above the
   overlay is still below `--z-menu` (60) and `--z-toast` (80), so a real menu or
   toast still covers them, and `pointer-events` above leaves the rest of the
   fixed row transparent to the sheet underneath. `:has()` scopes the lift to
   those two kinds (install and the chin notice stay where they were); a browser
   without `:has()` drops the whole rule and keeps 30, which is today's
   behaviour rather than a new failure. */
.pwa-stack:has(.pwa-pill[data-kind="update"]),
.pwa-stack:has(.pwa-pill[data-kind="offline"]) {
  z-index: calc(var(--z-overlay, 50) + 1);
}

/* ── material ────────────────────────────────────────────────────────────
   One warm charcoal material for every piece of install chrome, expressed
   through the app's own surface tokens so a change there moves this with it.
   The literals are fallbacks: this file stays correct on its own, exactly as
   the note at the top promises. */
.pwa-stack,
.pwa-sheet-backdrop {
  --pwa-surface: var(--panel, #1e1b18);
  --pwa-surface-raised: var(--card, #24211d);
  --pwa-ink: var(--white, #faf7f3);
  --pwa-ink-2: var(--text-2, #cdc8c2);
  --pwa-ink-3: var(--muted, #a8a29c);
  --pwa-line: var(--line-2, rgba(255, 255, 255, 0.11));
  --pwa-lift: var(--shadow-2, 0 12px 32px rgba(0, 0, 0, 0.45));
  /* a sleeve sits on the surface rather than floating in it */
  --pwa-sleeve-ring: 0 0 0 1px var(--line-2, rgba(255, 255, 255, 0.11));
}

@media (max-width: 1080px) {
  .pwa-stack { bottom: var(--pwa-bottom, calc(94px + env(safe-area-inset-bottom, 0px))); }
}

@media (max-width: 650px) {
  .pwa-stack { bottom: var(--pwa-bottom, calc(148px + env(safe-area-inset-bottom, 0px))); }
}

/* ── pills: update + connection status ─────────────────────────────────── */

.pwa-pill {
  display: flex;
  align-items: center;
  gap: 9px;
  /* a landscape notch squeezes the row from the sides, so the width follows
     the padded content box, not the viewport */
  max-width: min(440px, calc(100vw - 24px));
  max-width: min(440px, 100%);
  min-height: 40px;
  padding: 4px 6px 4px 14px;
  border: 1px solid var(--pwa-line);
  border-radius: var(--r-pill, 999px);
  /* Opaque first, then the frosted version: a browser without color-mix()
     keeps the solid warm charcoal instead of dropping the background. */
  background: var(--pwa-surface);
  background: color-mix(in srgb, var(--pwa-surface) 96%, transparent);
  color: var(--pwa-ink);
  box-shadow: var(--pwa-lift);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.005em;
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  animation: pwa-rise 220ms cubic-bezier(0.22, 0.68, 0.18, 1);
}

.pwa-pill-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pwa-pill-dot {
  flex: none;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent, #ff997b);
  box-shadow: 0 0 0 3px #ff997b29;
}

.pwa-pill[data-tone="offline"] .pwa-pill-dot {
  background: var(--warn, #eab369);
  box-shadow: 0 0 0 3px #eab36929;
}

.pwa-pill[data-tone="online"] .pwa-pill-dot {
  background: var(--ok, #7ed3a2);
  box-shadow: 0 0 0 3px #7ed3a229;
}

/* the bottom-edge self-check: amber, and its numbers must line up */
.pwa-pill[data-tone="warn"] .pwa-pill-dot {
  background: var(--warn, #eab369);
  box-shadow: 0 0 0 3px #eab36929;
}
.pwa-pill[data-tone="warn"] .pwa-pill-text {
  font-variant-numeric: tabular-nums;
}

/* The desktop install notice (see the desktop block at the end of this file).
   Its one action is the only thing worth tapping in that corner, so unlike the
   update pill's Refresh it is filled; and a notification has room for one
   readable sentence, so this pill may be wider than the update/offline ones
   (which never render at those widths anyway). */
.pwa-pill[data-kind="install"] { max-width: min(560px, calc(100vw - 40px)); }
.pwa-pill[data-kind="install"] .pwa-pill-action {
  padding: 0 14px;
  background: var(--accent, #ff997b);
  color: var(--accent-ink, #251914);
}
.pwa-pill[data-kind="install"] .pwa-pill-action:hover { background: var(--accent-2, #ffab92); }

.pwa-pill-action,
.pwa-pill-dismiss {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  min-height: 44px;
  min-width: 44px;
  padding: 0 12px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--accent, #ff997b);
  font: inherit;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

.pwa-pill-dismiss {
  width: 44px;
  padding: 0;
  color: var(--pwa-ink-3);
  font-size: 15px;
  font-weight: 600;
}

.pwa-pill-action:hover,
.pwa-pill-dismiss:hover { background: #ffffff14; }

.pwa-pill-action:active { transform: scale(0.97); }

/* ── install chrome: one compact row ─────────────────────────────────────
   The offer used to be a card: a 38px coral app tile, two stacked 44px buttons
   in a column of their own, and a second line of copy. On a 390px phone that
   measured 120px tall and floated over the page — the loudest object on every
   screen, and a lid over the last station or library row. It is now a single
   54px band (capped at 56px): a 26px sleeve mark, one line of text, one primary
   action, one quiet dismiss, all on one baseline just above the player. */
.pwa-banner {
  position: relative;
  display: flex;
  align-items: center;
  gap: 9px;
  /* The app's gutter is the row's gutter (.pwa-stack pads by it). Height is the
     sum of its parts and is checked by test/ux.test.js: 44px controls + 4px
     padding + 1px border = 54px, under the contract's 56px cap. The controls
     are 44px for real — a real box, not a pseudo-element grown hit area —
     because a hit box has to be the box the finger lands on. */
  width: min(440px, 100%);
  min-height: 44px;
  max-height: 56px;
  padding: 4px 4px 4px 10px;
  border: 1px solid var(--pwa-line);
  border-radius: var(--r-md, 16px);
  /* warm charcoal, lit from above — the same material as the app's own
     floating surfaces, not a second palette. */
  background: linear-gradient(180deg, var(--pwa-surface-raised) 0%, var(--pwa-surface) 72%);
  box-shadow: var(--pwa-lift), inset 0 1px rgba(255, 255, 255, 0.06);
  color: var(--pwa-ink);
  animation: pwa-rise 240ms cubic-bezier(0.22, 0.68, 0.18, 1);
}

/* The mark is a sleeve, not a tile: 26px, --r-cover, one hairline ring. Small
   enough that the row reads as text first — the coral plate is a signpost for
   "this is sonora", not the loudest shape on the screen. */
.pwa-banner-art {
  flex: none;
  width: 26px;
  height: 26px;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: var(--r-cover, var(--r-xs, 8px));
  box-shadow: 0 0 0 1px var(--pwa-line), 0 3px 10px rgba(0, 0, 0, 0.34);
}

/* One line of copy, one line only. The explanatory sentence pwa.js renders
   stays in the DOM for screen readers (and is still announced, the row's
   accessible name is the title) but would otherwise cost two more lines. */
.pwa-banner-body {
  display: flex;
  flex-direction: column;
  justify-content: center;
  flex: 1 1 auto;
  min-width: 0;
}

.pwa-banner-title {
  margin: 0;
  overflow: hidden;
  font-family: "Inter Display", Inter, system-ui, sans-serif;
  font-size: 12.5px;
  font-weight: 800;
  letter-spacing: -0.012em;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--pwa-ink);
}

/* Visually hidden, not removed: "one tap from your home screen — full screen,
   works offline" is worth a screen reader's attention and nothing else's. */
.pwa-banner-text {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  font-size: 11.5px;
  line-height: 1.45;
  color: var(--pwa-ink-3);
}

/* Install and Not now, side by side on the row's centre line. */
.pwa-banner-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: none;
}

/* Both actions are 44px tall and at least 44px wide: the tap target is the
   box the finger lands on, so it is the box that is big. The row stays under
   56px because the padding gives way, not the control. */
.pwa-banner-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  min-width: 44px;
  margin: 0;
  padding: 0 13px;
  border: 1px solid transparent;
  border-radius: var(--r-pill, 999px);
  background: transparent;
  color: var(--pwa-ink-2);
  font: inherit;
  font-family: Inter, system-ui, sans-serif;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.005em;
  cursor: pointer;
  transition: background 140ms ease, color 140ms ease, transform 140ms ease;
}

.pwa-banner-btn.primary {
  background: var(--accent, #ff997b);
  color: var(--accent-ink, #251914);
}

.pwa-banner-btn.primary:hover { background: var(--accent-2, #ffab92); }
.pwa-banner-btn.primary:active { transform: scale(0.97); }

/* "Not now" is a dismiss, so it is a word, not a second button: muted ink, no
   border, and it only gains a surface under the pointer or the focus ring. */
.pwa-banner-btn.ghost { padding: 0 10px; color: var(--pwa-ink-3); font-weight: 700; }
.pwa-banner-btn.ghost:hover { background: rgba(255, 255, 255, 0.08); color: var(--pwa-ink); }
.pwa-banner-btn.ghost:active { transform: scale(0.97); }

/* ── the row pays for its own height ─────────────────────────────────────
   Even at 54px the band floats over the bottom of the page's scroll area, and
   on a phone that is exactly where the last station row or library card lands
   at full scroll. So for as long as an install offer exists, the scroll
   container is given that band (row + the player gap + its ring) back as real
   space: no row is ever left under the chrome. pwa.js removes the node on
   Install, on "Not now" and on the 14-day snooze, and the padding leaves with
   it — a dismissed offer costs the page nothing.

   This is the one selector in this file that is not a `.pwa-*` class, and it
   is why: app.css is not this file's to edit. It reserves that space from the
   scroll *viewport* (margin), not from the end of the scroll *content*
   (padding). Padding only helps a page that already overflows; on a short page
   — two station rows, the first radio card row — the band still sliced the
   last live line, which is exactly the case this rule exists to prevent.
   Shrinking the scroller puts the band in space no content can occupy, at any
   page length. Browsers without :has() drop the rule and keep the float. */
:root:has(.pwa-banner) .main { padding-bottom: 58px; }

/* The desktop offer is the same thing at notification weight, and it is a
   `.pwa-pill` rather than a `.pwa-banner`, so it needs the same reservation —
   it used to float over the top of the third card in the radio grid. The pill
   sits higher above the player than the band does, hence the roomier figure. */
@media (min-width: 651px) {
  :root:has(.pwa-pill) .main { padding-bottom: 72px; }
}

/* …and on any screen tall enough to afford the space, reserve it from the
   scroll viewport itself so the band can never sit on a rendered row either.
   The 700px floor is not arbitrary: at 320x568 shrinking the scroller robs the
   hero of its height and pushes its footer under the player, so the short-screen
   behaviour stays "scroll clear" and tall screens get "never covered". */
@media (min-height: 700px) {
  :root:has(.pwa-banner) .main { margin-bottom: 58px; padding-bottom: 0; }
  @media (min-width: 651px) {
    :root:has(.pwa-pill) .main { margin-bottom: 72px; padding-bottom: 0; }
  }
}

/* On a wide screen the band is a pill, so it must also stop straddling the
   content/rail boundary: it ends where the player's right cluster ends. */
@media (min-width: 651px) {
  .pwa-stack { right: calc(var(--rail-w, 0px) + var(--chrome-gutter, 24px)); }
}

/* ── iOS "Add to Home Screen" sheet ────────────────────────────────────── */

.pwa-sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 70; /* above the app's overlays, below the toast (80) */
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(16px + env(safe-area-inset-top, 0px)) 16px
    calc(16px + env(safe-area-inset-bottom, 0px));
  /* warm, near-black scrim: the page behind cools down instead of going blue */
  background: rgba(11, 9, 7, 0.76);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  animation: pwa-fade 160ms ease-out;
}

.pwa-sheet-backdrop[hidden] { display: none; }

.pwa-sheet {
  width: min(420px, 100%);
  max-height: calc(100dvh - 32px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  overflow: auto;
  padding: 22px;
  border: 1px solid var(--pwa-line);
  border-radius: var(--r-lg, 22px);
  background: linear-gradient(160deg, var(--pwa-surface-raised) 0%, var(--pwa-surface) 100%);
  box-shadow: var(--shadow-3, 0 28px 80px rgba(0, 0, 0, 0.55)), inset 0 1px rgba(255, 255, 255, 0.08);
  color: var(--pwa-ink);
  animation: pwa-pop 240ms cubic-bezier(0.22, 0.68, 0.18, 1);
}

.pwa-sheet-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 18px;
}

.pwa-sheet-art {
  flex: none;
  width: 44px;
  height: 44px;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: var(--r-cover, var(--r-xs, 8px));
  transform: rotate(-4deg);
  box-shadow: var(--pwa-sleeve-ring), 0 8px 22px rgba(0, 0, 0, 0.42);
}

.pwa-sheet-title {
  margin: 0 0 4px;
  font-family: "Inter Display", Inter, system-ui, sans-serif;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.6px;
  line-height: 1.2;
}

.pwa-sheet-text {
  margin: 0;
  font-size: 12px;
  line-height: 1.55;
  color: var(--pwa-ink-3);
}

.pwa-sheet-close {
  flex: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin: -8px -8px 0 auto;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  color: var(--pwa-ink);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

.pwa-sheet-close:hover { background: rgba(255, 255, 255, 0.14); }

.pwa-steps {
  display: grid;
  gap: 14px;
  margin: 0 0 20px;
  padding: 0;
  list-style: none;
}

.pwa-step {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.pwa-step-n {
  flex: none;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  margin-top: 1px;
  border-radius: 50%;
  background: #ff997b24;
  color: var(--accent, #ff997b);
  font-size: 11px;
  font-weight: 800;
}

.pwa-step strong {
  display: block;
  font-size: 12.5px;
  font-weight: 750;
  color: #f6f2ef;
}

.pwa-step p {
  margin: 3px 0 0;
  font-size: 11.5px;
  line-height: 1.5;
  color: #a29ea6;
}

.pwa-step b { color: #e9e4e0; font-weight: 750; }

.pwa-step-share {
  display: inline-block;
  width: 13px;
  height: 13px;
  margin: 0 1px -2px;
  color: #ffb49c;
}

.pwa-sheet-done { width: 100%; }

/* ── focus, motion, narrow screens ─────────────────────────────────────── */

.pwa-stack button:focus-visible,
.pwa-sheet button:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent, #ff997b) 75%, white);
  outline-offset: 2px;
}

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

@keyframes pwa-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes pwa-pop {
  from { opacity: 0; transform: translateY(14px) scale(0.985); }
  to { opacity: 1; transform: none; }
}

@media (max-width: 650px) {
  /* Bottom sheet on a phone: thumb-reachable, above the home indicator. */
  .pwa-sheet-backdrop { align-items: flex-end; padding-left: 0; padding-right: 0; padding-bottom: 0; }
  .pwa-sheet {
    width: 100%;
    max-height: calc(100dvh - env(safe-area-inset-top, 0px) - 24px);
    padding: 22px 20px calc(22px + env(safe-area-inset-bottom, 0px));
    border-radius: 22px 22px 0 0;
    animation-name: pwa-sheet-up;
  }
}

/* 320px phones: the same row, tightened. The sleeve mark stays (it is what
   makes the row sonora's) and the word "Not now" loses padding, not meaning. */
@media (max-width: 360px) {
  .pwa-banner { gap: 8px; padding: 4px 4px 4px 8px; }
  .pwa-banner-btn { padding: 0 11px; font-size: 11.5px; }
  .pwa-banner-btn.ghost { padding: 0 8px; }
  .pwa-pill { font-size: 11px; }
}

/* Landscape phones: the row is already one line, so it only needs to be
   shorter than the nav it sits above. Both art dimensions move together — a
   sleeve that changes width but not height is a squashed sleeve. */
@media (max-height: 480px) {
  .pwa-banner { padding: 4px 4px 4px 8px; gap: 8px; }
  .pwa-banner-art { width: 22px; height: 22px; }
}

@keyframes pwa-sheet-up {
  from { opacity: 0; transform: translateY(28px); }
  to { opacity: 1; transform: none; }
}

/* ── desktop ─────────────────────────────────────────────────────────────
   Windows and macOS install too: Chromium fires beforeinstallprompt there, and
   an installed PWA gets a Start-menu / Dock entry and a frameless, offline
   window. So the offer is not suppressed at desktop widths — pwa.js simply
   renders it as a one-line notice (.pwa-pill[data-kind="install"]) instead of
   the card, because the card used to sit on top of the sidebar's own buttons
   and the content grid. Declared last so it wins over the base rules above. */
@media (min-width: 1081px) {
  /* Bottom-right, in the corner a desktop notification belongs in: the left
     edge of a wide window is the sidebar's playlist list, which is nothing but
     rows to click, and the centre is where the app's own toasts appear. */
  .pwa-stack {
    align-items: flex-end;
    padding-right: calc(20px + var(--sar, 0px));
  }
  .pwa-pill { align-self: flex-end; }
}

/* On a phone the offer is part of the player stack, not a card on the glass.
   A 54px rounded card floating 148px up the screen covered whatever row was
   under it and read as a second design language. Flush to the edges, on the
   player's own surface, with a hairline instead of a shadow, it docks: the
   eye reads one bottom stack (offer → player → nav) instead of three layers. */
@media (max-width: 650px) {
  .pwa-stack {
    padding-left: 0;
    padding-right: 0;
    gap: 0;
  }
  .pwa-banner {
    width: 100%;
    max-width: none;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    border-bottom: 0;
    padding: 2px 8px 2px var(--gutter, 17px);
    background: var(--panel, #191a1f);
    box-shadow: inset 0 1px var(--line, rgba(255, 255, 255, 0.075));
  }
  /* the band now sits directly on the player, so its own lift is wrong */
  .pwa-banner::after { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .pwa-stack *,
  .pwa-pill,
  .pwa-banner,
  .pwa-sheet,
  .pwa-sheet-backdrop {
    animation: none !important;
    transition: none !important;
  }
}

@media (forced-colors: active) {
  .pwa-pill,
  .pwa-banner,
  .pwa-sheet { border: 1px solid CanvasText; }
  .pwa-banner-btn.primary { background: Highlight; color: HighlightText; }
}
