:root {
  --bg: #0c0b10;
  --bg-elevated: #16151c;
  --bg-chip: #22212b;
  --bg-chip-2: #2c2a36;
  --text: #f4f1ea;
  --text-dim: #9c97a8;
  --accent: #e8b86d;
  --accent-soft: rgba(232, 184, 109, 0.16);
  --danger: #e26d6d;
  --hairline: rgba(255, 255, 255, 0.08);
  --shadow: 0 16px 50px rgba(0, 0, 0, 0.45);
  --tabbar-h: 64px;
  --mini-h: 64px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --radius: 18px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100%;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}
body { overflow: hidden; height: 100dvh; }
button, input { font: inherit; color: inherit; }
button {
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}
img { display: block; max-width: 100%; }
[hidden] { display: none !important; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

/* Login */
.login-view {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 24px calc(32px + var(--safe-bottom));
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(232, 184, 109, 0.14), transparent 60%),
    var(--bg);
}
.login-card {
  width: 100%;
  max-width: 360px;
  text-align: center;
}
.login-logo {
  margin: 0 auto 20px;
  border-radius: 22px;
  box-shadow: var(--shadow);
}
.login-card h1 {
  font-size: 1.7rem;
  letter-spacing: -0.03em;
  margin: 0 0 8px;
  font-weight: 700;
}
.login-lead {
  color: var(--text-dim);
  margin: 0 0 28px;
  line-height: 1.4;
}
#login-form input[type="password"] {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--hairline);
  border-radius: 14px;
  padding: 14px 16px;
  margin-bottom: 12px;
  outline: none;
}
#login-form input[type="password"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
#login-submit, .btn-secondary, .btn-danger, .btn-ghost, .btn-primary {
  width: 100%;
  border-radius: 14px;
  padding: 14px 16px;
  font-weight: 600;
  margin-top: 8px;
}
#login-submit, .btn-primary {
  background: var(--accent);
  color: #1a140a;
}
.btn-secondary {
  background: var(--bg-chip);
  color: var(--text);
}
.btn-danger { background: rgba(226, 109, 109, 0.15); color: var(--danger); }
.btn-ghost { color: var(--text-dim); }
.login-error {
  color: var(--danger);
  margin: 14px 0 0;
  min-height: 1.3em;
}

/* App shell */
#app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.topbar {
  padding: calc(10px + var(--safe-top)) 16px 8px;
  background: linear-gradient(to bottom, var(--bg) 70%, transparent);
  flex-shrink: 0;
  z-index: 5;
}
.topbar-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
}
.topbar h1 {
  flex: 1;
  margin: 0;
  font-size: 1.55rem;
  letter-spacing: -0.03em;
  font-weight: 700;
}
.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--text);
}
.icon-btn:active { background: var(--bg-chip); }
.icon-btn.active { color: var(--accent); }
.scan-banner {
  margin-top: 6px;
  font-size: 0.82rem;
  color: var(--accent);
}

.main {
  flex: 1;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 4px 16px calc(var(--tabbar-h) + var(--mini-h) + var(--safe-bottom) + 16px);
}
.view { padding-bottom: 8px; }

/* Album grid */
.album-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px 12px;
}
@media (min-width: 700px) {
  .album-grid { grid-template-columns: repeat(4, 1fr); }
}
.album-card { text-align: left; width: 100%; }
.cover, .mini-cover, .np-cover, .row-cover {
  background:
    radial-gradient(circle at 30% 30%, #3a3546, #1c1a24 70%);
  color: #c8bfa8;
  overflow: hidden;
}
.cover {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 12px;
  object-fit: cover;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  margin-bottom: 8px;
}
.cover.placeholder, .row-cover.placeholder, .mini-cover.placeholder, .np-cover.placeholder {
  display: grid;
  place-items: center;
  font-weight: 700;
  letter-spacing: -0.04em;
}
.album-title, .mini-title, .np-title, .row-title {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.album-title { font-size: 0.95rem; }
.album-artist, .mini-artist, .np-artist, .row-sub {
  color: var(--text-dim);
  font-size: 0.82rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Lists */
.list { display: flex; flex-direction: column; }
.row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  width: 100%;
  text-align: left;
  border-bottom: 1px solid var(--hairline);
  min-height: 56px;
}
.row:last-child { border-bottom: 0; }
.row-cover {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
}
.row-body { flex: 1; min-width: 0; text-align: left; }
.row-no {
  width: 22px;
  color: var(--text-dim);
  text-align: center;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}
.row.playing .row-title, .row.playing .row-no { color: var(--accent); }
.more-btn { color: var(--text-dim); flex-shrink: 0; }

.section-title {
  margin: 18px 0 8px;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}
.empty {
  color: var(--text-dim);
  text-align: center;
  padding: 48px 16px;
  line-height: 1.5;
}

/* Detail */
.album-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  margin-bottom: 20px;
}
.album-hero .cover {
  width: min(72vw, 280px);
  border-radius: 16px;
}
.album-hero h2 {
  margin: 4px 0 2px;
  font-size: 1.35rem;
  letter-spacing: -0.03em;
}
.play-all {
  margin-top: 14px;
  background: var(--accent);
  color: #1a140a;
  font-weight: 700;
  border-radius: 999px;
  padding: 10px 28px;
}

/* Search */
.search-wrap { margin: 4px 0 16px; }
#search-input {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--hairline);
  border-radius: 14px;
  padding: 12px 14px;
  outline: none;
}
#search-input:focus { border-color: var(--accent); }

/* Tab bar & mini player */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: rgba(12, 11, 16, 0.92);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-top: 1px solid var(--hairline);
  display: flex;
  z-index: 20;
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--text-dim);
  font-size: 0.68rem;
  font-weight: 500;
}
.tab.active { color: var(--accent); }

.mini-player {
  position: fixed;
  left: 8px;
  right: 8px;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) - 4px);
  height: var(--mini-h);
  background: var(--bg-chip);
  border-radius: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 8px 8px 8px;
  box-shadow: var(--shadow);
  z-index: 25;
}
.mini-cover {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
}
.mini-meta { flex: 1; min-width: 0; text-align: left; }
.mini-title { font-size: 0.92rem; }
.play-btn { color: var(--text); }

/* Now playing */
.now-playing {
  position: fixed;
  inset: 0;
  z-index: 40;
  background:
    radial-gradient(900px 500px at 50% 0%, rgba(232, 184, 109, 0.16), transparent 55%),
    var(--bg);
  display: flex;
  flex-direction: column;
  padding: calc(8px + var(--safe-top)) 24px calc(20px + var(--safe-bottom));
  overflow: auto;
}
.np-handle-wrap { display: flex; justify-content: center; }
.np-close { color: var(--text-dim); }
.np-cover {
  width: min(86vw, 420px);
  aspect-ratio: 1;
  margin: 8px auto 24px;
  border-radius: 18px;
  object-fit: cover;
  box-shadow: var(--shadow);
}
.np-meta { text-align: center; margin-bottom: 18px; }
.np-title { font-size: 1.25rem; font-weight: 700; letter-spacing: -0.02em; }
.np-artist { margin-top: 4px; font-size: 1rem; }
.seek-wrap { margin: 4px 0 8px; }
#seek {
  width: 100%;
  accent-color: var(--accent);
  height: 4px;
}
.seek-times {
  display: flex;
  justify-content: space-between;
  color: var(--text-dim);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  margin-top: 4px;
}
.np-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 10px 0 16px;
}
.play-big {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--text);
  color: #111;
  display: grid;
  place-items: center;
}
.queue-toggle {
  color: var(--text-dim);
  font-size: 0.85rem;
  padding: 8px;
  align-self: center;
}
.queue-list { margin-top: 8px; }

/* Sheets */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet-card {
  width: 100%;
  max-width: 520px;
  background: var(--bg-elevated);
  border-radius: 20px 20px 0 0;
  padding: 20px 20px calc(20px + var(--safe-bottom));
  box-shadow: var(--shadow);
}
.sheet-card h2 { margin: 0 0 12px; font-size: 1.2rem; }
.muted { color: var(--text-dim); margin: 0 0 16px; line-height: 1.4; }
.sheet-action {
  width: 100%;
  text-align: left;
  padding: 14px 4px;
  border-bottom: 1px solid var(--hairline);
  font-size: 1rem;
}
.sheet-action:last-child { border-bottom: 0; }

.new-playlist {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.new-playlist input {
  flex: 1;
  background: var(--bg-chip);
  border: 1px solid var(--hairline);
  border-radius: 12px;
  padding: 12px;
  outline: none;
}
.new-playlist button {
  background: var(--accent);
  color: #1a140a;
  font-weight: 600;
  border-radius: 12px;
  padding: 0 16px;
}

.letter-head {
  position: sticky;
  top: 0;
  background: var(--bg);
  color: var(--accent);
  font-weight: 700;
  padding: 6px 0;
  font-size: 0.85rem;
}


.settings-h {
  margin: 4px 0 10px;
  font-size: 0.95rem;
  font-weight: 650;
}
.quality-list { margin-bottom: 8px; }
.quality-option {
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--bg-chip);
  margin-bottom: 8px;
  border: 1.5px solid transparent;
}
.quality-option.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.quality-name { font-weight: 650; }
.quality-hint {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-top: 3px;
  line-height: 1.35;
}
.quality-note { font-size: 0.82rem; margin: 4px 0 16px; line-height: 1.4; }
.np-quality-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}
.np-format {
  display: inline-block;
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 5px 10px;
  font-weight: 650;
}
.np-quality-btn {
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text);
  background: var(--bg-chip);
  border: 1px solid var(--hairline);
  border-radius: 999px;
  padding: 5px 10px;
  font-weight: 650;
}
.sheet-card {
  max-height: min(92dvh, 920px);
  overflow: auto;
}

/* Fallback shown until app.js starts (helps when the tunnel drops a file) */
.boot-fallback {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  background: #0c0b10;
  color: #f4f1ea;
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
}
.boot-fallback a { color: #e8b86d; }

.mini-player { cursor: pointer; }
.delete-playlist { margin-top: 8px; }
.retry-btn { max-width: 240px; margin-top: 16px; }
.row.current .row-title, .row.current .row-no { color: var(--accent); }

/* Repeat one: small "1" badge */
#btn-repeat { position: relative; }
#btn-repeat.repeat-one::after {
  content: "1";
  position: absolute;
  top: 6px;
  right: 6px;
  min-width: 14px;
  height: 14px;
  border-radius: 7px;
  background: var(--accent);
  color: #1a140a;
  font-size: 10px;
  font-weight: 700;
  line-height: 14px;
  text-align: center;
}

/* Loading state for play buttons */
.play-btn.loading svg, .play-big.loading svg { animation: hm-pulse 1s ease-in-out infinite; }
@keyframes hm-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + var(--mini-h) + var(--safe-bottom) + 12px);
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  background: rgba(44, 42, 54, 0.97);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 0.88rem;
  line-height: 1.35;
  text-align: center;
  box-shadow: var(--shadow);
  z-index: 60;
  pointer-events: none;
}
