:root {
  --bg: #ffffff;
  --surface: #f2f2f7;
  --surface2: #efeff4;
  --text: #000000;
  --text-dim: #8a8a8e;
  --accent: #fa2d48;
  --border: #e5e5ea;
  --mini-bg: rgba(247, 247, 250, 0.94);
  --tabbar-bg: rgba(249, 249, 249, 0.94);
  --np-top: #ececf1;
  --lyric-bg: rgba(255,255,255,0.94);
  --lyric-dim: rgba(0, 0, 0, 0.35);
  --sheet-bg: #f2f2f7;
  --sheet-border: #d8d8dd;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
}

#app { height: 100vh; height: -webkit-fill-available; position: relative; }

.view {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-top: var(--safe-top);
  padding-bottom: calc(84px + var(--safe-bottom)); /* タブバー(50px+安全域)の上に、余裕を持って空ける */
}
.view.active { display: flex; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px 4px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 5;
}
.topbar h1 { font-size: 28px; font-weight: 800; margin: 0; }
.topbar-actions { display: flex; align-items: center; gap: 2px; }

.icon-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 20px;
  padding: 6px 10px;
  cursor: pointer;
}

.filter-chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 8px 16px;
  -webkit-overflow-scrolling: touch;
}
.filter-chip {
  flex-shrink: 0;
  padding: 6px 14px;
  border-radius: 16px;
  background: var(--surface2);
  color: var(--text-dim);
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
}
.filter-chip.active { background: var(--accent); color: #fff; }

.search-bar { padding: 8px 16px; }
.search-bar input {
  width: 100%;
  background: var(--surface2);
  border: none;
  border-radius: 10px;
  padding: 9px 12px;
  color: var(--text);
  font-size: 16px;
}
.search-bar input::placeholder { color: var(--text-dim); }

.import-progress {
  margin: 4px 16px;
  padding: 8px 12px;
  background: var(--surface);
  border-radius: 10px;
  font-size: 13px;
  color: var(--text-dim);
}
.hidden { display: none !important; }

.track-list, .playlist-list {
  list-style: none;
  margin: 0;
  padding: 0 16px;
}

.track-item, .playlist-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.track-item.playing .track-title { color: var(--accent); }

.track-artwork, .playlist-artwork {
  width: 46px;
  height: 46px;
  border-radius: 6px;
  object-fit: cover;
  background: var(--surface2);
  flex-shrink: 0;
}
.playlist-artwork { border-radius: 8px; width: 54px; height: 54px; }

.track-meta { min-width: 0; flex: 1; }
.track-title, .playlist-name { font-size: 16px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.track-artist, .playlist-count { font-size: 13px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.track-menu-btn {
  background: none; border: none; color: var(--text-dim); font-size: 20px; padding: 6px;
}

.empty-hint {
  text-align: center;
  color: var(--text-dim);
  margin-top: 60px;
  padding: 0 32px;
  font-size: 15px;
  line-height: 1.6;
}

/* ===== ミニプレイヤー ===== */
.mini-player {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: calc(58px + var(--safe-bottom));
  background: var(--mini-bg);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.12);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  z-index: 20;
  cursor: pointer;
}
.mini-artwork { width: 38px; height: 38px; border-radius: 4px; object-fit: cover; background: var(--surface2); }
.mini-meta { flex: 1; min-width: 0; }
.mini-title { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-artist { font-size: 12px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-player .icon-btn { font-size: 22px; }

/* ===== タブバー ===== */
.tabbar {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: calc(50px + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: flex;
  background: var(--tabbar-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 0.5px solid var(--border);
  z-index: 15;
}
.tab-btn {
  flex: 1;
  min-width: 0;
  background: none;
  border: none;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 9px;
  padding-top: 4px;
}
.tab-btn.active { color: var(--accent); }
.tab-btn span:last-child { white-space: nowrap; }
.tab-icon { font-size: 19px; }

/* ===== Now Playing ===== */
#view-nowplaying {
  background: linear-gradient(180deg, var(--np-top), var(--bg) 65%);
  padding-left: 20px;
  padding-right: 20px;
  align-items: stretch;
}
.nowplaying-topbar { background: transparent; padding-left: 0; padding-right: 0; }
.np-from { font-size: 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; }

.np-artwork-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  max-height: 42vh;
  margin: 16px auto;
}
.np-artwork {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 10px;
  background: var(--surface2);
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
}
.np-lyrics {
  position: absolute;
  inset: 0;
  background: var(--lyric-bg);
  border-radius: 10px;
  overflow-y: auto;
  padding: 40% 20px;
  font-size: 16px;
  line-height: 2;
  text-align: center;
}

.lyric-line {
  padding: 8px 0;
  color: var(--lyric-dim);
  font-weight: 500;
  transition: color 0.25s ease, transform 0.25s ease;
  cursor: pointer;
}
.lyric-line.active {
  color: var(--text);
  font-weight: 700;
  transform: scale(1.06);
}

.np-meta { display: flex; align-items: center; gap: 8px; margin-top: 8px; text-align: left; }
.np-meta-text { flex: 1; min-width: 0; }
.np-title { font-size: 21px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.np-artist { font-size: 18px; color: var(--accent); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.np-more { width: 32px; height: 32px; border-radius: 50%; background: var(--surface2); color: var(--text-dim); font-size: 18px; padding: 0; flex-shrink: 0; }
.np-topbar-spacer { width: 40px; }

.np-seek { margin-top: 18px; }
.np-seek input[type="range"] {
  width: 100%;
  accent-color: var(--text);
  height: 4px;
}
.np-time { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-dim); margin-top: -2px; }

.np-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 44px;
  margin-top: 24px;
}
.ctrl-btn { background: none; border: none; color: var(--text); padding: 8px; display: flex; align-items: center; justify-content: center; }
.ctrl-btn.small { color: var(--text-dim); }
.ctrl-btn.small.active { color: var(--accent); }
.np-bottom { display: flex; align-items: center; justify-content: space-around; margin-top: 28px; padding: 0 24px; }
.speed-btn { font-size: 14px; font-weight: 700; min-width: 34px; }

/* スリープタイマー(再生画面の上部) */
.np-sleep-timer { color: var(--text-dim); }
.np-sleep-timer.active { color: var(--accent); }

/* 歌詞の拡大表示ボタン(ジャケット/歌詞の右上に重ねる) */
.lyrics-expand-btn {
  position: absolute; top: 8px; right: 8px; z-index: 3;
  width: 30px; height: 30px; border-radius: 50%; padding: 0; border: none;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.32); color: #fff;
}
.lyrics-expand-btn.active { background: var(--accent); }

/* 拡大表示中: ジャケットを隠し、歌詞の枠を画面の残りいっぱいに広げて、文字も大きくする */
body.lyrics-expanded #view-nowplaying .np-artwork-wrap { aspect-ratio: auto; max-height: none; flex: 1 1 auto; }
body.lyrics-expanded #view-nowplaying .np-artwork { display: none; }
body.lyrics-expanded #view-nowplaying .np-lyrics { font-size: 23px; line-height: 2.3; padding: 30% 24px; }

@media (min-width: 700px) {
  .np-artwork-wrap { max-width: 420px; }
}

.app-version { font-size: 12px; font-weight: 400; color: var(--text-dim); margin-left: 6px; }

/* ===== 選択メニュー(アクションシート) ===== */
.sheet-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,0.35);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  width: 100%; max-width: 520px; max-height: 80vh;
  display: flex; flex-direction: column; gap: 8px;
  padding: 8px 8px calc(8px + var(--safe-bottom));
}
.sheet-title {
  text-align: center; padding: 10px 12px; font-size: 13px; color: var(--text-dim);
  background: var(--sheet-bg); border-radius: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sheet-list { display: flex; flex-direction: column; overflow-y: auto; background: var(--sheet-bg); border-radius: 14px; }
.sheet-btn {
  background: var(--sheet-bg); color: var(--accent); border: none; font-size: 17px;
  padding: 15px 12px; border-top: 1px solid var(--sheet-border); text-align: center;
}
.sheet-list .sheet-btn:first-child { border-top: none; }
.sheet-btn.danger { color: #ff453a; }
.sheet-btn.cancel { border-radius: 14px; font-weight: 600; border-top: none; }

/* ===== 一覧先頭の 再生 / シャッフル ボタン ===== */
.play-row { list-style: none; display: flex; gap: 12px; padding: 8px 16px 12px; }
.play-row-btn {
  flex: 1; border: none; border-radius: 10px; padding: 12px 0;
  background: var(--surface2); color: var(--accent); font-size: 16px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; gap: 6px;
}

/* ===== 右端のインデックスバー ===== */
.index-bar {
  position: fixed; right: 2px; z-index: 20;
  top: calc(var(--safe-top) + 110px); bottom: calc(130px + var(--safe-bottom));
  width: 24px; display: flex; flex-direction: column; justify-content: space-between; align-items: center;
  font-size: 10px; font-weight: 700; color: var(--accent); line-height: 1;
  touch-action: none; user-select: none; -webkit-user-select: none;
  border-radius: 10px; transition: background 0.15s;
}
.index-bar.touching { background: rgba(120, 120, 128, 0.22); }
.index-bar span { width: 20px; text-align: center; border-radius: 50%; }
.index-bar span.current { background: var(--accent); color: #fff; }

/* インデックスバーをなぞっている間、画面中央に大きく今の文字を出す(Apple Musicと同様) */
.view.has-index .track-list, .view.has-index .playlist-list { padding-right: 30px; }

/* あ〜わの一覧が無い画面でも、右端の「⋯」などが画面の端に寄り過ぎてタップしにくくならないよう、細いスクロールバーを付ける(文字送りの機能は無い、見た目だけのもの) */
.plain-scrollbar {
  position: fixed; right: 3px; z-index: 20;
  top: calc(var(--safe-top) + 110px); bottom: calc(130px + var(--safe-bottom));
  width: 4px; pointer-events: none;
}
.plain-scrollbar-thumb { position: absolute; right: 0; width: 4px; min-height: 24px; border-radius: 2px; background: rgba(120, 120, 128, 0.35); }
:root[data-theme="dark"] .plain-scrollbar-thumb { background: rgba(255, 255, 255, 0.28); }
.view.has-plain-scrollbar .track-list, .view.has-plain-scrollbar .playlist-list { padding-right: 18px; }
.view.has-plain-scrollbar .search-bar, .view.has-plain-scrollbar .play-row, .view.has-plain-scrollbar .import-progress { margin-right: 14px; }

/* ===== 白基調の仕上げ ===== */
.topbar h1 { display: flex; align-items: baseline; white-space: nowrap; }
.app-version { font-size: 11px; margin-left: 6px; }
.topbar-actions .icon-btn { padding: 6px 7px; display: flex; align-items: center; }
.tab-icon { display: flex; }
/* ミニプレイヤーが出ているときは、画面自体の下端をミニプレイヤーの上で止める(スクロール領域を後ろに足すだけだと、
   ちょうど画面に収まる量の内容のときにスクロールバーが出ず、隠れた分に気づけずボタンが押せないままになるため) */
body.mini-open .view:not(#view-nowplaying) { bottom: calc(116px + var(--safe-bottom)); padding-bottom: 0; }
.np-open .mini-player, .np-open .tabbar { display: none; }
.np-open #view-nowplaying { padding-bottom: calc(24px + var(--safe-bottom)); }

/* ===== ライブラリの複数選択モード ===== */
.select-mode-btn { font-size: 14px; font-weight: 600; }
body.select-mode-active .mini-player { display: none; }
body.select-mode-active #view-library { bottom: calc(116px + var(--safe-bottom)); padding-bottom: 0; }
#view-library.select-mode-active #btn-library-more,
#view-library.select-mode-active #btn-add { display: none; }

.select-action-bar {
  position: absolute; left: 0; right: 0; bottom: calc(50px + var(--safe-bottom));
  height: 58px; display: flex; align-items: center; gap: 10px;
  padding: 0 16px; background: var(--mini-bg);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-top: 0.5px solid var(--border); z-index: 16;
}
.select-bar-btn { background: none; border: none; color: var(--accent); font-size: 15px; font-weight: 600; padding: 8px 6px; white-space: nowrap; }
.select-bar-btn:disabled { color: var(--text-dim); opacity: .5; }
.select-bar-btn.danger { color: #ff3b30; }
.select-count { flex: 1; text-align: center; font-size: 13px; color: var(--text-dim); }
.select-bar-actions { display: flex; }

.track-item.select-mode .track-menu-btn, .track-item.select-mode .fav-mark { display: none; }
.select-check {
  width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--border);
  flex-shrink: 0; position: relative; box-sizing: border-box;
}
.select-check.on { background: var(--accent); border-color: var(--accent); }
.select-check.on::after {
  content: ''; position: absolute; left: 6px; top: 2px; width: 6px; height: 11px;
  border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg);
}
.view.has-index .search-bar, .view.has-index .play-row, .view.has-index .import-progress { margin-right: 26px; }
.view.has-index .search-bar, .view.has-index .play-row { padding-right: 16px; }

.year-sort-btn { font-size: 14px; font-weight: 600; white-space: nowrap; }

/* 曲が多くて画面に収まらないとき、絞り込みの行などが縮んで見えなくなるのを防ぐ */
.view > * { flex-shrink: 0; }

/* 仮想スクロール用: 行の高さを固定する(js/app.js の ROW_H / PLAY_H / HEADER_ROW_H と一致させること) */
.track-list .track-item { height: 63px; }
.play-row { height: 64px; padding-top: 8px; padding-bottom: 12px; }
.v-spacer { list-style: none; margin: 0; padding: 0; border: 0; }

/* あ・か・さ…の見出し行(本物のApple Musicと同じく、曲の間に実際の行として挟む) */
.section-header-row {
  height: 32px; box-sizing: border-box;
  display: flex; align-items: flex-end;
  font-size: 20px; font-weight: 700; color: var(--text);
  padding-bottom: 4px;
}

/* 画面の切り替えを速くする: 見えていない画面を display:none で破棄せず、描画だけ省略して表示計算(レイアウト)を保つ。
   曲が多い一覧の作り直しを、切り替えのたびに行わずに済む。未対応のブラウザでは従来どおり display:none */
@supports (content-visibility: hidden) {
  .view:not(.active) { display: flex; content-visibility: hidden; visibility: hidden; pointer-events: none; }
}

/* 歌詞のタイミング調整(歌詞欄の下に固定) */
.lyric-offset { position: absolute; left: 0; right: 0; bottom: 10px; z-index: 2; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 6px 6px; }
.lyric-offset-break { flex-basis: 100%; height: 0; }
.lyric-sync-btn.waiting { background: var(--accent); color: #fff; }
.lyric-offset-btn, .lyric-offset-label {
  border: none; border-radius: 14px; padding: 6px 12px; font-size: 12px; font-weight: 600;
  background: var(--surface); color: var(--accent); cursor: pointer; box-shadow: 0 1px 4px rgba(0,0,0,0.15);
}
.lyric-offset-label { color: var(--text-dim); }

.drag-handle { font-size: 26px; color: var(--text-dim); padding: 8px 6px 8px 16px; touch-action: none; cursor: grab; user-select: none; -webkit-user-select: none; }
.playlist-item.dragging, .edit-row.dragging { position: relative; z-index: 5; background: var(--surface2); box-shadow: 0 4px 14px rgba(0,0,0,.18); }

/* お気に入り(★) */
.np-fav { display: flex; align-items: center; color: var(--text-dim); padding: 6px 8px; }
.np-fav.on { color: var(--accent); }
.fav-mark { color: var(--accent); font-size: 13px; flex-shrink: 0; }

/* プレイリストに曲を追加する画面 */
.add-btn { width: 32px; height: 32px; border-radius: 50%; border: 0; background: var(--surface2); color: var(--accent); font-size: 18px; font-weight: 700; flex-shrink: 0; }
.add-btn.on { background: var(--accent); color: #fff; }


/* プレイリスト内の曲の並べ替え中の行 */
.edit-row { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border); height: 63px; box-sizing: border-box; }

.sort-select { width: 100%; padding: 10px 12px; border: 0; border-radius: 10px; background: var(--surface2); color: var(--text); font-size: 15px; }

/* 再生待ち画面・トースト */
.queue-heading { font-size: 15px; font-weight: 700; color: var(--text-dim); margin: 14px 16px 4px; }
.toast { position: fixed; left: 50%; bottom: 150px; transform: translateX(-50%); background: rgba(30,30,30,.92); color: #fff; padding: 10px 18px; border-radius: 20px; font-size: 14px; z-index: 50; opacity: 0; pointer-events: none; transition: opacity .2s; }
.toast.show { opacity: 1; }

/* 曲情報の編集・設定の入力欄 */
.form-body { padding: 0 16px 24px; }
.form-row { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--text-dim); padding: 8px 0; }
.form-row input, .form-row select { font-size: 17px; padding: 10px 12px; border: 0; border-radius: 10px; background: var(--surface2); color: var(--text); width: 100%; }
.form-note { font-size: 12px; color: var(--text-dim); padding: 10px 0 2px; word-break: break-all; }
.form-row-with-btn { display: flex; gap: 8px; align-items: stretch; }
.form-row-with-btn input { flex: 1; min-width: 0; }
.form-row-pick-btn { flex: none; border: 0; border-radius: 10px; padding: 0 14px; background: var(--surface2); color: var(--accent); font-size: 14px; font-weight: 600; white-space: nowrap; }

/* ===== ダークモード ===== */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #000000;
  --surface: #1c1c1e;
  --surface2: #2c2c2e;
  --text: #ffffff;
  --text-dim: #98989f;
  --border: #38383a;
  --mini-bg: rgba(44, 44, 46, 0.94);
  --tabbar-bg: rgba(28, 28, 30, 0.94);
  --np-top: #2b2b30;
  --lyric-bg: rgba(20, 20, 22, 0.94);
  --lyric-dim: rgba(255, 255, 255, 0.4);
  --sheet-bg: #2c2c2e;
  --sheet-border: #48484a;
}

/* ===== 設定画面 ===== */
.topbar-left { display: flex; align-items: center; gap: 2px; min-width: 0; }
.settings-btn { padding: 6px 6px; display: flex; align-items: center; }
.settings-section { margin: 18px 0 4px; font-size: 13px; font-weight: 700; color: var(--text-dim); }
.form-check { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; font-size: 16px; color: var(--text); border-bottom: 1px solid var(--border); }
.form-check input { width: 22px; height: 22px; accent-color: var(--accent); }
.settings-btn-row { padding: 10px 0; }
.settings-action { border: 0; border-radius: 10px; padding: 10px 14px; background: var(--surface2); color: var(--accent); font-size: 15px; font-weight: 600; }
.settings-action.danger { color: #ff453a; }

/* 曲情報の編集画面: ジャケット写真の変更 */
.edit-artwork-row { display: flex; align-items: center; gap: 14px; padding: 10px 0; }
.edit-artwork-preview { width: 84px; height: 84px; border-radius: 10px; object-fit: cover; background: var(--surface2); flex-shrink: 0; }
.edit-artwork-btns { display: flex; flex-direction: column; gap: 8px; flex: 1; }
.edit-artwork-btns .settings-action { width: 100%; }

/* 右へスワイプ → 次に再生 */
.track-item { touch-action: pan-y; position: relative; overflow: hidden; }
.track-item > :not(.swipe-hint) { transition: transform .2s ease; }
.track-item.swipe-active > :not(.swipe-hint) { transform: translateX(var(--sx, 0px)); transition: none; }
.swipe-hint { position: absolute; inset: 0; display: flex; align-items: center; padding-left: 18px; background: #af52de; color: #fff; font-size: 15px; font-weight: 700; visibility: hidden; opacity: .75; }
.swipe-hint.ready { opacity: 1; }
.track-item.swipe-active .swipe-hint { visibility: visible; }

.diag-output { font-size: 11px; line-height: 1.5; white-space: pre-wrap; word-break: break-all; color: var(--text); background: var(--surface2); border-radius: 10px; padding: 10px; margin: 0 0 12px; user-select: text; -webkit-user-select: text; }
.diag-output:empty { display: none; }
