/* Deck: a terminal-style car player. Rules: every target is big (rows 88px, buttons 76px+),
   everything is always visible (no drawers, menus or overlays), and nothing blocks the screen. */
:root {
  --bg: #0e0e10;
  --raise: #18181b;
  --press: #2a2633;
  --line: #3f3f46;
  --rowline: #222226;
  --text: #ececec;
  --dim: #9a9aa2;
  --accent: #a78bfa;
  --accent-bg: #1c1730;
  --accent-line: #7c5cff;
  --green: #4ade80;
  --green-dim: #2c6b43;
  --red: #f87171;
  --row: 88px;
  --btn: 76px;
  --rail: 128px;
  --font: "JetBrains Mono", "SF Mono", Menlo, "DejaVu Sans Mono", "Liberation Mono", Consolas, monospace;
  color-scheme: dark;
}

/* Day: the same terminal look, light, for bright sunlight. Picked by the Auto/Day/Night setting. */
html[data-theme="day"] {
  --bg: #f5f5f2;
  --raise: #e8e8e4;
  --press: #ddd6fb;
  --line: #b4b4bc;
  --rowline: #dededa;
  --text: #141417;
  --dim: #55555f;
  --accent: #6d28d9;
  --accent-bg: #ece5ff;
  --accent-line: #7c3aed;
  --green: #15803d;
  --green-dim: #9fcbae;
  --red: #dc2626;
  color-scheme: light;
}
html[data-theme="day"] #q::-webkit-search-cancel-button { filter: none; }
html[data-theme="day"] #scrub { box-shadow: 0 -10px 40px #0003; }

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 20px/1.3 var(--font);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}
button, input { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; touch-action: manipulation; }
svg { width: 32px; height: 32px; fill: currentColor; display: block; flex: none; }
[hidden] { display: none !important; }
.box { border: 1px solid var(--line); border-radius: 6px; min-width: 0; min-height: 0; position: relative; }

/* ---------- frame: rail | right column ---------- */
#app {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-columns: var(--rail) minmax(0, 1fr);
  gap: 10px;
  padding: 8px;
}
#right {
  position: relative;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 10px;
  min-width: 0;
  min-height: 0;
  container: right / inline-size;
}
body.on-now #browse { display: none; }
#browse, #now { grid-row: 1; }
#bar { grid-row: 2; }
#now { display: none; }
body.on-now #now { display: grid; }

/* ---------- rail: always visible, one tap to any section ---------- */
#rail { display: flex; flex-direction: column; gap: 8px; min-height: 0; }
#rail button {
  flex: 1 1 0;
  min-height: 64px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 15px;
  letter-spacing: .02em;
}
#rail svg { width: 36px; height: 36px; }
#rail button.on { border-color: var(--accent-line); color: var(--accent); background: var(--accent-bg); font-weight: 700; }
#rail button:active, .btn:active, .controls button:active, .pager button:active, .row:active {
  background: var(--press);
}

/* ---------- browse ---------- */
#browse { display: flex; flex-direction: column; overflow: hidden; }
#head {
  display: flex; align-items: center; gap: 10px; padding: 10px 10px 8px; min-height: 96px; flex-wrap: wrap;
  border-bottom: 1px solid var(--rowline);
}
#head .htitle {
  flex: 1 1 12ch; min-width: 0; font-size: 24px; font-weight: 700; padding: 0 8px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#head .htitle .dim { font-weight: 400; color: var(--dim); }
.btn {
  min-height: var(--btn); min-width: var(--btn); padding: 0 22px; border: 1px solid var(--line); border-radius: 6px;
  display: inline-flex; align-items: center; justify-content: center; gap: 10px; white-space: nowrap; flex: none;
}
.btn svg { width: 28px; height: 28px; }
.btn.primary { border-color: var(--accent-line); color: var(--accent); font-weight: 700; }
.btn.danger { border-color: var(--red); color: var(--red); }
.btn.on { border-color: var(--accent-line); color: var(--accent); background: var(--accent-bg); font-weight: 700; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px; border-bottom: 1px solid var(--rowline); }
.chips .btn { min-height: 64px; padding: 0 18px; flex: 1 0 auto; }
#searchbox { border-bottom: 1px solid var(--rowline); }
#searchbox .chips { border-bottom: 0; padding-top: 0; }
#q {
  display: block; width: calc(100% - 20px); margin: 10px; height: var(--btn); padding: 0 18px;
  background: var(--raise); border: 1px solid var(--accent-line); border-radius: 6px; outline: 0; font-size: 22px;
  -webkit-user-select: text; user-select: text;
}
#q::-webkit-search-cancel-button { filter: invert(1); height: 28px; width: 28px; }

/* A list with big page buttons beside it, so nobody has to aim a scroll. */
.scroller { flex: 1; display: flex; min-height: 0; }
.list { flex: 1; min-width: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.pager { width: 92px; flex: none; display: flex; flex-direction: column; gap: 8px; padding: 8px; }
.pager button { flex: 1; border: 1px solid var(--line); border-radius: 6px; display: grid; place-items: center; }
.pager button svg { width: 40px; height: 40px; }
.pager button:disabled { opacity: .25; }

.row {
  display: flex; align-items: center; gap: 18px; min-height: var(--row); padding: 10px 18px 10px 14px;
  border-bottom: 1px solid var(--rowline); border-left: 5px solid transparent; cursor: pointer;
  content-visibility: auto; contain-intrinsic-size: auto var(--row);
}
.row .thumb {
  width: 66px; height: 66px; flex: none; object-fit: cover; border-radius: 3px; background: var(--raise);
  image-rendering: pixelated;
}
.row .no { width: 66px; flex: none; text-align: center; color: var(--dim); font-size: 22px; }
.row .no svg { margin: 0 auto; width: 34px; height: 34px; color: var(--accent); }
.row .txt { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.row .t, .row .s { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .t { font-size: 22px; }
.row .s { font-size: 17px; color: var(--dim); }
.row .end { flex: none; color: var(--dim); font-size: 19px; text-align: right; font-variant-numeric: tabular-nums; }
.row.on { border-left-color: var(--accent-line); background: var(--accent-bg); color: var(--accent); }
.row.on .t { font-weight: 700; }
.row.on .s, .row.on .end { color: var(--accent); opacity: .85; }
.row.done { opacity: .6; }
.empty { padding: 34px 28px; color: var(--dim); white-space: pre-line; line-height: 1.6; font-size: 20px; }

/* ---------- compact player bar ---------- */
/* Controls first: on the left, closest to the driver. */
#bar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-areas: "controls meta cover";
  align-items: center;
  gap: 18px;
  padding: 10px 10px 10px 12px;
}
.cover { background: var(--raise); object-fit: cover; image-rendering: pixelated; border-radius: 4px; cursor: pointer; }
#bar-cover { grid-area: cover; width: 96px; height: 96px; }
#bar-meta { grid-area: meta; }
#bar-controls { grid-area: controls; }
.meta { min-width: 0; cursor: pointer; display: flex; flex-direction: column; gap: 4px; }
.title { color: var(--accent); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sub { color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sub.status { color: var(--green); }
#bar-title { font-size: 22px; }
#bar-sub { font-size: 17px; }
.prog { position: relative; overflow: hidden; white-space: pre; color: var(--green-dim); font-variant-numeric: tabular-nums; }
.prog .done { color: var(--green); }
.prog.busy { color: var(--accent); }
.prog .measure { position: absolute; visibility: hidden; }
#bar-prog { font-size: 15px; padding: 10px 0; margin: -8px 0 -10px; cursor: pointer; touch-action: none; }

/* Fine-seek panel above the player bar, only while a finger is on a seek bar. It never takes taps. */
#scrub {
  position: absolute; left: 0; right: 0; z-index: 30; pointer-events: none;
  background: var(--bg); border-color: var(--accent-line); padding: 14px 20px 12px;
  box-shadow: 0 -10px 40px #000d;
}
.scrub-top { display: flex; justify-content: space-between; align-items: baseline; gap: 20px; }
#scrub-time { font-size: 40px; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
#scrub-delta { font-size: 26px; color: var(--green); font-variant-numeric: tabular-nums; }
#scrub-zoom { font-size: 22px; height: 52px; display: flex; align-items: center; }
.scrub-scale { display: flex; justify-content: space-between; gap: 12px; color: var(--dim); font-size: 16px; }
.scrub-scale span:nth-child(2) { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.controls { display: flex; align-items: center; gap: 8px; }
.controls button {
  width: 88px; height: 88px; border: 1px solid var(--line); border-radius: 8px; display: grid; place-items: center; flex: none;
}
.controls svg { width: 38px; height: 38px; }
.controls .play { width: 112px; border-color: var(--accent-line); color: var(--accent); }
.controls .play svg { width: 46px; height: 46px; }
body:not(.long) .long-only { display: none !important; }
.controls .play.wake { background: var(--accent-bg); animation: wake 1.2s ease-in-out infinite; }
@keyframes wake { 50% { box-shadow: 0 0 0 6px #7c5cff55; } }

@container right (max-width: 820px) {
  #bar { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "meta cover" "controls controls"; }
  #bar-cover { width: 76px; height: 76px; }
  #bar-controls { justify-content: flex-start; }
  #bar-controls button { flex: 1; width: auto; max-width: 140px; }
}

/* ---------- Now: the big player ---------- */
#now {
  grid-template-columns: minmax(0, 1fr) minmax(0, 34%);
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas: "np cover" "queue cover";  /* Controls on the left, cover on the right. */
  gap: 14px 28px;
  padding: 18px;
}
#media { grid-area: cover; position: relative; align-self: center; min-width: 0; }
#now-cover { display: block; width: 100%; aspect-ratio: 1; }
.np { grid-area: np; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
#now-title { font-size: clamp(24px, 3cqw, 34px); font-weight: 700; }
#now-sub { font-size: 20px; }
.seekrow { display: flex; align-items: center; gap: 14px; font-size: 18px; font-variant-numeric: tabular-nums; }
#seek { flex: 1; min-width: 0; height: 76px; display: flex; align-items: center; cursor: pointer; touch-action: none; font-size: 18px; }
#now-extras { padding: 4px 0 0; border: 0; }
#now-extras .btn { flex: 0 1 auto; }
.queue { grid-area: queue; min-height: 0; display: flex; flex-direction: column; border-top: 1px solid var(--line); }
.qhead { display: flex; align-items: center; gap: 10px; min-height: 84px; padding: 4px 0; }
.qhead .legend-inline { flex: 1; font-weight: 700; font-size: 20px; }
.queue .pager { padding-right: 0; }

@container right (max-width: 820px) {
  #now { grid-template-columns: minmax(0, 1fr); grid-template-areas: "np" "queue"; padding: 12px; }
  #media { display: none; }
  body.video #now { grid-template-areas: "cover" "np" "queue"; grid-template-rows: auto auto minmax(0, 1fr); }
  body.video #media { display: block; }
}

/* ---------- settings ---------- */
.settings { padding: 8px 24px 30px; line-height: 1.6; }
.settings h4 { margin: 26px 0 10px; font-size: 20px; }
.settings p { color: var(--dim); font-size: 17px; margin: 8px 0; }
.settings .chips { padding: 0; border: 0; }
.settings .chips .btn { flex: 0 1 220px; }
.settings code { color: var(--green); word-break: break-all; font-size: 17px; -webkit-user-select: all; user-select: all; }

/* ---------- smaller windows ---------- */
@media (max-width: 760px) {
  :root { --rail: 96px; }
  #rail button { font-size: 13px; }
  #rail svg { width: 32px; height: 32px; }
  .pager { width: 80px; }
  .row .thumb, .row .no { width: 56px; height: 56px; }
}
@media (max-height: 620px) {
  :root { --row: 80px; --btn: 68px; }
  #head { min-height: 84px; padding: 6px 8px; }
  #bar-cover { width: 76px; height: 76px; }
  .controls button { height: 76px; }
  #seek { height: 64px; }
  #rail button { gap: 2px; }
}

/* ---------- login ---------- */
.login-page { display: grid; place-items: center; min-height: 100%; padding: 20px; overflow: auto; }
.login { width: min(460px, 100%); padding: 34px 28px 22px; display: flex; flex-direction: column; gap: 14px; }
.login .legend { position: absolute; top: -0.75em; left: 22px; background: var(--bg); padding: 0 8px; font-size: 16px; }
.login input {
  height: var(--btn); background: var(--raise); border: 1px solid var(--line); border-radius: 6px;
  padding: 0 16px; outline: 0; -webkit-user-select: text; user-select: text;
}
.login input:focus { border-color: var(--accent-line); }
.login .btn { border-color: var(--accent-line); color: var(--accent); font-weight: 700; width: 100%; }
.login .error { color: var(--red); margin: 0; min-height: 1.2em; }
.login .dim { color: var(--dim); }
.login .small { font-size: 15px; }

/* Short window (the browser card at half height): the player bar becomes one row so the list keeps room. */
@media (max-height: 620px) {
  #bar { grid-template-columns: auto minmax(0, 1fr); grid-template-areas: "controls meta"; gap: 14px; padding: 8px 14px 8px 8px; }
  #bar-cover, #bar-sub { display: none; }  /* Keep the seek bar, drop the artist line. */
  #bar.has-status #bar-sub { display: block; }  /* A message replaces the seek bar for a moment. */
  #bar.has-status #bar-prog { display: none; }
  #bar-title { font-size: 20px; }
  #bar-controls { justify-content: flex-start; gap: 6px; }
  #bar-controls button { flex: none; width: 76px; height: 76px; }
  #bar-controls .play { width: 96px; }
  #q { height: 64px; margin: 8px 10px; width: calc(100% - 20px); }
  .chips { padding: 8px 10px; }
  .chips .btn { min-height: 60px; }
}
@media (max-height: 620px) {
  /* The bar below already shows title and artist: give the queue the room. */
  #now { padding: 8px 12px; gap: 6px 20px; }
  #now-title, #now-sub { display: none; }
  .qhead { min-height: 68px; }
  .qhead .btn { min-height: 60px; }
}

/* Settings sits at the bottom of the rail, a little smaller than the main tabs. */
#rail button[data-tab="settings"] { flex: 0 0 auto; min-height: 64px; flex-direction: row; gap: 8px; }
#rail button[data-tab="settings"] svg { width: 28px; height: 28px; }
@media (max-width: 760px) {
  #rail button[data-tab="settings"] { flex-direction: column; gap: 2px; }
  #rail button[data-tab="settings"] span { font-size: 12px; }
}
@media (max-height: 620px) {
  #rail { gap: 6px; }
  #rail button { min-height: 56px; }
  #rail button[data-tab="settings"] { min-height: 52px; }
}

/* A row being held: it fills in, so you can see the long press is working. */
.row.pressing { background: var(--press); transition: background .55s ease-in; }

/* ---------- long-press menu ---------- */
#menu { position: fixed; inset: 0; z-index: 50; background: #000a; display: grid; place-items: center; padding: 16px; }
.menu-box { width: min(560px, 94vw); background: var(--bg); border-color: var(--accent-line); padding: 22px; }
.menu-title { font-size: 24px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.menu-sub { color: var(--dim); font-size: 18px; margin: 6px 0 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menu-actions { display: grid; gap: 10px; }
.menu-actions .btn { width: 100%; min-height: 84px; font-size: 22px; }
@media (max-height: 620px) {
  .menu-box { padding: 14px; }
  .menu-sub { margin-bottom: 10px; }
  .menu-actions { grid-template-columns: 1fr 1fr; gap: 8px; }
  .menu-actions .btn { min-height: 72px; font-size: 20px; }
}

/* ---------- YouTube channels ---------- */
.row .thumb.round { border-radius: 50%; }
.divider { padding: 18px 18px 8px 19px; font-size: 16px; font-weight: 700; color: var(--dim); letter-spacing: .04em; border-bottom: 1px solid var(--rowline); }

/* ---------- video (Now tab) ---------- */
#now-video { display: none; width: 100%; aspect-ratio: 16 / 9; background: #000; border-radius: 4px; }
body.video #now-video { display: block; }
body.video #now-cover { display: none; }
body.video #now { grid-template-columns: minmax(0, 1fr) minmax(0, 54%); }
#video-note {
  position: absolute; inset: 0; display: none; place-items: center; text-align: center; padding: 12px;
  background: #000b; color: #fff; font-size: 20px; border-radius: 4px;
}
#video-note.on { display: grid; }

/* Full screen after Maximize: only the video, plus two big buttons. */
body.cinema #media { position: fixed; inset: 0; z-index: 60; background: #000; display: grid; place-items: center; }
body.cinema #now-video { width: 100vw; height: 100vh; aspect-ratio: auto; object-fit: contain; border-radius: 0; }
#cinema-bar { position: fixed; left: 16px; bottom: 16px; z-index: 61; display: flex; gap: 12px; }
#cinema-bar .btn { background: #000b; color: #fff; border-color: #ffffff66; min-height: 88px; font-size: 20px; }
#cinema-bar .play { width: 112px; }
#cinema-bar .play svg { width: 44px; height: 44px; }
/* In the browser's own full screen only #media is shown, so keep the video filling it. */
#media:fullscreen { background: #000; display: grid; place-items: center; }
#media:fullscreen #now-video { width: 100vw; height: 100vh; aspect-ratio: auto; object-fit: contain; }
