/* Quiet — design tokens */
:root {
  --paper: #F7F5F1;
  --paper-2: #F0EEE8;
  --ink: #1A1915;
  --ink-2: #54524A;
  --ink-3: #8B887D;
  --hairline: #E3E0D8;
  --hairline-2: #D6D2C8;
  --accent: #C2452A;
  --accent-soft: #C2452A14;
  --accent-ink: #A93A22;
  --row-h: 44px;
  --rail-w: 224px;
  --side-w: 304px;
  --topbar-h: 56px;
  --transport-h: 72px;
  --radius: 8px;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: ui-serif, "New York", Georgia, "Times New Roman", serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, monospace;
  --shadow-1: 0 1px 2px #1A191514, 0 4px 16px #1A19151A;
  --shadow-2: 0 2px 6px #1A19151F, 0 16px 48px #1A19152E;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #161513;
    --paper-2: #1D1B18;
    --ink: #ECE9E2;
    --ink-2: #B0ACA1;
    --ink-3: #77736A;
    --hairline: #2A2823;
    --hairline-2: #38352E;
    --accent: #E2603F;
    --accent-soft: #E2603F1F;
    --accent-ink: #EC7355;
    --shadow-1: 0 1px 2px #0006, 0 4px 16px #0008;
    --shadow-2: 0 2px 6px #0008, 0 16px 48px #000A;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input { font: inherit; color: inherit; }
kbd {
  font-family: var(--mono); font-size: 11px; color: var(--ink-3);
  border: 1px solid var(--hairline-2); border-bottom-width: 1.5px;
  border-radius: 4px; padding: 0 4px; line-height: 1.5; display: inline-block;
}
.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
::selection { background: var(--accent-soft); }

/* ---------- App grid ---------- */
.app {
  display: grid;
  grid-template-areas:
    "topbar topbar topbar"
    "rail main side"
    "transport transport transport";
  grid-template-columns: var(--rail-w) 1fr var(--side-w);
  grid-template-rows: var(--topbar-h) 1fr var(--transport-h);
  height: 100dvh;
}

/* ---------- Topbar ---------- */
.topbar {
  grid-area: topbar;
  display: flex; align-items: center; gap: 16px;
  padding: 0 20px;
  border-bottom: 1px solid var(--hairline);
  background: var(--paper);
}
.iconbtn.topbar-menu { display: none; }
.searchwrap {
  position: relative; margin-left: auto; width: min(380px, 42vw);
  display: flex; align-items: center;
}
.search-ic { position: absolute; left: 10px; color: var(--ink-3); pointer-events: none; }
#search {
  width: 100%; height: 34px;
  padding: 0 34px 0 32px;
  background: var(--paper-2);
  border: 1px solid transparent;
  border-radius: var(--radius);
  outline: none;
  transition: border-color .15s, background .15s;
}
#search::placeholder { color: var(--ink-3); }
#search:focus { background: var(--paper); border-color: var(--hairline-2); }
#search::-webkit-search-cancel-button { -webkit-appearance: none; }
.search-kbd { position: absolute; right: 8px; pointer-events: none; }
.searchwrap:focus-within .search-kbd { display: none; }

/* ---------- Rail ---------- */
.rail {
  grid-area: rail;
  border-right: 1px solid var(--hairline);
  display: flex; flex-direction: column;
  padding: 14px 10px;
  overflow-y: auto;
  background: var(--paper);
  min-height: 0;
}
.rail-group { margin-bottom: 18px; }
.rail-item {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; padding: 6px 10px;
  border-radius: 6px;
  color: var(--ink-2);
  font-size: 13.5px;
  text-align: left;
  transition: background .12s, color .12s;
}
.rail-item:hover { background: var(--paper-2); color: var(--ink); }
.rail-item[aria-current="page"] { background: var(--paper-2); color: var(--ink); font-weight: 550; }
.rail-count { font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.rail-heading {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--ink-3); padding: 0 10px 6px;
}
.rail-heading .iconbtn { color: var(--ink-3); }
.rail-heading .iconbtn:hover { color: var(--ink); }
.rail-playlist-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  width: 100%; padding: 6px 10px; border-radius: 6px;
  color: var(--ink-2); font-size: 13.5px; text-align: left;
}
.rail-playlist-item:hover { background: var(--paper-2); color: var(--ink); }
.rail-playlist-item[aria-current="page"] { background: var(--paper-2); color: var(--ink); font-weight: 550; }
.rail-playlist-item .pl-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rail-foot { margin-top: auto; padding-top: 12px; }
.rail-footbtn { color: var(--ink-3); font-size: 12.5px; padding: 6px 10px; border-radius: 6px; width: 100%; text-align: left; }
.rail-footbtn:hover { background: var(--paper-2); color: var(--ink-2); }

.iconbtn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 6px; color: var(--ink-2);
  transition: background .12s, color .12s;
}
.iconbtn:hover { background: var(--paper-2); color: var(--ink); }

/* ---------- Main ---------- */
.main { position: relative; grid-area: main; display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--paper); }
.shared-track {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 18px 24px;
  padding: 16px 28px;
  border-bottom: 1px solid var(--hairline);
  background: var(--paper-2);
}
.shared-track-copy { min-width: 0; }
.shared-track-kicker {
  display: block;
  margin-bottom: 3px;
  color: var(--accent-ink);
  font-size: 10.5px;
  font-weight: 650;
  letter-spacing: .06em;
  text-transform: uppercase;
}
.shared-track h2 {
  margin: 0;
  overflow: hidden;
  font-family: var(--serif);
  font-size: 19px;
  font-weight: 600;
  line-height: 1.3;
  text-overflow: ellipsis;
  text-wrap: balance;
  white-space: nowrap;
}
.shared-track-meta { margin: 4px 0 0; color: var(--ink-3); font-size: 12px; font-variant-numeric: tabular-nums; }
.shared-track-actions { display: flex; align-items: center; justify-content: flex-end; gap: 6px; }
.shared-track-blocked { grid-column: 1 / -1; margin: -8px 0 0; color: var(--ink-2); font-size: 12px; }
.return-to-track {
  position: absolute;
  right: 24px;
  bottom: 16px;
  z-index: 5;
  padding: 8px 12px;
  border: 1px solid var(--hairline-2);
  border-radius: 18px;
  background: var(--ink);
  color: var(--paper);
  box-shadow: var(--shadow-1);
  font-size: 12.5px;
}
.return-to-track:hover { background: var(--accent); color: #fff; }
.viewhead {
  display: flex; align-items: baseline; gap: 14px;
  padding: 20px 28px 14px;
}
.viewtitle { font-family: var(--serif); font-size: 26px; font-weight: 600; margin: 0; letter-spacing: 0.005em; }
.viewmeta { color: var(--ink-3); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.viewactions { margin-left: auto; display: flex; gap: 6px; }
.textbtn {
  font-size: 13px; color: var(--ink-2); padding: 6px 12px;
  border: 1px solid var(--hairline-2); border-radius: 6px;
  transition: background .12s, color .12s;
}
.textbtn:hover { background: var(--paper-2); color: var(--ink); }
.textbtn.primary { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.textbtn.primary:hover { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- Track list ---------- */
.listscroll { flex: 1; min-height: 0; overflow-y: auto; outline: none; scrollbar-gutter: stable; }
.listbox { position: relative; }
.row {
  position: absolute; left: 0; right: 0;
  display: flex; align-items: center; gap: 12px;
  height: var(--row-h);
  padding: 0 28px;
  cursor: default;
  border-bottom: 1px solid transparent;
  user-select: none;
}
.row:hover { background: var(--paper-2); }
.row[aria-selected="true"] { background: var(--paper-2); box-shadow: inset 2px 0 0 var(--ink-3); }
.row[aria-current="true"] { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.row.playing .row-title { color: var(--accent-ink); font-weight: 550; }
.row.playing .row-idx { color: var(--accent); }
.row-idx {
  width: 30px; flex: none;
  font-size: 11.5px; color: var(--ink-3);
  font-variant-numeric: tabular-nums; text-align: right;
}
.row-eq { display: none; width: 30px; flex: none; justify-content: flex-end; align-items: flex-end; gap: 2px; height: 12px; }
.row.playing .row-idx { visibility: hidden; width: 30px; }
.row.playing .row-eq { display: inline-flex; margin-left: -42px; margin-right: 12px; }
.row-eq i { width: 2.5px; background: var(--accent); border-radius: 1px; animation: eq 0.9s ease-in-out infinite; }
.row-eq i:nth-child(1) { height: 7px; animation-delay: -0.2s; }
.row-eq i:nth-child(2) { height: 12px; animation-delay: -0.5s; }
.row-eq i:nth-child(3) { height: 5px; animation-delay: -0.8s; }
.paused .row-eq i, .row-eq.paused i { animation-play-state: paused; }
@keyframes eq { 0%, 100% { transform: scaleY(0.5);} 50% { transform: scaleY(1);} }
@media (prefers-reduced-motion: reduce) {
  .row-eq i { animation: none; height: 8px; }
}
.row-title {
  flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 14px;
}
.row-dur { font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; flex: none; }
.row-star { flex: none; color: var(--accent); width: 16px; display: inline-flex; }
.row-star svg { display: block; }
.row-actions {
  position: absolute; right: 20px; top: 50%; transform: translateY(-50%);
  display: none; gap: 2px;
  background: var(--paper-2);
  border-radius: 6px;
  padding-left: 4px;
}
.row:hover .row-actions, .row:focus-within .row-actions, .row[aria-selected="true"] .row-actions { display: flex; }
.row-actions .iconbtn { width: 26px; height: 26px; }
.row-actions .iconbtn.on { color: var(--accent); }
.row-actions .iconbtn.on:hover { color: var(--accent-ink); }

/* ---------- Empty / loading states ---------- */
.empty {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; color: var(--ink-3); text-align: center; padding: 40px;
}
.empty-title { font-family: var(--serif); font-size: 19px; color: var(--ink-2); }
.empty-hint { font-size: 13px; max-width: 340px; line-height: 1.6; }
.skel { height: var(--row-h); display: flex; align-items: center; gap: 12px; padding: 0 28px; }
.skel i { display: block; height: 10px; border-radius: 5px; background: var(--paper-2); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: .6; } 50% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .skel i { animation: none; } }

/* ---------- Side panel ---------- */
.side {
  grid-area: side;
  border-left: 1px solid var(--hairline);
  display: flex; flex-direction: column;
  background: var(--paper);
  min-height: 0;
  min-width: 0;
}
.side-heading {
  font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--ink-3); margin: 0; padding: 16px 20px 8px;
  display: flex; justify-content: space-between; align-items: baseline;
}
.side-count { font-variant-numeric: tabular-nums; }
.side-now { border-bottom: 1px solid var(--hairline); padding-bottom: 16px; }
.side-nowbody { padding: 4px 20px 0; }
.side-nowactions { padding: 10px 20px 0; }
.side-nowactions .textbtn { font-size: 12.5px; padding: 5px 10px; }
.side-now-title {
  font-family: var(--serif); font-size: 17px; line-height: 1.35; font-weight: 600;
  margin: 0 0 6px;
  overflow-wrap: anywhere;
}
.side-now-meta { color: var(--ink-3); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.side-now-empty { color: var(--ink-3); font-size: 13px; line-height: 1.6; }
.side-queue { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.side-queuebody { flex: 1; overflow-y: auto; padding: 0 8px 12px; }
.qrow {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 12px; border-radius: 6px;
  font-size: 13px; color: var(--ink-2);
  width: 100%; text-align: left;
}
.qrow:hover { background: var(--paper-2); color: var(--ink); }
.qrow.current { color: var(--accent-ink); }
.qrow-idx { flex: none; width: 18px; font-size: 11px; color: var(--ink-3); text-align: right; font-variant-numeric: tabular-nums; }
.qrow-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qrow-dur { flex: none; font-size: 11.5px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.side-queue-empty { color: var(--ink-3); font-size: 13px; padding: 4px 20px; line-height: 1.6; }

/* ---------- Transport ---------- */
.transport {
  grid-area: transport;
  border-top: 1px solid var(--hairline);
  background: var(--paper);
  position: relative;
  display: flex; flex-direction: column;
}
.seek { height: 14px; margin-top: -7px; padding: 5px 0; cursor: pointer; z-index: 2; }
.seek-track { height: 3px; background: var(--hairline-2); position: relative; transition: height .12s; }
.seek:hover .seek-track, .seek:focus-visible .seek-track { height: 5px; }
.seek-fill { position: absolute; inset: 0 auto 0 0; width: 0%; background: var(--accent); }
.transport-row {
  flex: 1; display: flex; align-items: center; gap: 12px;
  padding: 0 16px 6px;
  min-height: 0;
}
.t-group { display: flex; align-items: center; gap: 2px; flex: none; }
.t-left { width: 220px; }
.t-right { width: 220px; justify-content: flex-end; }
.tbtn[aria-pressed="true"] { color: var(--accent); }
.tbtn-play {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--ink); color: var(--paper);
  display: inline-flex; align-items: center; justify-content: center;
  margin: 0 4px;
  transition: background .15s, transform .1s;
}
.tbtn-play:hover { background: var(--accent); color: #fff; }
.tbtn-play:active { transform: scale(0.94); }
.t-center { flex: 1; min-width: 0; display: flex; justify-content: center; }
.t-now {
  display: flex; align-items: baseline; gap: 12px; min-width: 0; max-width: 100%;
  padding: 4px 10px; border-radius: 6px;
}
.t-now:hover { background: var(--paper-2); }
.t-title {
  font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  min-width: 0;
}
.t-time { font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; flex: none; }
.t-sep { margin: 0 3px; opacity: .6; }
.volwrap { display: flex; align-items: center; gap: 4px; }
#volume {
  -webkit-appearance: none; appearance: none;
  width: 84px; height: 3px; border-radius: 2px;
  background: var(--hairline-2); outline-offset: 4px;
}
#volume::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 11px; height: 11px; border-radius: 50%;
  background: var(--ink); border: none; cursor: pointer;
}
#volume::-moz-range-thumb {
  width: 11px; height: 11px; border-radius: 50%;
  background: var(--ink); border: none; cursor: pointer;
}
.t-notice {
  position: absolute; left: 50%; bottom: calc(100% + 8px); transform: translateX(-50%);
  background: var(--ink); color: var(--paper);
  font-size: 12.5px; padding: 7px 14px; border-radius: 6px;
  box-shadow: var(--shadow-1); white-space: nowrap;
}

/* ---------- Palette (add to playlist) ---------- */
.palette {
  position: fixed; inset: 0; z-index: 40;
  background: #1A191540;
  display: flex; align-items: flex-start; justify-content: center;
  padding-top: 18vh;
}
.palette-box {
  width: min(440px, calc(100vw - 32px));
  background: var(--paper);
  border: 1px solid var(--hairline);
  border-radius: 12px;
  box-shadow: var(--shadow-2);
  overflow: hidden;
}
.palette-head {
  font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--ink-3); padding: 14px 16px 0;
}
#paletteInput {
  width: 100%; border: 0; background: none; outline: none;
  padding: 12px 16px; font-size: 15px;
  border-bottom: 1px solid var(--hairline);
}
.palette-list { max-height: 280px; overflow-y: auto; padding: 6px; }
.palette-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  width: 100%; padding: 8px 10px; border-radius: 6px;
  font-size: 14px; text-align: left; color: var(--ink-2);
}
.palette-item .pl-count { font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.palette-item[aria-selected="true"] { background: var(--paper-2); color: var(--ink); }
.palette-item.create { color: var(--accent-ink); }
.palette-foot {
  border-top: 1px solid var(--hairline);
  padding: 9px 16px; font-size: 12px; color: var(--ink-3);
}

/* ---------- Sheet (mobile now playing) ---------- */
.sheet {
  position: fixed; inset: 0; z-index: 35;
  background: var(--paper);
  display: flex; flex-direction: column;
}
.sheet-handle { display: flex; justify-content: center; padding: 10px 0 4px; cursor: pointer; }
.sheet-handle span { width: 36px; height: 4px; border-radius: 2px; background: var(--hairline-2); }
.sheet-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.sheet-now { padding: 12px 24px 16px; border-bottom: 1px solid var(--hairline); }
.sheet-now h2 { font-family: var(--serif); font-size: 21px; font-weight: 600; margin: 0 0 4px; overflow-wrap: anywhere; line-height: 1.3; }
.sheet-queuehead {
  font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--ink-3); padding: 14px 24px 6px;
}
.sheet-queue { flex: 1; overflow-y: auto; padding: 0 12px 24px; }

/* ---------- Help dialog ---------- */
.help {
  position: fixed; inset: 0; z-index: 45;
  background: #1A191540;
  display: flex; align-items: center; justify-content: center;
}
.help-box {
  width: min(400px, calc(100vw - 32px));
  background: var(--paper); border: 1px solid var(--hairline);
  border-radius: 12px; box-shadow: var(--shadow-2); padding: 20px;
}
.help-head { font-family: var(--serif); font-size: 18px; font-weight: 600; margin-bottom: 12px; }
.help-grid {
  display: grid; grid-template-columns: auto 1fr; gap: 7px 18px;
  margin: 0 0 16px; font-size: 13px; color: var(--ink-2);
}
.help-grid dt { font-family: var(--mono); font-size: 12px; color: var(--ink); }
.help-grid dd { margin: 0; }
.help-close {
  width: 100%; padding: 8px; border: 1px solid var(--hairline-2); border-radius: 6px;
  color: var(--ink-2);
}
.help-close:hover { background: var(--paper-2); color: var(--ink); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--transport-h) + 14px);
  transform: translateX(-50%);
  background: var(--ink); color: var(--paper);
  padding: 8px 16px; border-radius: 20px;
  font-size: 13px; box-shadow: var(--shadow-1);
  z-index: 50; white-space: nowrap;
  max-width: calc(100vw - 32px); overflow: hidden; text-overflow: ellipsis;
}

.scrim { position: fixed; inset: 0; z-index: 29; background: #1A19152E; }

/* ---------- Responsive ---------- */
@media (max-width: 1180px) {
  .app { grid-template-columns: var(--rail-w) 1fr 0; }
  .side {
    position: fixed; top: 0; right: 0; bottom: 0; z-index: 30;
    width: min(340px, 88vw);
    transform: translateX(100%);
    transition: transform .22s ease;
    box-shadow: var(--shadow-2);
  }
  .side.open { transform: none; }
}
@media (max-width: 860px) {
  .app { grid-template-columns: 0 1fr 0; }
  .rail {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 30;
    width: min(280px, 84vw);
    transform: translateX(-100%);
    transition: transform .22s ease;
    box-shadow: var(--shadow-2);
  }
  .rail.open { transform: none; }
  .iconbtn.topbar-menu { display: inline-flex; }
  .viewhead { padding: 14px 16px 10px; }
  .shared-track { padding: 14px 16px; }
  .shared-track-actions { flex-wrap: wrap; }
  .return-to-track { right: 16px; }
  .row { padding: 0 16px; }
  .row-actions { right: 8px; }
}
@media (max-width: 700px) {
  :root { --row-h: 50px; --transport-h: 64px; }
  .searchwrap { width: auto; flex: 1; }
  .search-kbd { display: none; }
  .topbar { padding: 0 12px; gap: 10px; }
  .t-left { width: auto; }
  #btnShuffle, #btnRepeat, .volwrap, .t-time { display: none; }
  .t-right { width: auto; }
  .viewtitle { font-size: 21px; }
  .shared-track { grid-template-columns: 1fr; gap: 12px; }
  .shared-track h2 { font-size: 17px; white-space: normal; }
  .shared-track-actions { justify-content: flex-start; }
  .shared-track-actions .textbtn { padding: 6px 9px; font-size: 12px; }
  .row-idx { display: none; }
  .row.playing .row-eq { margin-left: 0; }
}
