:root {
  --bg: #121212;
  --fg: #fff;
  --sub: rgba(255, 255, 255, 0.62);
  --dim: rgba(255, 255, 255, 0.38);
  --accent: #1ed760;
  --card: rgba(255, 255, 255, 0.07);
  --tint: #333;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); overscroll-behavior: none; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
.hidden { display: none !important; }

#bg {
  position: fixed; inset: 0; z-index: 0;
  background: linear-gradient(180deg, var(--tint) 0%, var(--bg) 62%);
  transition: background 0.6s;
}

.screen { position: fixed; inset: 0; z-index: 1; }

/* ---------- Library ---------- */
#library { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: calc(var(--safe-t) + 28px) 20px 0; }
.lib-head h1 { margin: 0; font-size: 30px; font-weight: 800; letter-spacing: 0.01em; }
.lib-head p { margin: 4px 0 0; color: var(--sub); font-size: 13px; }
.lib-actions { display: flex; gap: 10px; margin: 20px 0 14px; }
.pill {
  padding: 10px 20px; border-radius: 999px; font-size: 14px; font-weight: 700;
  background: var(--card); border: 1px solid rgba(255, 255, 255, 0.14);
}
.pill.primary { background: var(--accent); color: #000; border-color: transparent; }
.pill.tiny { padding: 6px 12px; font-size: 12px; font-weight: 600; }
.pill:active { transform: scale(0.97); }
.pill[disabled] { opacity: 0.5; }

.offline-card {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 14px; border-radius: 12px; background: var(--card); margin-bottom: 6px;
}
.offline-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.offline-text strong { font-size: 14px; }
.offline-text span { font-size: 12px; color: var(--sub); }
.bar { height: 3px; background: rgba(255, 255, 255, 0.15); border-radius: 2px; overflow: hidden; margin: 4px 0 10px; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }

#song-list { list-style: none; margin: 8px 0 0; padding: 0; }
.song {
  display: flex; align-items: center; gap: 14px; padding: 8px 0; cursor: pointer;
}
.song:active { opacity: 0.7; }
.song img { width: 56px; height: 56px; border-radius: 6px; object-fit: cover; background: #222; flex: none; }
.song-text { flex: 1; min-width: 0; }
.song-title { display: block; font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.song-sub { display: block; font-size: 13px; color: var(--sub); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.song.current .song-title { color: var(--accent); }
.song-state { flex: none; font-size: 11px; color: var(--dim); text-align: right; min-width: 44px; }
.song-state.on { color: var(--accent); }
.lib-pad { height: calc(96px + var(--safe-b)); }

/* ---------- Mini player ---------- */
.mini {
  position: fixed; z-index: 5; left: 8px; right: 8px; bottom: calc(8px + var(--safe-b));
  display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-radius: 10px;
  background: var(--tint); box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5); overflow: hidden;
}
.mini::before { content: ""; position: absolute; inset: 0; background: rgba(0, 0, 0, 0.28); }
.mini > * { position: relative; }
.mini img { width: 44px; height: 44px; border-radius: 5px; object-fit: cover; flex: none; }
.mini-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.mini-text b { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-text span { font-size: 12px; color: var(--sub); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
#mini-progress { position: absolute; left: 10px; right: 10px; bottom: 0; height: 2px; background: rgba(255, 255, 255, 0.2); }
#mini-progress i { display: block; height: 100%; width: 0; background: #fff; }

.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; flex: none; }
.icon-btn svg { width: 26px; height: 26px; fill: currentColor; }
.icon-btn.small svg { width: 22px; height: 22px; }
.icon-btn:active { transform: scale(0.92); }
.icon-btn.on { color: var(--accent); }

/* ---------- Player ---------- */
.player { z-index: 10; display: flex; flex-direction: column; padding: calc(var(--safe-t) + 6px) 0 calc(var(--safe-b) + 10px); }
.player::before { content: ""; position: absolute; inset: 0; z-index: -1; background: linear-gradient(180deg, var(--tint) 0%, #121212 85%); transition: background 0.6s; }
.p-head { display: flex; align-items: center; justify-content: space-between; padding: 0 12px; height: 50px; }
.p-head-text { flex: 1; text-align: center; font-size: 12px; color: var(--sub); letter-spacing: 0.04em; }
.kara {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 999px; font-size: 13px; font-weight: 700;
  border: 1px solid rgba(255, 255, 255, 0.35); background: rgba(0, 0, 0, 0.2);
}
.kara .kara-ic svg { width: 14px; height: 14px; fill: currentColor; display: block; }
.kara[aria-pressed="true"] { background: var(--accent); color: #000; border-color: transparent; }

.p-info { display: flex; align-items: center; gap: 12px; padding: 6px 20px 10px; }
.p-info img { width: 56px; height: 56px; border-radius: 6px; object-fit: cover; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4); }
.p-info b { display: block; font-size: 18px; line-height: 1.25; }
.p-info span { display: block; font-size: 13px; color: var(--sub); margin-top: 2px; }

.lyrics {
  flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; position: relative;
  padding: 0 22px; outline: none;
  -webkit-mask-image: linear-gradient(180deg, transparent 0, #000 7%, #000 88%, transparent 100%);
  mask-image: linear-gradient(180deg, transparent 0, #000 7%, #000 88%, transparent 100%);
}
.lyrics::-webkit-scrollbar { display: none; }
.lyrics .spacer-t { height: 28vh; }
.lyrics .spacer-b { height: 52vh; }
.ly {
  display: block; width: 100%; text-align: left; padding: 9px 0;
  font-size: 25px; line-height: 1.42; font-weight: 800; letter-spacing: 0.01em;
  color: rgba(255, 255, 255, 0.4); transition: color 0.25s, transform 0.25s; transform-origin: left center;
}
.ly .ph { display: inline-block; }
.ly.past { color: rgba(255, 255, 255, 0.55); }
.ly.active { color: #fff; }
.ly:active { opacity: 0.7; }
.ly-empty { color: var(--sub); font-size: 15px; padding: 40px 0; }

.p-controls { padding: 6px 22px 0; }
.seek input[type="range"] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 22px; background: transparent; margin: 0; display: block;
}
.seek input[type="range"]::-webkit-slider-runnable-track {
  height: 4px; border-radius: 2px;
  background: linear-gradient(90deg, #fff var(--p, 0%), rgba(255, 255, 255, 0.25) var(--p, 0%));
}
.seek input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%; background: #fff; margin-top: -5px;
}
.seek input[type="range"]::-moz-range-track { height: 4px; border-radius: 2px; background: rgba(255, 255, 255, 0.25); }
.seek input[type="range"]::-moz-range-progress { height: 4px; border-radius: 2px; background: #fff; }
.seek input[type="range"]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 0; }
.times { display: flex; justify-content: space-between; font-size: 11px; color: var(--sub); margin-top: 2px; font-variant-numeric: tabular-nums; }

.ctrl-row { display: flex; align-items: center; justify-content: space-between; margin: 6px 0 4px; }
.play-btn { width: 68px; height: 68px; border-radius: 50%; background: #fff; color: #000; display: grid; place-items: center; }
.play-btn svg { width: 30px; height: 30px; fill: #000; }
.play-btn:active { transform: scale(0.94); }
.p-foot { display: flex; align-items: center; justify-content: space-between; min-height: 30px; margin-top: 2px; }
#p-mode-note { font-size: 12px; color: var(--sub); }

.toast {
  position: fixed; z-index: 30; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translateX(-50%);
  background: rgba(40, 40, 40, 0.96); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 13px;
  max-width: 88vw; text-align: center; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
}

@media (min-width: 720px) {
  #library { padding-left: calc(50% - 340px); padding-right: calc(50% - 340px); }
  .mini { left: calc(50% - 340px); right: calc(50% - 340px); }
  .player { padding-left: calc(50% - 300px); padding-right: calc(50% - 300px); }
}

/* ---------- Tabs / playlists ---------- */
.tabs { display: flex; gap: 8px; margin: 10px 0 12px; }
.tab { padding: 8px 16px; border-radius: 999px; font-size: 14px; font-weight: 700; background: var(--card); color: var(--sub); }
.tab.on { background: #fff; color: #000; }
.empty { color: var(--sub); font-size: 14px; line-height: 1.7; text-align: center; padding: 36px 0; }

.pl-new { display: flex; align-items: center; gap: 14px; width: 100%; padding: 8px 0; text-align: left; font-size: 16px; font-weight: 600; }
.pl-new-plus { width: 56px; height: 56px; border-radius: 6px; background: var(--card); display: grid; place-items: center; font-size: 26px; color: var(--sub); flex: none; }
#pl-list, #pv-list, #sheet-list { list-style: none; margin: 0; padding: 0; }
.pl-mosaic { width: 56px; height: 56px; border-radius: 6px; overflow: hidden; background: #222; display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; flex: none; }
.pl-mosaic img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pl-mosaic.one { grid-template-columns: 1fr; grid-template-rows: 1fr; }
.pl-mosaic.two { grid-template-rows: 1fr; }

.row-more { flex: none; width: 36px; height: 36px; display: grid; place-items: center; border-radius: 50%; color: var(--sub); }
.row-more svg { width: 22px; height: 22px; fill: currentColor; }
.row-more:active { background: var(--card); }
.row-edit { display: flex; align-items: center; gap: 2px; flex: none; }
.row-edit .row-more { width: 34px; }
.row-edit .danger { color: #ff6b6b; }

.plview { z-index: 3; background: var(--bg); display: flex; flex-direction: column; }
.pv-head { display: flex; align-items: center; justify-content: space-between; padding: calc(var(--safe-t) + 8px) 12px 0; height: calc(var(--safe-t) + 52px); flex: none; }
.pv-body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 4px 20px 0; }
.pv-body h2 { margin: 6px 0 0; font-size: 26px; font-weight: 800; line-height: 1.3; overflow-wrap: anywhere; }
.pv-body p { margin: 4px 0 0; color: var(--sub); font-size: 13px; }
.pl-delete { display: block; width: 100%; margin: 24px 0 0; padding: 12px; border-radius: 12px; background: var(--card); color: #ff6b6b; font-weight: 700; }

.sheet { position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; }
.sheet-back { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.55); }
.sheet-panel {
  position: relative; width: 100%; max-height: 78dvh; display: flex; flex-direction: column;
  background: #242424; border-radius: 18px 18px 0 0; padding: 14px 18px calc(var(--safe-b) + 14px);
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-bottom: 8px; }
.sheet-head b { font-size: 16px; overflow-wrap: anywhere; }
#sheet-list { overflow-y: auto; -webkit-overflow-scrolling: touch; min-height: 0; }
.sheet-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; cursor: pointer; }
.sheet-row:active { opacity: 0.7; }
.sheet-row img, .sheet-row .pl-mosaic { width: 44px; height: 44px; border-radius: 5px; object-fit: cover; flex: none; }
.sheet-row .song-text { flex: 1; min-width: 0; }
.check { width: 24px; height: 24px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.4); display: grid; place-items: center; flex: none; }
.check.on { background: var(--accent); border-color: var(--accent); }
.check.on::after { content: ""; width: 6px; height: 11px; border: solid #000; border-width: 0 2.5px 2.5px 0; transform: rotate(45deg) translate(-1px, -1px); }
#sheet-foot .pl-new { padding-top: 12px; }
.p-note { min-height: 16px; padding: 0 2px; font-size: 12px; color: var(--sub); }
.p-foot { gap: 8px; justify-content: flex-start; }

.pill { white-space: nowrap; flex: none; }
.sheet-head b { min-width: 0; }
