/* ============================================================
   AMBIENT — style.css  (v2 公開版)
   ============================================================ */

/* ── CSS Variables ── */
:root {
  --bg-start: #080d14;
  --bg-end:   #071019;

  --card-bg:            rgba(255, 255, 255, 0.04);
  --card-bg-active:     rgba(120, 190, 220, 0.09);
  --card-border:        rgba(255, 255, 255, 0.07);
  --card-border-active: rgba(120, 190, 220, 0.40);

  --accent:       #78bedd;
  --accent-dim:   rgba(120, 190, 221, 0.55);
  --text-primary:   #e8edf2;
  --text-secondary: #7a8fa0;
  --text-muted:     #3e5265;
  --text-error:     #e07a7a;

  --radius-card: 20px;
  --radius-btn:  50px;
  --radius-input: 10px;

  --font-display: 'Cormorant Garamond', Georgia, serif;
  --font-body:    'Noto Sans JP', sans-serif;

  --transition: 0.35s cubic-bezier(0.4, 0, 0.2, 1);

  /* スリープタイマーカウントダウン用カラー */
  --timer-color: var(--accent-dim);
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

/* ── Body ── */
body {
  min-height: 100vh;
  background-color: var(--bg-start);
  font-family: var(--font-body);
  color: var(--text-primary);
  overflow-x: hidden;
  /* 背景はbg-layerで管理 */
}

/* ── ノイズグレイン ── */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='1'/%3E%3C/svg%3E");
  opacity: 0.028;
  pointer-events: none;
  z-index: 0;
}

/* ============================================================
   背景フォトレイヤー (ランダムクロスフェード)
   ============================================================ */
#bg-img-a, #bg-img-b {
  position: fixed;
  inset: 0;
  z-index: -2;
  background-size: cover;
  background-position: center;
  opacity: 0;
  transition: opacity 2.5s ease;
}

/* ============================================================
   背景テーマ
   #bg-layer に data-theme を付与して切り替える。
   カテゴリ優先順は script.js の BG_PRIORITY で定義。
   ============================================================ */
#bg-layer {
  position: fixed;
  inset: 0;
  z-index: -1;
  opacity: 0.68;
  transition: background 3s ease;
  /* デフォルト (再生なし) */
  background:
    radial-gradient(ellipse at 30% 20%, #0e2035 0%, var(--bg-start) 60%),
    radial-gradient(ellipse at 75% 80%, #071a2e 0%, var(--bg-end)   60%);
  background-blend-mode: screen;
}

#bg-layer[data-theme="rain"] {
  background:
    radial-gradient(ellipse at 40% 10%, #0a1e38 0%, #060c14 65%),
    radial-gradient(ellipse at 70% 90%, #081428 0%, #050a11 60%);
  background-blend-mode: screen;
}

#bg-layer[data-theme="sea"] {
  background:
    radial-gradient(ellipse at 30% 30%, #082a3a 0%, #050e16 60%),
    radial-gradient(ellipse at 80% 70%, #041822 0%, #040c12 60%);
  background-blend-mode: screen;
}

#bg-layer[data-theme="night"] {
  background:
    radial-gradient(ellipse at 50% 20%, #0d1a10 0%, #060c08 60%),
    radial-gradient(ellipse at 60% 80%, #081408 0%, #050c06 60%);
  background-blend-mode: screen;
}

#bg-layer[data-theme="airport"] {
  background:
    radial-gradient(ellipse at 35% 25%, #111824 0%, #080c12 60%),
    radial-gradient(ellipse at 65% 75%, #0c141c 0%, #060a10 60%);
  background-blend-mode: screen;
}

#bg-layer[data-theme="birds"] {
  background:
    radial-gradient(ellipse at 30% 30%, #101c0e 0%, #080c06 60%),
    radial-gradient(ellipse at 70% 70%, #0c1a14 0%, #060c08 60%);
  background-blend-mode: screen;
}

#bg-layer[data-theme="city"] {
  background:
    radial-gradient(ellipse at 40% 20%, #1a1208 0%, #0c0906 60%),
    radial-gradient(ellipse at 70% 80%, #14100a 0%, #0a0806 60%);
  background-blend-mode: screen;
}

#bg-layer[data-theme="bonfire"] {
  background:
    radial-gradient(ellipse at 50% 30%, #1e1008 0%, #0e0806 60%),
    radial-gradient(ellipse at 60% 70%, #160c06 0%, #0c0604 60%);
  background-blend-mode: screen;
}

#bg-layer[data-theme="underwater"] {
  background:
    radial-gradient(ellipse at 40% 40%, #041820 0%, #030c12 60%),
    radial-gradient(ellipse at 65% 65%, #02141c 0%, #020a10 60%);
  background-blend-mode: screen;
}

/* ── Layout ── */
.wrapper {
  position: relative;
  z-index: 1;
  max-width: 1200px;
  margin: 0 auto;
  padding: 52px 20px 80px;
}

/* ============================================================
   Header
   ============================================================ */
header {
  text-align: center;
  margin-bottom: 48px;
  animation: fadeUp 0.9s ease both;
  position: relative;
}

/* ── 言語切り替えボタン ── */
.lang-toggle {
  position: absolute;
  top: 0;
  right: 0;
  display: flex;
  gap: 4px;
}

.btn-lang {
  height: 30px;
  padding: 0 12px;
  border-radius: var(--radius-btn);
  border: 1px solid rgba(255, 255, 255, 0.10);
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 11px;
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-lang:hover {
  border-color: rgba(255, 255, 255, 0.22);
  color: var(--text-secondary);
}

.btn-lang.active {
  border-color: var(--accent-dim);
  color: var(--accent);
  background: rgba(120, 190, 220, 0.08);
}

/* ── ロゴ画像 ── */
.header-logo {
  display: block;
  margin: 0 auto 0;
  max-width: min(340px, 60vw);
  height: auto;
  filter: brightness(1.05);
}

.header-eyebrow {
  font-size: 11px;
  font-weight: 300;
  letter-spacing: 0.35em;
  text-transform: uppercase;
  color: var(--accent-dim);
  margin-bottom: 14px;
}

header h1 {
  font-family: var(--font-display);
  font-size: clamp(44px, 8vw, 88px);
  font-weight: 300;
  letter-spacing: 0.06em;
  line-height: 1;
}

header h1 em {
  font-style: italic;
  color: var(--accent);
}

.header-desc {
  margin-top: 18px;
  font-size: 13px;
  font-weight: 300;
  color: var(--text-secondary);
  letter-spacing: 0.04em;
  line-height: 1.9;
}

/* ============================================================
   Restore Banner
   ============================================================ */
.restore-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 32px;
  padding: 14px 20px;
  border-radius: 14px;
  border: 1px solid rgba(120, 190, 220, 0.25);
  background: rgba(120, 190, 220, 0.06);
  animation: fadeUp 0.5s ease both;
}

.restore-text {
  flex: 1;
  font-size: 13px;
  color: var(--text-secondary);
  min-width: 160px;
}

.btn-restore {
  padding: 8px 20px;
  border-radius: var(--radius-btn);
  border: 1px solid rgba(120, 190, 220, 0.40);
  background: rgba(120, 190, 220, 0.12);
  color: var(--accent);
  font-family: var(--font-body);
  font-size: 12px;
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-restore:hover {
  background: rgba(120, 190, 220, 0.22);
}

.btn-restore-dismiss {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: color var(--transition);
}

.btn-restore-dismiss:hover { color: var(--text-secondary); }

/* ============================================================
   Section 共通
   ============================================================ */
.section-title {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 300;
  letter-spacing: 0.14em;
  color: var(--text-secondary);
  text-align: center;
  margin-bottom: 18px;
}

/* ============================================================
   Sleep Timer
   ============================================================ */
.timer-section {
  margin-bottom: 44px;
  animation: fadeUp 0.9s 0.08s ease both;
}

.timer-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.timer-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.btn-timer {
  min-width: 64px;
  height: 40px;
  padding: 0 18px;
  border-radius: var(--radius-btn);
  border: 1px solid rgba(255, 255, 255, 0.10);
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 12px;
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-timer:hover {
  border-color: rgba(255, 255, 255, 0.22);
  color: var(--text-secondary);
}

.btn-timer.active {
  border-color: var(--accent-dim);
  color: var(--accent);
  background: rgba(120, 190, 220, 0.08);
}

.timer-display {
  font-size: 13px;
  color: var(--accent-dim);
  letter-spacing: 0.08em;
}

#timer-remaining {
  font-variant-numeric: tabular-nums;
  font-size: 15px;
  color: var(--accent);
}

/* ============================================================
   Preset Section
   ============================================================ */
.preset-section {
  margin-bottom: 44px;
  animation: fadeUp 0.9s 0.12s ease both;
}

.preset-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}

.btn-preset {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 20px;
  border-radius: var(--radius-btn);
  border: 1px solid rgba(255, 255, 255, 0.10);
  background: rgba(255, 255, 255, 0.03);
  cursor: pointer;
  transition: all var(--transition);
  min-width: 80px;
}

.btn-preset:hover {
  border-color: var(--accent-dim);
  background: rgba(120, 190, 220, 0.07);
  transform: translateY(-2px);
}

.btn-preset:active { transform: scale(0.97); }

.preset-icon {
  font-size: 16px;
  display: flex;
  gap: 4px;
  align-items: center;
  justify-content: center;
}

.preset-icon-img {
  width: 20px;
  height: 20px;
  object-fit: contain;
  opacity: 0.72;
  transition: opacity var(--transition);
}

.btn-preset:hover .preset-icon-img { opacity: 1; }

.preset-name {
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.07em;
  color: var(--text-secondary);
}

.preset-desc {
  font-size: 10px;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

/* ============================================================
   Favorites Section
   ============================================================ */
.favorites-section {
  margin-bottom: 48px;
  animation: fadeUp 0.9s 0.16s ease both;
}

.favorites-save-row {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.favorite-name-input {
  flex: 1;
  min-width: 0;
  height: 44px;
  padding: 0 16px;
  border-radius: var(--radius-input);
  border: 1px solid rgba(255, 255, 255, 0.10);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 13px;
  outline: none;
  transition: border-color var(--transition);
}

.favorite-name-input::placeholder { color: var(--text-muted); }

.favorite-name-input:focus {
  border-color: rgba(120, 190, 220, 0.35);
}

.btn-save-favorite {
  height: 44px;
  padding: 0 22px;
  border-radius: var(--radius-btn);
  border: 1px solid rgba(120, 190, 220, 0.30);
  background: rgba(120, 190, 220, 0.10);
  color: var(--accent);
  font-family: var(--font-body);
  font-size: 12px;
  letter-spacing: 0.08em;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition);
}

.btn-save-favorite:hover {
  background: rgba(120, 190, 220, 0.20);
  border-color: rgba(120, 190, 220, 0.55);
}

.favorites-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.favorites-empty {
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  padding: 16px 0;
}

/* お気に入りエントリ */
.favorite-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.07);
  background: rgba(255, 255, 255, 0.03);
  transition: all var(--transition);
}

.favorite-item:hover {
  border-color: rgba(255, 255, 255, 0.13);
  background: rgba(255, 255, 255, 0.05);
}

.favorite-name {
  flex: 1;
  font-size: 13px;
  color: var(--text-secondary);
  letter-spacing: 0.03em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.favorite-meta {
  font-size: 10px;
  color: var(--text-muted);
  white-space: nowrap;
}

.btn-apply-favorite {
  padding: 6px 16px;
  border-radius: var(--radius-btn);
  border: 1px solid rgba(120, 190, 220, 0.25);
  background: transparent;
  color: var(--accent-dim);
  font-family: var(--font-body);
  font-size: 11px;
  letter-spacing: 0.07em;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn-apply-favorite:hover {
  border-color: rgba(120, 190, 220, 0.55);
  color: var(--accent);
  background: rgba(120, 190, 220, 0.08);
}

.btn-delete-favorite {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: color var(--transition);
  flex-shrink: 0;
}

.btn-delete-favorite:hover { color: var(--text-error); }

/* ============================================================
   Cards Grid  — always 4 columns, scales gracefully
   ============================================================ */
.cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 0;
}

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

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

/* ============================================================
   Card
   ============================================================ */
.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-card);
  padding: 24px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  transition:
    border-color var(--transition),
    background   var(--transition),
    box-shadow   var(--transition),
    transform    var(--transition);
  animation: fadeUp 0.9s ease both;
}

.card.is-playing {
  background: var(--card-bg-active);
  border-color: var(--card-border-active);
  box-shadow:
    0 0 40px rgba(120, 190, 220, 0.10),
    0 0  1px rgba(120, 190, 220, 0.40) inset;
  transform: translateY(-3px);
}

/* ── カードヘッダー ── */
.card-header {
  display: flex;
  align-items: center;
  gap: 12px;
}

.card-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(120, 190, 220, 0.08);
  border: 1px solid rgba(120, 190, 220, 0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  transition: background var(--transition), border-color var(--transition);
}

.card-icon-img {
  width: 22px;
  height: 22px;
  object-fit: contain;
  opacity: 0.75;
  transition: opacity var(--transition);
}

.card.is-playing .card-icon-img {
  opacity: 1;
}

.card.is-playing .card-icon {
  background: rgba(120, 190, 220, 0.16);
  border-color: rgba(120, 190, 220, 0.45);
}

.card-title {
  font-family: var(--font-display);
  font-size: clamp(16px, 1.8vw, 22px);
  font-weight: 300;
  letter-spacing: 0.04em;
  flex: 1;
}

/* ── サウンドウェーブ ── */
.playing-indicator {
  display: flex;
  align-items: center;
  gap: 3px;
  height: 14px;
  opacity: 0;
  transition: opacity var(--transition);
}

.card.is-playing .playing-indicator { opacity: 1; }

.playing-indicator span {
  display: block;
  width: 3px;
  border-radius: 2px;
  background: var(--accent);
  animation: bar 1.2s ease-in-out infinite;
}

.playing-indicator span:nth-child(1) { height:  6px; animation-delay: 0.00s; }
.playing-indicator span:nth-child(2) { height: 12px; animation-delay: 0.20s; }
.playing-indicator span:nth-child(3) { height:  8px; animation-delay: 0.10s; }
.playing-indicator span:nth-child(4) { height: 14px; animation-delay: 0.30s; }
.playing-indicator span:nth-child(5) { height:  5px; animation-delay: 0.15s; }

/* ── トラック名 ── */
.card-track {
  font-size: 11px;
  font-weight: 300;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  min-height: 16px;
  transition: color var(--transition);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card.is-playing .card-track { color: var(--accent-dim); }
.card-track.is-error { color: var(--text-error) !important; }

/* ── ボタン ── */
.card-controls {
  display: flex;
  gap: 8px;
}

.btn {
  flex: 1;
  height: 44px;         /* スマホで押しやすいサイズ */
  border-radius: var(--radius-btn);
  border: 1px solid transparent;
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  cursor: pointer;
  transition:
    background var(--transition),
    border-color var(--transition),
    color var(--transition),
    box-shadow var(--transition),
    transform 0.15s ease;
  outline: none;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}

.btn:active { transform: scale(0.95); }

.btn-play {
  background: rgba(120, 190, 220, 0.12);
  border-color: rgba(120, 190, 220, 0.30);
  color: var(--accent);
}

.btn-play:hover {
  background: rgba(120, 190, 220, 0.22);
  border-color: rgba(120, 190, 220, 0.60);
  box-shadow: 0 0 16px rgba(120, 190, 220, 0.18);
}

.btn-stop {
  background: transparent;
  border-color: var(--text-muted);
  color: var(--text-muted);
}

.btn-stop:hover {
  border-color: var(--text-secondary);
  color: var(--text-secondary);
}

.btn-switch {
  width: 100%;
  background: transparent;
  border-color: rgba(255, 255, 255, 0.08);
  color: var(--text-muted);
}

.btn-switch:hover {
  border-color: rgba(255, 255, 255, 0.18);
  color: var(--text-secondary);
}

/* ── 音量スライダー ── */
.volume-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.volume-label {
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  text-transform: uppercase;
  white-space: nowrap;
  width: 28px;
  text-align: right;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  height: 4px;           /* スマホで操作しやすい高さ */
  background: linear-gradient(
    to right,
    var(--accent-dim) 0%,
    var(--accent-dim) var(--fill, 70%),
    var(--text-muted) var(--fill, 70%),
    var(--text-muted) 100%
  );
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;           /* スマホで操作しやすいサイズ */
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px rgba(120, 190, 220, 0.5);
  transition: transform 0.15s ease;
}

input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.25); }

input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}

/* ============================================================
   Footer
   ============================================================ */
footer {
  margin-top: 52px;
  text-align: center;
  animation: fadeUp 0.9s 0.5s ease both;
}

.btn-stop-all {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  height: 52px;
  padding: 0 44px;
  border-radius: var(--radius-btn);
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-secondary);
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  cursor: pointer;
  transition: all var(--transition);
  -webkit-tap-highlight-color: transparent;
}

.btn-stop-all:hover {
  border-color: rgba(255, 255, 255, 0.25);
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.08);
}

.btn-stop-all:active { transform: scale(0.97); }

.btn-stop-all svg {
  width: 13px;
  height: 13px;
  opacity: 0.7;
}

/* ============================================================
   Keyframes
   ============================================================ */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(18px); }
  to   { opacity: 1; transform: translateY(0);    }
}

@keyframes bar {
  0%, 100% { transform: scaleY(0.4); opacity: 0.5; }
  50%       { transform: scaleY(1.0); opacity: 1.0; }
}

/* ============================================================
   スマホ専用調整
   ============================================================ */
@media (max-width: 579px) {
  .wrapper { padding: 40px 16px 100px; }

  /* タイマーボタンを大きく */
  .btn-timer { min-width: 72px; height: 44px; }

  /* プリセットボタンの余白 */
  .btn-preset { min-width: 72px; padding: 14px 14px; }

  /* カード内余白を確保 */
  .card { padding: 22px 18px 18px; gap: 16px; }

  /* フッターを固定に近い位置にする余白 */
  footer { margin-top: 60px; }
}
