/*
 * player.css：每一頁底部的音樂播放列（HTML 在 layout.php 的 #mp，動作在 player.js）。
 * 顏色都用 style.css 的變數，所以會跟著淺色／深色模式換。
 *   列表是空的：左下角一顆「♪ 音樂」小按鈕（.mp-fab）
 *   有歌：整條播放列（.mp-bar）固定在畫面最下面
 */

.mp { --mp-fill: var(--sticker); }

/* 有播放列時，頁面最下面多留一點空間，內容才不會被擋住 */
body.has-mp { padding-bottom: 92px; }
/* 提示訊息（style.css 的 .toast）移到播放列上方，不要疊在播放列上 */
body.has-mp .toast { bottom: calc(108px + env(safe-area-inset-bottom)); }   /* 也要高過播放列上緣的小三角形 */

/* ---------- 列表空的時候：左下角的小按鈕 ---------- */
.mp-fab {
  position: fixed; left: 14px; bottom: 14px; z-index: 45;
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 40px; padding: 0 16px;
  border: 1px solid var(--mat-line-strong); border-radius: 999px;
  background: var(--mat-deep); color: var(--on-mat);
  font: inherit; font-size: 15px; font-weight: 700;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .35);
  cursor: pointer;
}
.mp-fab span { color: var(--sticker); font-size: 18px; }
.mp-fab:hover { background: var(--sticker); color: var(--sticker-ink); }
.mp-fab:hover span { color: inherit; }
.mp[data-state="ready"] .mp-fab { display: none; }
.mp[data-state="empty"] .mp-bar { display: none; }

/* ---------- 播放列 ---------- */
.mp-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 45;
  background: var(--mat-deep); color: var(--on-mat);
  border-top: 1px solid var(--mat-line-strong);
  box-shadow: 0 -6px 20px rgba(0, 0, 0, .3);
  padding-bottom: env(safe-area-inset-bottom);
}
.mp-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center; gap: 12px;
  max-width: 1080px; margin: 0 auto; padding: 6px 16px 10px;
}

/* 正在播的歌：點了到那則貼文 */
.mp-now { display: flex; align-items: center; gap: 10px; min-width: 0; color: inherit; text-decoration: none; }
.mp-note {
  flex: none; display: grid; place-items: center;
  width: 40px; height: 40px; border-radius: 8px;
  background: color-mix(in srgb, var(--sticker) 22%, transparent); color: var(--sticker); font-size: 20px;
}
.mp.is-playing .mp-note { animation: mp-bob 1.2s ease-in-out infinite; }
@keyframes mp-bob { 50% { transform: translateY(-2px); } }
.mp-now-text { display: grid; min-width: 0; line-height: 1.35; }
.mp-title { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mp-now:hover .mp-title { text-decoration: underline; text-underline-offset: 3px; }
.mp-time { color: var(--on-mat-soft); font-size: 12px; font-variant-numeric: tabular-nums; }

/* 中間：隨機、上一首、播放、下一首、重複 */
.mp-ctrl { display: flex; align-items: center; gap: 6px; }
.mp-btn {
  position: relative; flex: none; display: grid; place-items: center;
  width: 36px; height: 36px; padding: 0;
  border: 0; border-radius: 50%; background: none; color: var(--on-mat-soft); cursor: pointer;
}
.mp-btn:hover { background: rgba(255, 255, 255, .08); color: var(--on-mat); }
.mp-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.mp-btn svg .fill { fill: currentColor; stroke: none; }
/* 隨機／重複打開時：黃色＋下面一個小點 */
.mp-shuffle[aria-pressed="true"], .mp-repeat:not([data-mode="off"]) { color: var(--sticker); }
.mp-shuffle[aria-pressed="true"]::after, .mp-repeat:not([data-mode="off"])::after {
  content: ""; position: absolute; bottom: 2px; left: 50%;
  width: 4px; height: 4px; margin-left: -2px; border-radius: 50%; background: currentColor;
}
/* 單曲循環：重複圖示中間多一個「1」 */
.mp-one { display: none; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); font-size: 9px; font-weight: 700; line-height: 1; }
.mp-repeat[data-mode="one"] .mp-one { display: block; }

.mp-play {
  flex: none; display: grid; place-items: center;
  width: 46px; height: 46px; padding: 0;
  border: 0; border-radius: 50%;
  background: var(--sticker); color: var(--sticker-ink); cursor: pointer;
}
.mp-play:hover { filter: brightness(.95); }
.mp-play svg { width: 22px; height: 22px; fill: currentColor; }
.mp-i-pause, .mp.is-playing .mp-i-play { display: none; }
.mp.is-playing .mp-i-pause { display: block; }
/* 換頁後瀏覽器不讓自動播：播放鈕閃一圈，提醒按一下 */
.mp.is-wait .mp-play { animation: mp-pulse 1.4s ease-out infinite; }
@keyframes mp-pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--sticker) 70%, transparent); }
  100% { box-shadow: 0 0 0 14px transparent; }
}

/* 右邊：喇叭（靜音／音量）、清單 */
.mp-side { display: flex; align-items: center; justify-content: flex-end; gap: 6px; }
/* 音量：寬螢幕＝喇叭鈕旁邊直接一條音量條（.mp-volbox 平常就攤開）
   窄螢幕／手機（≤720px）＝.mp-volbox 變成喇叭鈕上方彈出的小框，按喇叭鈕才開（.is-open，player.js 加的） */
.mp-volwrap { position: relative; display: flex; align-items: center; gap: 6px; }
.mp-volbox { display: flex; align-items: center; gap: 8px; }
.mp-volnote, .mp-volmute { display: none; }
/* 這個裝置不能由網頁改音量（iPhone／iPad，player.js 偵測後加 no-vol）：藏起音量條 */
.no-vol .mp-vol { display: none; }
.mp-i-mute, .mp.is-muted .mp-i-vol { display: none; }
.mp.is-muted .mp-i-mute { display: block; }
.mp-count {
  position: absolute; top: 0; right: -2px;
  min-width: 17px; height: 17px; padding: 0 4px;
  border-radius: 999px; background: var(--sticker); color: var(--sticker-ink);
  font-size: 11px; font-weight: 700; line-height: 17px; text-align: center;
}
.mp-count[hidden] { display: none; }

/* 進度條：貼在播放列最上緣，整條都能拖 */
.mp-seek, .mp-vol {
  --p: 0%;
  -webkit-appearance: none; appearance: none;
  margin: 0; padding: 0; background: transparent; cursor: pointer;
}
.mp-seek { display: block; width: 100%; height: 16px; margin-top: -8px; }
.mp-vol { width: 90px; height: 22px; --p: 100%; }
.mp-note.has-img { background: none; overflow: hidden; }
.mp-note-img { display: block; width: 100%; height: 100%; object-fit: cover; }
.mp-seek::-webkit-slider-runnable-track, .mp-vol::-webkit-slider-runnable-track {
  height: 4px; border-radius: 2px;
  background: linear-gradient(to right, var(--mp-fill) var(--p), rgba(255, 255, 255, .18) var(--p));
}
.mp-seek::-webkit-slider-thumb, .mp-vol::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px; margin-top: -5px;
  border: 0; border-radius: 50%; background: var(--mp-fill);
  box-shadow: 0 1px 4px rgba(0, 0, 0, .4);
}
.mp-seek::-moz-range-track, .mp-vol::-moz-range-track { height: 4px; border-radius: 2px; background: rgba(255, 255, 255, .18); }
.mp-seek::-moz-range-progress, .mp-vol::-moz-range-progress { height: 4px; border-radius: 2px; background: var(--mp-fill); }
.mp-seek::-moz-range-thumb, .mp-vol::-moz-range-thumb { width: 14px; height: 14px; border: 0; border-radius: 50%; background: var(--mp-fill); }
.mp-seek:hover::-webkit-slider-runnable-track { height: 6px; }
.mp-seek:hover::-webkit-slider-thumb { margin-top: -4px; }

/* ---------- 電腦版：播放列上緣正中間的小三角形（按了開關音樂清單）----------
   像一個從播放列頂端冒出來的小分頁，顏色跟播放列一樣；清單關著 ▲、開著轉成 ▼（data-open，player.js 設的）
   蓋在進度條上面一點點（只有中間 32px），所以 z-index 比進度條高 */
.mp-toggle {
  position: absolute; left: 50%; bottom: 100%; z-index: 1;
  display: flex; align-items: center; justify-content: center; gap: 7px;
  height: 26px; padding: 0 16px; transform: translateX(-50%); white-space: nowrap;
  border: 1px solid var(--mat-line-strong); border-bottom: 0; border-radius: 12px 12px 0 0;
  background: var(--mat-deep); color: var(--on-mat);
  font: inherit; font-size: 13px; font-weight: 700; line-height: 1;
  box-shadow: 0 -3px 8px rgba(0, 0, 0, .18);
  cursor: pointer;
}
.mp-toggle svg { flex: none; display: block; width: 16px; height: 9px; fill: currentColor; transition: transform .2s ease; }
.mp-toggle[data-open="true"] svg { transform: rotate(180deg); }
/* 文字用 CSS 加（不用改 HTML）：展開時「收起」、收起時「♪ 展開」 */
.mp-toggle::after { content: "收起"; }
.mp-toggle[data-open="false"]::after { content: "♪ 展開播放列"; }
.mp-toggle:hover, .mp-toggle:focus-visible { color: var(--sticker); }
.mp-toggle:hover { background: color-mix(in srgb, var(--on-mat) 8%, var(--mat-deep)); }
/* 收起來時：整顆變橘色，貼在畫面最下緣，一眼就看得到 */
.mp.is-collapsed .mp-toggle { background: var(--sticker); border-color: var(--sticker); color: var(--sticker-ink); box-shadow: 0 -2px 10px rgba(0, 0, 0, .3); }
.mp.is-collapsed .mp-toggle:hover { filter: brightness(1.06); color: var(--sticker-ink); background: var(--sticker); }
.mp.is-collapsed.is-playing .mp-toggle svg { animation: mp-bob 1.2s ease-in-out infinite; }

/* 電腦版收起播放列：整條往下滑出畫面，只剩三角形鈕貼在畫面最下緣中間
   鈕在播放列裡面，所以要單獨設 visibility: visible（播放列滑完才 hidden，裡面的按鈕不會被 Tab 選到） */
.mp-bar { transition: transform .32s ease, visibility 0s linear 0s; }
.mp.is-collapsed .mp-bar {
  transform: translateY(100%); visibility: hidden;
  box-shadow: none; border-top-color: transparent;
  transition: transform .32s ease, visibility 0s linear .32s;
}
.mp.is-collapsed .mp-toggle { visibility: visible; }
/* 收起來時頁面下方不用留那麼多空間 */
body.has-mp.mp-collapsed { padding-bottom: 44px; }
body.has-mp.mp-collapsed .toast { bottom: calc(50px + env(safe-area-inset-bottom)); }

/* 手機版的收起把手：電腦版不需要，先藏起來（窄螢幕的樣式在最下面） */
.mp-dock { display: none; }

.mp :focus-visible { outline: 3px solid var(--sticker); outline-offset: 2px; }
/* 清單會捲動（overflow），往外框的焦點框左右會被切掉：清單裡改成往內框 */
.mp-list :focus-visible { outline-offset: -3px; }

/* ---------- 清單面板（播放列表／所有音樂） ---------- */
.mp-panel {
  position: fixed; right: 16px; bottom: 96px; z-index: 46;
  display: flex; flex-direction: column;
  width: min(380px, calc(100vw - 32px)); max-height: min(70vh, 560px);
  border: 1px solid var(--rule); border-radius: 12px;
  background: var(--paper); color: var(--ink);
  box-shadow: 0 16px 40px rgba(0, 0, 0, .4);
  overflow: hidden;
}
.mp-panel[hidden] { display: none; }
.mp[data-state="empty"] .mp-panel { left: 14px; right: auto; bottom: 66px; }
.mp-panel-head { display: flex; align-items: center; gap: 8px; padding: 10px 10px 0 12px; }
.mp-tabs { display: flex; gap: 4px; flex: 1; }
.mp-tab {
  min-height: 34px; padding: 0 14px;
  border: 0; border-radius: 999px; background: none; color: var(--ink-soft);
  font: inherit; font-size: 14px; font-weight: 700; cursor: pointer;
}
.mp-tab[aria-selected="true"] { background: var(--sticker); color: var(--sticker-ink); }
.mp-loud {
  min-height: 30px; padding: 0 12px; flex: none;
  border: 1.5px solid var(--line, currentColor); border-radius: 999px; background: none; color: var(--ink-soft);
  font: inherit; font-size: 13px; font-weight: 700; cursor: pointer; white-space: nowrap;
}
.mp-loud[aria-pressed="true"] { background: var(--sticker); color: var(--sticker-ink); border-color: transparent; }
.mp-loud[hidden] { display: none; }
.mp-close {
  width: 32px; height: 32px; padding: 0;
  border: 0; border-radius: 50%; background: none; color: var(--ink-soft);
  font-size: 22px; line-height: 1; cursor: pointer;
}
.mp-close:hover { background: var(--hover); color: var(--ink); }
.mp-pane { display: flex; flex-direction: column; min-height: 0; }
.mp-pane[hidden] { display: none; }
.mp-pane-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px; border-bottom: 1px solid var(--rule);
  color: var(--ink-soft); font-size: 13px;
}
.mp-pane-bar .linklike { color: var(--ink-soft); font-size: 13px; }
.mp-pane-bar .linklike[hidden] { display: none; }
.mp-list { margin: 0; padding: 4px 0; list-style: none; overflow-y: auto; }
.mp-empty { margin: 0; padding: 18px 16px; color: var(--ink-soft); font-size: 14px; }
.mp-empty[hidden] { display: none; }
.mp-item { display: flex; align-items: center; gap: 4px; padding: 0 8px 0 4px; }
.mp-item:hover { background: var(--hover); }
.mp-item-main {
  flex: 1; min-width: 0;
  display: flex; align-items: center; gap: 10px;
  min-height: 46px; padding: 4px 6px;
  border: 0; background: none; color: inherit; text-align: left;
  font: inherit; font-size: 15px; cursor: pointer;
}
.mp-item-num { flex: none; width: 22px; color: var(--ink-soft); font-size: 13px; text-align: center; font-variant-numeric: tabular-nums; }
.mp-item-text { display: grid; min-width: 0; line-height: 1.35; }
.mp-item-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mp-item-sub { color: var(--ink-soft); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mp-item.is-current .mp-item-title { font-weight: 700; }
.mp-item.is-current .mp-item-num { color: var(--red); }
.mp-item-btn {
  flex: none; width: 32px; height: 32px; padding: 0;
  border: 1px solid var(--rule); border-radius: 50%; background: var(--paper); color: var(--ink-soft);
  font-size: 16px; line-height: 1; cursor: pointer;
}
.mp-item-btn:hover { border-color: var(--ink-soft); color: var(--ink); }
.mp-item-btn.is-in { border-color: transparent; background: var(--sticker); color: var(--sticker-ink); }

/* 貼文播放器上的「＋ 列表」 */
.ap-add {
  flex: none; min-height: 28px; padding: 0 10px;
  border: 1px solid var(--rule); border-radius: 999px;
  background: var(--paper); color: var(--ink-soft);
  font: inherit; font-size: 13px; cursor: pointer;
}
.ap-add:hover { border-color: var(--ink-soft); color: var(--ink); }

/* ---------- 手機、窄螢幕 ---------- */
@media (max-width: 720px) {
  body.has-mp { padding-bottom: 128px; }
  body.has-mp .toast { bottom: calc(120px + env(safe-area-inset-bottom)); }
  .mp-row {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "now side" "ctrl ctrl";
    row-gap: 4px; padding: 4px 12px 8px;
  }
  .mp-now { grid-area: now; }
  .mp-side { grid-area: side; }
  .mp-ctrl { grid-area: ctrl; justify-content: center; gap: 14px; }
  .mp-note { width: 34px; height: 34px; font-size: 17px; }
  /* 音量條：變成彈出框（按喇叭鈕才出現），手指好拖：整條 40px 高 */
  .mp-volbox {
    display: none; position: absolute; right: -44px; bottom: calc(100% + 12px);
    flex-direction: column; align-items: stretch; gap: 8px;
    width: 220px; padding: 12px 14px;
    border: 1px solid var(--mat-line-strong); border-radius: 12px;
    background: var(--mat-deep); box-shadow: 0 8px 24px rgba(0, 0, 0, .45);
  }
  .mp-volwrap.is-open .mp-volbox { display: flex; }
  .mp-vol { width: 100%; height: 36px; }
  .mp-volmute {
    display: block; min-height: 34px; padding: 0 12px;
    border: 1px solid var(--mat-line-strong); border-radius: 999px;
    background: none; color: var(--on-mat); font: inherit; font-size: 14px; cursor: pointer;
  }
  .no-vol .mp-volnote { display: block; color: var(--on-mat-soft); font-size: 13px; line-height: 1.5; }
  .mp-panel, .mp[data-state="empty"] .mp-panel { left: 8px; right: 8px; width: auto; bottom: 132px; max-height: 62vh; }
  .mp[data-state="empty"] .mp-panel { bottom: 66px; }

  /* 小三角形（開清單）在手機上不顯示：清單用右邊的清單鈕開 */
  .mp-toggle { display: none; }

  /* ---------- 把播放列收到左邊（player.js 在 #mp 加 is-collapsed）----------
     展開時：播放列左端一條小把手（◀），按了收起。
     收起時：整條播放列往左滑出畫面，只剩貼在畫面左邊的小把手（♪ ▶），按了滑回來。 */
  .mp-row { padding-left: 32px; }   /* 左邊空出把手的位置 */
  .mp[data-state="ready"] .mp-dock {
    position: fixed; left: 0; bottom: calc(26px + env(safe-area-inset-bottom)); z-index: 46;
    display: flex; align-items: center; justify-content: center; gap: 4px;
    width: 22px; height: 52px; padding: 0;
    border: 1px solid transparent; border-left: 0; border-radius: 0 10px 10px 0;
    background: color-mix(in srgb, var(--on-mat) 9%, var(--mat-deep)); color: var(--on-mat-soft);
    font: inherit; cursor: pointer;
    transition: width .3s ease, height .3s ease, bottom .3s ease, background-color .2s, box-shadow .3s;
  }
  .mp-dock svg { flex: none; width: 8px; height: 12px; fill: currentColor; transform: rotate(180deg); transition: transform .3s ease; }
  .mp-dock-note { display: none; color: var(--sticker); font-size: 19px; line-height: 1; }
  .mp-dock:hover { color: var(--sticker); }
  /* 收起來：把手變成 ♪ ▶ */
  .mp.is-collapsed .mp-dock {
    width: 58px; height: 46px; bottom: calc(14px + env(safe-area-inset-bottom));
    border-color: var(--mat-line-strong);
    background: var(--mat-deep); color: var(--on-mat);
    box-shadow: 0 4px 14px rgba(0, 0, 0, .35);
  }
  .mp.is-collapsed .mp-dock svg { transform: none; }
  .mp.is-collapsed .mp-dock-note { display: block; }
  .mp.is-collapsed.is-playing .mp-dock-note { animation: mp-bob 1.2s ease-in-out infinite; }
  /* 播放列滑出去；滑完才 visibility: hidden（裡面的按鈕不會被 Tab 鍵選到），滑回來時馬上看得到 */
  .mp-bar { transition: transform .32s ease, visibility 0s linear 0s; }
  .mp.is-collapsed .mp-bar {
    transform: translateX(-100%); visibility: hidden;
    transition: transform .32s ease, visibility 0s linear .32s;
  }
  /* 收起來時頁面下方只要留把手的空間 */
  body.has-mp.mp-collapsed { padding-bottom: 76px; }
  body.has-mp.mp-collapsed .toast { bottom: calc(72px + env(safe-area-inset-bottom)); }
}

/* 系統設定「減少動態效果」：不要滑、不要轉 */
@media (prefers-reduced-motion: reduce) {
  .mp-bar, .mp-dock, .mp-dock svg, .mp-toggle svg { transition: none !important; }
  .mp.is-collapsed.is-playing .mp-dock-note { animation: none; }
}

/* 清單裡的歌曲縮圖（方形、上傳音檔時選的展示圖自動縮出來的） */
.mp-item-img { flex: none; width: 40px; height: 40px; border-radius: 6px; object-fit: cover; background: var(--hover); }
.mp-item.is-current .mp-item-img { outline: 2px solid var(--sticker); outline-offset: 1px; }
