/* ─────────────────────────────────────────────────────────────
   Euphoria — styles
   ───────────────────────────────────────────────────────────── */
:root {
  color-scheme: dark;
  --bg: #07070e;
  --surface: rgba(16, 15, 30, 0.78);
  --surface-strong: rgba(14, 13, 26, 0.94);
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.16);
  --text: #ece8f6;
  --text-2: #a9a2bf;
  --text-dim: #8d86a6;
  --accent: #b88aff;
  --accent-2: #5ce0d8;
  --rose: #ff6b8a;
  --gold: #ffd66b;
  --tonic: #5ce0d8;
  --sub: #b88aff;
  --dom: #ff6b8a;
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 18px;
  --r-xl: 24px;
  --font-display: 'Cinzel', 'Times New Roman', serif;
  --font-body: 'Quicksand', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'Fira Code', ui-monospace, 'SF Mono', Menlo, monospace;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  width: 100%; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--text);
  font-family: var(--font-body); font-weight: 500;
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  user-select: none; -webkit-user-select: none;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: var(--r-sm); }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 1.25em; height: 1.25em; flex: none; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
kbd {
  font-family: var(--font-mono); font-size: 0.62rem; font-weight: 500;
  padding: 0.1rem 0.35rem; border-radius: 5px; border: 1px solid var(--line-strong);
  color: var(--text-dim); background: rgba(255, 255, 255, 0.03);
}
@media (pointer: coarse) { kbd { display: none; } }

#stage { position: fixed; inset: 0; z-index: 0; display: block; }
#app { position: fixed; inset: 0; z-index: 1; }

/* ── Screens ──────────────────────────────────────────────── */
.screen {
  position: absolute; inset: 0;
  padding: calc(var(--safe-t) + 12px) calc(var(--safe-r) + 16px) calc(var(--safe-b) + 12px) calc(var(--safe-l) + 16px);
  opacity: 0; visibility: hidden; pointer-events: none;
  transform: scale(0.985);
  transition: opacity 0.45s var(--ease-out), transform 0.45s var(--ease-out), visibility 0s linear 0.45s;
}
.screen.active { opacity: 1; visibility: visible; pointer-events: auto; transform: none; transition-delay: 0s; }
.scroll-screen { overflow-y: auto; -webkit-overflow-scrolling: touch; }

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  min-height: 46px; padding: 0.65rem 1.3rem; border-radius: var(--r-md);
  background: rgba(255, 255, 255, 0.04); border: 1px solid var(--line-strong);
  font-weight: 600; font-size: 0.95rem; letter-spacing: 0.02em;
  transition: background 0.2s, border-color 0.2s, transform 0.15s var(--ease-out), box-shadow 0.2s;
}
.btn:hover { background: rgba(255, 255, 255, 0.08); border-color: rgba(255, 255, 255, 0.26); }
.btn:active { transform: scale(0.97); }
.btn.primary {
  background: linear-gradient(135deg, rgba(184, 138, 255, 0.34), rgba(92, 224, 216, 0.22));
  border-color: rgba(184, 138, 255, 0.55);
  box-shadow: 0 6px 24px rgba(140, 108, 255, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.12);
}
.btn.primary:hover { box-shadow: 0 8px 30px rgba(140, 108, 255, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.16); }
.btn.subtle { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.subtle:hover { color: var(--text); background: rgba(255, 255, 255, 0.05); }
.btn.danger { color: var(--rose); }
.icon-btn {
  display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 50%;
  color: var(--text-2); border: 1px solid var(--line); background: rgba(10, 10, 20, 0.45);
  transition: color 0.2s, border-color 0.2s, background 0.2s, transform 0.15s;
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
}
.icon-btn:hover { color: var(--text); border-color: var(--line-strong); }
.icon-btn:active { transform: scale(0.93); }
.chip-btn {
  display: inline-flex; align-items: center; gap: 0.35rem; padding: 0.35rem 0.8rem; border-radius: 999px;
  font-size: 0.8rem; font-weight: 600; color: var(--accent-2); border: 1px solid rgba(92, 224, 216, 0.35);
  background: rgba(92, 224, 216, 0.08); transition: background 0.2s;
}
.chip-btn:hover { background: rgba(92, 224, 216, 0.16); }
.chip-btn .icon { width: 1em; height: 1em; }

/* ── Title ────────────────────────────────────────────────── */
#screen-title { display: grid; place-items: center; overflow-y: auto; }
.title-wrap { display: flex; flex-direction: column; align-items: center; gap: clamp(1.4rem, 4vh, 2.6rem); width: min(520px, 100%); padding: 2vh 0; }
.logo { text-align: center; }
.logo h1 {
  font-family: var(--font-display); font-weight: 900; text-transform: uppercase;
  font-size: clamp(2.8rem, 11vw, 5.6rem); letter-spacing: 0.14em; line-height: 1; margin-right: -0.14em;
  background: linear-gradient(100deg, #ff8fb1 0%, #ffd66b 22%, #7ef0c8 45%, #5ce0d8 60%, #8c9dff 78%, #c58cff 100%);
  background-size: 220% 100%;
  -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: shimmer 9s ease-in-out infinite alternate;
  filter: drop-shadow(0 0 28px rgba(160, 120, 255, 0.35));
}
@keyframes shimmer { from { background-position: 0% 50%; } to { background-position: 100% 50%; } }
.tagline { margin-top: 0.8rem; font-size: clamp(0.8rem, 2.6vw, 1rem); letter-spacing: 0.5em; text-transform: uppercase; color: var(--text-2); font-weight: 500; margin-right: -0.5em; }
.title-menu { display: flex; flex-direction: column; gap: 0.75rem; width: 100%; }
.btn-hero {
  position: relative; display: flex; align-items: center; justify-content: center; gap: 0.9rem;
  width: 100%; min-height: 76px; padding: 0.9rem 1.4rem; border-radius: var(--r-lg);
  background: linear-gradient(120deg, rgba(184, 138, 255, 0.3), rgba(92, 224, 216, 0.2) 60%, rgba(255, 214, 107, 0.14));
  border: 1px solid rgba(200, 170, 255, 0.5);
  box-shadow: 0 10px 40px rgba(130, 100, 255, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.15);
  overflow: hidden; transition: transform 0.2s var(--ease-out), box-shadow 0.3s;
}
.btn-hero::after {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(105deg, transparent 35%, rgba(255, 255, 255, 0.14) 50%, transparent 65%);
  transform: translateX(-100%); animation: sweep 5s ease-in-out 1.5s infinite;
}
@keyframes sweep { 0%, 70% { transform: translateX(-100%); } 100% { transform: translateX(100%); } }
.btn-hero:hover { transform: translateY(-2px); box-shadow: 0 14px 48px rgba(130, 100, 255, 0.32), inset 0 1px 0 rgba(255, 255, 255, 0.2); }
.btn-hero:active { transform: scale(0.985); }
.btn-hero .icon { width: 1.9rem; height: 1.9rem; color: #fff; }
.btn-hero-text { display: flex; flex-direction: column; align-items: flex-start; }
.btn-hero-label { font-family: var(--font-display); font-weight: 700; font-size: 1.6rem; letter-spacing: 0.12em; text-transform: uppercase; }
.btn-hero-sub { font-size: 0.8rem; color: var(--text-2); letter-spacing: 0.04em; }
.mode-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.6rem; }
.mode-card {
  display: flex; flex-direction: column; align-items: center; gap: 0.25rem; padding: 0.9rem 0.4rem;
  min-height: 96px; justify-content: center; border-radius: var(--r-md);
  background: var(--surface); border: 1px solid var(--line);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  transition: border-color 0.2s, transform 0.2s var(--ease-out), background 0.2s;
}
.mode-card:hover { border-color: rgba(184, 138, 255, 0.45); transform: translateY(-2px); background: rgba(24, 22, 44, 0.85); }
.mode-card:active { transform: scale(0.97); }
.mode-card .icon { width: 1.5rem; height: 1.5rem; color: var(--accent); }
.mode-name { font-weight: 700; font-size: 0.98rem; letter-spacing: 0.03em; }
.mode-sub { font-size: 0.72rem; color: var(--text-dim); text-align: center; line-height: 1.25; }
.mode-card.done .mode-sub { color: var(--accent-2); }
.btn-continue {
  display: flex; align-items: center; gap: 0.6rem; justify-content: center; min-height: 48px;
  border-radius: var(--r-md); border: 1px dashed rgba(92, 224, 216, 0.4); color: var(--accent-2);
  font-weight: 600; background: rgba(92, 224, 216, 0.05); transition: background 0.2s;
}
.btn-continue:hover { background: rgba(92, 224, 216, 0.1); }
.continue-score { font-family: var(--font-mono); font-size: 0.8rem; color: var(--text-2); }
.title-tools { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.3rem; width: 100%; }
.tool-btn {
  display: flex; flex-direction: column; align-items: center; gap: 0.3rem; min-height: 64px; text-align: center; line-height: 1.2;
  padding: 0.5rem 0.6rem; border-radius: var(--r-md); color: var(--text-2); font-size: 0.74rem; font-weight: 600;
  transition: color 0.2s, background 0.2s;
}
.tool-btn:hover { color: var(--text); background: rgba(255, 255, 255, 0.05); }
.tool-btn .icon { width: 1.4rem; height: 1.4rem; }
.title-hint { font-size: 0.74rem; letter-spacing: 0.18em; text-transform: uppercase; color: var(--text-dim); text-align: center; min-height: 1.2em; transition: opacity 0.6s; }

/* ── Game screen ──────────────────────────────────────────── */
#screen-game.active {
  display: grid;
  grid-template-columns: minmax(130px, 168px) 1fr minmax(130px, 168px);
  grid-template-rows: auto auto minmax(0, 1fr) auto auto;
  grid-template-areas: "top top top" "left coach right" "left board right" "palette palette palette" "ribbon ribbon ribbon";
  gap: 10px 16px;
  pointer-events: none;
}
#screen-game.active > * { pointer-events: auto; }
#screen-game.active > .banner { pointer-events: none; }
#screen-game { display: grid; }
.hud-top { grid-area: top; display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 1rem; }
.hud-label { display: block; font-size: 0.66rem; letter-spacing: 0.2em; text-transform: uppercase; color: var(--text-dim); font-weight: 600; }
.hud-score { display: flex; flex-direction: column; min-width: 0; }
.hud-value { align-self: flex-start; display: inline-block; transform-origin: left center; font-family: var(--font-mono); font-weight: 600; font-size: clamp(1.4rem, 3vw, 1.9rem); line-height: 1.1; font-variant-numeric: tabular-nums; transition: color 0.3s; }
.hud-value.bump { animation: bump 0.35s var(--ease-spring); }
@keyframes bump { 40% { transform: scale(1.12); color: var(--gold); } }
.hud-sub { font-family: var(--font-mono); font-size: 0.7rem; color: var(--text-dim); min-height: 1.2em; }
.hud-sub.beat { color: var(--gold); }
.hud-wave { display: flex; flex-direction: column; align-items: flex-end; gap: 0.25rem; min-width: 150px; }
.wave-track { width: 150px; height: 5px; border-radius: 3px; background: rgba(255, 255, 255, 0.08); overflow: hidden; }
.wave-track i { display: block; height: 100%; width: 0%; border-radius: inherit; background: linear-gradient(90deg, var(--accent-2), var(--accent)); transition: width 0.5s var(--ease-out); }
.hud-key { font-weight: 700; font-size: 1.02rem; letter-spacing: 0.03em; color: var(--text); }
.hud-key.flash { animation: keyflash 1.2s var(--ease-out); }
@keyframes keyflash { 0% { color: var(--gold); text-shadow: 0 0 18px var(--gold); } 100% { color: var(--text); text-shadow: none; } }

.dock { display: flex; flex-direction: column; gap: 1rem; align-self: center; }
.dock-left { grid-area: left; align-items: stretch; }
.dock-right { grid-area: right; align-items: center; }
.dock-label { font-size: 0.66rem; letter-spacing: 0.2em; text-transform: uppercase; color: var(--text-dim); font-weight: 600; }
.queue, .hold, .tool, .meter, .combo, .goals {
  border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--line);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
}
.queue { display: flex; flex-direction: column; align-items: center; gap: 0.6rem; padding: 0.8rem 0.6rem 0.9rem; }
.queue-notes { display: flex; flex-direction: column; align-items: center; gap: 0.6rem; }
.queue-rest { display: flex; gap: 0.5rem; }
.hold { display: flex; flex-direction: column; align-items: center; gap: 0.5rem; padding: 0.75rem 0.6rem; transition: border-color 0.2s, background 0.2s; }
.hold:hover { border-color: var(--line-strong); }
.hold:active .note-chip { transform: scale(0.92); }
.tool { display: flex; align-items: center; justify-content: center; gap: 0.5rem; padding: 0.7rem 0.6rem; min-height: 48px; transition: border-color 0.2s, background 0.2s, color 0.2s; color: var(--text-2); }
.tool .icon { width: 1.3rem; height: 1.3rem; }
.tool-text { display: flex; gap: 0.35rem; align-items: baseline; font-weight: 600; font-size: 0.9rem; }
.tool-text b { font-family: var(--font-mono); color: var(--accent); }
.tool:hover:not(:disabled) { border-color: var(--line-strong); color: var(--text); }
.tool:disabled { opacity: 0.4; }
.tool.armed { border-color: var(--rose); color: var(--rose); background: rgba(255, 107, 138, 0.1); box-shadow: 0 0 20px rgba(255, 107, 138, 0.18); }

/* Hexagonal note chips (flat-top, matching the board). */
.note-chip {
  --c: #666;
  width: 46px; aspect-ratio: 1.1547; display: grid; place-items: center;
  clip-path: polygon(25% 2%, 75% 2%, 100% 50%, 75% 98%, 25% 98%, 0% 50%);
  background:
    radial-gradient(circle at 50% 28%, color-mix(in srgb, var(--c) 70%, white 30%) 0%, var(--c) 48%, color-mix(in srgb, var(--c) 45%, #0a0a18) 100%);
  color: #fff; font-weight: 700; font-size: 1rem; text-shadow: 0 1px 4px rgba(0, 0, 0, 0.45);
  transition: transform 0.25s var(--ease-spring), opacity 0.3s, background 0.3s;
}
.note-chip.big { width: 76px; font-size: 1.55rem; filter: drop-shadow(0 0 14px color-mix(in srgb, var(--c) 55%, transparent)); }
.note-chip.empty { background: rgba(255, 255, 255, 0.05); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12); color: var(--text-dim); text-shadow: none; }
.note-chip.dim { opacity: 0.85; }
.note-chip.enter { animation: chipIn 0.35s var(--ease-spring); }
@keyframes chipIn { from { transform: translateY(14px) scale(0.6); opacity: 0; } }
.hold .note-chip { width: 56px; }

.meter { display: flex; flex-direction: column; align-items: center; gap: 0.5rem; padding: 0.8rem 0.6rem; width: 100%; }
.meter-track { position: relative; width: 22px; height: clamp(110px, 24vh, 220px); border-radius: 12px; background: rgba(255, 255, 255, 0.05); overflow: hidden; box-shadow: inset 0 0 0 1px var(--line); }
.meter-track i {
  position: absolute; left: 0; right: 0; bottom: 0; height: 0%; border-radius: inherit;
  background: linear-gradient(0deg, var(--accent), var(--accent-2) 60%, var(--gold));
  transition: height 0.45s var(--ease-out);
}
.meter-text { font-family: var(--font-mono); font-size: 0.78rem; color: var(--text-2); }
.meter.full .meter-track { box-shadow: inset 0 0 0 1px rgba(255, 214, 107, 0.6), 0 0 22px rgba(255, 214, 107, 0.35); }
.meter.active .meter-track i { background: linear-gradient(0deg, #ff8fb1, #ffd66b, #7ef0c8, #8c9dff); background-size: 100% 300%; animation: flow 1.6s linear infinite; }
.meter.active .meter-text { color: var(--gold); }
@keyframes flow { to { background-position: 0 300%; } }
.combo { display: flex; flex-direction: column; align-items: center; gap: 0.3rem; padding: 0.7rem 0.6rem; width: 100%; transition: border-color 0.3s, box-shadow 0.3s; }
.combo-value { font-family: var(--font-mono); font-weight: 600; font-size: 1.7rem; line-height: 1; color: var(--text-2); transition: color 0.3s; }
.combo.on .combo-value { color: var(--gold); }
.combo.on { border-color: rgba(255, 214, 107, 0.35); }
.combo.hot { box-shadow: 0 0 26px rgba(255, 140, 80, 0.25); }
.combo.hot .combo-value { color: #ffab5c; }
.combo-pips { display: flex; gap: 5px; height: 6px; }
.combo-pips i { width: 14px; height: 4px; border-radius: 2px; background: rgba(255, 255, 255, 0.1); transition: background 0.3s; }
.combo-pips i.on { background: var(--gold); }
.goals { display: flex; flex-direction: column; gap: 0.45rem; padding: 0.8rem 0.75rem; width: 100%; font-size: 0.8rem; }
.goal { display: grid; grid-template-columns: 18px 1fr; gap: 0.45rem; align-items: start; color: var(--text-2); line-height: 1.3; }
.goal .tick { width: 16px; height: 16px; margin-top: 1px; border-radius: 50%; border: 1.5px solid var(--line-strong); display: grid; place-items: center; font-size: 0.6rem; }
.goal.done { color: var(--text); }
.goal.done .tick { background: var(--accent-2); border-color: var(--accent-2); color: #062320; }
.goal .count { font-family: var(--font-mono); color: var(--text-dim); font-size: 0.72rem; }
.goal.bump { animation: bump 0.4s var(--ease-spring); }
.goals-title { display: flex; justify-content: space-between; gap: 0.5rem; font-size: 0.66rem; letter-spacing: 0.2em; text-transform: uppercase; color: var(--text-dim); font-weight: 600; }
.goals-title span { letter-spacing: 0.04em; text-transform: none; font-family: var(--font-mono); color: var(--accent-2); }
.goals-title span.low { color: var(--rose); }

.board-area { grid-area: board; position: relative; min-height: 0; min-width: 0; outline: none; touch-action: none; cursor: pointer; border-radius: var(--r-xl); }
.board-area:focus-visible { box-shadow: inset 0 0 0 2px rgba(184, 138, 255, 0.35); outline: none; }
.board-area.muting { cursor: crosshair; }

.ribbon { grid-area: ribbon; min-height: 58px; display: flex; align-items: center; justify-content: center; overflow: hidden; mask-image: linear-gradient(90deg, transparent 0, black 12%, black 88%, transparent 100%); -webkit-mask-image: linear-gradient(90deg, transparent 0, black 12%, black 88%, transparent 100%); }
.ribbon-track { display: flex; align-items: center; gap: 0.35rem; }
.ribbon-empty { font-size: 0.78rem; color: var(--text-dim); letter-spacing: 0.06em; }
.prog-chip {
  --f: var(--text-2);
  display: flex; flex-direction: column; align-items: center; padding: 0.3rem 0.65rem; border-radius: 10px; min-width: 52px;
  border: 1px solid color-mix(in srgb, var(--f) 45%, transparent); background: color-mix(in srgb, var(--f) 9%, rgba(10, 10, 20, 0.6));
  animation: chipIn 0.4s var(--ease-spring);
}
.prog-chip b { font-weight: 700; font-size: 0.98rem; color: var(--f); letter-spacing: 0.02em; }
.prog-chip span { font-family: var(--font-mono); font-size: 0.66rem; color: var(--text-2); }
.prog-chip.T { --f: var(--tonic); } .prog-chip.S { --f: var(--sub); } .prog-chip.D { --f: var(--dom); }
.prog-link { font-size: 0.6rem; color: var(--text-dim); font-family: var(--font-mono); white-space: nowrap; }
.prog-link.cad { color: var(--gold); }

.palette {
  grid-area: palette; justify-self: center; z-index: 3;
  display: flex; flex-wrap: wrap; justify-content: center; gap: 0.35rem; padding: 0.55rem 0.7rem; border-radius: var(--r-lg);
  background: var(--surface-strong); border: 1px solid var(--line); max-width: 100%;
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
}
.palette .note-chip { width: 44px; cursor: pointer; flex: none; opacity: 0.6; }
.palette .note-chip.sel { opacity: 1; transform: translateY(-4px) scale(1.08); }
.palette-tool { flex: none; display: grid; place-items: center; width: 44px; border-radius: 10px; color: var(--text-2); }
.palette-tool:hover { color: var(--rose); }
.palette select {
  flex: none; align-self: center; min-height: 40px; padding: 0 0.6rem; border-radius: 10px; border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.05); color: var(--text); font: 600 0.85rem var(--font-body); cursor: pointer;
}
.palette select option { background: #14122a; }

.coach {
  grid-area: coach; justify-self: center; z-index: 4; display: grid; place-items: center; min-height: 4.6rem;
  width: min(480px, 100%); padding: 0.8rem 1.2rem; border-radius: var(--r-lg);
  background: var(--surface-strong); border: 1px solid rgba(184, 138, 255, 0.35);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.45); text-align: center; animation: coachIn 0.45s var(--ease-out);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
}
.coach p { font-size: 1rem; line-height: 1.5; }
.coach.swap p { animation: fadeUp 0.35s var(--ease-out); }
.coach b { color: var(--gold); font-weight: 700; }
.coach-next { margin-top: 0.7rem; padding: 0.45rem 1.2rem; border-radius: 999px; background: rgba(184, 138, 255, 0.2); border: 1px solid rgba(184, 138, 255, 0.5); font-weight: 600; }
@keyframes coachIn { from { opacity: 0; transform: translateY(-8px); } }

.banner {
  position: absolute; left: 0; right: 0; top: 24%; z-index: 4; pointer-events: none; text-align: center;
  font-family: var(--font-display); font-weight: 700; letter-spacing: 0.18em; text-transform: uppercase; opacity: 0;
}
.banner.show { animation: banner 1.6s var(--ease-out) forwards; }
.banner .b-main { display: block; font-size: clamp(1.6rem, 5vw, 2.8rem); text-shadow: 0 0 30px rgba(255, 214, 107, 0.45); }
.banner .b-sub { display: block; margin-top: 0.4rem; font-family: var(--font-body); font-size: 0.9rem; letter-spacing: 0.3em; color: var(--text-2); }
@keyframes banner { 0% { opacity: 0; transform: scale(0.9); letter-spacing: 0.4em; } 18% { opacity: 1; transform: none; letter-spacing: 0.18em; } 72% { opacity: 1; } 100% { opacity: 0; transform: translateY(-14px); } }

/* Portrait phones and narrow windows: stack everything around the board. */
@media (max-aspect-ratio: 5/6), (max-width: 760px) and (min-height: 561px) {
  #screen-game.active {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto minmax(0, 1fr) auto auto auto;
    grid-template-areas: "top" "right" "coach" "board" "left" "palette" "ribbon";
    gap: 8px;
    padding-left: calc(var(--safe-l) + 10px); padding-right: calc(var(--safe-r) + 10px);
  }
  .hud-top { gap: 0.6rem; }
  .hud-wave { min-width: 0; }
  .wave-track { width: 96px; }
  .hud-key { font-size: 0.85rem; }
  .dock { flex-direction: row; gap: 0.5rem; align-self: stretch; }
  .dock-left { justify-content: center; align-items: stretch; }
  .queue { flex-direction: row; padding: 0.45rem 0.7rem; gap: 0.6rem; }
  .queue .dock-label, .hold .dock-label { display: none; }
  .queue-notes { flex-direction: row; gap: 0.5rem; align-items: center; }
  .queue-rest { gap: 0.35rem; }
  .note-chip { width: 38px; font-size: 0.85rem; }
  .note-chip.big { width: 58px; font-size: 1.2rem; }
  .hold { flex-direction: row; padding: 0.45rem 0.7rem; }
  .hold .note-chip { width: 46px; }
  .hold::before { content: 'Hold'; font-size: 0.6rem; letter-spacing: 0.18em; text-transform: uppercase; color: var(--text-dim); writing-mode: vertical-rl; transform: rotate(180deg); font-weight: 600; }
  .tool { flex-direction: column; gap: 0.15rem; padding: 0.4rem 0.55rem; font-size: 0.8rem; min-width: 0; }
  .tool-text { font-size: 0.74rem; }
  .dock kbd { display: none; }
  .dock-right { flex-direction: row; align-items: stretch; }
  .meter { flex-direction: row; padding: 0.45rem 0.8rem; gap: 0.6rem; flex: 1; width: auto; min-width: 0; }
  .meter-track { width: auto; flex: 1; height: 10px; }
  .meter-track i { top: 0; bottom: 0; right: auto; height: auto !important; width: var(--fill, 0%); transition: width 0.45s var(--ease-out); }
  .meter.active .meter-track i { background-size: 300% 100%; animation-name: flowx; }
  @keyframes flowx { to { background-position: 300% 0; } }
  .combo { flex-direction: row; width: auto; padding: 0.45rem 0.8rem; gap: 0.5rem; }
  .combo .dock-label { display: inline; font-size: 0.58rem; }
  .combo-value { font-size: 1.15rem; }
  .goals { flex: 1; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 0.25rem 0.8rem; width: auto; padding: 0.45rem 0.8rem; font-size: 0.76rem; }
  .goals-title { width: 100%; }
  .ribbon { min-height: 48px; }
  .prog-chip { min-width: 44px; padding: 0.22rem 0.5rem; }
  .prog-chip b { font-size: 0.85rem; }
  .palette { gap: 0.3rem; padding: 0.45rem 0.5rem; }
  .banner .b-sub { font-size: 0.72rem; letter-spacing: 0.16em; padding: 0 1rem; }
  .palette .note-chip { width: 40px; }
  .coach { padding: 0.6rem 0.9rem; min-height: 4.2rem; }
  .coach p { font-size: 0.9rem; }
}
@media (max-width: 380px) {
  .hud-top { grid-template-columns: auto 1fr auto auto; gap: 0.4rem; }
  .icon-btn { width: 40px; height: 40px; }
  .wave-track { width: 70px; }
}
/* Landscape phones: short screens keep the side docks but pack them tightly. */
@media (max-height: 560px) and (min-aspect-ratio: 5/6) {
  #screen-game.active { gap: 6px 12px; padding-top: calc(var(--safe-t) + 6px); padding-bottom: calc(var(--safe-b) + 6px); grid-template-columns: minmax(110px, 140px) 1fr minmax(110px, 140px); }
  .hud-top .icon-btn { width: 38px; height: 38px; }
  .hud-value { font-size: 1.3rem; }
  .dock { gap: 0.4rem; }
  .dock .dock-label, .dock kbd { display: none; }
  .queue { padding: 0.45rem; gap: 0.3rem; }
  .queue-notes { gap: 0.35rem; }
  .note-chip { width: 34px; font-size: 0.8rem; }
  .note-chip.big { width: 52px; font-size: 1.1rem; }
  .hold { padding: 0.4rem; flex-direction: row; justify-content: center; gap: 0.5rem; }
  .hold::before { content: 'Hold'; font-size: 0.6rem; letter-spacing: 0.18em; text-transform: uppercase; color: var(--text-dim); font-weight: 600; }
  .hold .note-chip { width: 42px; }
  .tool { padding: 0.35rem; min-height: 40px; }
  .meter { padding: 0.45rem; gap: 0.3rem; }
  .meter-track { height: clamp(60px, 22vh, 110px); }
  .combo { padding: 0.4rem; }
  .combo-value { font-size: 1.2rem; }
  .ribbon { min-height: 40px; }
  .prog-chip { padding: 0.15rem 0.45rem; }
  .coach { min-height: 3.2rem; padding: 0.45rem 0.8rem; }
  .coach p { font-size: 0.85rem; }
  .palette { grid-area: left; align-self: center; gap: 0.25rem; padding: 0.4rem; }
  .palette .note-chip { width: 34px; font-size: 0.75rem; }
  .palette select { width: 100%; }
}

/* ── Pages: journey, chord book, stats ────────────────────── */
.page-head {
  position: sticky; top: calc(-12px - var(--safe-t)); z-index: 2; display: grid; grid-template-columns: 44px 1fr auto; align-items: center; gap: 0.8rem;
  max-width: 980px; margin: 0 auto 0.6rem; padding: 0.6rem 0;
}
.page-head::before {
  content: ''; position: absolute; z-index: -1; inset: calc(-12px - var(--safe-t)) -50vw -18px;
  background: linear-gradient(rgba(7, 7, 14, 0.94) 65%, rgba(7, 7, 14, 0));
}
.page-head h2 { font-family: var(--font-display); font-weight: 700; font-size: clamp(1.4rem, 4vw, 2rem); letter-spacing: 0.1em; text-transform: uppercase; }
.page-meta { font-family: var(--font-mono); font-size: 0.85rem; color: var(--gold); display: flex; align-items: center; gap: 0.3rem; }
.page-meta .icon { width: 1rem; height: 1rem; }
.page-intro { max-width: 980px; margin: 0 auto 1rem; color: var(--text-2); font-size: 0.9rem; }
.page-body { max-width: 980px; margin: 0 auto; padding-bottom: 3rem; }
.chapter { margin-bottom: 1.8rem; }
.chapter-head { display: flex; align-items: baseline; gap: 0.8rem; margin-bottom: 0.8rem; }
.chapter-head h3 { font-family: var(--font-display); font-size: 1.1rem; letter-spacing: 0.08em; }
.chapter-head p { color: var(--text-dim); font-size: 0.82rem; }
.level-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 0.7rem; }
.level-card {
  position: relative; display: flex; flex-direction: column; align-items: flex-start; gap: 0.3rem; padding: 0.9rem 1rem; min-height: 104px;
  border-radius: var(--r-md); background: var(--surface); border: 1px solid var(--line); text-align: left;
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  transition: border-color 0.2s, transform 0.2s var(--ease-out), background 0.2s;
}
.level-card:hover:not(:disabled) { border-color: rgba(184, 138, 255, 0.45); transform: translateY(-2px); }
.level-card:active:not(:disabled) { transform: scale(0.98); }
.level-card:disabled { opacity: 0.45; }
.level-card.next { border-color: rgba(92, 224, 216, 0.5); box-shadow: 0 0 24px rgba(92, 224, 216, 0.12); }
.level-num { font-family: var(--font-mono); font-size: 0.7rem; color: var(--text-dim); }
.level-name { font-family: var(--font-display); font-weight: 700; font-size: 1rem; letter-spacing: 0.04em; }
.level-idea { font-size: 0.76rem; color: var(--text-2); line-height: 1.35; }
.level-stars { position: absolute; top: 0.8rem; right: 0.9rem; display: flex; gap: 2px; color: rgba(255, 255, 255, 0.14); }
.level-stars .icon { width: 0.95rem; height: 0.95rem; }
.level-stars .on { color: var(--gold); filter: drop-shadow(0 0 4px rgba(255, 214, 107, 0.6)); }
.level-card .icon.lock { position: absolute; top: 0.8rem; right: 0.9rem; color: var(--text-dim); }

.book-family { margin-bottom: 1.4rem; }
.book-family h3 { font-family: var(--font-display); font-size: 1rem; letter-spacing: 0.08em; margin-bottom: 0.6rem; color: var(--text-2); }
.book-row { display: grid; grid-template-columns: minmax(130px, 200px) 1fr; gap: 0.8rem; align-items: center; padding: 0.55rem 0; border-bottom: 1px solid var(--line); }
.book-type b { display: block; font-weight: 700; }
.book-type span { font-size: 0.74rem; color: var(--text-dim); font-family: var(--font-mono); }
.book-roots { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 4px; }
.root-chip {
  --c: #555; aspect-ratio: 1.1547; display: grid; place-items: center; font-size: 0.66rem; font-weight: 700;
  clip-path: polygon(25% 2%, 75% 2%, 100% 50%, 75% 98%, 25% 98%, 0% 50%);
  background: rgba(255, 255, 255, 0.04); color: rgba(255, 255, 255, 0.22); transition: transform 0.15s;
}
.root-chip.found { background: radial-gradient(circle at 50% 30%, color-mix(in srgb, var(--c) 70%, white 30%), var(--c) 55%, color-mix(in srgb, var(--c) 50%, #0a0a18)); color: #fff; }
.root-chip:hover { transform: scale(1.12); }
@media (max-width: 600px) {
  .book-row { grid-template-columns: 1fr; gap: 0.4rem; }
  .book-roots { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 4px; }
  .root-chip { font-size: 0.8rem; }
}

.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0.7rem; margin-bottom: 1.6rem; }
.stat-card { padding: 1rem; border-radius: var(--r-md); background: var(--surface); border: 1px solid var(--line); }
.stat-card b { display: block; font-family: var(--font-mono); font-size: 1.45rem; font-weight: 600; color: var(--text); }
.stat-card span { font-size: 0.72rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--text-dim); font-weight: 600; }
.stat-section h3 { font-family: var(--font-display); font-size: 1rem; letter-spacing: 0.08em; margin: 0 0 0.7rem; color: var(--text-2); }
.bars { display: flex; flex-direction: column; gap: 0.4rem; margin-bottom: 1.6rem; }
.bar-row { display: grid; grid-template-columns: 120px 1fr 48px; gap: 0.6rem; align-items: center; font-size: 0.82rem; }
.bar-row i { display: block; height: 8px; border-radius: 4px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); min-width: 2px; }
.bar-row span:last-child { font-family: var(--font-mono); color: var(--text-2); text-align: right; }
.daily-strip { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 1.6rem; }
.daily-day { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; font-family: var(--font-mono); font-size: 0.66rem; background: rgba(255, 255, 255, 0.04); color: var(--text-dim); }
.daily-day.played { background: rgba(92, 224, 216, 0.18); color: var(--accent-2); }
.daily-day.today { box-shadow: inset 0 0 0 1px var(--gold); }

/* ── Overlays ─────────────────────────────────────────────── */
.overlay {
  position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px;
  background: rgba(4, 4, 10, 0.62); opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity 0.3s var(--ease-out), visibility 0s linear 0.3s;
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.overlay.active { opacity: 1; visibility: visible; pointer-events: auto; transition-delay: 0s; }
.panel {
  position: relative; width: min(460px, 100%); max-height: calc(100dvh - 32px); overflow-y: auto; overscroll-behavior: contain;
  padding: clamp(1.4rem, 4vw, 2.2rem); border-radius: var(--r-xl); text-align: center;
  background: linear-gradient(180deg, rgba(26, 23, 48, 0.96), rgba(13, 12, 26, 0.97));
  border: 1px solid rgba(184, 138, 255, 0.22);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55), 0 0 60px rgba(140, 108, 255, 0.1), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  transform: translateY(14px) scale(0.97); transition: transform 0.4s var(--ease-out);
}
.panel.narrow { width: min(340px, 100%); }
.overlay.active .panel { transform: none; }
.panel h2 { font-family: var(--font-display); font-weight: 700; font-size: 1.6rem; letter-spacing: 0.08em; margin-bottom: 0.5rem; }
.panel-kicker { font-size: 0.72rem; letter-spacing: 0.28em; text-transform: uppercase; color: var(--accent); font-weight: 600; margin-bottom: 0.4rem; }
.panel-sub { color: var(--text-2); font-size: 0.9rem; line-height: 1.5; margin-bottom: 1.2rem; }
.panel-close { position: absolute; top: 12px; right: 12px; }
.stack { display: flex; flex-direction: column; gap: 0.55rem; }
.stack .btn { width: 100%; }
.row { display: flex; gap: 0.6rem; justify-content: center; flex-wrap: wrap; margin-top: 1.3rem; }
.big-score { font-family: var(--font-mono); font-weight: 600; font-size: clamp(2.6rem, 10vw, 3.6rem); line-height: 1.1; background: linear-gradient(90deg, #fff, var(--gold)); -webkit-background-clip: text; background-clip: text; color: transparent; font-variant-numeric: tabular-nums; }
.badge { display: inline-block; margin-top: 0.4rem; padding: 0.25rem 0.8rem; border-radius: 999px; font-size: 0.75rem; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: #1d1404; background: linear-gradient(90deg, #ffd66b, #ffb35c); animation: pop 0.5s var(--ease-spring); }
@keyframes pop { from { transform: scale(0.4); opacity: 0; } }
.stars { display: flex; justify-content: center; gap: 0.5rem; margin: 0.6rem 0 0.2rem; color: rgba(255, 255, 255, 0.12); }
.stars .icon { width: 2.6rem; height: 2.6rem; transition: color 0.3s; }
.stars .icon.on { color: var(--gold); filter: drop-shadow(0 0 10px rgba(255, 214, 107, 0.6)); animation: pop 0.5s var(--ease-spring) both; }
.result-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.5rem; margin: 1.2rem 0 0.4rem; }
.result-grid div { padding: 0.6rem 0.4rem; border-radius: var(--r-sm); background: rgba(255, 255, 255, 0.03); border: 1px solid var(--line); }
.result-grid dt { font-size: 0.66rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--text-dim); font-weight: 600; }
.result-grid dd { font-family: var(--font-mono); font-size: 1.05rem; margin-top: 0.15rem; }
.song { margin-top: 0.8rem; text-align: left; }
.song-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; margin-bottom: 0.5rem; font-size: 0.72rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--text-dim); font-weight: 600; }
.song-chords { display: flex; flex-wrap: wrap; gap: 0.3rem; max-height: 120px; overflow-y: auto; }
.song-chords .prog-chip { animation: none; min-width: 0; padding: 0.2rem 0.45rem; transition: transform 0.2s, background 0.2s; }
.song-chords .prog-chip b { font-size: 0.8rem; }
.song-chords .prog-chip.playing { transform: translateY(-3px); background: color-mix(in srgb, var(--f) 30%, transparent); }
.level-concept { color: var(--text-2); line-height: 1.6; font-size: 0.95rem; margin: 0.4rem 0 1rem; }
.level-concept b { color: var(--text); }
.goal-list { list-style: none; display: flex; flex-direction: column; gap: 0.4rem; text-align: left; padding: 0.8rem 1rem; border-radius: var(--r-md); background: rgba(255, 255, 255, 0.03); border: 1px solid var(--line); }
.goal-list li { display: flex; gap: 0.6rem; align-items: center; font-size: 0.9rem; }
.goal-list li::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--accent-2); box-shadow: 0 0 8px var(--accent-2); flex: none; }
.goal-list .limit::before { background: var(--text-dim); box-shadow: none; }
.goal-list .missed { color: var(--text-2); }
.goal-list .missed::before { background: var(--rose); box-shadow: 0 0 8px var(--rose); }
.goal-list .met::before { content: '✓'; width: auto; height: auto; background: none; box-shadow: none; color: var(--accent-2); font-weight: 700; }
#over-goals { margin-top: 1rem; }

.settings { display: flex; flex-direction: column; text-align: left; margin-top: 0.6rem; }
.setting { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem 1rem; padding: 0.75rem 0; border-bottom: 1px solid var(--line); cursor: pointer; min-height: 52px; }
.setting > span { display: flex; flex-direction: column; font-weight: 600; font-size: 0.95rem; flex: 1 1 6rem; }
.setting small { font-size: 0.74rem; color: var(--text-dim); font-weight: 500; margin-top: 0.1rem; }
input[type=range] { width: 46%; accent-color: var(--accent); height: 28px; cursor: pointer; }
.switch { appearance: none; -webkit-appearance: none; flex: none; width: 46px; height: 28px; border-radius: 14px; background: rgba(255, 255, 255, 0.1); position: relative; cursor: pointer; transition: background 0.2s; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #cfc8e2; transition: transform 0.25s var(--ease-spring), background 0.2s; }
.switch:checked { background: rgba(184, 138, 255, 0.55); }
.switch:checked::after { transform: translateX(18px); background: #fff; }
.segmented { display: flex; flex: none; margin-left: auto; padding: 3px; border-radius: 10px; background: rgba(255, 255, 255, 0.06); }
.segmented button { min-width: 48px; min-height: 36px; padding: 0 0.7rem; border-radius: 8px; color: var(--text-2); font-weight: 600; font-size: 0.9rem; white-space: nowrap; transition: background 0.2s, color 0.2s; }
#set-spelling button:not([data-value=auto]) { font-size: 1.05rem; }
.segmented button[aria-checked=true] { background: rgba(184, 138, 255, 0.35); color: #fff; }

.howto { min-height: 280px; text-align: left; }
.howto-page { display: none; animation: fadeUp 0.35s var(--ease-out); }
.howto-page.active { display: block; }
.howto-page p { color: var(--text-2); line-height: 1.6; margin-bottom: 0.7rem; font-size: 0.95rem; }
.howto-page p b { color: var(--text); }
.howto-art { display: flex; justify-content: center; align-items: center; gap: 0.35rem 0.3rem; margin: 0.6rem 0 1.1rem; min-height: 72px; flex-wrap: wrap; }
.howto-art .note-chip { width: 44px; font-size: 0.95rem; }
.howto-art .break { flex-basis: 100%; height: 0; }
.howto-art .incoming-art { width: 52px; height: 45px; }
.howto-page p.tip { font-size: 0.85rem; color: var(--accent-2); }
.howto-art .arrow { color: var(--text-dim); font-size: 1.2rem; margin: 0 0.3rem; }
.howto-art .label { color: var(--gold); font-weight: 700; margin-left: 0.4rem; }
.howto-art .note-chip.dead { filter: grayscale(0.8) brightness(0.7); }
.howto-nav { display: flex; align-items: center; justify-content: space-between; margin-top: 1rem; }
.dots { display: flex; gap: 6px; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: rgba(255, 255, 255, 0.15); transition: background 0.3s, transform 0.3s; }
.dots i.on { background: var(--accent); transform: scale(1.3); }
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } }

.toasts { position: fixed; top: calc(var(--safe-t) + 14px); left: 50%; transform: translateX(-50%); z-index: 30; display: flex; flex-direction: column; align-items: center; gap: 0.4rem; pointer-events: none; width: min(92vw, 420px); }
.toast {
  display: flex; align-items: center; gap: 0.6rem; padding: 0.6rem 1rem; border-radius: var(--r-md);
  background: var(--surface-strong); border: 1px solid rgba(184, 138, 255, 0.35); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  font-size: 0.85rem; animation: toastIn 0.4s var(--ease-spring), toastOut 0.4s var(--ease-out) forwards; animation-delay: 0s, var(--life, 2.6s);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
}
.toast b { color: var(--gold); }
.toast .icon { color: var(--gold); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-12px) scale(0.95); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-8px); } }

/* On phones the top of the screen is busy, so toasts rise from the bottom. */
@media (max-aspect-ratio: 5/6), (max-width: 760px) and (min-height: 561px) {
  .toasts { top: auto; bottom: calc(var(--safe-b) + 12px); }
}

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