/* ==========================================================================
   base.css — layout, structure, responsive behaviour.
   Anything that is *shape* lives here. Anything that is *skin* lives in the
   theme-*.css files, scoped to html[data-theme="…"].
   ========================================================================== */

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

:root {
  --gap: 14px;
  --radius: 0px;            /* themes override */
  --font-ui: "Tahoma", "Geneva", "DejaVu Sans", Verdana, sans-serif;
  --font-lcd: "Lucida Console", "DejaVu Sans Mono", "Courier New", monospace;

  /* filled in by the themes */
  --bg: #1a1a1a;
  --chrome: #303030;
  --chrome-hi: #4a4a4a;
  --chrome-lo: #141414;
  --panel: #242424;
  --ink: #e8e8e8;
  --ink-dim: #9a9a9a;
  --line: #000;
  --lcd-bg: #0b0f0b;
  --lcd-ink: var(--accent);
  --row-hover: rgba(255,255,255,.07);
  --row-active: var(--accent);
  --row-active-ink: #000;
}

/* ---- selectable interface colours ------------------------------------- */
html[data-accent="teal"]    { --accent:#16b5a8; --accent-lo:#0a6f67; --accent-hi:#5ff0e2; }
html[data-accent="cyan"]    { --accent:#28c8f0; --accent-lo:#0d7ea0; --accent-hi:#8ae8ff; }
html[data-accent="lime"]    { --accent:#6fd41f; --accent-lo:#3d7d0c; --accent-hi:#b6f96b; }
html[data-accent="amber"]   { --accent:#f0a828; --accent-lo:#9c6606; --accent-hi:#ffd27a; }
html[data-accent="magenta"] { --accent:#ea3bb0; --accent-lo:#94146c; --accent-hi:#ff92d8; }
html[data-accent="red"]     { --accent:#e8412f; --accent-lo:#961a0e; --accent-hi:#ff8f82; }
html[data-accent="violet"]  { --accent:#9a6bf0; --accent-lo:#5a2fa8; --accent-hi:#cbb0ff; }
html[data-accent="silver"]  { --accent:#c4ccd4; --accent-lo:#79838d; --accent-hi:#ecf1f5; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  padding: 0 0 env(safe-area-inset-bottom);
  background: var(--bg);
  color: var(--ink);
  font: 13px/1.45 var(--font-ui);
  overflow-x: hidden;
}

button, select, input { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
svg { display: block; fill: currentColor; }
.togbtn svg, .volicon { fill: none; stroke: currentColor; stroke-width: 2;
                        stroke-linecap: round; stroke-linejoin: round; }
.tbtn svg, .togbtn svg { width: 100%; height: 100%; }

/* ---------- top bar ----------------------------------------------------- */
.topbar {
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  padding: 8px 14px; padding-top: calc(8px + env(safe-area-inset-top));
  background: var(--chrome);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 40;
}
.brand { font-weight: 700; letter-spacing: .5px; color: var(--accent); }
.brand span { color: var(--ink-dim); font-weight: 400; }
.topbar-group { display: flex; align-items: center; gap: 8px; }
.tb-label { color: var(--ink-dim); font-size: 11px; text-transform: uppercase; letter-spacing: .6px; }

.tb-select, .search, .btn {
  background: var(--panel); color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px 8px; min-height: 34px;
}
.tb-select { max-width: 100%; }
.grow { flex: 1; min-width: 0; }
.btn:hover, .tb-select:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn-sm { min-height: 28px; padding: 4px 8px; font-size: 12px; }

.accent-row { display: flex; gap: 6px; flex-wrap: wrap; }
.sw {
  width: 22px; height: 22px; border: 2px solid transparent;
  border-radius: var(--radius); cursor: pointer; padding: 0;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.6);
}
.sw[aria-pressed="true"] { border-color: var(--ink); }

/* ---------- app grid ---------------------------------------------------- */
#app {
  max-width: 1120px; margin: 0 auto; padding: var(--gap);
  display: grid; gap: var(--gap);
  grid-template-columns: 1.45fr 1fr;
  grid-template-areas: "player player" "library playlists";
}
.player    { grid-area: player; }
.library   { grid-area: library; }
.playlists { grid-area: playlists; }

@media (max-width: 860px) {
  #app { grid-template-columns: 1fr; grid-template-areas: "player" "library" "playlists"; }
}

/* ---------- player ------------------------------------------------------ */
.player {
  background: var(--chrome);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.player-titlebar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 5px 9px; font-size: 11px; font-weight: 700;
  letter-spacing: .5px; text-transform: uppercase;
}
.pt-btns { display: flex; gap: 4px; }
.pt-btns i { width: 11px; height: 11px; display: block; border: 1px solid var(--line); background: var(--chrome-hi); }

.player-body {
  display: grid; gap: 12px; padding: 12px;
  grid-template-columns: 116px minmax(0,1fr);
  grid-template-areas: "art display" "controls controls";
  align-items: start;
}
.art-wrap  { grid-area: art; }
.display   { grid-area: display; min-width: 0; }
.controls  { grid-area: controls; }

@media (min-width: 620px) {
  .player-body {
    grid-template-columns: 132px minmax(0,1fr);
    grid-template-areas: "art display" "art controls";
  }
}

/* album art */
.art-wrap { position: relative; aspect-ratio: 1; width: 100%; background: var(--lcd-bg);
            border: 1px solid var(--line); overflow: hidden; }
.art { width: 100%; height: 100%; object-fit: cover; display: none; }
.art.on { display: block; }
.art-fallback {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: 46px; color: var(--accent-lo); opacity: .7;
}
.art.on + .art-fallback { display: none; }

/* lcd readout */
.lcd {
  background: var(--lcd-bg); border: 1px solid var(--line);
  padding: 7px 9px; font-family: var(--font-lcd); overflow: hidden;
}
.lcd-line { overflow: hidden; white-space: nowrap; }
.lcd-title { display: inline-block; color: var(--lcd-ink); font-size: 14px; }
.lcd-title.scroll { animation: marquee 14s linear infinite; }
@keyframes marquee {
  0%, 12%   { transform: translateX(0); }
  88%, 100% { transform: translateX(var(--shift, -40%)); }
}
.lcd-sub { display: flex; justify-content: space-between; gap: 10px;
           font-size: 11px; color: var(--accent-lo); margin-top: 3px; }
.lcd-artist { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lcd-rate { flex: none; }

/* visualiser */
.viz { display: block; width: 100%; height: 66px; margin-top: 8px;
       background: var(--lcd-bg); border: 1px solid var(--line); }

/* seek */
.seekrow { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.t { font-family: var(--font-lcd); font-size: 11px; color: var(--ink-dim); flex: none;
     min-width: 34px; }
.t-dur { text-align: right; }
.seek {
  position: relative; flex: 1; height: 20px; cursor: pointer;
  display: flex; align-items: center; touch-action: none;
}
.seek::before {
  content: ""; position: absolute; left: 0; right: 0; height: 6px;
  background: var(--chrome-lo); border: 1px solid var(--line);
}
.seek-buf, .seek-fill { position: absolute; left: 0; height: 6px; pointer-events: none; }
.seek-buf  { background: var(--chrome-hi); width: 0; }
.seek-fill { background: var(--accent); width: 0; }
.seek-knob {
  position: absolute; width: 11px; height: 16px; left: 0; margin-left: -5px;
  background: var(--chrome-hi); border: 1px solid var(--line); pointer-events: none;
}
.seek:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* transport */
.controls { display: flex; align-items: center; gap: 10px 14px; flex-wrap: wrap; }
.transport { display: flex; gap: 6px; }
.tbtn {
  width: 42px; height: 34px; padding: 7px 9px;
  background: var(--chrome-hi); border: 1px solid var(--line);
  border-radius: var(--radius); color: var(--ink);
}
.tbtn:hover { color: var(--accent); }
.tbtn:active { background: var(--chrome-lo); }
.tbtn-play { width: 52px; color: var(--accent); }
.i-pause { display: none; }
body.playing .i-play  { display: none; }
body.playing .i-pause { display: block; }

.toggles { display: flex; gap: 6px; flex-wrap: wrap; }
.togbtn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 10px; min-height: 34px; font-size: 11px;
  background: var(--chrome-hi); border: 1px solid var(--line);
  border-radius: var(--radius); color: var(--ink-dim);
  text-transform: uppercase; letter-spacing: .5px;
}
.togbtn svg { width: 15px; height: 15px; flex: none; }
.togbtn[aria-pressed="true"], .togbtn[data-mode="all"], .togbtn[data-mode="one"] {
  color: var(--row-active-ink); background: var(--accent); border-color: var(--accent-lo);
}

.volrow { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 132px; }
.volicon { width: 17px; height: 17px; color: var(--ink-dim); flex: none; }
.vol { flex: 1; min-width: 70px; accent-color: var(--accent); height: 22px; }

/* lyrics */
.lyrics-pane { border-top: 1px solid var(--line); background: var(--lcd-bg); }
.lyrics-head { padding: 6px 12px; font-size: 11px; text-transform: uppercase;
               letter-spacing: .6px; color: var(--accent); border-bottom: 1px solid var(--line); }
.lyrics-text {
  margin: 0; padding: 12px; max-height: 260px; overflow: auto;
  font-family: var(--font-lcd); font-size: 12px; line-height: 1.6;
  color: var(--ink-dim); white-space: pre-wrap;
}

.statusbar {
  display: flex; justify-content: space-between; gap: 10px;
  padding: 5px 10px; font-size: 11px; color: var(--ink-dim);
  background: var(--chrome); border-top: 1px solid var(--line);
}
#statusMsg { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#statusCount { flex: none; }

/* ---------- panels ------------------------------------------------------ */
.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); display: flex; flex-direction: column;
  min-height: 0;
}
.panel-head {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 7px 10px; background: var(--chrome); border-bottom: 1px solid var(--line);
}
.panel-title { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .7px; }
.panel-meta  { font-size: 11px; color: var(--ink-dim); }

.libbar { display: flex; gap: 6px; padding: 8px; padding-bottom: 0; flex-wrap: wrap; }
.libbar .search { flex: 1; min-width: 120px; }

/* track list */
.tracklist, .pl-list { list-style: none; margin: 8px 0 0; padding: 0; overflow-y: auto; }
.tracklist { max-height: 46vh; min-height: 180px; }
@media (max-width: 860px) { .tracklist { max-height: 60vh; } }

.trow {
  display: grid; grid-template-columns: 30px 1fr auto auto; gap: 8px;
  align-items: center; padding: 7px 10px; cursor: pointer;
  border-bottom: 1px solid rgba(0,0,0,.35);
}
.trow:hover { background: var(--row-hover); }
.trow.current { background: var(--row-active); color: var(--row-active-ink); }
.trow.current .tr-artist, .trow.current .tr-time { color: inherit; opacity: .8; }
.tr-num { font-family: var(--font-lcd); font-size: 11px; color: var(--ink-dim); text-align: right; }
.trow.current .tr-num { color: inherit; }
.tr-main { min-width: 0; }
.tr-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tr-artist { font-size: 11px; color: var(--ink-dim); overflow: hidden;
             text-overflow: ellipsis; white-space: nowrap; }
.tr-time { font-family: var(--font-lcd); font-size: 11px; color: var(--ink-dim); }
.tr-add {
  width: 26px; height: 26px; line-height: 1; font-size: 16px;
  color: var(--ink-dim); border: 1px solid transparent; border-radius: var(--radius);
}
.tr-add:hover { color: var(--accent); border-color: var(--line); }
.trow.current .tr-add { color: inherit; }
.tracklist .empty, .pl-list .empty { padding: 18px 12px; color: var(--ink-dim); text-align: center; }

/* playlists */
.pl-list { padding: 0 0 6px; }
.plrow { border-bottom: 1px solid rgba(0,0,0,.35); }
.plrow-top { display: flex; align-items: center; gap: 8px; padding: 8px 10px; }
.pl-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis;
           white-space: nowrap; cursor: pointer; }
.pl-name:hover { color: var(--accent); }
.pl-count { font-size: 11px; color: var(--ink-dim); flex: none; }
.pl-act { width: 28px; height: 28px; color: var(--ink-dim); border: 1px solid transparent; }
.pl-act:hover { color: var(--accent); border-color: var(--line); }
.pl-act.danger:hover { color: #ff6b5a; }
.pl-io { display: flex; gap: 6px; padding: 8px; border-top: 1px solid var(--line); }

/* add-to-playlist popover */
.addpop {
  position: fixed; z-index: 60; left: 50%; top: 50%; transform: translate(-50%,-50%);
  width: min(300px, calc(100vw - 32px));
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: 0 10px 40px rgba(0,0,0,.65);
}
.addpop-head { padding: 8px 10px; background: var(--chrome); border-bottom: 1px solid var(--line);
               font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; }
.addpop-list { list-style: none; margin: 0; padding: 0; max-height: 46vh; overflow: auto; }
.addpop-list li { padding: 9px 10px; cursor: pointer; border-bottom: 1px solid rgba(0,0,0,.35); }
.addpop-list li:hover { background: var(--row-hover); color: var(--accent); }
.addpop #addPopClose { margin: 8px; }

/* ---------- touch ------------------------------------------------------- */
/* Fingers are not mice. On a touch screen the small decorative controls get
   grown to a comfortable target instead of staying pixel-accurate. */
@media (pointer: coarse) {
  .sw        { width: 32px; height: 32px; }
  .accent-row{ gap: 8px; }
  .tr-add    { width: 38px; height: 38px; font-size: 20px; }
  .pl-act    { width: 38px; height: 38px; font-size: 15px; }
  .trow      { padding: 10px; }
  .plrow-top { padding: 10px; }
  .vol       { height: 34px; }
  .seek      { height: 30px; }
  .seek-knob { width: 15px; height: 22px; margin-left: -7px; }
  .tbtn      { height: 44px; }
  .togbtn    { min-height: 40px; }
}

/* ---------- a11y / motion ---------------------------------------------- */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important;
                           transition-duration: .001ms !important; }
}
