:root {
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --ink: #f3eee6;
  --ink-soft: #b8b4c8;
  --ink-faint: #8a87a0;
  --glass: rgba(24, 28, 54, 0.55);
  --glass-strong: rgba(22, 26, 50, 0.86);
  --line: rgba(243, 238, 230, 0.12);
  --accent: #f0b89a;
  --accent-deep: #d98f86;
  --sage: #9fc9b8;
  --gold: #ecd08f;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #161b36;
  color: var(--ink);
  font-family: var(--sans);
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

canvas#scene { position: fixed; inset: 0; display: block; }
.hidden { display: none !important; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.glass {
  background: var(--glass);
  -webkit-backdrop-filter: blur(14px) saturate(120%);
  backdrop-filter: blur(14px) saturate(120%);
  border: 1px solid var(--line);
}

.layer {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: calc(16px + var(--sat)) 16px calc(18px + var(--sab));
  z-index: 5;
  pointer-events: none;
}
.layer > * { pointer-events: auto; }

.eyebrow { font-size: 11px; font-weight: 600; letter-spacing: 0.18em; text-transform: uppercase; color: var(--ink-faint); }
.star { color: var(--gold); }

/* ---------- Home ---------- */
.top { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.brand {
  margin: 0;
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(24px, 7vw, 32px);
  letter-spacing: 0.01em;
  white-space: nowrap;
  color: var(--ink);
  text-shadow: 0 0 24px rgba(240, 184, 154, 0.25);
}
.top-right { display: flex; align-items: center; gap: 8px; }
.pill {
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 13px;
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.icon-btn {
  appearance: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--glass);
  border: 1px solid var(--line);
  color: var(--ink);
  cursor: pointer;
}

.home-bottom { display: flex; flex-direction: column; gap: 10px; align-items: center; }
.next-card {
  width: 100%;
  max-width: 400px;
  border-radius: 24px;
  padding: 18px 18px 18px;
  text-align: center;
}
.next-title { font-family: var(--serif); font-size: 26px; margin: 6px 0 2px; text-wrap: balance; }
.next-origin { font-size: 13px; color: var(--ink-soft); margin-bottom: 14px; }

.btn {
  appearance: none;
  border: 0;
  font: inherit;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.12s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn:active { transform: scale(0.97); }
.btn.primary {
  width: 100%;
  padding: 15px 0;
  border-radius: 999px;
  background: linear-gradient(180deg, #f4c5a8, var(--accent-deep));
  color: #2a1d22;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.02em;
  box-shadow: 0 8px 28px rgba(217, 143, 134, 0.3);
}
.btn.primary svg { width: 16px; height: 16px; }
.btn.quiet {
  width: 100%;
  padding: 12px 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ink-soft);
  font-size: 15px;
  font-weight: 500;
}

.nav { display: flex; gap: 10px; width: 100%; max-width: 400px; }
.nav-btn {
  flex: 1;
  appearance: none;
  font: inherit;
  font-weight: 500;
  font-size: 13px;
  color: var(--ink);
  border-radius: 18px;
  padding: 11px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  cursor: pointer;
}
.nav-btn svg { color: var(--accent); }

/* ---------- Play ---------- */
#playUi { justify-content: flex-start; }
.play-top { display: flex; align-items: center; gap: 10px; }
.song-info { flex: 1; min-width: 0; border-radius: 16px; padding: 9px 14px 11px; }
.song-name { font-family: var(--serif); font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.progress { margin-top: 7px; height: 4px; border-radius: 99px; background: rgba(243, 238, 230, 0.12); overflow: hidden; }
#progressFill { height: 100%; width: 0; border-radius: 99px; background: linear-gradient(90deg, var(--sage), var(--accent)); transition: width 0.3s ease; }
.hint {
  margin: auto auto 34%;
  max-width: 300px;
  text-align: center;
  font-family: var(--serif);
  font-size: 19px;
  line-height: 1.45;
  white-space: pre-line;
  color: var(--ink);
  text-shadow: 0 2px 16px rgba(10, 12, 30, 0.8);
  pointer-events: none !important;
  animation: breathe 3s ease-in-out infinite;
}
@keyframes breathe { 0%, 100% { opacity: 0.55; } 50% { opacity: 1; } }

/* tempo */
.tempo {
  align-self: center;
  margin-top: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 12px;
  color: var(--ink-soft);
}
.tempo input { width: 150px; accent-color: var(--accent); touch-action: pan-x; }

/* unlocks */
.btn.unlock {
  width: 100%;
  padding: 13px 10px;
  border-radius: 999px;
  background: transparent;
  border: 1px solid rgba(236, 208, 143, 0.7);
  color: var(--gold);
  font-size: 15px;
  font-weight: 600;
}
.unlock-progress { margin: 0; font-size: 13px; color: var(--ink-soft); }
.unlock-progress .bar { display: block; height: 3px; border-radius: 9px; background: rgba(243, 238, 230, 0.1); margin-top: 6px; overflow: hidden; }
.unlock-progress .bar i { display: block; height: 100%; background: var(--gold); }
.unlock-chip {
  appearance: none;
  width: 100%;
  margin-top: 10px;
  border: 1px solid rgba(236, 208, 143, 0.5);
  background: rgba(236, 208, 143, 0.06);
  color: var(--gold);
  border-radius: 14px;
  padding: 8px 12px;
  font: inherit;
  font-size: 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  cursor: pointer;
}
.unlock-chip .eyebrow { color: var(--gold); opacity: 0.8; }

/* ---------- Song complete ---------- */
.modal { justify-content: center; align-items: center; background: rgba(12, 14, 32, 0.35); pointer-events: auto; animation: fade 0.5s ease; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.card {
  width: 100%;
  max-width: 360px;
  background: var(--glass-strong);
  border-radius: 28px;
  padding: 24px 20px 14px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 20px 60px rgba(5, 6, 20, 0.5);
  animation: rise 0.6s cubic-bezier(0.2, 1, 0.3, 1);
}
@keyframes rise { from { transform: translateY(20px); opacity: 0; } to { transform: none; opacity: 1; } }
.card h2 { margin: 0 0 4px; font-family: var(--serif); font-weight: 400; font-size: 26px; text-wrap: balance; }
.rewards { display: flex; gap: 10px; margin: 4px 0 6px; }
.rewards > div {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 108px;
}
.rewards b { font-family: var(--serif); font-weight: 400; font-size: 34px; color: var(--gold); }
.rewards span { font-size: 12px; color: var(--ink-soft); line-height: 1.3; }
#doneBloom { width: 48px; height: 48px; }
.break-note {
  margin: 0;
  border: 1px solid rgba(159, 201, 184, 0.3);
  background: rgba(159, 201, 184, 0.08);
  border-radius: 16px;
  padding: 11px 13px;
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink);
}

/* ---------- Sheets ---------- */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: rgba(8, 10, 24, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fade 0.2s ease;
}
.sheet-panel {
  width: 100%;
  max-width: 520px;
  max-height: 86vh;
  overflow-y: auto;
  touch-action: pan-y;
  background: #1b2040;
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 26px 26px 0 0;
  padding: 18px 16px calc(24px + var(--sab));
  animation: up 0.35s cubic-bezier(0.2, 1, 0.3, 1);
}
@keyframes up { from { transform: translateY(30%); } to { transform: none; } }
.sheet-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.sheet-head h2 { margin: 0; flex: 1; font-family: var(--serif); font-weight: 400; font-size: 26px; }
.close {
  appearance: none;
  border: 1px solid var(--line);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}
.close svg { width: 16px; height: 16px; }
.sheet-note { margin: 0 0 14px; color: var(--ink-soft); font-size: 14px; line-height: 1.5; }
.muted { color: var(--ink-faint); font-size: 13px; text-align: center; margin: 16px 0 0; line-height: 1.45; }

.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.row {
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  background: rgba(243, 238, 230, 0.03);
  border-radius: 16px;
  padding: 12px;
}
.row .ico {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: rgba(243, 238, 230, 0.05);
  color: var(--accent);
}
.row .ico.locked { color: var(--ink-faint); }
.row .body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.row .body b { font-family: var(--serif); font-weight: 400; font-size: 17px; }
.row .body small { color: var(--ink-soft); font-size: 12px; line-height: 1.4; }
.row .act {
  flex: none;
  appearance: none;
  border: 1px solid transparent;
  font: inherit;
  font-weight: 600;
  font-size: 13px;
  padding: 9px 14px;
  border-radius: 999px;
  cursor: pointer;
  background: var(--accent);
  color: #2a1d22;
}
.row .act.buy { background: transparent; border-color: rgba(236, 208, 143, 0.6); color: var(--gold); }
.row .act.cant { background: transparent; border-color: var(--line); color: var(--ink-faint); }
.row .act.owned { background: transparent; color: var(--sage); cursor: default; }
.row.current { border-color: rgba(240, 184, 154, 0.5); background: rgba(240, 184, 154, 0.06); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.bcard {
  appearance: none;
  font: inherit;
  color: var(--ink);
  border: 1px solid var(--line);
  background: rgba(243, 238, 230, 0.03);
  border-radius: 20px;
  padding: 12px 8px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}
.bcard.selected { border-color: rgba(240, 184, 154, 0.6); background: rgba(240, 184, 154, 0.07); }
.bcard canvas { width: 96px; height: 96px; }
.bcard b { font-family: var(--serif); font-weight: 400; font-size: 17px; }
.bcard small { font-size: 12px; color: var(--ink-soft); }
.bcard .tag { margin-top: 6px; font-size: 12px; font-weight: 600; padding: 5px 12px; border-radius: 999px; border: 1px solid var(--line); }
.bcard .tag.buy { border-color: rgba(236, 208, 143, 0.6); color: var(--gold); }
.bcard .tag.cant { color: var(--ink-faint); }
.bcard .tag.sel { background: var(--accent); border-color: transparent; color: #2a1d22; }
.bcard .tag.use { color: var(--accent); }

.settings { display: flex; flex-direction: column; gap: 8px; }
.set-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  background: rgba(243, 238, 230, 0.03);
  border-radius: 16px;
  padding: 12px 14px;
  font-weight: 500;
  font-size: 15px;
}
.set-row > span { display: flex; flex-direction: column; gap: 3px; }
.set-row small { font-weight: 400; font-size: 12px; color: var(--ink-faint); }
.set-row input[type="range"] { width: 45%; accent-color: var(--accent); }
.set-row select {
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 7px 9px;
  background: #232850;
}
.switch {
  appearance: none;
  width: 46px;
  height: 26px;
  flex: none;
  margin: 0;
  border-radius: 99px;
  background: rgba(243, 238, 230, 0.15);
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
}
.switch::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--ink);
  transition: transform 0.2s;
}
.switch:checked { background: var(--sage); }
.switch:checked::after { transform: translateX(20px); background: #1b2040; }
input:focus-visible, select:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Toast ---------- */
#toasts {
  position: fixed;
  top: calc(68px + var(--sat));
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--glass-strong);
  border: 1px solid var(--line);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  max-width: calc(100% - 32px);
  text-align: center;
  animation: rise 0.35s ease, fade 0.4s ease 2.4s reverse forwards;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* shown only if drawing fails, so the problem can be reported */
.err {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(12px + var(--sab));
  z-index: 30;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(120, 30, 40, 0.9);
  color: #fff;
  font: 12px/1.4 ui-monospace, Menlo, monospace;
  user-select: text;
  -webkit-user-select: text;
}
