:root{
  --bg:#0b0d12;
  --text:#e9ecff;
  --muted:#a8b0d6;
  --line:rgba(255,255,255,.08);
  --accent:#7c5cff;
  --accent2:#19d3ff;

  /* Appleっぽい“ガラス感” */
  --glass: rgba(255,255,255,.06);
  --glass2: rgba(255,255,255,.03);

  --shadow: 0 10px 30px rgba(0,0,0,.35);
  --radius: 18px;

  /* controls sizing（3列固定の軸） */
  --ctrl: 72px;       /* 1マスのサイズ */
  --ctrlGap: 14px;
  --ctrlRadius: 22px;

  --focus: rgba(25,211,255,.55);

  /* JSが設定していない場合の保険 */
  --topbarH: 76px;

  /* ★dockしたときの上余白 */
  --dockTop: calc(env(safe-area-inset-top, 0px) + 8px);
}

*{ box-sizing:border-box; }
html,body{ height:100%; }

body{
  margin:0;
  background: var(--bg);
  color:var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Segoe UI", sans-serif;

  /* ★横はみ出しの根絶 */
  overflow-x: clip;
  /* clipが効かない環境への保険 */
  max-width: 100%;
  min-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* iPhone/Androidの変なタップ不安定対策 */
button, .item, input[type="range"]{
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button{
  font: inherit;
  cursor: pointer;
  user-select:none;
  -webkit-user-select:none;
  color: inherit;
  background: none;
  border: none;
}

/* フォーカスリング（iOS/キーボード対応） */
:focus-visible{
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 14px;
}

/* ===== Topbar ===== */
.topbar{
  position:sticky;
  top:0;
  z-index:100; /* ← nowPlaying より上 */

  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;

  /* ★狭い端末で右が切れる原因を潰す */
  flex-wrap: wrap;

  padding: 14px 14px;
  padding-top: calc(14px + env(safe-area-inset-top, 0px));

  border-bottom:1px solid var(--line);
  background: rgba(11,13,18,.78);

  max-width: 100%;
  overflow: hidden;
}
@supports ((-webkit-backdrop-filter: blur(14px)) or (backdrop-filter: blur(14px))) {
  .topbar{
    background: rgba(11,13,18,.62);
    -webkit-backdrop-filter: blur(14px);
    backdrop-filter: blur(14px);
  }
}

.brand{ display:flex; gap:10px; align-items:center; min-width:0; }

.logo{
  width:38px;height:38px;
  border-radius:12px;
  display:grid;place-items:center;
  background: linear-gradient(135deg, rgba(124,92,255,.92), rgba(25,211,255,.78));
  box-shadow: 0 12px 32px rgba(0,0,0,.40);
  font-weight:900;
  flex:0 0 auto;
}

.brandText{
  display:flex;
  flex-direction:column;
  justify-content:center;
  height:42px;
  min-width:0;
}
.brandText .title{
  font-weight:900;
  letter-spacing:.02em;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}
.brandText .subtitle{
  color:var(--muted);
  font-size:12px;
  margin-top:2px;
  height:14px;
  line-height:14px;
  overflow:hidden;
  white-space:nowrap;
  text-overflow:ellipsis;
}

/* ★右側ボタン群が原因で横幅が伸びるのを防止 */
.topActions{
  display:flex;
  gap:8px;
  align-items:center;
  flex:0 0 auto;
  flex-wrap: wrap;
  justify-content: flex-end;
  max-width: 100%;
}

.chip{
  border:1px solid var(--line);
  background: rgba(255,255,255,.05);
  color:var(--text);
  padding:8px 10px;
  border-radius:999px;
  font-weight:900;
  box-shadow: 0 6px 16px rgba(0,0,0,.18);
  white-space: nowrap;
}
.chip:active{ transform: translateY(1px); }
.chip.active{
  border-color: rgba(124,92,255,.75);
  background: rgba(124,92,255,.20);
}

/* ===== Layout / Cards ===== */
.layout{
  max-width:980px;
  margin: 0 auto;
  padding: 14px;
  padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  display:grid;
  gap:14px;
  max-width: 100%;
}

.card{
  background: linear-gradient(180deg, var(--glass), var(--glass2));
  border:1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow:hidden;
}

/* ===== Now Playing（見やすく＋“滑らかに最上部へ”） ===== */
.nowPlaying{
  /* sticky（topbar下） */
  position: sticky;
  top: calc(var(--topbarH, 76px) + 14px);
  z-index: 50; /* listsより上 / topbarより下 */

  display:grid;
  grid-template-columns: min(160px, 40vw) minmax(0, 1fr);
  gap:14px;
  padding:14px;
  align-items:center;

  max-width: 100%;
  overflow: hidden;

  /* ★常に読める板（透明すぎをやめる） */
  background: rgba(12, 14, 20, .92);
  border-bottom: 1px solid rgba(255,255,255,.08);

  /* ★モーション：topを滑らかに変える（fixed切替しない） */
  transition:
    top .22s ease,
    transform .22s ease,
    opacity .22s ease,
    box-shadow .22s ease,
    background .22s ease,
    border-radius .22s ease;
  will-change: top, transform, opacity;
}

@supports ((-webkit-backdrop-filter: blur(14px)) or (backdrop-filter: blur(14px))){
  .nowPlaying{
    -webkit-backdrop-filter: blur(14px);
    backdrop-filter: blur(14px);
    background: rgba(12, 14, 20, .78);
  }
}

/* ★topbarが消えた後：stickyのまま“画面最上部に詰める” */
.nowPlaying.is-docked{
  /* fixed にしない！ */
  top: var(--dockTop);

  /* “下→上”に寄せるために少しだけ上へ */
  transform: translateY(-6px);

  /* 板感を強める */
  border-radius: 18px;
  box-shadow: 0 18px 50px rgba(0,0,0,.55);
  background: rgba(10, 12, 18, .96);
}
@supports ((-webkit-backdrop-filter: blur(16px)) or (backdrop-filter: blur(16px))){
  .nowPlaying.is-docked{
    background: rgba(10, 12, 18, .84);
    -webkit-backdrop-filter: blur(18px);
    backdrop-filter: blur(18px);
  }
}

/* motion弱めたい人向け */
@media (prefers-reduced-motion: reduce){
  .nowPlaying{ transition:none; }
}

/* cover / meta */
.coverWrap{
  width: min(160px, 40vw);
  height: min(160px, 40vw);
  border-radius: 18px;
  overflow:hidden;
  background: rgba(0,0,0,.25);
  border:1px solid rgba(255,255,255,.10);
  box-shadow: 0 18px 40px rgba(0,0,0,.45);
  flex:0 0 auto;
}
.cover{ width:100%; height:100%; object-fit:cover; display:block; }

.meta{ min-width:0; overflow:hidden; max-width: 100%; }
.songTitle{
  font-size:18px;
  font-weight:900;
  line-height:1.2;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}
.songArtist{
  margin-top:6px;
  color:var(--muted);
  font-size:13px;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}

/* ===== Controls：3列固定（崩れにくい） ===== */
.controls{
  margin-top:12px;

  display:grid;
  grid-template-columns: repeat(3, var(--ctrl));
  grid-auto-rows: var(--ctrl);
  gap: var(--ctrlGap);

  align-items:center;

  width: 100%;
  max-width: calc(var(--ctrl) * 3 + var(--ctrlGap) * 2);
  margin-inline: auto;

  justify-content:center;
  overflow: hidden;
}

/* ボタン：アイコン専用（サイズはマスにフィット） */
.btn.iconBtn{
  width:100%;
  height:100%;
  padding:0;

  border:1px solid var(--line);
  background: rgba(255,255,255,.04);
  border-radius: var(--ctrlRadius);

  display:flex;
  align-items:center;
  justify-content:center;

  overflow:hidden;
}

/* 中央の再生だけ目立たせる */
.btn.primary.iconBtn{
  background: linear-gradient(135deg, rgba(124,92,255,.9), rgba(25,211,255,.65));
  border-color: rgba(255,255,255,.12);
  box-shadow: 0 10px 30px rgba(0,0,0,.25);
}

/* ON状態（shuffle/repeat） */
.btn.on{
  background: rgba(255,255,255,.10);
  border-color: rgba(255,255,255,.18);
}

/* fav ON */
.btn.fav-on{
  border-color: rgba(255,105,180,.55);
  background: rgba(255,105,180,.12);
}

/* ===== SVG icon（inline） ===== */
.icon{
  width: 26px;
  height: 26px;
  display:block;
  color: rgba(233,236,255,.95);
}
.btn.primary .icon{
  width: 28px;
  height: 28px;
}
.icon.stroke{
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}
.icon.fill{ fill: currentColor; }

/* ===== SVG icon（外部ファイル img） ===== */
.iconImg{
  width: 26px;
  height: 26px;
  max-width: 70%;
  max-height: 70%;
  display:block;
  object-fit: contain;
  pointer-events:none;
  user-select:none;
  -webkit-user-select:none;
}
.btn.iconBtn .iconImg{
  width: min(26px, 70%);
  height: min(26px, 70%);
}
.btn.primary .iconImg{
  width: 28px;
  height: 28px;
}

/* ===== Seek ===== */
.seek{
  margin-top:12px;
  display:grid;
  grid-template-columns: 46px minmax(0, 1fr) 46px;
  align-items:center;
  gap:10px;
  max-width: 100%;
}
.time{
  color:var(--muted);
  font-size:12px;
  text-align:center;
}

input[type="range"]{
  width:100%;
  -webkit-appearance:none;
  appearance:none;
  height: 28px;
  background: transparent;
  min-width: 0;
}

input[type="range"]::-webkit-slider-runnable-track{
  height: 6px;
  border-radius: 999px;
  background: rgba(255,255,255,.20);
  box-shadow: inset 0 1px 2px rgba(0,0,0,.35);
}
input[type="range"]::-webkit-slider-thumb{
  -webkit-appearance:none;
  appearance:none;
  width: 26px;
  height: 26px;
  border-radius: 999px;
  background: rgba(255,255,255,.95);
  border: 1px solid rgba(0,0,0,.10);
  margin-top: -10px;
  box-shadow: 0 10px 20px rgba(0,0,0,.35);
}

input[type="range"]::-moz-range-track{
  height: 6px;
  border-radius: 999px;
  background: rgba(255,255,255,.20);
  box-shadow: inset 0 1px 2px rgba(0,0,0,.35);
}
input[type="range"]::-moz-range-thumb{
  width: 26px;
  height: 26px;
  border-radius: 999px;
  background: rgba(255,255,255,.95);
  border: 1px solid rgba(0,0,0,.10);
  box-shadow: 0 10px 20px rgba(0,0,0,.35);
}
input[type="range"]:disabled{ opacity: .45; }

/* ===== Lists ===== */
.lists{
  padding: 14px;
  position: relative;
  z-index: 1; /* nowPlaying(50)より下 */
}

.listHeader{
  display:flex;
  gap:10px;
  align-items:center;
  justify-content:space-between;
  flex-wrap:wrap;
  max-width: 100%;
}

.tabs{ display:flex; gap:8px; flex-wrap: wrap; }

.tab{
  border:1px solid var(--line);
  background: rgba(255,255,255,.05);
  color:var(--text);
  padding:8px 10px;
  border-radius: 999px;
  font-weight:900;
  box-shadow: 0 6px 16px rgba(0,0,0,.18);
  white-space: nowrap;
}
.tab:active{ transform: translateY(1px); }
.tab.active{
  border-color: rgba(124,92,255,.75);
  background: rgba(124,92,255,.20);
}

.search{
  flex:1;
  min-width: 220px;
  border:1px solid rgba(255,255,255,.10);
  background: rgba(0,0,0,.22);
  color:var(--text);
  padding:10px 12px;
  border-radius: 16px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.06);
  max-width: 100%;
}
.search::placeholder{ color: rgba(168,176,214,.7); }

.list{
  margin-top:12px;
  display:grid;
  gap:10px;
}

.item{
  display:flex;
  gap:12px;
  align-items:center;
  padding:10px;
  border-radius: 18px;
  border:1px solid rgba(255,255,255,.08);
  background: rgba(255,255,255,.03);
  cursor:pointer;
  min-width:0;
  transition: background .12s ease, border-color .12s ease, transform .08s ease;
}
.item:hover{
  background: rgba(255,255,255,.06);
  border-color: rgba(255,255,255,.12);
}
.item:active{ transform: translateY(1px); }
.item.active{
  border-color: rgba(25,211,255,.42);
  background: rgba(25,211,255,.10);
}

.itemCover{
  width:52px;height:52px;
  border-radius: 14px;
  overflow:hidden;
  border:1px solid rgba(255,255,255,.10);
  background: rgba(0,0,0,.2);
  flex:0 0 auto;
}
.itemCover img{ width:100%; height:100%; object-fit:cover; display:block; }

.itemMeta{ min-width:0; flex:1; }
.itemTitle{
  font-weight:900;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}
.itemArtist{
  color:var(--muted);
  font-size:12px;
  margin-top:4px;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}

.badge{
  font-size:11px;
  padding:6px 9px;
  border-radius: 999px;
  border:1px solid rgba(255,255,255,.10);
  background: rgba(124,92,255,.14);
  color:var(--text);
  font-weight:900;
  flex:0 0 auto;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.06);
}

.empty{ color:var(--muted); padding:18px 6px; text-align:center; }
.hidden{ display:none; }

/* ===== Toast ===== */
.toast{
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  background: rgba(0,0,0,.78);
  border:1px solid rgba(255,255,255,.10);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 999px;
  box-shadow: 0 12px 26px rgba(0,0,0,.45);
  z-index: 200;
  max-width: calc(100% - 24px);
}
@supports ((-webkit-backdrop-filter: blur(10px)) or (backdrop-filter: blur(10px))) {
  .toast{
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
  }
}

/* ===== Responsive（3列固定は維持しつつマスを縮める） */
@media (max-width:720px){
  :root{
    --ctrl: 64px;
    --ctrlGap: 12px;
    --ctrlRadius: 20px;
  }

  .nowPlaying{ grid-template-columns: min(120px, 38vw) minmax(0, 1fr); }
  .coverWrap{ width: min(120px, 38vw); height: min(120px, 38vw); }

  .topbar{ padding-left:12px; padding-right:12px; }
  .chip{ padding:7px 9px; }

  .icon{ width:28px; height:28px; }
  .btn.primary .icon{ width:30px; height:30px; }
}

/* ★さらに狭い端末（右切れ根絶） */
@media (max-width:420px){
  :root{
    --ctrl: 58px;
    --ctrlGap: 10px;
    --ctrlRadius: 18px;
  }
  .search{ min-width: 160px; }
}
@media (max-width:360px){
  :root{
    --ctrl: 54px;
    --ctrlGap: 10px;
    --ctrlRadius: 18px;
  }
}

/* ===== Special row highlight ===== */
.item.is-special{
  background: linear-gradient(135deg, rgba(170, 90, 255, .18), rgba(0,0,0,0));
  border: 1px solid rgba(170, 90, 255, .22);
}

.item.is-special:hover{
  background: linear-gradient(135deg, rgba(170, 90, 255, .24), rgba(0,0,0,0));
}

/* 選択中（active）のSpecialは少し強め */
.item.is-special.active{
  background: linear-gradient(135deg, rgba(170, 90, 255, .30), rgba(0,0,0,0));
  border-color: rgba(170, 90, 255, .38);
  box-shadow: 0 0 0 1px rgba(170, 90, 255, .18) inset;
}
/* Splash overlay */
.splashOverlay{
  position: fixed;
  inset: 0;
  z-index: 99999;
  display: grid;
  place-items: center;
  background: #0b0d12;
  opacity: 0;
  pointer-events: none;
  transition: opacity 420ms ease;
}

.splashOverlay.show{
  opacity: 1;
  pointer-events: auto;
}

.splashInner{
  width: min(72vw, 360px);
  aspect-ratio: 1 / 1; /* 正方形 */
  display: grid;
  place-items: center;
}

.splashInner img{
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 18px;
  opacity: 0;
  transform: translateY(6px) scale(0.985);
  transition: opacity 420ms ease, transform 520ms ease;
}

.splashOverlay.show .splashInner img{
  opacity: 1;
  transform: translateY(0) scale(1);
}

/* スプラッシュ中は裏を操作できないように */
html.splashLock, body.splashLock{
  overflow: hidden;
  touch-action: none;
}
