/* Music Studio — Casara
   Palette: gold #C7A24B, light gold #EBD389, cream #FBF7EE, ink #2A2622, wine #9C2B3E */

:root {
  color-scheme: dark;
  --gold: #c7a24b;
  --gold-light: #ebd389;
  --gold-dark: #9c7d33;
  --wine: #9c2b3e;
  --cream: #fbf7ee;

  --bg: #171412;
  --bg-elevated: #211d1a;
  --bg-sheet: #1b1815;
  --surface: #272220;
  --surface-hover: #322b27;
  --text: #f3ece1;
  --text-dim: #a9a099;
  --text-faint: #6f6862;
  --border: rgba(199, 162, 75, 0.16);
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.45);

  --tap: 48px;
  --bar-height: 60px;
  --mini-height: 62px;
  --radius: 16px;
  --radius-sm: 10px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

[data-theme='light'] {
  color-scheme: light;
  --bg: #fbf7ee;
  --bg-elevated: #fffdf8;
  --bg-sheet: #fffdf8;
  --surface: #f2ead9;
  --surface-hover: #e9dfc9;
  --text: #2a2622;
  --text-dim: #6d635a;
  --text-faint: #9a9089;
  --border: rgba(42, 38, 34, 0.12);
  --shadow: 0 12px 30px rgba(90, 70, 30, 0.18);
  --gold-dark: #8a6d2a;
}

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

html, body {
  margin: 0;
  height: 100%;
  overscroll-behavior-y: none;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', Roboto, system-ui, -apple-system, 'Helvetica Neue', sans-serif;
  font-size: 15px;
  line-height: 1.45;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

button, input, select { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; }
ul { list-style: none; margin: 0; padding: 0; }
h1, h2, h3 { margin: 0; font-weight: 600; }

.icon { width: 24px; height: 24px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.icon--filled { fill: currentColor; stroke: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ------------------------------------------------------------- app bar */

.appbar {
  padding: calc(var(--safe-top) + 6px) 6px 0;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex: none;
  z-index: 5;
}

.appbar__row {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 52px;
  padding: 0 6px;
}

.appbar__brand { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.appbar__logo { height: 26px; width: auto; display: block; }
.appbar__title { font-size: 1.05rem; letter-spacing: 0.01em; white-space: nowrap; }
.appbar__title span { color: var(--gold); }

.iconbtn {
  width: var(--tap); height: var(--tap);
  display: grid; place-items: center;
  border-radius: 50%;
  color: var(--text);
  flex: none;
}
.iconbtn:active { background: var(--surface-hover); }
.iconbtn[aria-pressed='true'] { color: var(--gold); }
.iconbtn--gold { color: var(--gold); }

.search { padding: 0 12px 10px; display: none; }
.search.is-open { display: block; }
.search input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 11px 16px;
  outline: none;
}
.search input:focus { border-color: var(--gold); }

.tabs {
  display: flex;
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 0 8px;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  padding: 10px 14px 12px;
  color: var(--text-dim);
  font-weight: 600;
  font-size: 0.92rem;
  white-space: nowrap;
  border-bottom: 3px solid transparent;
}
.tab[aria-selected='true'] { color: var(--gold); border-bottom-color: var(--gold); }

/* --------------------------------------------------------------- views */

.main { flex: 1; overflow: hidden; position: relative; }

.view {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-bottom: calc(var(--mini-height) + var(--safe-bottom) + 16px);
  display: none;
  scrollbar-width: thin;
}
.view.is-active { display: block; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  color: var(--text-dim);
  font-size: 0.86rem;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 2;
}
.toolbar__count { flex: 1; }
.toolbar select {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.84rem;
}

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 13px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 0.85rem;
  font-weight: 600;
}
.chip--gold { background: var(--gold); color: #1c1813; border-color: transparent; }

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  min-height: 64px;
  width: 100%;
  text-align: left;
}
.row:active { background: var(--surface-hover); }
.row.is-playing .row__title { color: var(--gold); }

.art {
  width: 48px; height: 48px;
  border-radius: 8px;
  background: linear-gradient(145deg, var(--surface), var(--bg-elevated));
  object-fit: cover;
  flex: none;
  display: grid;
  place-items: center;
  color: var(--gold-dark);
  overflow: hidden;
}
.art--lg { width: 100%; height: auto; aspect-ratio: 1; border-radius: var(--radius); }
.art--video { aspect-ratio: 16 / 9; width: 100%; height: auto; border-radius: 12px; }

.row__text { flex: 1; min-width: 0; }
.row__title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row__sub {
  color: var(--text-dim);
  font-size: 0.83rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.row__meta { color: var(--text-faint); font-size: 0.8rem; font-variant-numeric: tabular-nums; flex: none; }

.section-letter {
  position: sticky;
  top: 44px;
  background: var(--bg);
  color: var(--gold);
  font-weight: 700;
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  padding: 6px 14px;
  z-index: 1;
}

/* A–Z index rail — the thing Samsung Music removed and users keep asking for */
.azrail {
  position: absolute;
  right: 0;
  top: 46px;
  bottom: calc(var(--mini-height) + var(--safe-bottom) + 8px);
  width: 22px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 1px;
  font-size: 0.6rem;
  color: var(--text-faint);
  z-index: 3;
  touch-action: none;
}
.azrail button { padding: 0; line-height: 1; color: inherit; }
.azrail button.is-hit { color: var(--gold); font-weight: 700; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 14px;
  padding: 6px 14px 14px;
}
.grid--wide { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.card { text-align: left; width: 100%; }
.card__title { font-weight: 600; font-size: 0.9rem; margin-top: 7px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card__sub { color: var(--text-dim); font-size: 0.78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card__badge {
  position: absolute; right: 6px; bottom: 6px;
  background: rgba(0, 0, 0, 0.72); color: #fff;
  border-radius: 6px; padding: 1px 6px; font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
}
.card__wrap { position: relative; }

.empty {
  padding: 48px 28px;
  text-align: center;
  color: var(--text-dim);
}
.empty svg { width: 56px; height: 56px; color: var(--gold-dark); margin-bottom: 14px; }
.empty h3 { color: var(--text); margin-bottom: 8px; }
.empty p { margin: 0 0 18px; font-size: 0.9rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap);
  padding: 0 20px;
  border-radius: 999px;
  background: var(--gold);
  color: #1c1813;
  font-weight: 700;
}
.btn:active { background: var(--gold-light); }
.btn--ghost { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn--danger { background: var(--wine); color: #fff; }
.btn--block { width: 100%; }

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

.mini {
  position: fixed;
  left: 0; right: 0;
  bottom: var(--safe-bottom);
  height: var(--mini-height);
  display: none;
  align-items: center;
  gap: 10px;
  padding: 0 8px 0 10px;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  z-index: 20;
}
.mini.is-visible { display: flex; }
.mini__progress {
  position: absolute; left: 0; top: 0; height: 2px;
  background: var(--gold);
  width: 0;
  transition: width 0.25s linear;
}
.mini__text { flex: 1; min-width: 0; }
.mini__title { font-size: 0.92rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini__sub { font-size: 0.78rem; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ------------------------------------------------------------- sheets */

.sheet {
  position: fixed;
  inset: 0;
  background: var(--bg-sheet);
  z-index: 40;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
  padding-bottom: var(--safe-bottom);
  overscroll-behavior: contain;
}
.sheet.is-open { transform: translateY(0); }
.sheet__head {
  display: flex; align-items: center; gap: 8px;
  padding: calc(var(--safe-top) + 6px) 8px 6px;
  flex: none;
}
.sheet__head h2 { flex: 1; font-size: 1rem; text-align: center; }
.sheet__body { flex: 1; overflow-y: auto; padding: 0 18px 24px; }

.menu { position: fixed; inset: 0; z-index: 60; display: none; }
.menu.is-open { display: block; }
.menu__scrim { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.55); }
.menu__panel {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  background: var(--bg-elevated);
  border-radius: 20px 20px 0 0;
  padding: 8px 0 calc(var(--safe-bottom) + 10px);
  max-height: 78vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}
.menu__panel::before {
  content: '';
  display: block;
  width: 38px; height: 4px;
  border-radius: 2px;
  background: var(--text-faint);
  margin: 4px auto 10px;
}
.menu__title { padding: 4px 20px 10px; color: var(--text-dim); font-size: 0.85rem; }
.menu__item {
  display: flex; align-items: center; gap: 14px;
  width: 100%;
  padding: 14px 20px;
  text-align: left;
}
.menu__item:active { background: var(--surface-hover); }
.menu__item--danger { color: var(--wine); }
[data-theme='light'] .menu__item--danger { color: #8b2033; }

/* ---------------------------------------------------------- now playing */

.np { justify-content: flex-start; }
.np__body { flex: 1; display: flex; flex-direction: column; padding: 0 22px 12px; overflow: hidden; }
.np__artwrap { flex: 1; display: grid; place-items: center; min-height: 0; padding: 4px 0 14px; }
.np__art {
  width: min(78vw, 46vh);
  aspect-ratio: 1;
  border-radius: 22px;
  object-fit: cover;
  box-shadow: var(--shadow);
  background: linear-gradient(150deg, var(--surface), var(--bg-elevated));
  display: grid; place-items: center;
  color: var(--gold-dark);
  overflow: hidden;
}
.np__art img { width: 100%; height: 100%; object-fit: cover; }
.np__meta { text-align: center; margin-bottom: 8px; }
.np__title { font-size: 1.16rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.np__artist { color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.seek { display: flex; align-items: center; gap: 10px; font-size: 0.76rem; color: var(--text-dim); font-variant-numeric: tabular-nums; }
input[type='range'] {
  -webkit-appearance: none; appearance: none;
  flex: 1; height: 30px; background: transparent;
}
input[type='range']::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: var(--surface-hover); }
input[type='range']::-moz-range-track { height: 4px; border-radius: 2px; background: var(--surface-hover); }
input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 15px; height: 15px; border-radius: 50%;
  background: var(--gold); margin-top: -5.5px;
  border: 0;
}
input[type='range']::-moz-range-thumb { width: 15px; height: 15px; border: 0; border-radius: 50%; background: var(--gold); }
input[type='range']:disabled::-webkit-slider-thumb { background: var(--text-faint); }

.np__controls {
  display: flex; align-items: center; justify-content: space-between;
  margin: 6px 0 2px;
}
.np__play {
  width: 68px; height: 68px;
  border-radius: 50%;
  background: var(--gold);
  color: #1c1813;
  display: grid; place-items: center;
}
.np__play .icon { width: 30px; height: 30px; }
.np__controls .iconbtn .icon { width: 28px; height: 28px; }
.np__extra { display: flex; justify-content: space-around; padding-top: 2px; }
.np__extra .iconbtn .icon { width: 21px; height: 21px; }

.lyrics { padding: 10px 0 24px; text-align: center; color: var(--text-dim); line-height: 2; }
.lyrics .is-current { color: var(--gold); font-weight: 700; font-size: 1.06rem; }

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

.videoplayer {
  position: fixed; inset: 0;
  background: #000;
  z-index: 70;
  display: none;
}
.videoplayer.is-open { display: block; }
.videoplayer video { width: 100%; height: 100%; object-fit: contain; background: #000; }
.videoplayer__overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; justify-content: space-between;
  background: linear-gradient(180deg, rgba(0,0,0,.66), transparent 26%, transparent 62%, rgba(0,0,0,.78));
  opacity: 1;
  transition: opacity 0.25s;
  color: #fff;
}
.videoplayer__overlay.is-hidden { opacity: 0; pointer-events: none; }
.videoplayer__top, .videoplayer__bottom {
  display: flex; align-items: center; gap: 6px;
  padding: calc(var(--safe-top) + 6px) 8px 8px;
}
.videoplayer__bottom { flex-direction: column; align-items: stretch; padding: 8px 14px calc(var(--safe-bottom) + 12px); }
.videoplayer__title { flex: 1; font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.videoplayer__center { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 44px; }
.videoplayer__center .iconbtn { background: rgba(0,0,0,.4); color: #fff; width: 64px; height: 64px; }
.videoplayer__center .icon { width: 30px; height: 30px; }
.videoplayer__row { display: flex; align-items: center; justify-content: space-between; gap: 4px; }
.videoplayer .seek { color: #ddd; }
.videoplayer__toast {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0,0,0,.72);
  padding: 10px 18px; border-radius: 12px;
  font-weight: 600; font-size: 0.95rem;
  opacity: 0; transition: opacity 0.2s;
}
.videoplayer__toast.is-visible { opacity: 1; }
.videoplayer.is-locked .videoplayer__top,
.videoplayer.is-locked .videoplayer__bottom,
.videoplayer.is-locked .videoplayer__center { display: none; }
.videoplayer__unlock { display: none; position: absolute; left: 12px; top: 50%; transform: translateY(-50%); background: rgba(0,0,0,.5); color: #fff; }
.videoplayer.is-locked .videoplayer__unlock { display: grid; }
.videoplayer video::cue { font-size: var(--cue-size, 1rem); background: rgba(0,0,0,.6); }

/* ------------------------------------------------------------ settings */

.set-group { margin: 20px 0 8px; color: var(--gold); font-size: 0.82rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; }
.set-item { display: flex; align-items: center; gap: 12px; padding: 13px 0; border-bottom: 1px solid var(--border); }
.set-item__text { flex: 1; min-width: 0; }
.set-item__label { font-weight: 600; }
.set-item__hint { color: var(--text-dim); font-size: 0.82rem; }
.set-item select, .set-item input[type='number'] {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 10px; min-width: 110px;
}

.switch { width: 46px; height: 27px; border-radius: 999px; background: var(--surface-hover); position: relative; flex: none; transition: background 0.2s; }
.switch::after {
  content: ''; position: absolute; top: 3px; left: 3px;
  width: 21px; height: 21px; border-radius: 50%;
  background: var(--text-dim); transition: transform 0.2s, background 0.2s;
}
.switch[aria-checked='true'] { background: rgba(199, 162, 75, 0.34); }
.switch[aria-checked='true']::after { transform: translateX(19px); background: var(--gold); }

.eq { display: flex; justify-content: space-between; gap: 4px; padding: 14px 0 4px; }
.eq__band { display: flex; flex-direction: column; align-items: center; gap: 6px; flex: 1; }
.eq__band input[type='range'] {
  writing-mode: vertical-lr;
  direction: rtl;
  width: 30px;
  height: 130px;
}
.eq__band span { font-size: 0.63rem; color: var(--text-dim); }
.eq__value { font-size: 0.63rem; color: var(--gold); font-variant-numeric: tabular-nums; }

.progressbar { height: 6px; border-radius: 3px; background: var(--surface-hover); overflow: hidden; margin: 10px 0; }
.progressbar > div { height: 100%; background: var(--gold); width: 0; transition: width 0.2s; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--mini-height) + var(--safe-bottom) + 18px);
  transform: translateX(-50%) translateY(20px);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 18px;
  max-width: 88vw;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 90;
  font-size: 0.9rem;
}
.toast.is-visible { opacity: 1; transform: translateX(-50%) translateY(0); }

.banner {
  position: fixed;
  left: 12px; right: 12px;
  bottom: calc(var(--mini-height) + var(--safe-bottom) + 12px);
  background: var(--gold);
  color: #1c1813;
  border-radius: 14px;
  padding: 12px 14px;
  display: none;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow);
  z-index: 85;
}
.banner.is-visible { display: flex; }
.banner p { margin: 0; flex: 1; font-size: 0.88rem; font-weight: 600; }
.banner button { font-weight: 700; text-decoration: underline; }

.splash {
  position: fixed; inset: 0;
  background: var(--bg);
  display: grid; place-items: center;
  z-index: 100;
  transition: opacity 0.35s;
}
.splash img { width: 210px; max-width: 62vw; }
.splash.is-gone { opacity: 0; pointer-events: none; }

@media (min-width: 720px) {
  .np__body { max-width: 560px; margin: 0 auto; width: 100%; }
  .view { padding-left: max(0px, calc(50% - 480px)); padding-right: max(0px, calc(50% - 480px)); }
  .azrail { right: max(0px, calc(50% - 480px)); }
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
