:root {
  color-scheme: dark;
  --bg: #0b0b0d;
  --surface: #16161a;
  --text: #f5f5f7;
  --text-dim: #a7a7ad;
  --accent: #1db954;
  --now-playing-height: 88px;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  overflow-x: hidden;
  /* スクロールバーの出現/消失自体でビューポート幅が変わらないよう常に領域を確保する
     (非対応ブラウザは無視されるだけで実害なし) */
  scrollbar-gutter: stable;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overflow-x: hidden;
}

body.has-now-playing {
  padding-bottom: calc(var(--now-playing-height) + env(safe-area-inset-bottom, 0px));
}

/* 隠し機能: コナミコマンドで発動するパーティーモード(画面全体が波打つ色に染まる)
   body自体の背景色にすると、ジャケット画像が画面のほとんどを占めているため
   ほぼ見えない。画面全体に重なる半透明レイヤーをmix-blend-modeで
   ジャケット画像ごと着色することで、埋まり具合に関係なく必ず見えるようにする。 */
body.party-mode::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 100;
  pointer-events: none;
  background: linear-gradient(-45deg, #1db954, #1ed760, #ff6b6b, #6b5bff, #1db954);
  background-size: 400% 400%;
  mix-blend-mode: overlay;
  opacity: 0.85;
  animation: party-gradient 12s ease infinite;
}

@keyframes party-gradient {
  0% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0% 50%;
  }
}

/* パーティーモード中はプレイリスト名を虹色グラデーション+明滅する光彩でキラキラさせる */
body.party-mode .playlist-name {
  background: linear-gradient(
    90deg,
    #ff3b3b, #ff9f1c, #ffe74c, #4cff5b, #4cd7ff, #6b5bff, #ff3b3b
  );
  background-size: 300% auto;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
  animation: rainbow-shift 4s linear infinite, sparkle-glow 1.4s ease-in-out infinite;
}

@keyframes rainbow-shift {
  0% {
    background-position: 0% 50%;
  }
  100% {
    background-position: 300% 50%;
  }
}

@keyframes sparkle-glow {
  0%,
  100% {
    filter: drop-shadow(0 0 4px rgba(255, 255, 255, 0.3));
  }
  50% {
    filter: drop-shadow(0 0 16px rgba(255, 255, 255, 0.95));
  }
}

img {
  max-width: 100%;
}

[hidden] {
  display: none !important;
}

.site-header {
  display: flex;
  align-items: center;
  gap: 14px;
  /* 固定の高さにすると、見出しが複数行に折り返した時にはみ出した分が
     下のグリッドと重なってしまうため、中身に応じて自動で伸びる高さにする。 */
  padding: 12px 20px;
  text-align: left;
}

.x-link {
  flex-shrink: 0;
  margin-left: auto;
  display: inline-flex;
  color: var(--text-dim);
  opacity: 0.85;
  transition: opacity 0.15s ease, color 0.15s ease;
}

.x-link:hover,
.x-link:focus-visible {
  opacity: 1;
  color: var(--text);
}

.playlist-link {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
  text-decoration: none;
  opacity: 0.9;
  transition: opacity 0.15s ease;
}

.playlist-link:hover,
.playlist-link:focus-visible {
  opacity: 1;
}

.playlist-link-icon {
  flex-shrink: 0;
}

.playlist-name {
  margin: 0;
  min-width: 0;
  overflow-wrap: break-word;
  overflow: visible;
  font-size: clamp(2.5rem, 8vw, 5.5rem);
  font-weight: 900;
  letter-spacing: -0.03em;
  line-height: 1.05;
  color: var(--text);
}

main {
  padding: 0 16px;
  /* 波紋演出の transform:scale() がページ下端で縦スクロール領域を
     わずかに広げ、スクロールバーの出現/消失で auto-fill の列数が
     一瞬変わってしまうのを防ぐため、はみ出しをここで止める */
  overflow: hidden;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}

@media (max-width: 480px) {
  .grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }
}

.tile {
  position: relative;
  aspect-ratio: 1;
  border: none;
  padding: 0;
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  background: var(--surface);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.tile:hover,
.tile:focus-visible {
  transform: scale(1.03);
}

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

.tile .open-link {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  text-decoration: none;
  font-size: 0.75rem;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.tile:hover .open-link,
.tile:focus-within .open-link {
  opacity: 1;
}

.queue-add-btn {
  position: absolute;
  bottom: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  border: none;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
  opacity: 0.85;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.queue-add-btn:hover,
.queue-add-btn:focus-visible {
  opacity: 1;
  transform: scale(1.1);
}

.queue-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  color: #000;
  display: none;
  align-items: center;
  justify-content: center;
}

.tile.queued .queue-badge {
  display: flex;
}

.play-icon {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s ease;
  pointer-events: none;
}

.play-icon-badge {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-pause {
  display: none;
}

/* 既定(未再生タイル)はplay_arrowを表示。再生中(一時停止していない)だけpauseに切り替える */
.tile.playing:not(.paused) .icon-play {
  display: none;
}

.tile.playing:not(.paused) .icon-pause {
  display: block;
}

.tile:hover .play-icon,
.tile:focus-visible .play-icon {
  opacity: 1;
}

.tile.playing .play-icon {
  opacity: 0;
}

.tile.playing:hover .play-icon,
.tile.playing:focus-visible .play-icon {
  opacity: 1;
}

@media (hover: none) {
  .play-icon {
    opacity: 1;
  }

  .play-icon-badge {
    width: 32px;
    height: 32px;
    background: rgba(0, 0, 0, 0.4);
  }

  .icon-play,
  .icon-pause {
    width: 16px;
    height: 16px;
  }

  .tile.playing .play-icon {
    opacity: 0;
  }
}

.eq-badge {
  position: absolute;
  top: 6px;
  left: 6px;
  display: none;
  align-items: flex-end;
  gap: 2px;
  height: 16px;
  padding: 4px 5px;
  background: rgba(0, 0, 0, 0.6);
  border-radius: 4px;
}

.tile.playing .eq-badge {
  display: flex;
}

.eq-bar {
  width: 3px;
  height: 100%;
  background: var(--accent);
  transform-origin: bottom;
  animation: eq-bounce 0.9s ease-in-out infinite;
}

.eq-bar:nth-child(1) {
  animation-delay: 0s;
}

.eq-bar:nth-child(2) {
  animation-delay: 0.2s;
}

.eq-bar:nth-child(3) {
  animation-delay: 0.4s;
}

.tile.playing.paused .eq-bar {
  animation-play-state: paused;
  transform: scaleY(0.3);
}

@keyframes eq-bounce {
  0%,
  100% {
    transform: scaleY(0.35);
  }
  50% {
    transform: scaleY(1);
  }
}

.grid.has-playing .tile:not(.playing) img {
  filter: saturate(0.25) brightness(0.7);
}

.tile.playing {
  z-index: 2;
  transform: scale(1.08);
  animation: playing-pulse 1.8s ease-in-out infinite;
}

.tile.playing.paused {
  animation-play-state: paused;
  box-shadow: 0 0 0 3px var(--accent), 0 0 16px 2px rgba(29, 185, 84, 0.6), 0 10px 24px rgba(0, 0, 0, 0.5);
}

@keyframes playing-pulse {
  0%,
  100% {
    box-shadow: 0 0 0 3px var(--accent), 0 0 16px 2px rgba(29, 185, 84, 0.6), 0 10px 24px rgba(0, 0, 0, 0.5);
  }
  50% {
    box-shadow: 0 0 0 3px var(--accent), 0 0 30px 8px rgba(29, 185, 84, 0.9), 0 10px 24px rgba(0, 0, 0, 0.5);
  }
}

.tile.playing img {
  filter: none;
}

/* 隠し機能: パーティーモード中、ホバーしたジャケットから波紋のように広がる演出
   (PC限定。--ripple-delayはJS側でホバー元からの距離に応じて設定する) */
.tile.ripple {
  animation: ripple-pulse 0.6s ease-out;
  animation-delay: var(--ripple-delay, 0s);
}

@keyframes ripple-pulse {
  0% {
    transform: scale(1);
  }
  30% {
    transform: scale(1.12);
  }
  100% {
    transform: scale(1);
  }
}

/* モバイル（ホバー不可）：常時オーバーレイで曲名・アーティストを表示 */
.tile-overlay {
  display: none;
}

@media (hover: none) {
  .tile-overlay {
    display: block;
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 6px 6px 4px;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.85), rgba(0, 0, 0, 0));
    color: #fff;
    font-size: 0.68rem;
    line-height: 1.25;
    pointer-events: none;
  }

  .tile-overlay .overlay-name {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .tile-overlay .overlay-artist {
    color: #d0d0d5;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

.empty-message {
  text-align: center;
  color: var(--text-dim);
  margin-top: 40px;
}

.empty-message code {
  background: var(--surface);
  padding: 2px 6px;
  border-radius: 4px;
}

/* デスクトップ用ツールチップ（hover 可能な環境のみ JS が表示する） */
.tooltip {
  position: fixed;
  z-index: 50;
  max-width: 260px;
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 0.8rem;
  line-height: 1.5;
  pointer-events: none;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

.tooltip .tt-name {
  font-weight: 700;
  margin-bottom: 2px;
}

.tooltip .tt-artist,
.tooltip .tt-album {
  color: var(--text-dim);
}

.tooltip .tt-meta {
  margin-top: 6px;
  color: var(--text-dim);
  font-size: 0.75rem;
}

/* キューパネル(再生バーのすぐ上に開く引き出し) */
.queue-panel {
  position: fixed;
  left: 0;
  right: 0;
  bottom: var(--now-playing-height);
  z-index: 39;
  max-height: 45vh;
  overflow-y: auto;
  background: #101012;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  transform: translateY(100%);
  opacity: 0;
  visibility: hidden;
  transition: transform 0.2s ease, opacity 0.2s ease, visibility 0s linear 0.2s;
}

.queue-panel.open {
  transform: translateY(0);
  opacity: 1;
  visibility: visible;
  transition: transform 0.2s ease, opacity 0.2s ease, visibility 0s linear 0s;
}

.queue-panel-header {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: #101012;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.queue-panel-title {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-dim);
}

.queue-panel-close {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  padding: 4px;
}

.queue-panel-close:hover,
.queue-panel-close:focus-visible {
  color: var(--text);
}

.queue-list {
  list-style: none;
  margin: 0;
  padding: 4px 0;
}

.queue-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
}

.queue-item-info {
  min-width: 0;
  flex: 1 1 auto;
}

.queue-item-name {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.queue-item-artist {
  margin: 0;
  font-size: 0.75rem;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.queue-item-remove {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  border: none;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.queue-item-remove:hover,
.queue-item-remove:focus-visible {
  background: rgba(255, 255, 255, 0.16);
  color: var(--text);
}

.queue-empty {
  padding: 24px 14px;
  text-align: center;
  color: var(--text-dim);
  font-size: 0.8rem;
}

/* Now Playing バー */
.now-playing {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--now-playing-height);
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom, 0px));
  background: #101012;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  /* display:none だと埋め込みiframeが0サイズで初期化され再生できなくなるため、
     画面外へスライドさせる方式で隠す(レイアウト・iframeは維持したまま)。 */
  transform: translateY(100%);
  visibility: hidden;
  pointer-events: none;
  transition: transform 0.2s ease, visibility 0s linear 0.2s;
}

body.has-now-playing .now-playing {
  transform: translateY(0);
  visibility: visible;
  pointer-events: auto;
  transition: transform 0.2s ease, visibility 0s linear 0s;
}

.np-embed {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  height: 80px;
}

.np-embed iframe {
  /* Spotify側のスクリプトがiframeへ幅を直接指定してくることがあり、
     外部スタイルシートの通常指定では上書きできない場合があるため
     !important で必ず親要素の幅に収める(はみ出し防止)。 */
  width: 100% !important;
  max-width: 100%;
  height: 80px;
  border: none;
}

.np-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.np-transport {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* 閉じるボタンは曲送り系(シャッフル/前/次)と意図が異なるため、
   間隔を広げ、区切り線を入れて別グループだと分かるようにする */
.close-btn {
  position: relative;
  margin-left: 12px;
}

.close-btn::before {
  content: "";
  position: absolute;
  left: -12px;
  top: 50%;
  transform: translateY(-50%);
  width: 1px;
  height: 20px;
  background: rgba(255, 255, 255, 0.15);
}

.control-btn {
  background: var(--surface);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.7rem;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
}

.control-btn[aria-pressed="true"] {
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
}

.icon-btn {
  position: relative;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 50%;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}

.queue-count-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--accent);
  color: #000;
  font-size: 0.6rem;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
}

.icon-btn[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #000;
}

@media (max-width: 700px) {
  .control-btn {
    padding: 6px 8px;
    font-size: 0.65rem;
  }
}

@media (max-width: 600px) {
  /* Spotify埋め込み自体の内部要素(カバー・曲名・+/…/再生ボタン等)が
     横幅の大半を要求するため、狭い画面ではシャッフル/前後ボタンが
     画面外に押し出されてしまう。埋め込みとボタン列を上下2段に分けて
     常にボタンが見えるようにする。 */
  :root {
    --now-playing-height: 132px;
  }

  .now-playing {
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    padding: 6px 12px calc(6px + env(safe-area-inset-bottom, 0px));
  }

  .np-controls {
    justify-content: center;
  }
}
