:root {
  --bg: #f6f3ec;
  --bg2: #efe9dd;
  --fg: #211f1b;
  --muted: #6b6459;
  --accent: #b5623a;
  --card: #fffdf8;
  --line: #e2dccf;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 8px 24px rgba(0, 0, 0, 0.05);
  --radius: 16px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0e0c;
    --bg2: #17150f;
    --fg: #ece7db;
    --muted: #9a9284;
    --accent: #d8895f;
    --card: #1c1a15;
    --line: #2c281f;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.3);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif;
  background: linear-gradient(180deg, var(--bg), var(--bg2));
  color: var(--fg);
  min-height: 100vh;
  padding-bottom: 120px;
  -webkit-font-smoothing: antialiased;
}
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: max(16px, env(safe-area-inset-top)) 20px 12px;
}
.brand { font-size: 22px; letter-spacing: 0.12em; margin: 0; font-weight: 600; }
.icon-btn, .text-btn {
  background: none; border: none; color: var(--muted); font-size: 20px; cursor: pointer;
}
.text-btn { font-size: 14px; }
main { max-width: 640px; margin: 0 auto; padding: 0 16px; }

.composer { margin-top: 8px; }
.lead { color: var(--muted); font-size: 15px; margin: 4px 0 16px; }
.presets { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.preset {
  padding: 14px 6px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--card); color: var(--fg); font-size: 14px; cursor: pointer;
  transition: transform 0.08s ease, border-color 0.15s;
}
.preset:active { transform: scale(0.97); }
.preset.on { border-color: var(--accent); color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }

.freeinput { margin-top: 14px; }
#moodText {
  width: 100%; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; font-size: 16px; background: var(--card); color: var(--fg); resize: vertical;
  font-family: inherit;
}
.primary {
  margin-top: 10px; width: 100%; padding: 15px; border: none; border-radius: var(--radius);
  background: var(--accent); color: #fff; font-size: 16px; font-weight: 600; cursor: pointer;
}
.primary:disabled { opacity: 0.5; }
.progress {
  margin-top: 12px; padding: 12px 14px; border-radius: 12px; background: var(--card);
  border: 1px solid var(--line); font-size: 14px; color: var(--muted);
  display: flex; align-items: center; gap: 10px;
}
.spin {
  width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.8s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.library { margin-top: 32px; }
.lib-head { display: flex; align-items: baseline; justify-content: space-between; }
.lib-head h2 { font-size: 16px; margin: 0; }
.tracks { list-style: none; padding: 0; margin: 12px 0 0; }
.track {
  display: flex; align-items: center; gap: 12px; padding: 14px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  margin-bottom: 10px; box-shadow: var(--shadow);
}
.play {
  flex: 0 0 auto; width: 44px; height: 44px; border-radius: 50%; border: none;
  background: var(--accent); color: #fff; font-size: 15px; cursor: pointer;
}
.t-body { flex: 1; min-width: 0; }
.t-title { font-weight: 600; font-size: 15px; }
.t-sub { color: var(--muted); font-size: 13px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.t-note { color: var(--muted); font-size: 12px; margin-top: 4px; opacity: 0.85; }
.t-meta { color: var(--muted); font-size: 12px; flex: 0 0 auto; }
.empty { color: var(--muted); font-size: 14px; text-align: center; padding: 24px; }

.player {
  position: fixed; left: 0; right: 0; bottom: 0;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--card); border-top: 1px solid var(--line); box-shadow: var(--shadow);
}
.player-info { margin-bottom: 8px; }
.p-title { font-weight: 600; font-size: 14px; }
.p-sub { color: var(--muted); font-size: 12px; }
#audio { width: 100%; }

dialog { border: none; border-radius: var(--radius); background: var(--card); color: var(--fg); max-width: 420px; width: 90%; box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
.settings-form { display: flex; flex-direction: column; gap: 12px; }
.settings-form h3 { margin: 0; }
.settings-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.settings-form input, .settings-form select {
  padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--fg); font-size: 15px;
}
.settings-form menu { display: flex; justify-content: flex-end; gap: 10px; padding: 0; margin: 8px 0 0; }
.settings-form menu .primary { width: auto; margin: 0; padding: 10px 18px; }

/* 今日の曲(主役) */
.today {
  margin: 8px 0 24px; padding: 22px; border-radius: 20px;
  background: linear-gradient(135deg, var(--card), var(--bg2));
  border: 1px solid var(--line); box-shadow: var(--shadow); text-align: center;
}
.today-label { font-size: 12px; letter-spacing: 0.18em; color: var(--accent); }
.today-title { font-size: 21px; font-weight: 700; margin: 8px 0 6px; }
.today-note { font-size: 13px; color: var(--muted); margin-bottom: 16px; line-height: 1.6; }
.today-play {
  padding: 13px 30px; border: none; border-radius: 999px; background: var(--accent);
  color: #fff; font-size: 16px; font-weight: 600; cursor: pointer; min-height: 44px;
}

/* strategy選択 */
.strat { display: flex; gap: 8px; margin-bottom: 12px; }
.strat-btn {
  flex: 1; padding: 10px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--card); color: var(--muted); font-size: 13px; cursor: pointer; min-height: 44px;
}
.strat-btn.on { border-color: var(--accent); color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }

/* フィードバック */
.feedback { display: flex; align-items: center; gap: 8px; margin-top: 10px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.feedback button {
  padding: 8px 12px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--bg); color: var(--fg); font-size: 12px; cursor: pointer; min-height: 36px;
}
.feedback button.picked { border-color: var(--accent); color: var(--accent); }
.hint { font-size: 12px; color: var(--muted); margin: 0; }
@media (prefers-reduced-motion: reduce) { .spin { animation: none; } }

.hidden { display: none !important; }
