:root {
  --bg: #0f1115;
  --bg-2: #171a21;
  --bg-3: #20242d;
  --line: #2a2f3a;
  --text: #eef0f4;
  --muted: #9aa1ad;
  --accent: #ff4d6d;
  --accent-2: #ff7a90;
  --radius: 12px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  padding-bottom: calc(72px + var(--safe-b));
}
[hidden] { display: none !important; }
a { color: var(--accent-2); }
h2 { font-size: 17px; margin: 18px 0 8px; }
button { font: inherit; color: inherit; }

.app { max-width: 1200px; margin: 0 auto; }

/* ---------- Player ---------- */
.player { padding: var(--safe-t) 0 8px; background: var(--bg); }
.video-wrap { position: relative; width: 100%; aspect-ratio: 16 / 9; background: #000; }
.video-wrap iframe, #yt-player { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.video-empty {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center;
  background: radial-gradient(circle at 30% 20%, #2a1520, #0b0c10 70%);
  color: var(--muted); padding: 16px;
}
.video-empty .logo { font-size: 34px; font-weight: 800; letter-spacing: -1px; color: var(--text); }
.video-empty .logo::first-letter { color: var(--accent); }
.video-empty p { margin: 6px 0 0; }

.now { display: flex; align-items: center; gap: 8px; padding: 12px 16px 0; }
.now-text { flex: 1; min-width: 0; }
.now-title { font-weight: 650; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.now-sub { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-height: 18px; }

.progress { display: flex; align-items: center; gap: 10px; padding: 6px 16px 0; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.progress span { width: 38px; }
.progress span:last-child { text-align: right; }
input[type=range] { flex: 1; accent-color: var(--accent); height: 24px; margin: 0; }

.controls { display: flex; justify-content: space-between; align-items: center; padding: 4px 24px 0; max-width: 420px; margin: 0 auto; }

.icon-btn {
  position: relative; background: none; border: 0; width: 44px; height: 44px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%; cursor: pointer; color: var(--text); flex: none;
}
.icon-btn:active { background: var(--bg-3); }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn[aria-pressed=true], .icon-btn[data-mode=all], .icon-btn[data-mode=one] { color: var(--accent); }
.icon-btn .badge-one { display: none; position: absolute; top: 8px; right: 6px; font-size: 10px; font-weight: 700; }
.icon-btn[data-mode=one] .badge-one { display: block; }
.icon-btn.play { width: 60px; height: 60px; background: var(--text); color: var(--bg); }
.icon-btn.play:active { background: #ccc; }
.icon-btn.play svg { width: 26px; height: 26px; fill: currentColor; stroke: none; }
.icon-btn.play .i-pause, .playing .icon-btn.play .i-play { display: none; }
.playing .icon-btn.play .i-pause { display: block; }

/* ---------- Content ---------- */
.content { padding: 0 16px; min-width: 0; }
.tabs {
  display: flex; gap: 4px; position: sticky; top: 0; z-index: 5;
  background: var(--bg); padding: calc(8px + var(--safe-t)) 0 8px; border-bottom: 1px solid var(--line);
}
.tabs button {
  flex: 1; background: none; border: 0; padding: 9px 4px; border-radius: 999px;
  color: var(--muted); font-weight: 600; cursor: pointer;
}
.tabs button[aria-selected=true] { background: var(--bg-3); color: var(--text); }
.tabs .tab-icon { flex: none; width: 44px; display: flex; align-items: center; justify-content: center; }
.tabs .tab-icon svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; }

.panel { padding-top: 12px; }
.search-form, .key-form { display: flex; gap: 8px; }
input[type=search], input[type=url], input[type=password], input[type=text] {
  flex: 1; min-width: 0; font: inherit; font-size: 16px; color: var(--text);
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 999px; padding: 10px 16px;
}
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--bg-3); color: var(--text);
  border-radius: 999px; padding: 9px 16px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn:active { filter: brightness(1.2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: none; border-color: transparent; color: var(--muted); }
.btn.danger { color: #ff8095; }
.btn[aria-pressed=true] { border-color: var(--accent); color: var(--accent-2); }
.btn.more { display: block; margin: 12px auto; }

.notice { margin-top: 12px; padding: 10px 14px; background: #2a1c10; border: 1px solid #5a3a14; border-radius: var(--radius); color: #ffd6a0; font-size: 14px; }
.status { color: var(--muted); font-size: 14px; padding: 8px 2px; }
.status:empty { display: none; }
.help { color: var(--muted); font-size: 14px; margin: 0 0 10px; }
.check { display: flex; align-items: center; gap: 8px; margin: 12px 0; color: var(--muted); }
.check input { accent-color: var(--accent); width: 18px; height: 18px; }

.recent { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.recent:empty { display: none; }
.chip { background: var(--bg-2); border: 1px solid var(--line); color: var(--muted); border-radius: 999px; padding: 5px 12px; font-size: 13px; cursor: pointer; }

.row-head { display: flex; align-items: center; gap: 8px; }
.row-head h2 { flex: 1; margin: 8px 0; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pl-actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 4px 0 8px; }

/* Track + playlist rows */
.tracks, .playlists { list-style: none; margin: 0; padding: 0; }
.track, .pl-row {
  display: flex; align-items: center; gap: 12px; padding: 8px 4px; border-radius: 10px; cursor: pointer;
}
.track:active, .pl-row:active { background: var(--bg-2); }
.track.current .t-title { color: var(--accent); }
.thumb { width: 64px; height: 36px; border-radius: 6px; object-fit: cover; background: var(--bg-3); flex: none; }
.pl-row .thumb { width: 52px; height: 52px; }
.t-text { flex: 1; min-width: 0; }
.t-title { font-weight: 550; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.t-sub { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.track .icon-btn { width: 36px; height: 36px; color: var(--muted); }
.track .icon-btn svg { width: 18px; height: 18px; }
.empty { color: var(--muted); text-align: center; padding: 32px 12px; }

/* ---------- Mini player (phones, when the big player is scrolled away) ---------- */
.mini {
  position: fixed; left: 8px; right: 8px; bottom: calc(8px + var(--safe-b)); z-index: 20;
  display: flex; align-items: center; gap: 10px; padding: 6px 6px 6px 8px;
  background: var(--bg-3); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 8px 24px rgba(0,0,0,.5); cursor: pointer;
}
.mini .thumb { width: 48px; height: 48px; }
.mini .icon-btn.play { width: 44px; height: 44px; }
.mini .icon-btn.play svg { width: 20px; height: 20px; }

/* ---------- Sheet ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 30; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 31; max-height: 80vh; overflow: auto;
  background: var(--bg-2); border-radius: 18px 18px 0 0; padding: 14px 16px calc(12px + var(--safe-b));
  max-width: 560px; margin: 0 auto;
}
.sheet-title { font-weight: 700; padding: 4px 4px 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sheet-body { display: flex; flex-direction: column; gap: 4px; }
.sheet-item { text-align: left; background: none; border: 0; padding: 12px 8px; border-radius: 10px; cursor: pointer; font-size: 16px; }
.sheet-item:active { background: var(--bg-3); }
.sheet-item.danger { color: #ff8095; }
.sheet-cancel { width: 100%; margin-top: 8px; }
.sheet form { display: flex; gap: 8px; }

.toast {
  position: fixed; left: 50%; bottom: calc(84px + var(--safe-b)); transform: translateX(-50%); z-index: 40;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-weight: 600;
  font-size: 14px; max-width: calc(100% - 32px); text-align: center; box-shadow: 0 6px 20px rgba(0,0,0,.4);
}

/* ---------- Wide screens: player on the left, library on the right ---------- */
@media (min-width: 900px) {
  body { padding-bottom: 0; }
  .app { display: grid; grid-template-columns: minmax(380px, 1fr) 1fr; gap: 24px; padding: 24px; }
  .player { position: sticky; top: 24px; align-self: start; padding: 0; background: var(--bg-2); border-radius: 16px; overflow: hidden; padding-bottom: 16px; }
  .content { padding: 0; }
  .tabs { padding-top: 0; }
  .mini { display: none !important; }
}
