/* ===== 画面の下のプレイヤーバー（app/assets/stylesheets/player.css） ===== */

/* バーの高さと色。ここを変えると、バー全体の見た目が変わる */
:root {
  --player-height: 88px;
  --player-background: var(--bg-surface);
  --player-text: var(--text-primary);
  --player-subtext: var(--text-secondary);
  --player-accent: var(--fill-strong);
  /* 音量のつまみ（Figma でデザインを決めたら、ここの色と大きさを差し替える） */
  --player-volume-track: rgba(237, 237, 234, 0.22); /* まだ届いていないところ */
  --player-volume-fill: var(--text-primary);                  /* 今の音量まで */
  --player-volume-thumb: var(--text-primary);                 /* つまみ */
  --player-volume-height: 4px;
  --player-volume-width: 96px;
}

/* バーに隠れないように、ページのいちばん下に余白をあける */
body {
  padding-bottom: calc(var(--player-height) + 24px);
}

.player-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 100;
  box-sizing: border-box;
  height: var(--player-height);
  padding: 0 16px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 2fr) minmax(0, 1fr);
  grid-template-areas:
    "now buttons  side"
    "now progress side";
  align-content: center;
  align-items: center;
  column-gap: 16px;
  row-gap: 6px;
  background: var(--player-background);
  color: var(--player-text);
  border-top: 1px solid var(--border-subtle);
  font-family: var(--font);
  font-size: 13px;
}

/* hidden が付いた部品は、必ず隠す */
.player-bar [hidden] {
  display: none !important;
}

/* 左：ジャケット・曲名・アーティスト */
.player-now {
  grid-area: now;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.player-artwork {
  flex: none;
  width: 56px;
  height: 56px;
  border-radius: 4px;
  overflow: hidden;
  background: var(--bg-raised);
}

.player-artwork img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.player-text {
  min-width: 0;
}

.player-title,
.player-artist {
  margin: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.player-title {
  display: block;
  color: var(--player-text);
  font-weight: bold;
  text-decoration: none;
}

a.player-title[href]:hover {
  text-decoration: underline;
}

.player-artist {
  margin-top: 2px;
  color: var(--player-subtext);
  font-size: 12px;
}

/* まん中：前・再生・次のボタン */
.player-buttons {
  grid-area: buttons;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 20px;
}

.player-buttons button {
  display: grid;
  place-items: center;
  padding: 4px;
  border: none;
  background: none;
  color: var(--player-text);
  cursor: pointer;
}

.player-buttons button:disabled {
  opacity: 0.3;
  cursor: default;
}

.player-buttons #player-toggle {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--fill-strong);
  color: var(--text-inverse);
}

/* 流れているあいだは「一時停止」の絵、止まっているあいだは「再生」の絵 */
.player-icon-pause {
  display: none;
}

.player-bar.is-playing .player-icon-play {
  display: none;
}

.player-bar.is-playing .player-icon-pause {
  display: block;
}

/* まん中：再生位置のバー */
.player-progress {
  grid-area: progress;
  justify-self: center;
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  max-width: 640px;
  color: var(--player-subtext);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.player-progress input[type="range"] {
  flex: 1;
  min-width: 0;
  height: 3px;
  margin: 0;
  -webkit-appearance: none;
  appearance: none;
  border-radius: 999px;
  /* 聴いたところまで白くぬる（長さは player.js が --progress で入れる） */
  background: linear-gradient(to right, var(--fill-strong) var(--progress, 0%), var(--bg-input) var(--progress, 0%));
  cursor: pointer;
}

.player-progress input[type="range"]:disabled {
  cursor: default;
}

.player-progress input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 10px;
  height: 10px;
  border: 0;
  border-radius: 50%;
  background: var(--fill-strong);
  opacity: 0; /* ふだんは隠し、マウスを乗せたときだけ出す */
}

.player-progress input[type="range"]::-moz-range-thumb {
  width: 10px;
  height: 10px;
  border: 0;
  border-radius: 50%;
  background: var(--fill-strong);
  opacity: 0;
}

.player-progress:hover input[type="range"]::-webkit-slider-thumb {
  opacity: 1;
}

.player-progress:hover input[type="range"]::-moz-range-thumb {
  opacity: 1;
}

/* 右：どこから流れているか・お知らせ・Apple Music のボタン */
.player-side {
  grid-area: side;
  display: flex;
  flex-wrap: wrap;  /* 横に入りきらないときは、ボタンと音量を2段にする */
  align-items: center;
  align-content: center;
  justify-content: flex-end;
  gap: 6px 14px;
  min-width: 0;
  overflow: hidden; /* どんなに狭くても、バーの外にはみ出さない */
  color: var(--player-subtext);
}

/* 曲名の下の小さな文字（お知らせ・試聴のクレジット） */
.player-meta {
  margin: 2px 0 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: var(--player-subtext);
  font-size: 10px;
}

.player-meta.is-message {
  color: var(--warning);
}

/* 聴くサービスのボタン（小さな丸い文字ボタン） */
.player-services {
  flex: none;
  display: flex;
  gap: 6px;
}

.player-service {
  flex: none;
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 10px;
  border: 1px solid var(--border-default);
  border-radius: 999px;
  background: none;
  color: var(--player-text);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.player-service:hover {
  border-color: var(--text-tertiary);
}

/* ===== 公式の埋め込みプレーヤー（「Apple Musicで1曲まるごと」「Spotifyで1曲まるごと」を押すと出る） ===== */
.full-player {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 101;
  box-sizing: border-box;
  height: var(--player-height); /* プレイヤーバーと同じ高さ（ページのせまさが変わらない） */
  padding: 4px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--player-background);
  border-top: 1px solid var(--border-subtle);
  font-family: var(--font);
}

.full-player[hidden] {
  display: none;
}

/* Spotify のプレーヤーの左の「前の曲」「次の曲」 */
.full-player-side {
  flex: none;
  display: flex;
  gap: 6px;
}

.full-player-side button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0; /* ふつうのボタンの左右のすきま（16px）が入ると、丸の中の絵が右にずれる */
  border: 1px solid var(--border-default);
  border-radius: 50%;
  background: none;
  color: var(--player-text);
  cursor: pointer;
}

.full-player-side button:disabled {
  opacity: 0.4;
  cursor: default;
}

/* 試聴の音量（白いシンプルなつまみ） */
.player-volume {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--player-subtext);
}

.player-volume:hover {
  color: var(--player-text);
}

.player-volume button {
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  cursor: pointer;
}

/* アイコン：音量に合わせて、波の数と × を出し分ける */
#player-mute .volume-off,
#player-mute[data-level="mute"] .volume-wave-1,
#player-mute[data-level="mute"] .volume-wave-2,
#player-mute[data-level="low"] .volume-wave-2 {
  display: none;
}

#player-mute[data-level="mute"] .volume-off {
  display: inline;
}

.player-volume input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: var(--player-volume-width);
  height: var(--player-volume-height);
  margin: 0;
  border-radius: 999px;
  background: linear-gradient(to right, var(--player-volume-fill) var(--volume, 80%), var(--player-volume-track) var(--volume, 80%));
  cursor: pointer;
}

.player-volume input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 12px;
  height: 12px;
  border: 0;
  border-radius: 50%;
  background: var(--player-volume-thumb);
  opacity: 0;            /* ふだんはつまみを隠し、マウスを乗せたときだけ出す */
  transition: opacity 0.15s;
}

.player-volume input[type="range"]::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border: 0;
  border-radius: 50%;
  background: var(--player-volume-thumb);
  opacity: 0;
  transition: opacity 0.15s;
}

.player-volume input[type="range"]::-moz-range-track {
  height: var(--player-volume-height);
  border-radius: 999px;
  background: transparent;
}

.player-volume:hover input[type="range"]::-webkit-slider-thumb,
.player-volume input[type="range"]:focus-visible::-webkit-slider-thumb {
  opacity: 1;
}

.player-volume:hover input[type="range"]::-moz-range-thumb,
.player-volume input[type="range"]:focus-visible::-moz-range-thumb {
  opacity: 1;
}

/* Spotify のプレーヤーの右の「Apple Musicで聴く」「閉じる」 */
.full-player-buttons {
  display: flex;
  gap: 6px;
}

/* Spotify の小さい公式プレーヤー（高さ80px） */
.full-player-frame {
  flex: 1;
  min-width: 0;
  max-width: 760px;
  height: 80px;
  margin: 0 auto;
}

.full-player-frame iframe {
  display: block;
  width: 100%;
  height: 80px;
  border: 0;
  border-radius: 12px;
  background: transparent;
}

.full-player-head {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  max-width: 220px;
  color: var(--player-subtext);
  font-size: 11px;
  text-align: right;
}

/* お知らせの文字：何も言うことがないときは、場所も取らない（プレーヤーの下をせまくしないため） */
#full-player-note:empty {
  display: none;
}

.full-player-head button {
  flex: none;
  padding: 4px 12px;
  border: 1px solid var(--border-default);
  border-radius: 999px;
  background: none;
  color: var(--player-text);
  font-size: 12px;
  cursor: pointer;
}

/* 公式のプレーヤーが出ているあいだは、同じ場所にある自分のバーをしまう（高さは同じなので、ページは変わらない） */
html:has(#full-player:not([hidden])) #player-bar {
  display: none;
}

/* 曲のページの「Spotifyで聴く」ボタン */
.listen-spotify {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 12px;
  border: 1px solid var(--border-default);
  border-radius: 999px;
  background: none;
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

/* 曲のページの「Apple Musicで聴く」「Spotifyで聴く」のリンクも、同じふちだけのボタン */
.listen-link {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 12px;
  border: 1px solid var(--border-default);
  border-radius: 999px;
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

.listen-spotify:hover,
.listen-link:hover {
  border-color: var(--text-tertiary);
}

/* スマホ（横はばが640px以下）のときは、3段にする */
@media (max-width: 640px) {
  :root {
    --player-height: 132px;
  }

  .player-bar {
    padding: 8px 12px;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "now      buttons"
      "progress progress"
      "side     side";
    column-gap: 12px;
  }

  .player-artwork {
    width: 44px;
    height: 44px;
  }

  .player-buttons {
    gap: 12px;
  }

  .player-progress {
    max-width: none;
  }

  .full-player {
    flex-direction: column;
    justify-content: center;
    align-items: stretch;
    gap: 4px;
    padding: 6px 12px;
  }

  .full-player-frame {
    flex: none;
    width: 100%;
  }

  .full-player {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas:
      "frame frame"
      "side  head";
    align-content: center;
  }

  .full-player-frame {
    grid-area: frame;
  }

  .full-player-side {
    grid-area: side;
  }

  .full-player-side button {
    width: 30px;
    height: 30px;
  }

  /* 下の段：左に 戻す・進む（side）、右に くわしく・読み込み直す・Apple Music・閉じる（head）。
     お知らせの文字が出たときだけ、その上に1行ふえる */
  .full-player-head {
    grid-area: head;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-items: center;
    gap: 4px 8px;
    max-width: none;
    text-align: left;
  }

  #full-player-note {
    flex: 1 0 100%; /* お知らせは、ボタンと同じ行に入れず、その上に出す */
  }

  .player-side {
    justify-content: space-between;
    gap: 8px;
  }

}

/* ===== 各ページの「再生」ボタン =====
   ・曲の行：ふちだけの丸いボタン（Figma の「アイコンボタン」Outline）。流しているあいだは ❚❚
     文字（「▶︎ 再生」）は画面には出さず、読み上げにだけ使う
   ・曲の詳細・推しの詳細：白い「▶︎ 再生」のボタン（下の .song-detail-actions .play-button） */
.play-button {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--border-default);
  border-radius: 999px;
  background: none;
  color: var(--text-primary);
  font-size: 0;
  line-height: 0;
  cursor: pointer;
}

.play-button::before {
  content: "";
  flex: none;
  width: 14px;
  height: 14px;
  margin-left: 1px; /* 三角は少し右に寄せると、まん中に見える */
  background: currentColor;
  -webkit-mask: var(--icon-play) center / contain no-repeat;
  mask: var(--icon-play) center / contain no-repeat;
}

.play-button.is-playing::before {
  -webkit-mask-image: var(--icon-pause);
  mask-image: var(--icon-pause);
}

.play-button:hover {
  border-color: var(--text-tertiary);
}

.play-button.is-current {
  border-color: var(--fill-strong);
}

.song-detail-actions .play-button {
  width: auto;
  height: 32px;
  padding: 0 14px;
  border: 0;
  background: var(--fill-strong);
  color: var(--text-inverse);
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
}

.song-detail-actions .play-button::before {
  display: none;
}

/* ===== 大きな再生画面（iPhone の再生画面のように。中身は layouts/_player_bar.html.erb） =====
   ・うしろ：いま流している曲のジャケットを、画面いっぱいに大きくぼかしたもの（.np-backdrop）
   ・まん中：大きなジャケットと、その下にジャケットの色の影（.np-shadow）
   ・流しているあいだはジャケットが大きく、止めると少し小さくなる（.now-playing.is-playing）
   色の濃さ・ぼかしの大きさは、.np-backdrop の filter と .np-dim の色で変えられる */
.player-artwork {
  cursor: pointer; /* 押すと大きな再生画面が開く */
}

.now-playing {
  position: fixed;
  inset: 0;
  z-index: 300;
  overflow: hidden;
  background: var(--bg-surface);
  color: #ffffff;
  font-family: var(--font);
  transform: translateY(100%);
  visibility: hidden;
  transition: transform 0.45s cubic-bezier(0.2, 0.9, 0.25, 1), visibility 0s linear 0.45s;
}

.now-playing.is-open {
  transform: none;
  visibility: visible;
  transition: transform 0.45s cubic-bezier(0.2, 0.9, 0.25, 1), visibility 0s;
}

/* 開いているあいだは、うしろのページを動かさない */
html.now-playing-open,
html.now-playing-open body {
  overflow: hidden;
}

.now-playing [hidden] {
  display: none !important;
}

/* うしろのぼかし（はみ出したところは見えない） */
.np-backdrop {
  position: absolute;
  top: -15%;
  left: -15%;
  width: 130%;
  height: 130%;
  object-fit: cover;
  filter: blur(70px) saturate(1.6);
  pointer-events: none;
  user-select: none;
}

/* 白い文字が読めるように、少しだけ暗くする（下ほど暗く） */
.np-dim {
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.2), rgba(0, 0, 0, 0.55));
  pointer-events: none;
}

.np-body {
  position: relative;
  box-sizing: border-box;
  height: 100%;
  max-width: 440px;
  margin: 0 auto;
  padding: max(56px, env(safe-area-inset-top)) 28px max(32px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 22px;
}

/* いちばん上の「﹀」（閉じる） */
.np-close {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  display: grid;
  place-items: center;
  width: 44px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.22); /* 明るいジャケットでも見えるように */
  color: #ffffff;
  cursor: pointer;
}

.np-close:hover {
  background: rgba(0, 0, 0, 0.36);
}

/* 大きなジャケット（止めているときは少し小さく） */
.np-art {
  position: relative;
  flex: none;
  width: min(100%, 50vh, 360px);
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.08); /* ジャケットがない曲 */
  transform: scale(0.82);
  transition: transform 0.6s cubic-bezier(0.2, 0.9, 0.25, 1.2);
}

.now-playing.is-playing .np-art {
  transform: scale(1);
}

.np-artwork {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 12px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
}

/* ジャケットの色の影 */
.np-shadow {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 12px;
  filter: blur(28px) saturate(1.5);
  opacity: 0.75;
  transform: translateY(18px) scale(0.92);
  transition: opacity 0.6s ease, transform 0.6s ease;
  pointer-events: none;
}

.now-playing:not(.is-playing) .np-shadow {
  opacity: 0.45;
  transform: translateY(10px) scale(0.88);
}

/* 曲名・アーティスト */
.np-text {
  min-width: 0;
}

.np-title,
.np-artist {
  display: block;
  margin: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.np-title {
  color: #ffffff;
  font-size: 20px;
  font-weight: bold;
  text-decoration: none;
}

.np-title:hover {
  text-decoration: underline;
}

.np-artist {
  margin-top: 4px;
  color: rgba(255, 255, 255, 0.7);
  font-size: 15px;
}

/* 試聴のクレジット（Apple の決まりで、試聴の近くに書く） */
.np-meta {
  margin: 6px 0 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: rgba(255, 255, 255, 0.45);
  font-size: 11px;
}

.np-meta:empty {
  display: none;
}

/* 再生位置（細い白い線。白い長さは player.js が --progress で入れる） */
.np-progress input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  width: 100%;
  height: 4px;
  margin: 0;
  border-radius: 999px;
  background: linear-gradient(to right, rgba(255, 255, 255, 0.9) var(--progress, 0%), rgba(255, 255, 255, 0.25) var(--progress, 0%));
  cursor: pointer;
}

.np-progress input[type="range"]:disabled {
  cursor: default;
}

.np-progress input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 12px;
  height: 12px;
  border: 0;
  border-radius: 50%;
  background: #ffffff;
}

.np-progress input[type="range"]::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border: 0;
  border-radius: 50%;
  background: #ffffff;
}

.np-progress input[type="range"]::-moz-range-track {
  height: 4px;
  border-radius: 999px;
  background: transparent;
}

.np-times {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  color: rgba(255, 255, 255, 0.6);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

/* 前・再生・次（丸い背景はつけない） */
.np-buttons {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 44px;
}

.np-buttons button {
  display: grid;
  place-items: center;
  padding: 4px;
  border: 0;
  background: none;
  color: #ffffff;
  cursor: pointer;
}

.np-buttons button:disabled {
  opacity: 0.35;
  cursor: default;
}

.now-playing.is-playing .player-icon-play {
  display: none;
}

.now-playing.is-playing .player-icon-pause {
  display: block;
}

/* 聴くサービス（小さな丸い文字ボタン） */
.np-services {
  display: flex;
  justify-content: center;
  gap: 8px;
}

.np-service {
  padding: 4px 12px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: #ffffff;
  font-size: 12px;
  cursor: pointer;
}

.np-service:hover {
  border-color: #ffffff;
}

/* 背の低い画面（横向きのスマホなど）：ジャケットを小さく、すきまをつめる */
@media (max-height: 560px) {
  .np-body {
    gap: 12px;
  }

  .np-art {
    width: min(100%, 38vh, 360px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .now-playing,
  .now-playing.is-open,
  .np-art,
  .np-shadow {
    transition: none;
  }
}

/* ===== Apple Music の公式プレーヤー
   Apple のプレーヤーは高さ175px より低くできない（低くすると中身が出ない）ので、
   はばを広げてから全体を小さく（--apple-scale 倍に）して、横長にする。押せるところは、そのまま押せる
   パソコン：0.72倍 → 高さ124px（前は175px）/ スマホ：0.78倍 → 高さ135px（下のはしの線は見せない）===== */
.full-player[data-service="apple"] {
  --apple-scale: 0.72;
}

html:has(#full-player[data-service="apple"]:not([hidden])) {
  --player-height: 150px;
}

.full-player[data-service="apple"] .full-player-frame {
  overflow: hidden;
  height: calc(175px * var(--apple-scale) - 2px);
  border-radius: 12px;
}

.full-player[data-service="apple"] .full-player-frame iframe {
  width: calc(100% / var(--apple-scale));
  height: 175px;
  border-radius: 0;
  transform: scale(var(--apple-scale));
  transform-origin: 0 0;
}

@media (max-width: 640px) {
  .full-player[data-service="apple"] {
    --apple-scale: 0.78;
    height: auto;
  }

  html:has(#full-player[data-service="apple"]:not([hidden])) {
    --player-height: 188px; /* プレーヤー（136px）＋ボタンの列（お知らせの文字は、ふだん出さない） */
  }
}
