/* Layout and components. Colour tokens come from theme.css.
   The structure follows the desktop app: script panel on the left, the player
   in the centre, the track list on the right. */

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--grad-bg);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 13px;
  line-height: 1.5;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; color: inherit; }
button { background: none; border: none; cursor: pointer; padding: 0; }
button:disabled { cursor: default; }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-active); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent-dim); }

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

.hidden { display: none !important; }

.app {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

/* ---------------- shared controls ---------------- */

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: var(--radius-xs);
  color: var(--text-dim);
  flex-shrink: 0;
  transition: background var(--transition), color var(--transition);
}

.icon-btn:hover:not(:disabled) { background: var(--bg-hover); color: var(--text-primary); }
.icon-btn:disabled { opacity: 0.35; }
.icon-btn--active { color: var(--accent); }
.icon-btn svg { width: 15px; height: 15px; }

.ctrl-select {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 3px 4px;
  cursor: pointer;
  outline: none;
  max-width: 130px;
}

.ctrl-select:hover { border-color: var(--accent-dim); color: var(--accent); }

.text-btn {
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--text-primary);
  white-space: nowrap;
  transition: background var(--transition), border-color var(--transition);
}

.text-btn:hover { background: var(--bg-hover); border-color: var(--accent-dim); }
.text-btn--primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.text-btn--primary:hover { background: var(--accent-dim); border-color: var(--accent-dim); }

/* ---------------- title bar ---------------- */

.titlebar {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  position: relative;
  z-index: 20;
}

.titlebar__row { display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 6px 0 10px; }

.titlebar__left { display: flex; align-items: center; gap: 7px; flex-shrink: 0; min-width: 0; }
.titlebar__logo { border-radius: var(--radius-xs); }
.titlebar__name { font-size: 12px; font-weight: 700; color: var(--accent); letter-spacing: 0.04em; }

.titlebar__group { display: flex; align-items: center; gap: 2px; min-width: 0; }
.titlebar__group--right { margin-left: auto; }

.titlebar__wbtn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 26px;
  border-radius: var(--radius-xs);
  color: var(--text-dim);
  transition: background var(--transition), color var(--transition);
}

.titlebar__wbtn:hover { background: var(--bg-hover); color: var(--text-primary); }
.titlebar__wbtn svg { width: 15px; height: 15px; }

.titlebar__btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 11px;
  border-radius: var(--radius-xs);
  color: var(--text-secondary);
  transition: background var(--transition), color var(--transition);
}

.titlebar__btn:hover:not(:disabled) { background: var(--bg-hover); color: var(--text-primary); }
.titlebar__btn:disabled { opacity: 0.4; }
.titlebar__btn--off { opacity: 0.45; }
.titlebar__btn--active { color: var(--accent); }
.titlebar__btn-label { font-size: 12px; }
.titlebar__btn svg { width: 15px; height: 15px; flex-shrink: 0; }

/* Pane switch: narrow screens only, moved into the bottom dock by script. */
.panes { display: none; }

.panes__btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  flex: 1;
  padding: 7px 0 6px;
  color: var(--text-dim);
  font-size: 10px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  transition: color var(--transition), background var(--transition);
}

.panes__icon { display: flex; }
.panes__icon svg { width: 20px; height: 20px; }
.panes__btn--active { color: var(--accent); }
.panes__btn--active .panes__icon { background: var(--accent-faint); border-radius: 999px; padding: 2px 12px; }

/* ---------------- three column layout ---------------- */

.layout { display: flex; flex: 1; overflow: hidden; min-height: 0; }

.layout__side {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--grad-panel);
  min-width: 0;
  width: 320px;
}

.layout__side--left { border-right: 1px solid var(--border-subtle); }
.layout__side--right { border-left: 1px solid var(--border-subtle); }

.layout__center { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }

.layout__handle {
  width: 5px;
  cursor: col-resize;
  flex-shrink: 0;
  background: transparent;
  transition: background 0.15s;
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
}

.layout__handle:hover, .layout__handle--active { background: var(--accent-faint); }
.layout__handle--collapsed { width: 0; cursor: default; }

/* ---------------- player ---------------- */

.player {
  --sub-h: 120px;
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto var(--sub-h) auto;
  height: 100%;
  min-width: 0;
  padding: 14px 20px 10px;
  row-gap: 10px;
  overflow: hidden;
}

.player--sub-collapsed { --sub-h: 0px; }

/* Collection bar */
.player__bar {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) 40px;
  align-items: center;
  padding: 0 4px 6px;
  border-bottom: 1px solid var(--border-subtle);
  min-height: 34px;
}

.player__bar-name { min-width: 0; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 1px; }

.player__collection-name {
  width: 100%;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player__collection-author {
  width: 100%;
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player__bar-btns { display: flex; align-items: center; justify-content: flex-end; }

/* Cover art */
.player__art { min-height: 0; display: flex; justify-content: center; align-items: center; overflow: hidden; }

.cover-art {
  position: relative;
  height: 100%;
  aspect-ratio: 1 / 1;
  max-width: 100%;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
}

.cover-art__bg {
  position: absolute;
  inset: 0;
  z-index: 0;
  background-size: cover;
  background-position: center;
  filter: blur(28px);
  opacity: 0.28;
  transform: scale(1.18);
  pointer-events: none;
}

.cover-art__img {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.cover-art__img--right { animation: slide-right 0.28s cubic-bezier(0.22, 1, 0.36, 1); }
.cover-art__img--left { animation: slide-left 0.28s cubic-bezier(0.22, 1, 0.36, 1); }

@keyframes slide-right { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes slide-left { from { transform: translateX(-40px); opacity: 0; } to { transform: none; opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  .cover-art__img--right, .cover-art__img--left { animation: none; }
  .script-panel__list { scroll-behavior: auto; }
}

.cover-art__nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 10;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.5);
  color: rgba(255, 255, 255, 0.95);
  opacity: 0;
  transition: opacity 0.18s, background 0.18s;
}

.cover-art:hover .cover-art__nav, .cover-art__nav:focus-visible { opacity: 1; }
.cover-art__nav:hover { background: rgba(0, 0, 0, 0.78); }
.cover-art__nav--prev { left: 10px; }
.cover-art__nav--next { right: 10px; }
.cover-art__nav svg { width: 20px; height: 20px; }

.cover-art__badge {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(0, 0, 0, 0.58);
  backdrop-filter: blur(4px);
  border-radius: 10px;
  padding: 2px 8px;
  font-size: 9px;
  color: rgba(255, 255, 255, 0.9);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  pointer-events: none;
}

.cover-art__badge svg { width: 9px; height: 9px; }

.cover-art__dots {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  display: flex;
  gap: 6px;
  padding: 5px 10px;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(6px);
  border-radius: 20px;
  max-width: 80%;
  overflow: hidden;
}

.cover-art__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.35);
  flex-shrink: 0;
  transition: background 0.18s, transform 0.18s;
}

.cover-art__dot--active { background: rgba(255, 255, 255, 0.92); transform: scale(1.25); }

.cover-art__placeholder {
  position: relative;
  display: grid;
  place-items: center;
  height: 100%;
  color: var(--text-dim);
}

.cover-art__placeholder svg { width: 42%; height: 42%; opacity: 0.35; }

.cover-art__open {
  position: absolute;
  right: 8px;
  bottom: 8px;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 9px;
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  font-size: 10px;
  opacity: 0;
  transition: opacity var(--transition);
}

.cover-art:hover .cover-art__open, .cover-art__open:focus-visible { opacity: 1; }
.cover-art__open svg { width: 12px; height: 12px; }

/* Track info */
.player__info { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.track-info { text-align: center; min-width: 0; }
.track-info--empty { color: var(--text-dim); padding: 12px 0; font-size: 12px; }

.track-info__title {
  font-size: clamp(16px, 2.2vw, 24px);
  font-weight: 700;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.track-info__artist { color: var(--text-secondary); margin-top: 3px; line-height: 1.35; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.track-info__album { color: var(--text-dim); margin-top: 2px; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.track-info__meta {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin-top: 6px;
  font-size: 11px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

.track-info__tags { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; margin-top: 7px; }

.tag {
  padding: 1px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-size: 10px;
}

.stars { display: inline-flex; gap: 1px; color: var(--accent-dim); vertical-align: -2px; }
.stars svg { width: 12px; height: 12px; }
.stars .off { opacity: 0.3; }

/* Subtitle zone */
.player__sub-handle {
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: ns-resize;
  position: relative;
  border-top: 1px solid var(--border-subtle);
  height: 14px;
}

.player--sub-collapsed .player__sub-handle { cursor: default; }
.player__sub-toggle { height: 18px; width: 40px; }

.player__sub-zone {
  position: relative;
  height: 100%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Tapping either side of the subtitle steps to the neighbouring cue. The
   middle is left alone so a tap meant for neither does nothing. */
.sub-nav {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 42%;
  z-index: 2;
  display: flex;
  align-items: flex-start;
  color: var(--text-dim);
  border-radius: var(--radius-sm);
  transition: background var(--transition), color var(--transition);
}

.sub-nav--prev { left: 0; justify-content: flex-start; }
.sub-nav--next { right: 0; justify-content: flex-end; }
.sub-nav:hover:not(:disabled) { background: var(--accent-faint); color: var(--accent); }
.sub-nav:active:not(:disabled) { background: var(--bg-active); }
.sub-nav:disabled { display: none; }

.sub-nav__hint {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 3px 8px;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  opacity: 0.55;
  white-space: nowrap;
}

.sub-nav:hover .sub-nav__hint { opacity: 1; }
.sub-nav__icon { display: flex; }
.sub-nav__icon svg { width: 11px; height: 11px; }

.player--sub-collapsed .sub-nav { display: none; }

.sub-overlay {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(128, 128, 128, 0.2);
  box-shadow: 0 2px 14px rgba(0, 0, 0, 0.25);
  overflow: hidden;
  background: var(--sub-bg);
  text-align: center;
  line-height: 1.5;
  word-break: break-word;
}

/* No subtitle on this track at all: the area disappears. */
.sub-overlay--empty { border-color: transparent; box-shadow: none; background: transparent; }

/* The track has subtitles but none is due right now. The box stays visible so
   the area does not appear and vanish, and so the side taps stay findable. */
.sub-overlay--idle {
  border-style: dashed;
  border-color: var(--border);
  box-shadow: none;
  background: transparent;
}

.sub-overlay__text { display: inline-block; width: 100%; }

/* Transport */
.player__transport { display: flex; flex-direction: column; gap: 8px; min-width: 0; }

.seekbar { display: flex; align-items: center; gap: 10px; padding: 0 4px; min-width: 0; }
.seekbar__time { font-size: 11px; color: var(--text-dim); min-width: 40px; font-variant-numeric: tabular-nums; }
.seekbar__time--right { text-align: right; }

.seekbar__track {
  flex: 1;
  min-width: 0;
  height: 44px;
  position: relative;
  cursor: pointer;
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border-subtle);
  touch-action: none;
}

.seekbar__wave { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.seekbar__progress { position: absolute; top: 0; left: 0; bottom: 0; width: 0; background: var(--accent-faint); pointer-events: none; }

.seekbar__loop-range {
  position: absolute;
  top: 0;
  bottom: 0;
  background: var(--accent-faint);
  border-left: 1px dashed var(--accent-dim);
  border-right: 1px dashed var(--accent-dim);
  pointer-events: none;
}

.seekbar__loop-mark {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--accent);
  pointer-events: none;
  z-index: 2;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  font-size: 9px;
  font-weight: 700;
  line-height: 14px;
  color: var(--accent-text);
}

.seekbar__loop-mark::before {
  content: '';
  position: absolute;
  bottom: 0;
  left: -7px;
  width: 14px;
  height: 14px;
  border-radius: 3px 3px 0 0;
  background: var(--accent);
  z-index: -1;
}

.seekbar__handle {
  position: absolute;
  top: 50%;
  left: 0;
  transform: translate(-50%, -50%);
  width: 2px;
  height: 26px;
  background: var(--accent);
  border-radius: 2px;
  pointer-events: none;
  box-shadow: 0 0 6px var(--accent);
}

.seekbar__track:hover .seekbar__handle { background: var(--text-primary); }

.seekbar__hover {
  position: absolute;
  top: 4px;
  transform: translateX(-50%);
  font-size: 10px;
  padding: 1px 6px;
  border-radius: var(--radius-xs);
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}

/* Buttons */
.controls { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 4px 6px; min-width: 0; }
.controls__main { display: flex; align-items: center; justify-content: center; gap: 6px; }

.ctrl-btn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  border-radius: 50%;
  padding: 8px;
  transition: background var(--transition), color var(--transition);
}

.ctrl-btn:hover:not(:disabled) { background: var(--bg-hover); color: var(--text-primary); }
.ctrl-btn:disabled { opacity: 0.3; }
.ctrl-btn--active { color: var(--accent); }
.ctrl-btn--active:hover:not(:disabled) { color: var(--accent); }
.ctrl-btn--small { padding: 7px; }
.ctrl-btn svg { width: 20px; height: 20px; }
.ctrl-btn--small svg { width: 17px; height: 17px; }

.ctrl-btn--text {
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  font-family: var(--font-mono);
  opacity: 0.6;
}

.ctrl-btn--text.ctrl-btn--active { opacity: 1; }

.ctrl-btn--play {
  background: var(--bg-elevated);
  padding: 12px;
  color: var(--text-primary);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.ctrl-btn--play:hover:not(:disabled) { background: var(--bg-hover); border-color: var(--accent-dim); }
.ctrl-btn--play svg { width: 24px; height: 24px; }

.ctrl-btn__tag {
  position: absolute;
  top: 2px;
  right: 0;
  font-size: 8px;
  font-weight: 700;
  color: var(--accent-text);
  background: var(--accent);
  border-radius: 6px;
  padding: 0 4px;
  line-height: 1.4;
}

.ctrl-btn--rate { border-radius: var(--radius-sm); padding: 6px 8px; }
.ctrl-btn__rate { font-size: 11px; font-weight: 700; font-family: var(--font-mono); min-width: 34px; text-align: center; }

/* Volume */
.player__bottom { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-width: 0; }
.volume-bar { display: flex; align-items: center; gap: 8px; padding: 0 4px; min-width: 0; flex: 1 1 auto; overflow: hidden; }
.extra-controls { display: flex; align-items: center; gap: 2px; flex-shrink: 0; margin-left: auto; }
.volume-bar__label { font-size: 11px; color: var(--text-dim); min-width: 34px; text-align: right; font-variant-numeric: tabular-nums; flex-shrink: 0; }

.slider { position: relative; height: 16px; display: flex; align-items: center; cursor: pointer; touch-action: none; }
.volume-bar__slider { flex: 1 1 40px; min-width: 30px; max-width: 140px; }
.slider__rail { width: 100%; height: 4px; border-radius: 2px; background: var(--bg-active); overflow: hidden; }
.slider__fill { height: 100%; width: 100%; background: var(--accent); border-radius: 2px; }

.slider__knob {
  position: absolute;
  top: 50%;
  left: 100%;
  width: 10px;
  height: 10px;
  margin-left: -5px;
  border-radius: 50%;
  background: var(--accent);
  transform: translateY(-50%) scale(0);
  transition: transform var(--transition);
  pointer-events: none;
}

.slider:hover .slider__knob, .slider--dragging .slider__knob, .slider:focus-visible .slider__knob { transform: translateY(-50%) scale(1); }

/* ---------------- script panel ---------------- */

.script-panel { flex: 1; overflow: hidden; display: flex; flex-direction: column; min-height: 0; }

.script-panel__toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 8px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border-subtle);
}

.script-panel__font { font-size: 11px; color: var(--text-secondary); min-width: 36px; text-align: center; font-family: var(--font-mono); font-weight: 600; }
.script-panel__spacer { flex: 1; }

.script-panel__list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  scroll-behavior: smooth;
  outline: none;
}

.script-panel__empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--text-dim);
  font-size: 12px;
  padding: 20px;
  text-align: center;
}

.script-panel__empty svg { width: 28px; height: 28px; opacity: 0.6; }

.script-line {
  padding: 8px 14px;
  line-height: 1.5;
  color: var(--text-secondary);
  border-radius: var(--radius-xs);
  margin: 0 6px;
  border-bottom: 1px solid var(--border-subtle);
  text-align: left;
  width: auto;
  cursor: default;
  transition: background var(--transition), color var(--transition);
  word-break: break-word;
}

.script-line--clickable { cursor: pointer; }
.script-line--clickable:hover { background: var(--bg-hover); color: var(--text-primary); }

.script-line--active {
  background: var(--accent-faint);
  color: var(--text-primary);
  font-weight: 500;
  border-left: 2px solid var(--accent);
  padding-left: 12px;
}

.script-line__time { display: block; font-size: 10px; color: var(--text-dim); font-family: var(--font-mono); margin-bottom: 2px; }
.script-line--active .script-line__time { color: var(--accent); }

/* ---------------- playlist panel ---------------- */

.playlist-panel { display: flex; flex-direction: column; height: 100%; min-height: 0; }

.playlist-panel__header {
  display: flex;
  flex-direction: column;
  padding: 8px 10px 6px;
  border-bottom: 1px solid var(--border-subtle);
  gap: 6px;
  flex-shrink: 0;
}

.playlist-search {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 2px 6px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  min-width: 0;
}

.playlist-search__icon { color: var(--text-dim); flex-shrink: 0; display: flex; }
.playlist-search__icon svg { width: 13px; height: 13px; }

.playlist-search__input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  font-size: 11px;
  color: var(--text-primary);
  min-width: 0;
  padding: 3px 0;
}

.playlist-search__input::placeholder { color: var(--text-dim); }
.playlist-search__input::-webkit-search-cancel-button { filter: grayscale(1); }

.playlist-stats { display: flex; align-items: center; gap: 8px; font-size: 10px; color: var(--text-dim); padding: 0 2px; font-variant-numeric: tabular-nums; }
.playlist-stats__sep { width: 3px; height: 3px; border-radius: 50%; background: var(--text-dim); opacity: 0.6; }

.playlist-scroll { flex: 1; overflow-y: auto; min-height: 0; padding-bottom: 6px; }

.playlist-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 140px;
  color: var(--text-dim);
  font-size: 12px;
  gap: 8px;
  padding: 20px;
  text-align: center;
}

.track-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  cursor: pointer;
  border-left: 2px solid transparent;
  position: relative;
  width: 100%;
  text-align: left;
  transition: background var(--transition);
}

.track-item:hover { background: var(--bg-hover); }
.track-item--active { background: var(--accent-faint); border-left-color: var(--accent); }

.track-item__index {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  min-width: 22px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

.track-item--active .track-item__index { color: var(--accent); }

.track-item__info { flex: 1; min-width: 0; }
.track-item__name { font-size: 12px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.track-item--active .track-item__name { color: var(--accent); }

.track-item__meta { display: flex; gap: 8px; font-size: 10px; color: var(--text-dim); margin-top: 2px; align-items: center; min-width: 0; }
.track-item__artist { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 55%; }
.track-item__rating, .track-item__tags { display: inline-flex; align-items: center; gap: 2px; color: var(--accent-dim); flex-shrink: 0; }
.track-item__rating svg, .track-item__tags svg { width: 10px; height: 10px; }
.track-item__subs { display: inline-flex; align-items: center; gap: 3px; color: var(--accent); font-weight: 600; font-size: 10px; letter-spacing: 0.02em; flex-shrink: 0; }
.track-item__time { font-size: 10px; color: var(--text-dim); font-variant-numeric: tabular-nums; flex-shrink: 0; }

/* Groups */
.group-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  margin: 8px 6px 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.group-header__icon { color: var(--accent); flex-shrink: 0; opacity: 0.8; display: flex; }
.group-header__icon svg { width: 13px; height: 13px; }
.group-header__name { flex: 1; font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.group-header__count { font-size: 10px; color: var(--text-dim); font-variant-numeric: tabular-nums; }

.track-item--grouped {
  margin: 0 6px;
  padding-left: 14px;
  border-left: 3px solid color-mix(in srgb, var(--accent) 40%, transparent);
  border-right: 1px solid var(--border);
  background: color-mix(in srgb, var(--accent) 5%, transparent);
}

.track-item--grouped.track-item--active { background: var(--accent-faint); border-left-color: var(--accent); }

.track-item--group-last {
  border-bottom-left-radius: var(--radius-sm);
  border-bottom-right-radius: var(--radius-sm);
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}

/* ---------------- status bar ---------------- */

.app-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  height: 22px;
  flex-shrink: 0;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
  font-size: 10px;
  color: var(--text-dim);
  gap: 12px;
}

.app-footer__status { display: flex; align-items: center; gap: 5px; min-width: 0; flex: 1; }
.app-footer__label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text-secondary); }
.app-footer__right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.app-footer__chip { display: inline-flex; align-items: center; gap: 3px; color: var(--text-secondary); font-variant-numeric: tabular-nums; }

/* ---------------- start and loading ---------------- */

.start { flex: 1; display: grid; place-items: center; padding: 32px; min-height: 0; overflow-y: auto; }

.start-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  max-width: 460px;
  padding: 40px 34px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  text-align: center;
}

.start-card--over { border-color: var(--accent); background: var(--bg-elevated); }
.start-card h1 { margin: 0; font-size: 20px; font-weight: 650; }
.start-card p { margin: 0; color: var(--text-secondary); }
.start-card__hint { color: var(--text-dim); font-size: 11px; }

.error {
  padding: 9px 12px;
  border: 1px solid var(--danger);
  border-radius: var(--radius-sm);
  background: var(--danger-dim);
  color: var(--danger);
  font-size: 12px;
}

.loading { flex: 1; display: grid; place-items: center; align-content: center; gap: 12px; color: var(--text-secondary); }

.spinner {
  width: 28px;
  height: 28px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------- drop overlay ---------------- */

.drop {
  position: fixed;
  inset: 0;
  z-index: 8000;
  display: grid;
  place-items: center;
  background: var(--overlay);
  backdrop-filter: blur(3px);
  font-size: 16px;
  font-weight: 600;
}

.drop__inner { padding: 30px 44px; border: 2px dashed var(--accent); border-radius: var(--radius-lg); background: var(--bg-surface); }

/* ---------------- modal ---------------- */

.modal-back {
  position: fixed;
  inset: 0;
  z-index: 8500;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--overlay);
  backdrop-filter: blur(2px);
}

.modal {
  display: flex;
  flex-direction: column;
  width: min(540px, 100%);
  max-height: 84vh;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.modal__head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border-subtle); }
.modal__head h2 { flex: 1; margin: 0; font-size: 14px; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal__body { padding: 16px; overflow-y: auto; }

dl.info { display: grid; grid-template-columns: minmax(92px, auto) minmax(0, 1fr); gap: 7px 16px; margin: 0; }
dl.info dt { color: var(--text-secondary); font-size: 12px; }
dl.info dd { margin: 0; overflow-wrap: anywhere; }

.section-label { margin: 18px 0 8px; color: var(--text-dim); font-size: 10px; font-weight: 700; letter-spacing: 0.09em; text-transform: uppercase; }
.section-label:first-child { margin-top: 0; }
.desc { white-space: pre-wrap; color: var(--text-secondary); }
.tag-row { display: flex; flex-wrap: wrap; gap: 5px; }

kbd {
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: var(--radius-xs);
  background: var(--bg-elevated);
  font-family: var(--font-mono);
  font-size: 11px;
  white-space: nowrap;
}

/* ---------------- image gallery ---------------- */

.gallery { position: fixed; inset: 0; z-index: 9000; background: rgba(0, 0, 0, 0.92); display: flex; align-items: center; justify-content: center; }
.gallery__inner { position: relative; display: flex; flex-direction: column; align-items: center; width: 100%; height: 100%; padding: 48px 12px 12px; gap: 10px; }
.gallery__close { position: absolute; top: 10px; right: 14px; color: #ccc; background: rgba(255, 255, 255, 0.08); }
.gallery__close:hover { color: #fff; background: rgba(255, 255, 255, 0.18); }
.gallery__counter { position: absolute; top: 14px; left: 50%; transform: translateX(-50%); font-size: 12px; color: #aaa; letter-spacing: 0.05em; font-variant-numeric: tabular-nums; }
.gallery__stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; width: 100%; gap: 8px; }
.gallery__img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: var(--radius-sm); box-shadow: 0 8px 40px rgba(0, 0, 0, 0.6); }

.gallery__nav {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #ccc;
  display: flex;
  align-items: center;
  justify-content: center;
}

.gallery__nav:hover { background: rgba(255, 255, 255, 0.18); color: #fff; }
.gallery__nav svg { width: 26px; height: 26px; }

.gallery__strip { display: flex; gap: 6px; overflow-x: auto; padding: 4px 0; max-width: 100%; flex-shrink: 0; }

.gallery__thumb {
  flex-shrink: 0;
  width: 60px;
  height: 60px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 2px solid transparent;
  opacity: 0.5;
  transition: opacity 0.15s, border-color 0.15s;
  background: transparent;
}

.gallery__thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gallery__thumb:hover { opacity: 0.8; }
.gallery__thumb--active { border-color: var(--accent); opacity: 1; }

/* ---------------- narrow screens ---------------- */

/* Everything the thumb needs lives in one bar at the bottom: what is playing,
   the transport, and the pane switch. The pane above it changes; this does not. */
.mobile-dock {
  flex-shrink: 0;
  padding: 6px 12px 0;
  background: var(--grad-panel);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.mobile-dock .player__transport { gap: 6px; }

/* A compact now playing line, shown while another pane is in front. */
.mobile-dock__now {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 2px 2px 6px;
  text-align: left;
  min-width: 0;
}

.mobile-dock__art {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  border-radius: var(--radius-xs);
  background: var(--bg-elevated) center / cover no-repeat;
  border: 1px solid var(--border-subtle);
}

.mobile-dock__text { min-width: 0; flex: 1; }
.mobile-dock__title { display: block; font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mobile-dock__artist { display: block; font-size: 10px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

@media (max-width: 900px) {
  .panes { display: flex; gap: 2px; border-top: 1px solid var(--border-subtle); margin-top: 4px; }

  /* The panel folds are meaningless once the panes are switched by the tabs. */
  .titlebar__panels { display: none; }
  .titlebar__btn-label { display: none; }
  .titlebar__btn { padding: 8px 10px; }
  .titlebar__wbtn { width: 38px; height: 30px; }

  /* Bigger side targets, and the hints stay lit since there is no hover. */
  .sub-nav { width: 45%; }
  .sub-nav__hint { opacity: 0.75; font-size: 10px; padding: 4px 9px; }

  .layout__handle { display: none; }
  .layout__side { width: auto; flex: 1; border: none; }

  /* One pane at a time. */
  .app[data-pane="script"] #pane-player,
  .app[data-pane="script"] #pane-list,
  .app[data-pane="player"] #pane-script,
  .app[data-pane="player"] #pane-list,
  .app[data-pane="list"] #pane-script,
  .app[data-pane="list"] #pane-player { display: none; }

  /* The transport has moved out, so the player grid loses its last row. */
  .player { grid-template-rows: auto minmax(0, 1fr) auto auto var(--sub-h); padding: 10px 12px 6px; row-gap: 8px; }
  .player__bar { min-height: 28px; padding-bottom: 4px; }
  .player__collection-name { font-size: 12px; }

  /* Touch has no hover, so the image controls are always visible. */
  .cover-art__nav { opacity: 1; width: 40px; height: 40px; background: rgba(0, 0, 0, 0.42); }
  .cover-art__open { opacity: 1; padding: 7px 12px; }
  .cover-art__dot { width: 10px; height: 10px; }
  .cover-art__dots { padding: 7px 12px; gap: 8px; }

  .track-info__title { font-size: 18px; }
  .track-info__meta { gap: 3px 9px; font-size: 10px; }

  /* Comfortable rows and hit targets. */
  .track-item { padding: 10px 10px; gap: 8px; }
  .track-item__name { font-size: 13px; }
  .script-line { padding: 11px 14px; }
  .icon-btn { width: 34px; height: 34px; }
  .ctrl-select { font-size: 11px; padding: 6px 6px; }
  .playlist-search__input { font-size: 16px; padding: 6px 0; } /* 16px keeps iOS from zooming */

  .mobile-dock .seekbar__track { height: 36px; }
  .mobile-dock .seekbar { gap: 8px; }
  .mobile-dock .controls__main { gap: 14px; }
  .mobile-dock .volume-bar { display: none; }
  .mobile-dock .player__bottom { justify-content: center; }
  .mobile-dock .extra-controls { margin-left: 0; gap: 4px; }
  .mobile-dock .ctrl-btn { padding: 10px; }
  .mobile-dock .ctrl-btn--play { padding: 14px; }

  .gallery__inner { padding: 44px 6px 8px; padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px)); }
  .gallery__nav { width: 40px; height: 40px; }
  .gallery__thumb { width: 50px; height: 50px; }
  .modal { max-height: 88vh; }
  .app-footer { display: none; }
}

@media (max-width: 560px) {
  .titlebar__row { padding: 0 6px; }
  .titlebar__name { display: none; }
  .start-card { padding: 28px 20px; }
  .player__sub-handle { height: 14px; }
}

/* Landscape phones are short: the artwork sits beside the text instead of above. */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 520px) {
  .titlebar__row--top { display: none; }
  .player {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto var(--sub-h);
    padding: 8px 12px 4px;
    column-gap: 14px;
  }
  .player__bar { display: none; }
  .player__art { grid-row: 1 / span 3; grid-column: 1; }
  .player__info { grid-column: 2; align-self: end; }
  .player__sub-handle { grid-column: 2; }
  .player__sub-zone { grid-column: 2; }
  .panes__label { display: none; }
  .mobile-dock__now { display: none !important; }
}
