:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --bg-elev: #ffffff;
  --bg-elev-2: #e9edf2;
  --border: #d6dce3;
  --text: #1c2128;
  --text-dim: #5b636d;
  --accent: #c25e0c;
  --accent-soft: rgba(194, 94, 12, 0.13);
  --accent-contrast: #ffffff; /* text/icon on a filled accent surface */
  --green: #1a7f37;
  --red: #cf222e;
  --yellow: #9a6700;
  --bg-translucent: rgba(244, 246, 248, 0.88);
  --player-bg: rgba(255, 255, 255, 0.96);
  --radius: 12px;
  --shadow: 0 8px 30px rgba(20, 30, 50, 0.12);
  --player-h: 34px; /* single-line status bar, ~= top bar height */
  --tab-h: 22px; /* the view-tabs line above the status bar */
  --bottom-h: calc(var(--player-h) + var(--tab-h)); /* total fixed bottom stack */
  --mono: "Hack", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d1117;
  --bg-elev: #161b22;
  --bg-elev-2: #1c2230;
  --border: #2a3240;
  --text: #e6edf3;
  --text-dim: #8b949e;
  --accent: #f0883e;
  --accent-soft: rgba(240, 136, 62, 0.15);
  --accent-contrast: #1a1205;
  --green: #3fb950;
  --red: #f85149;
  --yellow: #d29922;
  --bg-translucent: rgba(13, 17, 23, 0.85);
  --player-bg: rgba(22, 27, 34, 0.96);
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

html {
  height: 100%;
}

body {
  font-family: var(--mono);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  /* TUI three-row layout: header / scrolling list / fixed bottom bar. The body
     itself never scrolls, so the toolbar can't sit above (overlap) the list. */
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

/* ---------- Toolbar (compact top bar) ---------- */
.toolbar {
  flex: none;
  width: 100%;
  padding: 6px 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  background: var(--bg-translucent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.sort-controls {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.sort-label {
  margin-right: 2px;
  color: var(--text-dim);
  font-size: 0.76rem;
}

.sort-btn[aria-pressed="true"],
.quality-btn[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.btn {
  padding: 2px 8px;
  font-family: var(--mono);
  font-size: 0.76rem;
  color: var(--text);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 2px; /* square boxes, TUI-style */
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}

.btn:hover {
  background: var(--bg-elev-2);
}

.icon-btn {
  padding: 2px 7px;
  line-height: 1;
  font-size: 0.95rem;
}

.btn:focus-visible,
.search-input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.toggle[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.count {
  margin-left: auto;
  color: var(--text-dim);
  font-size: 0.85rem;
  white-space: nowrap;
}

/* ---------- Two-pane layout: sidebar facet filter + station list ---------- */
.main {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
}

.sidebar {
  flex: none;
  width: 210px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--border);
  background: var(--bg);
}

.facet-list {
  list-style: none;
  margin: 0;
  padding: 0 0 calc(var(--bottom-h) + 8px); /* clear the fixed bottom bars */
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  scroll-padding-bottom: calc(var(--bottom-h) + 8px);
}

.facet-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 2px 10px;
  font-size: 0.8rem;
  cursor: pointer;
  white-space: nowrap;
  /* the genre facet can be thousands of rows — skip off-screen layout/paint */
  content-visibility: auto;
  contain-intrinsic-size: auto 22px;
}

.facet-item:hover {
  background: var(--bg-elev-2);
}

.facet-item.is-sel {
  background: var(--bg-elev-2); /* muted while the sidebar is the inactive pane */
}

body[data-pane="facet"] .facet-item.is-sel {
  background: var(--accent);
  color: var(--accent-contrast);
}

.facet-name {
  overflow: hidden;
  text-overflow: ellipsis;
}

.facet-count {
  flex: none;
  color: var(--text-dim);
  font-size: 0.72rem;
}

body[data-pane="facet"] .facet-item.is-sel .facet-count {
  color: var(--accent-contrast);
}

/* ---------- Station list ---------- */
.content {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  position: relative; /* offsetParent for the virtual list's row math */
  width: 100%;
  padding: 6px 12px calc(var(--bottom-h) + 12px);
  /* keep the keyboard cursor clear of the fixed bottom bars when scrolling */
  scroll-padding-bottom: calc(var(--bottom-h) + 8px);
}

.station-list {
  list-style: none;
  margin: 0;
  padding: 0;
  /* Sizer for the virtual list: full scroll height, absolutely-positioned rows. */
  position: relative;
}

.station {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, transform 0.06s;
  box-sizing: border-box;
}

.station:hover {
  background: var(--bg-elev-2);
  border-color: #3a4456;
}

.station:active {
  transform: scale(0.995);
}

.station.is-active {
  border-color: var(--accent);
  background: linear-gradient(90deg, var(--accent-soft), var(--bg-elev));
}

/* Keyboard cursor (comfortable view): an accent focus ring, distinct from the
   playing row's fill. */
.station.is-cursor {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

/* Dim the list cursor while the sidebar is the active pane. */
body[data-pane="facet"] .station.is-cursor {
  border-color: var(--border);
  box-shadow: none;
}

.station-list:focus {
  outline: none;
}

.station-fav-ind {
  flex: none;
  width: 1.1em;
  text-align: center;
  font-size: 1rem;
  line-height: 1;
  color: var(--accent);
}

/* Country code: a dim, right-aligned, monospace 2-letter code. The preceding
   .station-body (flex: 1) pushes it to the right edge of the row. */
.station-cc {
  flex: none;
  margin-left: auto;
  min-width: 1.8em;
  text-align: right;
  font-family: var(--mono);
  font-size: 0.74rem;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  line-height: 1;
  cursor: default;
}

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

.station-name {
  font-weight: 600;
  font-size: 0.98rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.station-sub {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 2px;
  color: var(--text-dim);
  font-size: 0.8rem;
  min-width: 0; /* allow the row to shrink so the genre can ellipsis */
  overflow: hidden;
}

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

.badge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-dim);
}

.badge.quality {
  color: var(--accent);
}

.badge.unverified {
  color: var(--yellow);
  border-color: rgba(210, 153, 34, 0.4);
}

.station-eq {
  flex: none;
  width: 18px;
  height: 16px;
  display: none;
  align-items: flex-end;
  gap: 2px;
}

.station.is-active .station-eq {
  display: flex;
}

.station-eq span {
  width: 3px;
  background: var(--accent);
  border-radius: 2px;
  animation: eq 0.9s ease-in-out infinite;
}

.station-eq span:nth-child(1) { height: 40%; animation-delay: -0.2s; }
.station-eq span:nth-child(2) { height: 90%; animation-delay: -0.5s; }
.station-eq span:nth-child(3) { height: 60%; animation-delay: -0.1s; }

/* Pause the bars when the player is not actively playing.
   (body.is-playing is toggled from app.js.) */
body:not(.is-playing) .station-eq span {
  animation-play-state: paused;
  opacity: 0.55;
}

@keyframes eq {
  0%, 100% { transform: scaleY(0.4); }
  50% { transform: scaleY(1); }
}

.empty-state {
  text-align: center;
  color: var(--text-dim);
  padding: 48px 20px;
  font-size: 0.95rem;
}

.empty-state .empty-msg {
  display: block;
}

/* One-tap escape hatch shown when active filters leave the list empty. */
.empty-clear {
  margin-top: 14px;
}

/* ---------- View tabs (cmus-style), sit just above the status bar ---------- */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: var(--player-h);
  z-index: 20;
  height: var(--tab-h);
  display: flex;
  align-items: stretch;
  padding: 0 6px;
  background: var(--player-bg);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
}

.facet-tab {
  background: none;
  border: 0;
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 0.76rem;
  padding: 0 12px;
  cursor: pointer;
  white-space: nowrap;
}

.facet-tab:hover {
  color: var(--text);
}

.facet-tab.is-active {
  background: var(--accent);
  color: var(--accent-contrast);
  font-weight: 600;
}

/* ---------- Player (single-line bottom bar) ---------- */
.player {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  height: var(--player-h);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 10px;
  background: var(--player-bg);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  box-shadow: var(--shadow);
}

/* Hidden to keep the bar a single line tall. */
.player-art {
  display: none;
}

.player-meta {
  order: 2;
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 10px;
  overflow: hidden;
}

.player-name {
  font-weight: 600;
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 0 1 auto;
}

/* Now-playing track (artist — title), resolved from the station's metadata API.
   No `display` here on purpose: that keeps the [hidden] attribute working when
   there is no track to show. */
.player-track {
  font-size: 0.82rem;
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 0 1 auto;
  min-width: 0;
}

.player-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--text-dim);
  white-space: nowrap;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
}

.player-genre {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Most stations have no network or quality text: drop the empty span so it
   adds no flex gap. */
.player-network:empty,
.player-quality:empty {
  display: none;
}

.player-modes {
  color: var(--accent);
  white-space: nowrap;
  flex: none;
  font-size: 0.74rem;
}

/* Keyboard-only volume, shown as text in the status line (cmus-style). */
.player-vol {
  color: var(--text-dim);
  white-space: nowrap;
  flex: none;
  margin-left: auto;
}

/* cmus-style search line: a bottom-docked input that overlays the player bar
   while searching (Spacebar or / to open, Esc/Enter to leave). */
.search-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  height: var(--player-h);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  background: var(--player-bg);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--accent);
  box-shadow: var(--shadow);
}

.search-bar[hidden] {
  display: none;
}

.search-prompt {
  flex: none;
  color: var(--accent);
  font-weight: 700;
}

.search-input {
  flex: 1 1 auto;
  min-width: 0;
  height: 100%;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.85rem;
}

.search-input::placeholder {
  color: var(--text-dim);
}

/* ---------- High-density (cmus-style) view ---------- */
/* Toggled via <html data-density="compact">. A tight, monospace, table-like
   list with hairline row separators and an inverse-video selection bar. */
[data-density="compact"] .content {
  /* Full-bleed list in compact mode: edge-to-edge, no surrounding inset. The
     bottom value is scroll clearance for the fixed bars, not a visual margin. */
  padding: 0 0 calc(var(--bottom-h) + 12px);
}

[data-density="compact"] .station-list {
  /* Full-bleed table: no outer frame or rounding. Rows keep their hairline
     border-bottom separators and their own inner padding. */
  font-family: var(--mono);
}

[data-density="compact"] .station {
  border: 0;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  padding: 2px 10px;
  gap: 8px;
  font-size: 0.83rem;
  background: var(--bg-elev);
}

[data-density="compact"] .station.row-alt {
  background: var(--bg); /* subtle zebra striping (by absolute row index) */
}

[data-density="compact"] .station:hover {
  background: var(--bg-elev-2);
}

[data-density="compact"] .station.is-last {
  border-bottom: 0;
}

/* Name + meta collapse onto a single line with the meta right-aligned. */
[data-density="compact"] .station-body {
  display: flex;
  align-items: baseline;
  gap: 14px;
  min-width: 0;
}

[data-density="compact"] .station-name {
  flex: 1 1 auto;
  font-weight: 500;
}

[data-density="compact"] .station-sub {
  margin-top: 0;
  flex: 0 1 auto;
  font-size: 0.78rem;
}

[data-density="compact"] .station-fav-ind {
  width: 1em;
  font-size: 0.9rem;
}

[data-density="compact"] .badge {
  padding: 0 5px;
}

[data-density="compact"] .station-eq {
  display: none !important;
}

/* cmus cursor = inverse-video selection bar (the row you've moved to). */
[data-density="compact"] .station.is-cursor,
[data-density="compact"] .station.is-cursor:hover {
  background: var(--accent);
  color: var(--accent-contrast);
}

[data-density="compact"] .station.is-cursor .station-sub,
[data-density="compact"] .station.is-cursor .station-fav-ind,
[data-density="compact"] .station.is-cursor .station-cc {
  color: var(--accent-contrast);
}

/* Sidebar active → dim the list's compact cursor to a neutral bar. */
[data-density="compact"] body[data-pane="facet"] .station.is-cursor,
[data-density="compact"] body[data-pane="facet"] .station.is-cursor:hover {
  background: var(--bg-elev-2);
  color: var(--text);
}

[data-density="compact"] body[data-pane="facet"] .station.is-cursor .station-sub,
[data-density="compact"] body[data-pane="facet"] .station.is-cursor .station-fav-ind,
[data-density="compact"] body[data-pane="facet"] .station.is-cursor .station-cc {
  color: inherit;
}

[data-density="compact"] .station.is-cursor .badge {
  color: var(--accent-contrast);
  border-color: rgba(255, 255, 255, 0.45);
  background: rgba(255, 255, 255, 0.12);
}

/* Currently-PLAYING station = ▶ marker + accent name (cmus shows the playing
   track distinctly from the cursor). */
[data-density="compact"] .station.is-active .station-name::before {
  content: "▶ ";
  font-size: 0.8em;
}

[data-density="compact"] .station.is-active:not(.is-cursor) .station-name {
  color: var(--accent);
  font-weight: 600;
}

/* ---------- Responsive ---------- */
@media (max-width: 520px) {
  .sidebar {
    display: none; /* reclaim width on very small screens; use search instead */
  }
}

@media (max-width: 680px) {
  /* Keep the bar a single line; just tighten it and hide the mode flags. */
  .player {
    gap: 6px;
    padding: 0 8px;
  }
  .player-modes {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}

/* ---------- Help modal (keyboard shortcuts) ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(2px);
}

.modal[hidden] {
  display: none;
}

.modal-card {
  width: min(700px, 100%);
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.modal-body {
  padding: 12px 16px;
  overflow: auto;
}

.modal-foot {
  padding: 8px 16px;
  border-top: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 0.8rem;
}

.help-groups {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 6px 24px;
}

.help-group {
  margin: 0 0 10px;
  break-inside: avoid;
}

.help-group h3 {
  margin: 0 0 6px;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
}

.help-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 2px 0;
  font-size: 0.85rem;
}

.help-keys {
  flex: 0 0 116px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.help-desc {
  color: var(--text);
}

.help-na .help-desc {
  color: var(--text-dim);
  font-style: italic;
}

kbd {
  font-family: var(--mono);
  font-size: 0.76rem;
  line-height: 1.4;
  padding: 1px 6px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  color: var(--text);
  white-space: nowrap;
}

/* ---------- Saved songs ---------- */
/* The ♡ / ♥ next to the now-playing track. No `display` so [hidden] works. */
.song-save {
  flex: none;
  align-self: center;
  padding: 0 4px;
  font-family: var(--mono);
  font-size: 0.95rem;
  line-height: 1;
  color: var(--text-dim);
  background: none;
  border: 0;
  cursor: pointer;
}

.song-save:hover,
.song-save.is-saved {
  color: var(--accent);
}

.song-save:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

#songs-btn[aria-pressed="true"],
#history-btn[aria-pressed="true"],
#history-filter[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.songs-count {
  color: var(--text-dim);
  font-weight: 400;
  font-size: 0.8rem;
}

.songs-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.song-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 12px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
}

.song-row.is-cursor {
  background: var(--accent-soft);
  box-shadow: inset 2px 0 0 var(--accent);
}

/* The cursor row takes keyboard focus (j/k); the highlight above already marks
   it, so only show a ring for keyboard focus. */
.song-row:focus {
  outline: none;
}

.song-row:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.song-main {
  flex: 1 1 220px;
  min-width: 0;
}

.song-title {
  font-size: 0.88rem;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.song-sub {
  font-size: 0.76rem;
  color: var(--text-dim);
  overflow-wrap: anywhere;
}

.song-acts {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

a.song-act {
  text-decoration: none;
}

/* Play history: header tools, and the per-row ♥ (filled when saved). */
.history-tools {
  display: flex;
  align-items: center;
  gap: 6px;
}

.song-act.song-heart {
  min-width: 2.2em;
  color: var(--text-dim);
}

.song-act.song-heart.is-saved {
  color: var(--accent);
}

.songs-empty {
  margin: 8px 0;
  color: var(--text-dim);
  font-size: 0.85rem;
}

html[data-mobile] .song-save {
  min-width: 44px;
  min-height: 44px;
  font-size: 1.2rem;
}

html[data-mobile] .song-act {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 6px 10px;
  font-size: 0.85rem;
}

body.modal-open {
  overflow: hidden;
}

/* ---------- Mobile (touch devices) ----------
   Opt-in via <html data-mobile="1">, set by the inline head script from the user
   agent (NOT the viewport width). Desktop never matches these rules, so the
   keyboard-driven desktop UX is left completely untouched.

   Mobile-only controls are hidden everywhere by default; the rules further down
   reveal them only when data-mobile is present. */
#search-tab,
#facet-backdrop,
.facet-overlay-head,
.facet-overlay-search,
#search-close {
  display: none;
}

html[data-mobile] {
  /* Roomier bottom bars for touch — cascades into --bottom-h and its calcs. */
  --player-h: 48px;
  --tab-h: 46px;
}

/* The dense compact view is desktop-only: hide its toggle (it can't be reached
   any other way on mobile, since there's no keyboard). */
html[data-mobile] #density-toggle {
  display: none;
}

/* The "1 / 2 / 6" keyboard hints on the view tabs mean nothing without a keyboard. */
html[data-mobile] .tab-key {
  display: none;
}

/* ----- Bottom nav: Genre | Country | Network | Search as finger-sized targets ----- */
html[data-mobile] .tabbar {
  padding: 0;
}

html[data-mobile] .facet-tab,
html[data-mobile] #search-tab {
  flex: 1 1 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 100%;
  border: 0;
  border-right: 1px solid var(--border);
  background: none;
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 0.9rem;
  cursor: pointer;
}

html[data-mobile] #search-tab {
  border-right: 0;
}

/* A small caret hints the category tabs open a sheet (search has none). */
html[data-mobile] .facet-tab::after {
  content: "▴";
  font-size: 0.7em;
  opacity: 0.7;
}

html[data-mobile] .facet-tab.is-active {
  background: var(--accent);
  color: var(--accent-contrast);
}

/* ----- Category picker: the left facet pane, surfaced as a bottom sheet ----- */
/* Not shown inline on mobile; opened on demand by the Genre / Country / Network tabs. */
html[data-mobile] .sidebar {
  display: none;
}

html[data-mobile] body[data-overlay="facet"] .sidebar {
  display: flex;
  position: fixed;
  left: 0;
  right: 0;
  bottom: var(--bottom-h); /* float just above the nav + player stack */
  top: auto;
  width: auto;
  max-height: 60vh;
  z-index: 25;
  border-right: 0;
  border-top: 1px solid var(--border);
  border-radius: 12px 12px 0 0;
  background: var(--bg-elev);
  box-shadow: var(--shadow);
  overflow: hidden;
}

html[data-mobile] body[data-overlay="facet"] #facet-backdrop {
  display: block;
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  bottom: var(--bottom-h); /* leave the nav bar uncovered so tabs stay tappable */
  z-index: 22;
  background: rgba(0, 0, 0, 0.45);
}

html[data-mobile] .facet-overlay-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex: none;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}

html[data-mobile] .facet-overlay-head strong {
  font-size: 0.95rem;
}

html[data-mobile] .facet-overlay-search {
  display: block;
  flex: none;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}

html[data-mobile] #facet-filter {
  width: 100%;
  padding: 8px 10px;
  font-family: var(--mono);
  /* 16px: iOS Safari auto-zooms the page when a focused field's font is < 16px.
     Keeping the on-screen text inputs at 16px stops that focus-zoom while still
     allowing pinch-zoom (unlike a user-scalable=no viewport). */
  font-size: 16px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  outline: none;
}

/* Same 16px floor for the cmus-style search line, so tapping it on mobile
   doesn't zoom the page. */
html[data-mobile] .search-input {
  font-size: 16px;
}

html[data-mobile] #facet-filter:focus-visible {
  border-color: var(--accent);
}

/* Bigger facet rows for touch; drop the desktop bottom clearance (the sheet
   already floats above the nav bar). */
html[data-mobile] .facet-list {
  padding: 4px 0 8px;
  scroll-padding-bottom: 8px;
}

html[data-mobile] .facet-item {
  padding: 10px 14px;
  font-size: 0.92rem;
  contain-intrinsic-size: auto 40px;
}

html[data-mobile] .facet-count {
  font-size: 0.8rem;
}

/* Bigger tap target for the empty-state clear button on touch. */
html[data-mobile] .empty-clear {
  min-height: 44px;
  padding: 0 16px;
  font-size: 0.95rem;
}

/* ----- Search line: a cancel button (no Esc key on a touch device) ----- */
/* Both ✕ dismissal controls get a >=44px touch target (the .icon-btn padding
   alone is only ~20px tall, below the comfortable-tap minimum). */
html[data-mobile] #search-close,
html[data-mobile] #facet-overlay-close,
html[data-mobile] #songs-close,
html[data-mobile] #history-close,
html[data-mobile] #history-filter,
html[data-mobile] #history-clear {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  min-width: 44px;
  min-height: 44px;
}

/* ----- Swipe-to-favorite (touch): a reveal-behind action surface -----
   One shared layer the swipe handler drops behind the dragged row; the row
   slides right to uncover it. Only ever inserted on touch devices (app.js),
   so the rules below are inert on desktop. */
.station-swipe-action {
  position: absolute;
  left: 0;
  right: 0;
  display: none; /* the handler flips this to flex while a swipe is live */
  align-items: center;
  gap: 10px;
  padding-left: 26px;
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.95rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  pointer-events: none; /* never intercept a touch / become a click target */
}

.station-swipe-action .swipe-star {
  font-size: 1.35rem;
  line-height: 1;
  transition: transform 0.1s ease;
}

/* Past the commit threshold: a solid accent fill and a pop on the star. */
.station-swipe-action.is-armed {
  background: var(--accent);
  color: var(--accent-contrast);
}

.station-swipe-action.is-armed .swipe-star {
  transform: scale(1.3);
}

/* Already-favorited row: the swipe will REMOVE it — neutral, arming to red. */
.station-swipe-action.is-remove {
  background: var(--bg-elev-2);
  color: var(--text-dim);
}

.station-swipe-action.is-remove.is-armed {
  background: var(--red);
  color: #fff;
}

/* Pan vertically (scroll) natively while horizontal drags are handed to JS. */
html[data-mobile] .station {
  touch-action: pan-y;
}

/* ---------- Quality picker (w): four multi-select toggles ---------- */
.quality-modal .modal-card {
  width: min(460px, 100%);
}

.quality-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 4px;
}

.quality-option {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.quality-option[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.quality-option:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* Checkbox-style tick, filled when the option is ticked. */
.quality-check {
  flex: none;
  width: 1.1em;
  height: 1.1em;
  border: 1px solid var(--text-dim);
  border-radius: 4px;
  display: grid;
  place-items: center;
  font-size: 0.8rem;
  line-height: 1;
}

.quality-option[aria-pressed="true"] .quality-check {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-contrast);
}

.quality-option[aria-pressed="true"] .quality-check::after {
  content: "✓";
}

.quality-option-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.quality-hint {
  color: var(--text-dim);
  font-size: 0.8rem;
}

html[data-mobile] .quality-option {
  min-height: 44px;
}
