:root {
  --bg: #0a0a0a;
  --card: #161616;
  --card2: #1f1f1f;
  --line: #272727;
  --text: #f3f3f0;
  --dim: #9b9b95;
  --accent: #ffdb4d;
  --accent-down: #efc93a;
  --ink: #0a0a0a;
  --r: 14px;
  --gap: clamp(6px, 1.6vh, 12px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html {
  color-scheme: dark;
  height: 100%;
  /* app feel: no double-tap zoom, no edge rubber-banding */
  touch-action: manipulation;
  overscroll-behavior: none;
}

body {
  /* fixed pins the document — kills iOS body rubber-band in standalone;
     left/right + margin auto keep the 480px column centered */
  position: fixed;
  inset: 0;
  margin: 0 auto;
  max-width: 480px;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
  font-family: "Golos Text", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.35;
  -webkit-text-size-adjust: 100%;
  user-select: none;
  -webkit-user-select: none;
  padding: calc(env(safe-area-inset-top, 0px) + 8px)
           calc(env(safe-area-inset-right, 0px) + 16px)
           calc(env(safe-area-inset-bottom, 0px) + 12px)
           calc(env(safe-area-inset-left, 0px) + 16px);
}

input { user-select: text; -webkit-user-select: text; }

[hidden] { display: none !important; }

/* ---- header ---- */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 2px 10px;
  flex: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: .2px;
}

.logo {
  width: 20px;
  height: 20px;
  border-radius: 6px;
  background: var(--accent);
  position: relative;
  flex: none;
}
.logo::after {
  content: "";
  position: absolute;
  left: 7.5px;
  top: 5px;
  border-style: solid;
  border-width: 5px 0 5px 8px;
  border-color: transparent transparent transparent var(--ink);
}

.agent {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: var(--dim);
  max-width: 55%;
}
#agent-label { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
body[data-screen="pair"] .agent { visibility: hidden; }

.conn-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #555;
  flex: none;
  transition: background .2s ease;
}
.conn-dot.ok { background: #3ddc6c; }
.conn-dot.connecting { background: var(--accent); animation: blink 1s ease-in-out infinite; }
.conn-dot.down { background: #e5484d; }
@keyframes blink { 50% { opacity: .35; } }

/* ---- buttons ---- */
button {
  font: inherit;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r);
  min-height: 48px;
  padding: 6px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  cursor: pointer;
  position: relative;
  touch-action: manipulation;
  transition: transform .12s ease, background-color .15s ease, border-color .15s ease, opacity .2s ease;
}
button:active { transform: scale(.95); background: var(--card2); }
button:disabled { opacity: .5; }

button.accent {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--ink);
  font-weight: 700;
}
button.accent:active { background: var(--accent-down); }

.svgi { width: 24px; height: 24px; display: block; pointer-events: none; }
.ico { font-size: 19px; line-height: 1; }
.lbl { font-size: 11px; line-height: 1; color: var(--dim); }
button.accent .lbl { color: var(--ink); }

/* pending cmd spinner */
button.pending > * { opacity: .3; }
button.pending::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  top: calc(50% - 9px);
  left: calc(50% - 9px);
  border: 2px solid var(--accent);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
button.accent.pending::after { border-color: var(--ink); border-top-color: transparent; }
@keyframes spin { to { transform: rotate(1turn); } }

/* ---- pairing screen ---- */
#screen-pair {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-top: 9vh;
  overflow-y: auto;
}

.pair-logo {
  width: 72px;
  height: 72px;
  margin: 0 auto 4px;
  border-radius: 20px;
  background: var(--accent);
  position: relative;
  box-shadow: 0 10px 44px rgba(255, 219, 77, .22);
  flex: none;
}
.pair-logo::after {
  content: "";
  position: absolute;
  left: 29px;
  top: 21px;
  border-style: solid;
  border-width: 15px 0 15px 24px;
  border-color: transparent transparent transparent var(--ink);
}

#screen-pair h1 { margin: 0; font-size: 21px; text-align: center; }

.pair-text {
  margin: 0;
  text-align: center;
  font-size: 14.5px;
  line-height: 1.55;
  color: var(--dim);
}

#pair-input {
  height: 52px;
  padding: 0 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r);
  color: var(--text);
  font-size: 14px;
  outline: none;
  width: 100%;
}
#pair-input:focus { border-color: rgba(255, 219, 77, .55); }
#pair-input::placeholder { color: #6e6e68; }

#btn-pair { width: 100%; font-size: 16px; flex: none; }

#pair-status {
  min-height: 20px;
  text-align: center;
  font-size: 14px;
  color: var(--accent);
}

.pair-hint {
  margin: 2px 4px 0;
  padding: 12px 14px;
  background: rgba(255, 219, 77, .07);
  border: 1px solid rgba(255, 219, 77, .25);
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--dim);
}

/* ---- remote: fills the viewport, no scroll ---- */
#screen-remote {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

/* ---- search row ---- */
.searchrow { display: flex; gap: 8px; flex: none; }

#q {
  flex: 1;
  min-width: 0;
  height: 46px;
  padding: 0 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r);
  color: var(--text);
  font-size: 16px;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
}
#q:focus { border-color: rgba(255, 219, 77, .55); }
#q::placeholder { color: #6e6e68; }
#q::-webkit-search-cancel-button { display: none; }

#btn-track { width: 46px; min-height: 46px; flex: none; padding: 0; }
#btn-track .svgi { width: 22px; height: 22px; }
#btn-search { flex: none; min-height: 46px; padding: 0 15px; font-size: 14px; font-weight: 500; color: var(--text); }

/* ---- results: dropdown OVER the cover, layout never jumps ---- */
/* zero-height anchor would double the section gap — collapse it */
.results-anchor { position: relative; flex: none; margin-top: calc(-1 * var(--gap)); }

#results {
  position: absolute;
  top: 6px;
  left: 0;
  right: 0;
  z-index: 30;
  max-height: 52vh;
  overflow-y: auto;
  padding: 10px;
  /* lighter than resting cards: floats ABOVE them; translucent so blur reads */
  background: rgba(31, 31, 31, .88);
  border: 1px solid rgba(255, 255, 255, .09);
  border-radius: var(--r);
  box-shadow: 0 18px 50px rgba(0, 0, 0, .6);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  animation: dropin .18s ease;
}
@keyframes dropin { from { opacity: 0; transform: translateY(-6px); } }

.alt-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 2px 6px;
}
.alt-label { font-size: 12px; color: var(--dim); }
.alt-close {
  min-height: 0;
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 50%;
  background: transparent;
  border-color: transparent;
  color: var(--dim);
  font-size: 14px;
}

.list-close {
  width: 100%;
  min-height: 44px;
  margin-top: 8px;
  background: transparent;
  border-color: var(--line);
  color: var(--dim);
  font-size: 13.5px;
}

.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
  /* edge fade = "this scrolls" affordance */
  -webkit-mask-image: linear-gradient(90deg, #000 0, #000 calc(100% - 28px), transparent);
  mask-image: linear-gradient(90deg, #000 0, #000 calc(100% - 28px), transparent);
}
.chips::-webkit-scrollbar { display: none; }

.chip {
  flex: none;
  max-width: 75%;
  min-height: 46px;
  padding: 6px 16px;
  border-radius: 24px;
  font-size: 13.5px;
}
.chip > span {
  display: block;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.list { display: flex; flex-direction: column; gap: 8px; }
.list-row { display: flex; gap: 8px; }

.list-main {
  flex: 1;
  min-width: 0;
  align-items: flex-start;
  text-align: left;
  gap: 2px;
  padding: 8px 14px;
}
.list-title {
  font-size: 14.5px;
  font-weight: 600;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.list-artists {
  font-size: 12.5px;
  color: var(--dim);
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.list-queue { flex: none; width: 50px; color: var(--dim); }

/* ---- cover: hero, flexes with free height ---- */
.coverwrap {
  flex: 1 1 auto;
  min-height: 110px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#cover {
  position: relative;
  height: 100%;
  max-height: min(340px, 100%);
  aspect-ratio: 1;
  max-width: 100%;
  border-radius: 18px;
  overflow: hidden;
  background:
    radial-gradient(120% 120% at 20% 10%, #1d1d1d 0%, #141414 55%, #101010 100%);
  box-shadow: 0 14px 48px rgba(0, 0, 0, .55);
}

#cover .ph {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(40px, 9vh, 64px);
  color: #2d2d2d;
}

#cover img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity .4s ease;
}
#cover img.show { opacity: 1; }

.dot {
  position: absolute;
  top: 10px;
  left: 10px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #5c5c5c;
  box-shadow: 0 0 0 4px rgba(10, 10, 10, .5);
  transition: background .2s ease;
  z-index: 2;
}
.dot.playing { background: var(--accent); animation: pulse 2.2s ease-in-out infinite; }
.dot.paused { background: #8d8d87; }
@keyframes pulse {
  50% { box-shadow: 0 0 0 4px rgba(10, 10, 10, .5), 0 0 14px 3px rgba(255, 219, 77, .4); }
}

#time {
  position: absolute;
  right: 12px;
  bottom: 14px;
  z-index: 2;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  letter-spacing: .2px;
  padding: 3px 9px;
  border-radius: 99px;
  background: rgba(8, 8, 8, .62);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

/* progress: embedded in the cover's bottom edge, scaleX for buttery motion */
.progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 4px;
  z-index: 2;
  background: rgba(255, 255, 255, .14);
  transition: height .24s cubic-bezier(.2, .8, .2, 1);
}
#progress-fill {
  height: 100%;
  width: 100%;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
  transform-origin: left;
  transform: scaleX(0);
  transition: transform .5s linear;
  box-shadow: 0 0 10px rgba(255, 219, 77, .35);
}
#progress-fill.jump { transition: none; }

/* ---- scrubbing: hold the bar, it swells, big time takes the cover ---- */
#seekzone {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 34px;          /* finger-sized hit area over a 4px bar */
  z-index: 4;
  touch-action: none;    /* no scroll/zoom stealing mid-scrub */
  cursor: pointer;
}
#cover.scrubbing .progress {
  height: 12px;
  background: rgba(255, 255, 255, .22);
}
#cover.scrubbing #progress-fill {
  transition: none;      /* the bar must glue to the finger, not ease after it */
  box-shadow: 0 0 18px rgba(255, 219, 77, .55);
}
.scrub-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  background: linear-gradient(180deg, rgba(8, 8, 8, 0) 14%, rgba(8, 8, 8, .68) 100%);
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s ease;
}
#cover.scrubbing .scrub-overlay { opacity: 1; }
#scrub-pos {
  font-size: clamp(30px, 5.6vh, 42px);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: .5px;
  text-shadow: 0 2px 18px rgba(0, 0, 0, .75);
}
#scrub-dur {
  font-size: 15px;
  color: rgba(243, 243, 240, .72);
  font-variant-numeric: tabular-nums;
  padding-top: 16px;
}
#time, .dot { transition: opacity .18s ease; }
#cover.scrubbing #time, #cover.scrubbing .dot { opacity: 0; }

/* ---- now playing: marquee for overflow ---- */
.nowplaying { flex: none; padding: 0; }

.mq {
  overflow: hidden;
  white-space: nowrap;
  text-align: center;
}
/* fade mask only while scrolling — static titles keep their edge glyphs intact */
.mq.scroll {
  -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 14px, #000 calc(100% - 14px), transparent 100%);
  mask-image: linear-gradient(90deg, transparent 0, #000 14px, #000 calc(100% - 14px), transparent 100%);
}
.mq-in {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: bottom;
}
.mq.scroll .mq-in {
  max-width: none;
  overflow: visible;
  text-overflow: clip;
  padding: 0 14px;
  animation: mq var(--mq-dur, 12s) ease-in-out var(--mq-delay, 1.2s) infinite alternate;
}
@keyframes mq {
  0%, 12% { transform: translateX(0); }
  88%, 100% { transform: translateX(var(--mq-shift, -40px)); }
}

#title {
  font-size: clamp(15px, 2.4vh, 17.5px);
  font-weight: 650;
  min-height: 1.4em;
}
#artist {
  font-size: clamp(12.5px, 2vh, 14px);
  color: var(--dim);
  min-height: 1.4em;
}

/* ---- control rows ---- */
.row { display: grid; gap: 8px; flex: none; }
.row.r3 { grid-template-columns: repeat(3, 1fr); }
.row.r4 { grid-template-columns: repeat(4, 1fr); }

/* transport: round prev/next, big accent toggle */
.transport {
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  justify-items: center;
  padding: 0 18px;
}
.transport button {
  width: clamp(52px, 8.4vh, 60px);
  height: clamp(52px, 8.4vh, 60px);
  min-height: 0;
  padding: 0;
  border-radius: 50%;
  background: transparent;
  border-color: transparent;
}
.transport button:active { background: var(--card); }
.transport button.big {
  width: clamp(64px, 10.5vh, 76px);
  height: clamp(64px, 10.5vh, 76px);
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 8px 26px rgba(255, 219, 77, .25);
}
.transport button.big:active { background: var(--accent-down); transform: scale(.94); }
.transport .svgi { width: 26px; height: 26px; }
.transport .big .svgi { width: 30px; height: 30px; }

.reacts button { min-height: clamp(48px, 7.4vh, 54px); }
.reacts .svgi { width: 24px; height: 24px; }

/* vibe row belongs to the reacts cluster — pull it closer; tonal emoji to match
   the monochrome icon set */
.row.vibe { margin-top: calc(var(--gap) * -.4); }
.row.vibe button { padding: 6px 2px; min-height: clamp(46px, 7vh, 52px); }
.row.vibe .ico { font-size: 18px; filter: grayscale(1) brightness(1.4); opacity: .92; }
.row.vibe .lbl { font-size: 11px; letter-spacing: .15px; }

#btn-like.on { border-color: rgba(255, 219, 77, .65); background: rgba(255, 219, 77, .09); }
#btn-like.on .like-outline { fill: var(--accent); stroke: var(--accent); }
#btn-like.on .svgi { color: var(--accent); }
#btn-like.on .lbl { color: var(--accent); opacity: .85; }

/* ---- volume: mute speaker + slider + % ---- */
/* a separate cluster from the reacts/vibe block — give it air */
.volrow {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0;
  margin-top: calc(var(--gap) * .4);
}

#btn-mute {
  width: 48px;
  height: 48px;
  min-height: 0;
  flex: none;
  padding: 0;
  border-radius: 50%;
  background: transparent;
  border-color: transparent;
  color: var(--dim);
}
#btn-mute:active { background: var(--card); }
#btn-mute .sp-cross { display: none; }
/* red, not accent: yellow means "active" everywhere else on this screen */
#btn-mute.muted { color: #e5484d; }
#btn-mute.muted .sp-waves { display: none; }
#btn-mute.muted .sp-cross { display: block; }

body.muted-vol #vol { opacity: .4; }

#vol {
  flex: 1;
  min-width: 0;
  height: 48px;
  margin: 0;
  background: transparent;
  appearance: none;
  -webkit-appearance: none;
}
#vol::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 3px;
  background: #2a2a2a;
}
#vol::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 24px;
  height: 24px;
  margin-top: -9px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 2px 10px rgba(0, 0, 0, .55);
}
#vol::-moz-range-track { height: 6px; border-radius: 3px; background: #2a2a2a; }
#vol::-moz-range-thumb { width: 24px; height: 24px; border: none; border-radius: 50%; background: var(--accent); }

#vol-pct {
  flex: none;
  width: 42px;
  text-align: right;
  font-size: 12.5px;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
}

/* ---- agent offline overlay ---- */
#overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 24px;
  text-align: center;
  background: rgba(8, 8, 8, .74);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.ov-title { font-size: 20px; font-weight: 700; }
.ov-title::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #e5484d;
  margin-right: 10px;
  vertical-align: 1px;
}
.ov-hint { font-size: 13.5px; color: var(--dim); line-height: 1.5; }

/* ---- proto banner (terminal: reload required) ---- */
#banner {
  position: fixed;
  left: 50%;
  top: calc(env(safe-area-inset-top, 0px) + 10px);
  transform: translateX(-50%);
  z-index: 70;
  max-width: min(440px, 92vw);
  padding: 12px 18px;
  background: var(--accent);
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  border-radius: 12px;
  box-shadow: 0 10px 34px rgba(0, 0, 0, .5);
}

/* ---- toast ---- */
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 24px);
  transform: translate(-50%, 12px);
  z-index: 60;
  max-width: min(420px, 88vw);
  padding: 11px 16px;
  background: #1d1d1d;
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 14px;
  text-align: center;
  box-shadow: 0 8px 28px rgba(0, 0, 0, .55);
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s ease, transform .22s ease;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* very short screens: shave the chrome, keep the controls */
@media (max-height: 620px) {
  header { padding-bottom: 6px; }
  .nowplaying #artist { display: none; }
  .row.vibe .lbl { display: none; }
  .row.vibe .ico { font-size: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
  .mq.scroll .mq-in { animation: none !important; }
}
