/* ───────── Changes · jazz chord flashcards ───────── */
:root {
  --ink: #0e1118;
  --ink-2: #161a24;
  --ink-3: #1f2430;
  --line: rgba(240, 230, 210, 0.12);
  --text: #f0e7d5;
  --muted: #a39b8a;
  --paper: #f5ecd9;
  --paper-2: #ebdfc5;
  --paper-ink: #1c1a16;
  --paper-muted: #6f6650;
  --gold: #f2b134;
  --coral: #e8553d;
  --teal: #3fb8af;
  --radius: 20px;
  --f-display: 'Archivo', system-ui, sans-serif;
  --f-sym: 'Fraunces', Georgia, serif;
  --f-ui: 'Inter', system-ui, -apple-system, sans-serif;
  --f-music: 'Noto Music', 'Apple Symbols', 'Segoe UI Symbol', serif;
  color-scheme: dark;
  /* theme tokens (dark default) */
  --on-accent: #0e1118;
  --text-2: #d6cdbb;
  --hover: rgba(255, 255, 255, 0.05);
  --track: rgba(255, 255, 255, 0.08);
  --nav-bg: rgba(14, 17, 24, 0.74);
  --backdrop: rgba(5, 6, 10, 0.7);
  --gold-text: #f2b134;
  --card-shadow: 0 30px 60px -20px rgba(0, 0, 0, 0.7), 0 10px 20px -10px rgba(0, 0, 0, 0.5);
  --glow: 1;
}
:root[data-theme="light"] {
  color-scheme: light;
  --ink: #ece5d6;
  --ink-2: #f9f5ec;
  --ink-3: #e4dccb;
  --line: rgba(28, 26, 22, 0.13);
  --text: #1c1a16;
  --muted: #6b6352;
  --text-2: #3b362b;
  --paper: #fffcf6;
  --paper-2: #f3ead7;
  --hover: rgba(28, 26, 22, 0.05);
  --track: rgba(28, 26, 22, 0.1);
  --nav-bg: rgba(236, 229, 214, 0.82);
  --backdrop: rgba(40, 32, 20, 0.35);
  --gold-text: #8f620a;
  --card-shadow: 0 1px 2px rgba(60, 45, 20, 0.08), 0 18px 40px -18px rgba(60, 45, 20, 0.35);
  --glow: 0.55;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  background:
    radial-gradient(1200px 600px at 85% -10%, rgba(232, 85, 61, 0.18), transparent 60%),
    radial-gradient(900px 600px at -10% 30%, rgba(63, 184, 175, 0.12), transparent 60%),
    radial-gradient(800px 500px at 50% 120%, rgba(242, 177, 52, 0.1), transparent 60%),
    var(--ink);
  color: var(--text);
  font: 15px/1.5 var(--f-ui);
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
}
.grain {
  position: fixed; inset: 0; pointer-events: none; z-index: 100; opacity: 0.07; mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }
kbd {
  font: 600 0.72em/1 var(--f-ui); padding: 0.28em 0.45em; border-radius: 5px;
  border: 1px solid currentColor; opacity: 0.55; margin-left: 0.4em; vertical-align: 0.1em;
}

/* ───────── Header */
.top {
  display: flex; align-items: center; gap: 24px;
  padding: 22px clamp(16px, 4vw, 48px);
  max-width: 1280px; width: 100%; margin: 0 auto;
}
.brand { display: flex; align-items: baseline; gap: 14px; text-decoration: none; color: inherit; margin-right: auto; }
.brand-mark {
  font-family: var(--f-display); font-weight: 900; font-stretch: 62%;
  font-size: 40px; line-height: 0.8; letter-spacing: -0.01em; text-transform: uppercase;
  background: var(--gold); color: var(--on-accent); padding: 8px 12px 4px; border-radius: 4px;
  box-shadow: 6px 6px 0 var(--coral);
}
.brand-sub {
  font-family: var(--f-display); font-stretch: 75%; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.18em; font-size: 12px; color: var(--muted);
}
.tabs { display: flex; gap: 4px; background: var(--ink-2); border: 1px solid var(--line); padding: 4px; border-radius: 999px; }
.tab {
  background: none; border: 0; padding: 8px 18px; border-radius: 999px; color: var(--muted);
  font-weight: 600; font-size: 14px; transition: background 0.2s, color 0.2s;
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--text); color: var(--ink); }
.icon-btn {
  width: 40px; height: 40px; display: grid; place-items: center; border-radius: 50%;
  border: 1px solid var(--line); background: var(--ink-2); transition: border-color 0.2s;
}
.icon-btn:hover { border-color: var(--muted); }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn svg path:first-child { fill: currentColor; }
.icon-btn .mute { display: none; }
.icon-btn.muted .wave { display: none; }
.icon-btn.muted .mute { display: block; }
.icon-btn.muted { color: var(--muted); }

main { flex: 1; width: 100%; max-width: 1280px; margin: 0 auto; padding: 8px clamp(16px, 4vw, 48px) 32px; }

/* ───────── Toolbar */
.toolbar { display: flex; gap: 12px; align-items: stretch; justify-content: center; flex-wrap: wrap; }
.seg { display: flex; background: var(--ink-2); border: 1px solid var(--line); border-radius: 16px; padding: 5px; gap: 4px; }
.seg button {
  background: none; border: 0; border-radius: 12px; padding: 9px 18px; text-align: left;
  display: flex; flex-direction: column; gap: 1px; color: var(--muted); transition: background 0.2s, color 0.2s;
}
.seg button b { font-family: var(--f-display); font-stretch: 85%; font-weight: 800; font-size: 16px; letter-spacing: 0.01em; text-transform: uppercase; }
.seg button small { font-size: 11.5px; opacity: 0.8; }
.seg button:hover { color: var(--text); }
.seg button.active { background: var(--ink-3); color: var(--text); box-shadow: inset 0 -3px 0 var(--gold); }
.deck-btn {
  display: flex; align-items: center; gap: 12px; background: var(--ink-2); border: 1px solid var(--line);
  border-radius: 16px; padding: 8px 18px 8px 14px; text-align: left; transition: border-color 0.2s;
}
.deck-btn:hover { border-color: var(--muted); }
.deck-btn b { display: block; font-family: var(--f-display); font-stretch: 85%; font-weight: 800; text-transform: uppercase; font-size: 16px; }
.deck-btn small { color: var(--muted); font-size: 11.5px; }
.deck-stack { position: relative; width: 26px; height: 32px; }
.deck-stack i { position: absolute; inset: 0; border-radius: 4px; background: var(--paper); border: 1px solid var(--ink); }
.deck-stack i:nth-child(1) { transform: rotate(-12deg) translate(-3px, 1px); background: var(--teal); }
.deck-stack i:nth-child(2) { transform: rotate(-4deg); background: var(--coral); }
.deck-stack i:nth-child(3) { transform: rotate(6deg) translate(2px, 0); background: var(--gold); }

.mode-hint { text-align: center; color: var(--muted); margin: 18px auto 20px; max-width: 560px; font-size: 14px; min-height: 2.6em; }

/* ───────── Card */
.stage { perspective: 2000px; display: flex; justify-content: center; }
.card { width: 100%; max-width: 820px; cursor: default; }
.card.enter { animation: enter 0.45s cubic-bezier(0.2, 0.9, 0.3, 1.2); }
.card.shake { animation: shake 0.42s; }
@keyframes enter { from { opacity: 0; transform: translateY(18px) rotate(-1.2deg) scale(0.98); } }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
.card-inner {
  display: grid; transform-style: preserve-3d;
  transition: transform 0.7s cubic-bezier(0.3, 1.25, 0.4, 1);
}
.card.flipped .card-inner { transform: rotateY(180deg); }
.card.no-anim .card-inner { transition: none; }
.face {
  grid-area: 1 / 1; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.35), transparent 30%),
    var(--paper);
  color: var(--paper-ink); border-radius: var(--radius);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.6) inset, var(--card-shadow);
  position: relative; overflow: hidden; min-height: 400px;
  padding: clamp(20px, 4vw, 40px) clamp(20px, 4vw, 44px) clamp(20px, 4vw, 36px) clamp(30px, 5vw, 56px);
}
.face::before { /* colored spine */
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 12px; background: var(--front-c, var(--gold));
}
.back::before { background: var(--c); }
.face::after { /* record-sleeve corner */
  content: ''; position: absolute; right: -70px; top: -70px; width: 180px; height: 180px; border-radius: 50%;
  border: 22px solid var(--front-c, var(--gold)); opacity: 0.16;
}
.back::after { border-color: var(--c); }
.back { transform: rotateY(180deg); }
.card:not(.flipped) .front { cursor: pointer; }

.tag {
  display: inline-flex; align-items: center; gap: 7px; font: 700 11px/1 var(--f-ui);
  letter-spacing: 0.12em; text-transform: uppercase; color: var(--paper-ink);
  padding: 6px 10px 6px 8px; border-radius: 999px; background: color-mix(in srgb, var(--c) 22%, transparent);
}
.tag::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.tag.neutral { --c: var(--paper-muted); background: rgba(0, 0, 0, 0.06); }

/* front: spell */
.front-spell { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; height: 100%; min-height: 330px; gap: 8px; }
.big-sym { font-size: clamp(84px, 17vw, 168px); line-height: 1.05; margin: 10px 0 0; }
.prompt { margin: 0; color: var(--paper-muted); font-size: 15px; }
.flip-hint { margin-top: 18px; font-size: 12px; color: var(--paper-muted); letter-spacing: 0.04em; }
.flip-hint kbd { margin: 0 0.3em 0 0; }

/* chord symbol */
.sym { font-family: var(--f-sym); font-weight: 800; font-variation-settings: 'opsz' 144; letter-spacing: -0.02em; white-space: nowrap; }
.sym-root { font-size: 1em; }
.sym-acc { font-family: var(--f-music); font-weight: 400; font-size: 0.62em; vertical-align: 0.48em; margin-left: 0.02em; }
.sym-q {
  font-size: 0.5em; font-weight: 600; font-style: italic; position: relative; top: -0.72em;
  margin-left: 0.06em; letter-spacing: -0.01em;
}

/* front: name */
.front-name, .front-hear { display: flex; flex-direction: column; align-items: center; gap: 16px; text-align: center; }
.visuals { display: grid; grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.4fr); gap: 20px; align-items: center; width: 100%; }
.vis-staff, .vis-keys { background: rgba(255, 255, 255, 0.45); border: 1px solid rgba(28, 26, 22, 0.08); border-radius: 14px; padding: 10px; }
.vis-staff svg, .vis-keys svg { display: block; width: 100%; height: auto; }

/* front: hear */
.vinyl {
  width: min(250px, 60vw); aspect-ratio: 1; border-radius: 50%; border: 0; position: relative; margin: 6px 0;
  background:
    radial-gradient(circle, transparent 0 31%, transparent 31%),
    repeating-radial-gradient(circle, #15151a 0 2px, #222229 2px 3px),
    #111;
  box-shadow: 0 18px 40px -12px rgba(0, 0, 0, 0.6), inset 0 0 0 6px #0a0a0c;
  display: grid; place-items: center; transition: transform 0.2s;
}
.vinyl::before { /* sheen */
  content: ''; position: absolute; inset: 0; border-radius: 50%;
  background: conic-gradient(from 20deg, transparent 0 10%, rgba(255, 255, 255, 0.13) 14%, transparent 20% 55%, rgba(255, 255, 255, 0.1) 62%, transparent 68%);
}
.vinyl:hover { transform: scale(1.03); }
.vinyl-label {
  width: 38%; aspect-ratio: 1; border-radius: 50%; background: var(--coral); color: var(--paper);
  display: flex; flex-direction: column; align-items: center; justify-content: center; position: relative;
  box-shadow: inset 0 0 0 3px rgba(0, 0, 0, 0.15);
}
.vinyl-label::after { content: ''; position: absolute; width: 8px; height: 8px; border-radius: 50%; background: var(--ink); top: 50%; left: 50%; transform: translate(-50%, -50%); }
.vinyl-label b { font-family: var(--f-display); font-stretch: 62%; font-weight: 900; text-transform: uppercase; font-size: 15px; line-height: 1; margin-bottom: 18px; }
.vinyl-label small { font-size: 8px; letter-spacing: 0.12em; text-transform: uppercase; opacity: 0.85; }
.vinyl.spinning { animation: spin 2.4s cubic-bezier(0.2, 0.6, 0.4, 1); }
@keyframes spin { to { transform: rotate(720deg); } }

/* back */
.back-wrap { display: flex; flex-direction: column; gap: 18px; }
.back-head { display: flex; align-items: center; gap: 24px; flex-wrap: wrap; }
.back-sym { font-size: clamp(56px, 9vw, 84px); line-height: 1; }
.back-title { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; min-width: 0; }
.back-title h2, .detail-card h2 {
  margin: 0; font-family: var(--f-display); font-stretch: 75%; font-weight: 800; text-transform: uppercase;
  font-size: clamp(20px, 3vw, 26px); line-height: 1.05; letter-spacing: 0.01em;
}
.alts { margin: 0; font-size: 13px; color: var(--paper-muted); display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.alts span { font-family: var(--f-sym); font-weight: 600; color: var(--paper-ink); background: rgba(0, 0, 0, 0.06); padding: 1px 8px; border-radius: 6px; }

.pills { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.pill {
  display: flex; flex-direction: column; align-items: center; min-width: 56px; padding: 8px 10px 6px;
  border-radius: 12px; background: var(--paper-ink); color: var(--paper); line-height: 1.1;
  animation: pop 0.4s backwards;
}
.card.flipped .pill:nth-child(2), .detail-card .pill:nth-child(2) { animation-delay: 0.05s; }
.card.flipped .pill:nth-child(3), .detail-card .pill:nth-child(3) { animation-delay: 0.1s; }
.card.flipped .pill:nth-child(4), .detail-card .pill:nth-child(4) { animation-delay: 0.15s; }
.card.flipped .pill:nth-child(5), .detail-card .pill:nth-child(5) { animation-delay: 0.2s; }
.card.flipped .pill:nth-child(6), .detail-card .pill:nth-child(6) { animation-delay: 0.25s; }
.card.flipped .pill:nth-child(7), .detail-card .pill:nth-child(7) { animation-delay: 0.3s; }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(0.9); } }
.pill b { font-family: var(--f-sym), var(--f-music); font-size: 22px; font-weight: 700; }
.pill span { font-size: 11px; font-weight: 600; opacity: 0.65; letter-spacing: 0.04em; margin-top: 2px; font-family: var(--f-ui), var(--f-music); }
.pill.root { background: var(--c, var(--coral)); color: var(--paper-ink); }

.back-foot { display: flex; gap: 16px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.desc { margin: 0; color: var(--paper-muted); font-size: 14px; max-width: 52ch; }
.play-row { display: flex; gap: 8px; }

/* staff / keyboard drawing */
.staff .st-line, .staff .st-ledger { stroke: var(--paper-ink); stroke-width: 1.1; }
.staff .st-ledger { stroke-width: 1.4; }
.staff .st-bar { stroke: var(--paper-ink); stroke-width: 3; }
.staff .clef { font-family: var(--f-music); font-size: 64px; fill: var(--paper-ink); dominant-baseline: alphabetic; }
.staff .nh ellipse:first-child { fill: var(--paper-ink); }
.staff .nh-hole { fill: var(--paper); }
.staff .nh.root ellipse:first-child { fill: var(--coral); }
.staff .acc { fill: var(--paper-ink); stroke: var(--paper-ink); stroke-linecap: butt; }
.staff .st-label { font: 600 11px var(--f-ui), var(--f-music); fill: var(--paper-muted); }

.keyboard .wk { fill: #fffaf0; stroke: #2a2620; stroke-width: 1; }
.keyboard .bk { fill: #1d1b18; stroke: #000; stroke-width: 1; }
.keyboard .wk.hit { fill: var(--gold); }
.keyboard .bk.hit { fill: #d9951a; }
.keyboard .hit.root { fill: var(--coral); }
.keyboard text { text-anchor: middle; font-family: var(--f-ui), var(--f-music); pointer-events: none; }
.keyboard .k-name { font-size: 11px; font-weight: 700; fill: var(--paper-ink); }
.keyboard .k-int { font-size: 9px; font-weight: 600; fill: rgba(28, 26, 22, 0.7); }
.keyboard .k-on-black { fill: #fff; font-size: 8.5px; }
.keyboard .k-int.k-on-black { fill: rgba(255, 255, 255, 0.8); font-size: 7.5px; }
.keyboard .k-c { font-size: 8px; fill: #b2a88f; font-weight: 600; }
.card.flipped .keyboard .hit, .detail-card .keyboard .hit { animation: keypress 0.5s backwards; }
@keyframes keypress { from { fill-opacity: 0; } }

/* ───────── Buttons & controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 14px; padding: 14px 22px; font-weight: 700; font-size: 15px;
  transition: transform 0.12s, background 0.2s, box-shadow 0.2s;
}
.btn:active { transform: translateY(2px); }
.btn.primary { background: var(--gold); color: var(--on-accent); box-shadow: 0 4px 0 #b47d14; }
.btn.primary:hover { background: #f7c04f; }
.btn.primary:active { box-shadow: 0 2px 0 #b47d14; }
.btn.ghost { background: rgba(0, 0, 0, 0.06); color: var(--paper-ink); border: 1px solid rgba(0, 0, 0, 0.1); }
.btn.ghost:hover { background: rgba(0, 0, 0, 0.1); }
.btn.small { padding: 8px 14px; font-size: 13px; border-radius: 10px; }
.btn .i { width: 14px; height: 14px; fill: currentColor; }
.btn.wide { min-width: 280px; }
.btn.miss { background: var(--ink-3); color: var(--text); border: 1px solid var(--line); min-width: 170px; }
.btn.miss:hover { border-color: var(--coral); color: var(--coral); }
.btn.got { background: var(--teal); color: var(--on-accent); min-width: 170px; box-shadow: 0 4px 0 #23807a; }
.btn.got:hover { background: #55c9c0; }

.controls { display: flex; justify-content: center; gap: 12px; margin: 26px auto 0; max-width: 820px; flex-wrap: wrap; }
.choice-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; width: 100%; }
.choice {
  background: var(--ink-2); border: 1px solid var(--line); border-radius: 16px; padding: 14px 12px 12px;
  display: flex; flex-direction: column; align-items: center; gap: 4px; position: relative; min-height: 92px; justify-content: center;
  transition: border-color 0.2s, background 0.2s, transform 0.15s, opacity 0.3s;
}
.choice:hover { border-color: var(--gold); transform: translateY(-2px); }
.choice kbd { position: absolute; top: 9px; left: 9px; margin: 0; font-size: 10px; }
.choice-sym { font-size: 32px; line-height: 1.2; }
.choice-sym.q { font-family: var(--f-sym); font-weight: 700; font-style: italic; font-size: 26px; }
.choice-name { font-size: 12px; color: var(--muted); text-align: center; }
.choices.answered .choice { pointer-events: none; }
.choice.correct { background: color-mix(in srgb, var(--teal) 22%, var(--ink-2)); border-color: var(--teal); }
.choice.correct::after { content: '✓'; position: absolute; top: 8px; right: 12px; color: var(--teal); font-weight: 800; }
.choice.wrong { background: color-mix(in srgb, var(--coral) 22%, var(--ink-2)); border-color: var(--coral); }
.choice.wrong::after { content: '✕'; position: absolute; top: 8px; right: 12px; color: var(--coral); font-weight: 800; }
.choice.dim { opacity: 0.4; }
.next { margin-top: 4px; min-width: 240px; }

/* ───────── Stats */
.stats {
  display: flex; justify-content: center; gap: clamp(16px, 4vw, 44px); margin: 34px auto 0; padding: 18px 24px;
  border-top: 1px solid var(--line); max-width: 820px; flex-wrap: wrap;
}
.stats div { text-align: center; }
.stats dt { font-size: 10.5px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.stats dd { margin: 2px 0 0; font-family: var(--f-display); font-stretch: 70%; font-weight: 800; font-size: 30px; line-height: 1; }
.stats dd small { font-size: 16px; color: var(--muted); }
.stats .pulse dd { animation: bump 0.4s; color: var(--gold-text); }
@keyframes bump { 40% { transform: scale(1.35); } }
.mbar { display: block; width: 90px; height: 4px; background: var(--ink-3); border-radius: 4px; margin: 6px auto 0; overflow: hidden; }
.mbar i { display: block; height: 100%; background: linear-gradient(90deg, var(--teal), var(--gold)); }

/* ───────── Library */
.lib-head { display: flex; gap: 24px; justify-content: space-between; align-items: flex-end; flex-wrap: wrap; margin: 12px 0 28px; }
.lib-title { margin: 0; font-family: var(--f-display); font-stretch: 62%; font-weight: 900; text-transform: uppercase; font-size: clamp(40px, 7vw, 72px); line-height: 0.9; }
.lib-sub { margin: 10px 0 0; color: var(--muted); max-width: 460px; }
.root-picker { display: flex; flex-wrap: wrap; gap: 6px; max-width: 520px; }
.chip {
  border: 1px solid var(--line); background: var(--ink-2); border-radius: 10px; padding: 7px 12px; min-width: 44px;
  font-family: var(--f-sym), var(--f-music); font-weight: 700; font-size: 16px; color: var(--muted);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.chip:hover { color: var(--text); border-color: var(--muted); }
.chip.on { background: var(--text); color: var(--ink); border-color: var(--text); }

.lib-layout { display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 28px; align-items: start; }
.lib-cat { margin-bottom: 28px; }
.lib-cat h3 {
  display: flex; align-items: center; gap: 10px; margin: 0 0 12px; font-family: var(--f-display); font-stretch: 75%;
  font-weight: 800; text-transform: uppercase; font-size: 18px; letter-spacing: 0.03em;
}
.lib-cat h3 i { width: 22px; height: 6px; border-radius: 3px; background: var(--c); }
.lib-cat h3 small { color: var(--muted); font-family: var(--f-ui); font-size: 12px; font-weight: 600; }
.lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.tile {
  text-align: left; background: var(--ink-2); border: 1px solid var(--line); border-radius: 14px;
  padding: 12px 12px 10px; display: flex; flex-direction: column; gap: 2px; position: relative; overflow: hidden;
  transition: border-color 0.2s, transform 0.15s, background 0.2s;
}
.tile::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--c); opacity: 0.8; }
.tile:hover { border-color: var(--c); transform: translateY(-2px); }
.tile.sel { background: var(--paper); color: var(--paper-ink); border-color: var(--paper); }
.tile-sym { font-size: 30px; line-height: 1.25; }
.tile-name { font-size: 11.5px; color: var(--muted); line-height: 1.3; min-height: 2.6em; }
.tile.sel .tile-name { color: var(--paper-muted); }
.meter { height: 3px; background: var(--track); border-radius: 3px; margin-top: 6px; overflow: hidden; }
.tile.sel .meter { background: rgba(0, 0, 0, 0.1); }
.meter i { display: block; height: 100%; background: var(--c); }

.lib-detail { position: sticky; top: 20px; }
.detail-card {
  background: var(--paper); color: var(--paper-ink); border-radius: var(--radius); padding: 26px 26px 22px 34px;
  display: flex; flex-direction: column; gap: 14px; position: relative; overflow: hidden;
  box-shadow: var(--card-shadow);
}
.detail-card::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 10px; background: var(--c); }
.detail-card .tag { align-self: flex-start; }
.detail-sym { font-size: 76px; line-height: 1.05; margin-top: 4px; }
.formula { margin: 0; display: flex; gap: 6px; flex-wrap: wrap; }
.formula span { font: 700 13px var(--f-ui), var(--f-music); border: 1.5px solid var(--paper-ink); border-radius: 6px; padding: 2px 8px; }
.detail-stat { margin: 0; font-size: 12px; color: var(--paper-muted); border-top: 1px dashed rgba(0, 0, 0, 0.15); padding-top: 12px; }

/* ───────── Dialog */
.dialog {
  border: 1px solid var(--line); background: var(--ink-2); color: var(--text); border-radius: 22px; padding: 0;
  width: min(620px, calc(100vw - 32px)); box-shadow: var(--card-shadow);
}
.dialog::backdrop { background: var(--backdrop); backdrop-filter: blur(4px); }
.dialog[open] { animation: enter 0.3s ease-out; }
.dialog-body { padding: 24px; display: flex; flex-direction: column; gap: 24px; }
.dialog-head { display: flex; justify-content: space-between; align-items: center; }
.dialog h2 { margin: 0; font-family: var(--f-display); font-stretch: 70%; font-weight: 900; text-transform: uppercase; font-size: 32px; }
.dialog h3 { margin: 0; font-size: 12px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted); }
.dialog-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.mini-actions { display: flex; gap: 6px; }
.mini-actions button { background: none; border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px; font-size: 12px; color: var(--muted); }
.mini-actions button:hover { color: var(--text); border-color: var(--muted); }
.chip-grid { display: grid; gap: 8px; }
.chip-grid.roots { grid-template-columns: repeat(6, 1fr); }
.chip-grid.cats { grid-template-columns: repeat(2, 1fr); }
.chip.cat { font-family: var(--f-ui); font-size: 14px; font-weight: 600; text-align: left; display: flex; align-items: center; gap: 10px; padding: 11px 14px; }
.chip.cat i { width: 10px; height: 10px; border-radius: 50%; background: var(--c); flex: none; }
.chip.cat small { margin-left: auto; opacity: 0.6; font-size: 12px; }
.chip.cat.on { background: color-mix(in srgb, var(--c) 20%, var(--ink-2)); color: var(--text); border-color: var(--c); }
.dialog-foot { display: flex; justify-content: space-between; align-items: center; border-top: 1px solid var(--line); padding-top: 18px; }
.link-btn { background: none; border: 0; color: var(--muted); font-size: 13px; text-decoration: underline; text-underline-offset: 3px; }
.link-btn:hover { color: var(--coral); }

/* ───────── Footer */
.foot { display: flex; justify-content: center; gap: 22px; flex-wrap: wrap; padding: 20px 16px 28px; color: var(--muted); font-size: 12px; }
.foot kbd { margin: 0 2px; }

/* ───────── Responsive */
@media (max-width: 900px) {
  .lib-layout { grid-template-columns: 1fr; }
  .lib-detail { position: static; order: -1; scroll-margin-top: 16px; }
}
@media (max-width: 700px) {
  .top { flex-wrap: wrap; gap: 12px; padding-top: 16px; }
  .brand-mark { font-size: 32px; }
  .brand-sub { display: none; }
  .seg button { padding: 8px 12px; }
  .seg button small { display: none; }
  .deck-btn small { display: none; }
  .visuals { grid-template-columns: 1fr; gap: 12px; }
  .vis-staff svg { max-height: 170px; }
  .choice-grid { grid-template-columns: repeat(2, 1fr); }
  .btn.wide { min-width: 0; width: 100%; }
  .btn.miss, .btn.got { min-width: 0; flex: 1; }
  .face { min-height: 340px; }
  .front-spell { min-height: 280px; }
  .chip-grid.roots { grid-template-columns: repeat(4, 1fr); }
  .chip-grid.cats { grid-template-columns: 1fr; }
  .foot { display: none; }
  .stats dd { font-size: 24px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ───────── Inversions, scales, progressions */
.sym-slash { font-size: 0.5em; font-weight: 700; margin-left: 0.04em; letter-spacing: -0.01em; }
.sym-slash .sym-acc { font-size: 0.75em; vertical-align: 0.35em; }
.inv-name { margin: 0; font-size: 12px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--paper-muted); }

.scales h4 { margin: 0 0 10px; font-size: 11px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--paper-muted); }
.scales ul { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 8px; }
.scales li {
  display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 12px;
  background: rgba(255, 255, 255, 0.45); border: 1px solid rgba(28, 26, 22, 0.08);
}
.scales li.primary { border-color: var(--c); box-shadow: inset 3px 0 0 var(--c); }
.scales b { display: block; font-size: 13.5px; }
.scales small { display: block; font-size: 11.5px; color: var(--paper-muted); line-height: 1.35; margin-top: 3px; }
.scale-notes { display: flex; flex-wrap: wrap; gap: 3px 7px; margin-top: 3px; font-family: var(--f-sym), var(--f-music); font-weight: 700; font-size: 14px; }
.scale-notes i { font-style: normal; }
.scale-notes i.r { color: var(--coral); }
.scale-play {
  flex: none; width: 30px; height: 30px; border-radius: 50%; border: 0; background: var(--paper-ink); color: var(--paper);
  display: grid; place-items: center; transition: transform 0.15s, background 0.2s;
}
.scale-play:hover { transform: scale(1.1); background: var(--c, var(--coral)); }
.scale-play .i { width: 12px; height: 12px; fill: currentColor; margin-left: 2px; }
.detail-card .scales ul { grid-template-columns: 1fr; }

.inv-switch { display: flex; gap: 4px; background: rgba(0, 0, 0, 0.06); border-radius: 10px; padding: 3px; align-self: flex-start; }
.inv-switch button { border: 0; background: none; padding: 6px 12px; border-radius: 7px; font-size: 12.5px; font-weight: 700; color: var(--paper-muted); }
.inv-switch button.on { background: var(--paper-ink); color: var(--paper); }

.seg-mini { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; background: var(--ink); padding: 4px; border-radius: 12px; border: 1px solid var(--line); }
.seg-mini button { border: 0; background: none; border-radius: 9px; padding: 10px 8px; font-weight: 600; font-size: 13.5px; color: var(--muted); }
.seg-mini button.on { background: var(--text); color: var(--ink); }
.dialog-note { color: var(--muted); font-size: 11.5px; text-align: right; max-width: 60%; }

.card.is-prog { cursor: default; }
.card.is-prog .front { cursor: default; }
.prog { display: flex; flex-direction: column; gap: 22px; }
.prog-head { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; }
.prog-name {
  margin: 10px 0 4px; font-family: var(--f-display); font-stretch: 70%; font-weight: 900; text-transform: uppercase;
  font-size: clamp(30px, 5vw, 46px); line-height: 0.95;
}
.prog-key {
  flex: none; display: flex; flex-direction: column; align-items: center; background: var(--paper-ink); color: var(--paper);
  border-radius: 16px; padding: 10px 18px 8px; box-shadow: 5px 5px 0 var(--gold);
}
.prog-key small { font-size: 10px; letter-spacing: 0.16em; text-transform: uppercase; opacity: 0.7; }
.prog-key b { font-size: 46px; line-height: 1.05; }
.prog-row { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 10px; counter-reset: bar; }
.slot-btn {
  width: 100%; min-height: 150px; border: 2px dashed rgba(28, 26, 22, 0.22); background: rgba(255, 255, 255, 0.35);
  border-radius: 14px; padding: 10px 8px; display: flex; flex-direction: column; align-items: center; gap: 8px; color: var(--paper-ink);
  transition: transform 0.15s, background 0.2s, border-color 0.2s, box-shadow 0.2s; position: relative;
}
.slot-btn:hover { transform: translateY(-2px); border-color: var(--paper-ink); }
.roman { font-family: var(--f-sym); font-size: 26px; line-height: 1; }
.roman b { font-weight: 800; }
.roman sup { font-size: 0.52em; font-weight: 600; font-style: italic; margin-left: 1px; }
.slot-face { display: flex; flex-direction: column; align-items: center; gap: 4px; flex: 1; justify-content: center; }
.slot-q { font-family: var(--f-sym); font-size: 44px; font-weight: 300; opacity: 0.25; }
.slot.open .slot-btn { border-style: solid; border-color: var(--c); background: #fffaf0; box-shadow: inset 0 -5px 0 var(--c); }
.slot.just .slot-face { animation: pop 0.35s; }
.slot-sym { font-size: 30px; line-height: 1.2; }
.slot-notes { font-family: var(--f-sym), var(--f-music); font-weight: 600; font-size: 12.5px; text-align: center; }
.slot-scale { font-size: 10.5px; color: var(--paper-muted); text-align: center; line-height: 1.2; }
.slot.playing .slot-btn { transform: translateY(-6px); box-shadow: 0 10px 20px -8px rgba(0, 0, 0, 0.35), inset 0 -5px 0 var(--c); border-color: var(--c); }
.slot.playing .roman { color: var(--coral); }
.play-row.center { justify-content: center; }
.btn.ghost kbd { opacity: 0.4; }
@media (max-width: 700px) {
  .prog-head { flex-direction: column-reverse; }
  .prog-key { flex-direction: row; gap: 10px; align-self: flex-start; }
  .prog-key b { font-size: 32px; }
  .prog-row { grid-template-columns: repeat(2, 1fr); }
  .seg { flex-wrap: wrap; justify-content: center; }
  .dialog-row { flex-wrap: wrap; gap: 6px; }
  .dialog-note { text-align: left; max-width: none; }
}
.staff .clef8 { font: 700 12px var(--f-sym); fill: var(--paper-ink); text-anchor: middle; }

/* card height follows the visible face */
.card-inner { transition: transform 0.7s cubic-bezier(0.3, 1.25, 0.4, 1), height 0.45s ease; }
.face { align-self: start; }
.face[aria-hidden="true"] { pointer-events: none; }
.front { display: flex; flex-direction: column; justify-content: center; }
.front > * { width: 100%; }
.face[aria-hidden="true"] { max-height: var(--h, none); }
@media (max-width: 700px) {
  .top { flex-wrap: nowrap; gap: 8px; }
  .brand-mark { font-size: 26px; padding: 7px 9px 3px; box-shadow: 4px 4px 0 var(--coral); }
  .tab { padding: 7px 12px; font-size: 13px; }
  .icon-btn { width: 36px; height: 36px; flex: none; }
}

/* ───────── Slash / hybrid / upper-structure chords */
.sym.poly { display: inline-flex; flex-direction: column; align-items: center; vertical-align: middle; line-height: 1; gap: 0.04em; font-size: 0.62em; }
.poly-line { display: block; width: 110%; height: 0.07em; background: currentColor; border-radius: 1em; }
.poly-top, .poly-bot { white-space: nowrap; }
.sym.poly .sym-q { top: -0.55em; font-size: 0.55em; }
.sym.hybrid .sym-slash { font-size: 0.72em; margin-left: 0.02em; }
.equiv { margin: 0; font-size: 13px; font-weight: 600; color: var(--paper-ink); background: color-mix(in srgb, var(--c) 25%, transparent); padding: 3px 10px; border-radius: 8px; }
.detail-card .equiv { align-self: flex-start; }
.pill.up { background: #1d7f78; color: #fff; }
.keyboard .wk.hit.up { fill: #5fd0c6; }
.keyboard .bk.hit.up { fill: #1d9b91; }
.staff .nh.up ellipse:first-child { fill: #13716a; }
.choice-sym .sym.poly { font-size: 0.82em; }
.choice-sym .sym.hybrid .sym-q { font-size: 0.5em; }
.inv-hint {
  margin: 0; max-width: 46ch; text-align: center; font-size: 13px; color: var(--paper-ink);
  background: rgba(242, 177, 52, 0.22); border: 1px dashed rgba(180, 125, 20, 0.5); padding: 6px 12px; border-radius: 10px;
}
.prompt b { color: var(--paper-ink); }

/* ───────── Installable app */
.install-btn {
  display: inline-flex; align-items: center; gap: 6px; height: 40px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--gold-text); background: rgba(242, 177, 52, 0.12); color: var(--gold-text); font-weight: 700; font-size: 13px;
  transition: background 0.2s;
}
.install-btn:hover { background: rgba(242, 177, 52, 0.22); }
.install-btn[hidden] { display: none; }
.install-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.dialog.small { width: min(420px, calc(100vw - 32px)); }
.ios-steps { margin: 0; padding-left: 22px; display: flex; flex-direction: column; gap: 12px; line-height: 1.45; }
.ios-steps b { color: var(--gold-text); }
.share-i { width: 18px; height: 18px; vertical-align: -3px; fill: none; stroke: var(--text); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* full-screen on notched phones: keep content clear of the notch and home bar */
.top { padding-top: max(22px, env(safe-area-inset-top)); padding-left: max(clamp(16px, 4vw, 48px), env(safe-area-inset-left)); padding-right: max(clamp(16px, 4vw, 48px), env(safe-area-inset-right)); }
main { padding-left: max(clamp(16px, 4vw, 48px), env(safe-area-inset-left)); padding-right: max(clamp(16px, 4vw, 48px), env(safe-area-inset-right)); padding-bottom: max(32px, env(safe-area-inset-bottom)); }
@media (display-mode: standalone) { .foot { padding-bottom: max(28px, env(safe-area-inset-bottom)); } }
@media (max-width: 700px) {
  .top { padding-top: max(16px, env(safe-area-inset-top)); }
  .install-btn { padding: 0 10px; height: 36px; }
}

/* ───────── Learn */
.learn-hero { display: flex; justify-content: space-between; align-items: flex-end; gap: 24px; flex-wrap: wrap; margin: 12px 0 28px; }
.learn-root { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; font-weight: 600; }
.learn-root select {
  background: var(--ink-2); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px;
  font: 700 16px var(--f-sym), var(--f-music);
}
.learn-layout { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 32px; align-items: start; }
.learn-toc { position: sticky; top: 20px; display: flex; flex-direction: column; gap: 2px; }
.learn-toc a {
  display: flex; align-items: center; gap: 10px; color: var(--muted); text-decoration: none; font-size: 13.5px; font-weight: 600;
  padding: 7px 10px; border-radius: 8px; transition: background 0.15s, color 0.15s;
}
.learn-toc a:hover { background: var(--ink-2); color: var(--text); }
.learn-toc a i { width: 8px; height: 8px; border-radius: 50%; background: var(--c); flex: none; }
.learn-main { display: flex; flex-direction: column; gap: 28px; min-width: 0; }
.learn-main > * { scroll-margin-top: 20px; }

.basics { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.basic-card, .fam {
  background: var(--paper); color: var(--paper-ink); border-radius: var(--radius); padding: 26px 28px;
  box-shadow: var(--card-shadow); position: relative; overflow: hidden;
}
.basic-card h2, .sec-title {
  margin: 0 0 8px; font-family: var(--f-display); font-stretch: 72%; font-weight: 900; text-transform: uppercase; font-size: 26px; line-height: 1;
}
.sec-title { color: var(--text); margin-bottom: 16px; }
.basic-card p { margin: 0 0 16px; color: #3d382d; font-size: 14.5px; line-height: 1.6; }
.stack-vis { display: grid; gap: 10px; }


.fam::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 10px; background: var(--c); }
.fam { padding-left: 40px; scroll-margin-top: 20px; }
.fam-head { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; margin-bottom: 18px; }
.fam-num { font-family: var(--f-display); font-stretch: 62%; font-weight: 900; font-size: 54px; line-height: 0.8; color: var(--c); -webkit-text-stroke: 1px rgba(0,0,0,.12); }
.fam-head h2 { margin: 0; font-family: var(--f-display); font-stretch: 70%; font-weight: 900; text-transform: uppercase; font-size: clamp(28px, 4vw, 40px); line-height: 0.95; }
.fam-sum { margin: 4px 0 0; color: var(--paper-muted); font-size: 14px; font-style: italic; font-family: var(--f-sym); }
.fam-formula { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; }
.fam-formula span { font: 700 14px var(--f-ui), var(--f-music); border: 2px solid var(--paper-ink); border-radius: 8px; padding: 4px 10px; background: color-mix(in srgb, var(--c) 18%, transparent); }
.fam-body { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 28px; align-items: start; }
.fam-text { margin: 0; }
.fam-text dt { font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; font-weight: 700; color: var(--paper-muted); margin-top: 14px; }
.fam-text dt:first-child { margin-top: 0; }
.fam-text dd { margin: 4px 0 0; font-size: 14.5px; line-height: 1.6; color: #2f2b23; }
.fam-text b { color: var(--paper-ink); }
.fam-ex { display: flex; flex-direction: column; gap: 10px; background: rgba(255, 255, 255, 0.4); border: 1px solid rgba(28, 26, 22, 0.08); border-radius: 16px; padding: 14px; }
.ex-tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.ex-tabs button {
  border: 1.5px solid rgba(28, 26, 22, 0.18); background: transparent; border-radius: 10px; padding: 2px 12px; font-size: 22px; line-height: 1.5; color: var(--paper-ink);
}
.ex-tabs button.on { background: var(--paper-ink); color: var(--paper); border-color: var(--paper-ink); }
.ex-tabs button .sym.poly { font-size: 0.7em; }
.ex-title { font-family: var(--f-display); font-stretch: 78%; font-weight: 800; text-transform: uppercase; font-size: 16px; }
.ex-title .ex-equiv { font-family: var(--f-ui); text-transform: none; font-weight: 600; font-size: 12.5px; color: var(--paper-muted); }
.fam-ex .pills .pill { min-width: 46px; padding: 6px 8px 5px; }
.fam-ex .pill b { font-size: 18px; }
.fam-ex .vis-staff, .fam-ex .vis-keys { background: rgba(255, 255, 255, 0.55); }
.fam-tip { margin: 20px 0 0; padding: 12px 16px; border-radius: 12px; background: color-mix(in srgb, var(--c) 16%, transparent); font-size: 14px; line-height: 1.5; }
.fam-tip b { font-size: 10.5px; letter-spacing: 0.16em; text-transform: uppercase; margin-right: 10px; background: var(--paper-ink); color: var(--paper); padding: 2px 7px; border-radius: 5px; vertical-align: 1px; }
.fam-members { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 18px; padding-top: 16px; border-top: 1px dashed rgba(0, 0, 0, 0.15); }
.fam-members > span { font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; font-weight: 700; color: var(--paper-muted); margin-right: 6px; }
.mchip {
  border: 1px solid rgba(28, 26, 22, 0.16); background: rgba(255, 255, 255, 0.5); border-radius: 9px; padding: 1px 11px; font-size: 23px; line-height: 1.5; color: var(--paper-ink);
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
}
.mchip:hover { border-color: var(--c); background: #fff; transform: translateY(-1px); }
.mchip .sym.poly { font-size: 0.68em; }

.idea-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.idea { background: var(--ink-2); border: 1px solid var(--line); border-radius: 16px; padding: 18px 20px; }
.idea h3 { margin: 0 0 6px; font-family: var(--f-display); font-stretch: 78%; font-weight: 800; text-transform: uppercase; font-size: 17px; color: var(--gold-text); }
.idea p { margin: 0; color: var(--text-2); font-size: 14px; line-height: 1.55; }

.table-wrap { overflow-x: auto; border-radius: 16px; border: 1px solid var(--line); }
.cheat { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 640px; background: var(--ink-2); }
.cheat th { text-align: left; font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); padding: 12px 14px; border-bottom: 1px solid var(--line); }
.cheat td { padding: 10px 14px; border-bottom: 1px solid var(--line); color: var(--text-2); font-family: var(--f-ui), var(--f-music); }
.cheat tr:last-child td { border-bottom: 0; }
.cheat td:first-child { font-weight: 700; color: var(--text); white-space: nowrap; }
.cheat td:first-child i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--c); margin-right: 8px; }
.cheat .mchip { background: var(--paper); }

@media (max-width: 1000px) {
  .learn-layout { grid-template-columns: 1fr; }
  .learn-toc { position: static; flex-direction: row; flex-wrap: wrap; gap: 6px; }
  .learn-toc a { background: var(--ink-2); border: 1px solid var(--line); padding: 6px 10px; font-size: 12.5px; }
  .basics { grid-template-columns: 1fr; }
  .fam-body { grid-template-columns: 1fr; }
  .idea-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 700px) {
  .basic-card { padding: 20px; }
  .fam { padding: 22px 18px 20px 28px; }
  .fam-formula { margin-left: 0; }
  .idea-grid { grid-template-columns: 1fr; }
  .tab { padding: 7px 9px; }
}
@media (max-width: 700px) {
  .top { flex-wrap: wrap; row-gap: 12px; }
  .tabs { order: 3; flex: 1 0 100%; }
  .tab { flex: 1; padding: 8px 10px; font-size: 14px; }
}
.ios-note { margin: 0; font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.ios-note:empty { display: none; }

/* ───────── Compact phone layout: get the whole card on screen */
.lbl-short { display: none; }
@media (max-width: 700px) {
  .lbl-long { display: none; }
  .lbl-short { display: inline; }
  .top { padding-top: max(10px, env(safe-area-inset-top)); padding-bottom: 10px; row-gap: 8px; }
  .brand-mark { font-size: 24px; }
  .tab { padding: 6px 10px; font-size: 13.5px; }
  main { padding-top: 0; }
  .toolbar { flex-wrap: nowrap; gap: 8px; }
  .seg { flex: 1; flex-wrap: nowrap; padding: 4px; gap: 2px; border-radius: 14px; min-width: 0; }
  .seg button { flex: 1; padding: 8px 4px 7px; align-items: center; text-align: center; border-radius: 10px; min-width: 0; }
  .seg button b { font-size: 13.5px; letter-spacing: 0; }
  .deck-btn { flex: none; padding: 0 12px; border-radius: 14px; }
  .deck-btn > span:last-child { display: none; }
  .deck-stack { width: 22px; height: 28px; }
  .mode-hint { display: none; }
  .stage { margin-top: 14px; }
}
/* touchscreens: no keyboard hints */
.touch-only { display: none; }
@media (hover: none) and (pointer: coarse) {
  kbd, .kb-only, .foot { display: none !important; }
  .touch-only { display: inline; }
}

/* ───────── Design polish pass */
/* chord-symbol anatomy: one intact symbol, color-coded parts, aligned legend */
.anatomy { --an0: #e8553d; --an1: #b07a10; --an2: #c23a73; --an3: #1d7f78; display: flex; flex-direction: column; gap: 18px; margin-top: 6px; }
.an-symbol {
  align-self: center; font-family: var(--f-sym), var(--f-music); font-weight: 800; font-size: 92px; line-height: 1;
  font-variation-settings: 'opsz' 144; letter-spacing: -0.02em; padding-top: 6px; white-space: nowrap;
}
.an-p { display: inline-block; border-bottom: 5px solid currentColor; padding-bottom: 4px; }
.an-0 { color: var(--an0); } .an-1 { color: var(--an1); } .an-2 { color: var(--an2); } .an-3 { color: var(--an3); }
.an-sup { display: inline-flex; gap: 0.08em; font-size: 0.48em; font-style: italic; font-weight: 600; vertical-align: top; margin: 0.08em 0.06em 0 0.04em; }
.an-sup .an-p { border-bottom-width: 4px; padding-bottom: 2px; }
.an-bass { font-size: 0.56em; font-weight: 700; margin-left: 0.04em; }
.an-legend { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.an-legend li { display: flex; gap: 10px; align-items: flex-start; background: rgba(255, 255, 255, 0.45); border: 1px solid rgba(28, 26, 22, 0.08); border-radius: 12px; padding: 10px 12px; }
.an-chip {
  flex: none; min-width: 34px; height: 34px; padding: 0 6px; display: grid; place-items: center; border-radius: 9px;
  background: currentColor; font: 800 17px/1 var(--f-sym), var(--f-music);
}
.an-legend li .an-chip { color: inherit; }
.an-legend li.an-0 .an-chip { background: var(--an0); } .an-legend li.an-1 .an-chip { background: var(--an1); }
.an-legend li.an-2 .an-chip { background: var(--an2); } .an-legend li.an-3 .an-chip { background: var(--an3); }
.an-chip { color: #fff !important; }
.an-legend b { display: block; font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; }
.an-legend li.an-0 b { color: var(--an0); } .an-legend li.an-1 b { color: var(--an1); } .an-legend li.an-2 b { color: var(--an2); } .an-legend li.an-3 b { color: var(--an3); }
.an-legend small { display: block; font-size: 12.5px; line-height: 1.4; color: #4a4436; margin-top: 2px; }
@media (max-width: 420px) { .an-symbol { font-size: 76px; } .an-legend { grid-template-columns: 1fr; } }

/* Learn contents: active section; swipeable single row on small screens */
.learn-toc a.active { background: var(--ink-2); color: var(--text); box-shadow: inset 2px 0 0 var(--c, var(--gold)); }
@media (max-width: 1000px) {
  .learn-toc { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 calc(-1 * clamp(16px, 4vw, 48px)); padding: 2px clamp(16px, 4vw, 48px) 6px; scroll-padding-inline: 16px; }
  .learn-toc::-webkit-scrollbar { display: none; }
  .learn-toc a { flex: none; white-space: nowrap; }
  .learn-toc a.active { box-shadow: none; }
}

/* root pickers: even rows */
.root-picker { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 6px; width: min(100%, 600px); max-width: none; }
.root-picker .chip { min-width: 0; padding: 8px 0; }
@media (max-width: 700px) { .root-picker { grid-template-columns: repeat(6, minmax(0, 1fr)); width: 100%; } }

/* desktop mode bar no longer shifts when the Deck label changes */
.deck-btn { min-width: 236px; }
.deck-btn small { white-space: nowrap; }
@media (max-width: 700px) { .deck-btn { min-width: 0; } }

/* symbols with flats/sharps in secondary text: use the music font for the glyphs */
.alts span { font-family: var(--f-sym), var(--f-music); }
.alts span { letter-spacing: 0; }

/* cheat sheet: consistent example chips */
.cheat .mchip { min-width: 84px; text-align: center; }
.an-p, .an-sup .an-p { border-bottom: 0; padding-bottom: 0; }
.an-sup { gap: 0.14em; margin-left: 0.06em; margin-right: 0.1em; }
.basics .basic-card { display: flex; flex-direction: column; }
.basics .anatomy { flex: 1; justify-content: center; }

/* ───────── Desktop / laptop: proper site layout (phones unaffected: everything below is ≥701px) */
.top-actions { display: flex; align-items: center; gap: 12px; }
@media (max-width: 700px) { .top-actions { gap: 8px; } }

@media (min-width: 701px) {
  /* full-width sticky nav bar whose contents line up with the page column */
  .top {
    position: sticky; top: 0; z-index: 50; max-width: none; margin: 0;
    display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 24px;
    padding-top: max(12px, env(safe-area-inset-top)); padding-bottom: 12px;
    padding-left: calc(max(0px, (100% - 1280px) / 2) + clamp(16px, 4vw, 48px));
    padding-right: calc(max(0px, (100% - 1280px) / 2) + clamp(16px, 4vw, 48px));
    background: var(--nav-bg);
    -webkit-backdrop-filter: saturate(150%) blur(14px); backdrop-filter: saturate(150%) blur(14px);
    border-bottom: 1px solid var(--line);
  }
  .brand { margin-right: 0; justify-self: start; }
  .brand-mark { font-size: 30px; padding: 6px 10px 3px; box-shadow: 4px 4px 0 var(--coral); }
  .tabs { background: none; border: 0; padding: 0; gap: 2px; border-radius: 0; }
  .tab { position: relative; border-radius: 10px; padding: 9px 16px; font-size: 14.5px; color: var(--muted); }
  .tab:hover { background: var(--hover); }
  .tab.active { background: none; color: var(--text); }
  .tab.active::after { content: ''; position: absolute; left: 16px; right: 16px; bottom: 1px; height: 2px; border-radius: 2px; background: var(--gold); }
  .top-actions { justify-self: end; }
  main { padding-top: 32px; }

  /* sticky things sit below the nav bar now */
  .learn-main > *, .fam, .lib-detail { scroll-margin-top: 92px; }
}
@media (min-width: 1001px) { .learn-toc { top: 92px; } }
@media (min-width: 901px) { .lib-detail { top: 92px; } }

/* wide screens: three-column Practice: modes | card | progress */
@media (min-width: 1240px) {
  #view-practice:not([hidden]) {
    display: grid; grid-template-columns: 224px minmax(0, 1fr) 216px; column-gap: 32px; align-items: start;
    grid-template-areas: "tool stage stats" "hint stage stats" ". stage stats" ". controls stats";
    grid-template-rows: auto auto 1fr auto;
  }
  .toolbar { grid-area: tool; flex-direction: column; align-items: stretch; justify-content: flex-start; gap: 12px; }
  .seg { flex-direction: column; padding: 6px; gap: 2px; }
  .seg button { padding: 11px 14px; }
  .seg button.active { box-shadow: inset 3px 0 0 var(--gold); }
  .deck-btn { min-width: 0; width: 100%; padding: 12px 14px; }
  .mode-hint { grid-area: hint; text-align: left; margin: 14px 4px 0; max-width: none; min-height: 0; font-size: 13px; line-height: 1.55; }
  .stage { grid-area: stage; }
  .card { max-width: none; }
  #controls { grid-area: controls; width: 100%; max-width: none; margin-top: 24px; }

  .stats {
    grid-area: stats; display: grid; grid-template-columns: 1fr 1fr; gap: 18px 12px; margin: 0; padding: 20px;
    max-width: none; border: 1px solid var(--line); border-radius: 18px; background: var(--ink-2);
  }
  .stats::before { content: 'Your progress'; grid-column: 1 / -1; font-size: 11px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
  .stats div { text-align: left; }
  .stats .mastery { grid-column: 1 / -1; border-top: 1px solid var(--line); padding-top: 16px; }
  .mbar { width: 100%; margin: 10px 0 0; }
}
@media (min-width: 1240px) {
  #view-practice:not([hidden]) {
    grid-template-areas: "tool stage stats" "tool stage hint" ". controls .";
    grid-template-rows: auto 1fr auto;
  }
  .mode-hint {
    margin: 14px 0 0; padding: 16px 18px; border: 1px solid var(--line); border-radius: 18px; background: var(--hover);
    color: var(--text-2); font-size: 13px;
  }
  .mode-hint::before { content: 'How it works'; display: block; margin-bottom: 6px; font-size: 11px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
}
@media (min-width: 1240px) {
  /* explicit placement: side panels may run alongside the answer row, so they never push it down */
  #view-practice:not([hidden]) { grid-template-areas: none; grid-template-rows: auto auto auto; }
  .toolbar { grid-area: auto; grid-column: 1; grid-row: 1 / 3; }
  .stage { grid-area: auto; grid-column: 2; grid-row: 1 / 3; }
  #controls { grid-area: auto; grid-column: 2; grid-row: 3; }
  .stats { grid-area: auto; grid-column: 3; grid-row: 1; }
  .mode-hint { grid-area: auto; grid-column: 3; grid-row: 2 / 4; align-self: start; }
}

/* ───────── Light theme refinements */
:root[data-theme="light"] body {
  background:
    radial-gradient(1200px 600px at 85% -10%, rgba(232, 85, 61, 0.1), transparent 60%),
    radial-gradient(900px 600px at -10% 30%, rgba(63, 184, 175, 0.08), transparent 60%),
    radial-gradient(800px 500px at 50% 120%, rgba(242, 177, 52, 0.1), transparent 60%),
    var(--ink);
}
:root[data-theme="light"] .grain { opacity: 0.05; mix-blend-mode: multiply; }
:root[data-theme="light"] .tile.sel { background: var(--paper); border-color: var(--c); box-shadow: 0 0 0 2px var(--c); }
:root[data-theme="light"] .tile:not(.sel) { background: var(--ink-2); }
:root[data-theme="light"] .btn.miss { background: var(--ink-2); }
:root[data-theme="light"] .icon-btn.muted { color: var(--muted); }
:root[data-theme="light"] .install-btn { background: rgba(242, 177, 52, 0.18); }
:root[data-theme="light"] .cheat .mchip { border-color: var(--line); }
:root[data-theme="light"] .face, :root[data-theme="light"] .detail-card, :root[data-theme="light"] .basic-card, :root[data-theme="light"] .fam { border: 1px solid rgba(28, 26, 22, 0.08); }

/* theme toggle icon: show the moon in light mode (switch to dark), the sun in dark mode */
#theme-btn .sun { display: block; } #theme-btn .moon { display: none; }
:root[data-theme="light"] #theme-btn .sun { display: none; } :root[data-theme="light"] #theme-btn .moon { display: block; }
#theme-btn svg path, #theme-btn svg circle { fill: none; }
:root, body, .face, .tile, .chip, .seg, .tabs, .icon-btn, .deck-btn, .choice, .stats, .mode-hint, .idea, .cheat { transition: background-color 0.25s, border-color 0.25s, color 0.25s; }

/* wide screens: side columns match the card's height exactly */
@media (min-width: 1240px) {
  #view-practice:not([hidden]) { grid-template-rows: auto 1fr auto; row-gap: 0; }
  .toolbar { grid-row: 1 / 3; align-self: stretch; display: flex; }
  .toolbar .deck-btn { margin-top: auto; }
  .stage { grid-row: 1 / 3; align-self: start; }
  .stats { grid-row: 1; align-self: start; }
  .mode-hint { grid-row: 2; align-self: stretch; margin-top: 14px; }
  #controls { grid-row: 3; }
  .face { min-height: 480px; }
  .front-spell { min-height: 400px; }
}

/* ───────── Vocabulary tooltips (mouse devices only; the script doesn't run on touch) */
.term {
  text-decoration: underline dotted; text-decoration-thickness: 1.5px; text-underline-offset: 3px;
  text-decoration-color: color-mix(in srgb, currentColor 45%, transparent); cursor: help;
}
.term:hover { text-decoration-color: var(--gold); }
.gl-tip {
  position: fixed; z-index: 200; max-width: 300px; padding: 11px 14px; border-radius: 12px; pointer-events: none;
  background: #1c1a16; color: #f5ecd9; font: 13px/1.5 var(--f-ui), var(--f-music);
  box-shadow: 0 14px 36px -10px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255, 255, 255, 0.06);
  opacity: 0; transform: translateY(4px); transition: opacity 0.12s, transform 0.12s;
}
.gl-tip.on { opacity: 1; transform: none; }
.gl-tip b { display: block; margin-bottom: 3px; font-family: var(--f-display); font-stretch: 80%; font-weight: 800; text-transform: uppercase; letter-spacing: 0.04em; font-size: 12.5px; color: var(--gold); }

/* Library: the sticky detail panel scrolls on its own when it's taller than the screen */
@media (min-width: 901px) {
  .lib-detail {
    max-height: calc(100vh - 92px - 20px); overflow-y: auto;
    border-radius: var(--radius); scrollbar-width: thin; scrollbar-color: color-mix(in srgb, var(--paper-ink) 25%, transparent) transparent;
  }
  .lib-detail::-webkit-scrollbar { width: 8px; }
  .lib-detail::-webkit-scrollbar-thumb { background: rgba(28, 26, 22, 0.22); border-radius: 8px; border: 2px solid transparent; background-clip: padding-box; }
  .lib-detail .detail-card { box-shadow: none; }
}
@media (min-width: 1240px) { .mode-hint { background: var(--ink-2); } }
/* interval labels on the staff: a paper-colored halo so staff lines don't strike through them */
.staff .st-label { paint-order: stroke; stroke: #fbf6ea; stroke-width: 4px; stroke-linejoin: round; }

/* ───────── Wide-screen left column: one unified panel (modes → deck → shortcuts) */
.deck-fams, .deck-edit, .rail-keys { display: none; }
@media (min-width: 1240px) {
  .toolbar {
    gap: 0; padding: 8px; background: var(--ink-2); border: 1px solid var(--line); border-radius: 18px;
  }
  .toolbar .seg { background: none; border: 0; padding: 0; border-radius: 0; }
  .toolbar .deck-btn {
    margin: 8px 0 0; padding: 14px 12px; width: 100%; min-width: 0; background: none; border: 0; border-radius: 12px;
    position: relative; align-items: flex-start;
  }
  .toolbar .deck-btn::before { content: ''; position: absolute; left: 6px; right: 6px; top: -4px; height: 1px; background: var(--line); }
  .toolbar .deck-btn:hover { background: var(--hover); }
  .deck-text { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
  .deck-fams { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 7px; }
  .deck-fams i { width: 9px; height: 9px; border-radius: 50%; }
  .deck-edit { display: block; font-size: 12px; font-weight: 700; color: var(--gold-text); align-self: center; }
  .deck-edit::after { content: ' ›'; }
  .deck-stack { margin-top: 2px; }

  .rail-keys {
    display: grid; grid-template-columns: 1fr; gap: 7px; margin: auto 0 0; padding: 14px 12px 8px; position: relative;
    font-size: 12.5px; color: var(--muted);
  }
  .rail-keys::before { content: ''; position: absolute; left: 6px; right: 6px; top: 0; height: 1px; background: var(--line); }
  .rail-keys dt { font-size: 11px; letter-spacing: 0.16em; text-transform: uppercase; font-weight: 700; margin-bottom: 2px; }
  .rail-keys dd { margin: 0; display: flex; align-items: center; gap: 2px; }
  .rail-keys dd kbd { margin: 0; opacity: 0.8; }
  .rail-keys dd span { margin-left: auto; }
  /* the shortcuts live in the panel now, so the footer doesn't repeat them on Practice */
  body[data-view="practice"] .foot { display: none; }
}

/* Installed iPhone app: iOS blurs the strip under the status bar (and a little below it),
   so give the header extra room there. Browser tabs are unaffected. */
/* Installed iPhone app: the status bar is solid black (not see-through), so content starts
   below it and iOS has nothing to blur. Keep a little breathing room above the logo. */
@media (display-mode: standalone) and (max-width: 700px) {
  .top { padding-top: max(14px, env(safe-area-inset-top)); }
}
@media (min-width: 1240px) {
  .toolbar .seg button { padding: 9px 14px; }
  .toolbar .deck-btn { display: grid; grid-template-columns: auto 1fr auto; column-gap: 12px; align-items: start; padding: 12px; }
  .deck-edit { align-self: start; margin-top: 1px; }
  .deck-fams { flex-wrap: nowrap; gap: 4px; }
  .deck-fams i { width: 8px; height: 8px; flex: none; }
  .rail-keys { grid-template-columns: 1fr 1fr; gap: 8px 10px; padding: 12px 12px 6px; }
  .rail-keys dt { grid-column: 1 / -1; }
  .rail-keys dd { gap: 6px; font-size: 12px; }
  .rail-keys dd span { margin-left: 0; }
}
@media (min-width: 1240px) { .rail-keys dd { white-space: nowrap; } .face { min-height: 490px; } }

/* Keep the layout from shifting between pages: always reserve the scrollbar's space, so short
   pages (Practice) and long ones (Learn, Library) have the same width. Phones use overlay
   scrollbars, so this changes nothing there. */
html { scrollbar-gutter: stable; }
@supports not (scrollbar-gutter: stable) { html { overflow-y: scroll; } }

/* ───────── Deck popup: fits without scrolling */
.dialog { max-height: calc(100dvh - 24px); }
.dialog-body { gap: 20px; padding: 22px 24px; }
.dialog-head h2 { font-size: 30px; }
.dialog-row { margin-bottom: 10px; }
.dialog-note b { color: var(--text); font-family: var(--f-sym), var(--f-music); }
.chip.cat { padding: 10px 12px; font-size: 13.5px; }
.seg-mini button { padding: 9px 8px; }
.dialog-foot { padding-top: 16px; }
@media (min-width: 701px) {
  .dialog { width: min(780px, calc(100vw - 48px)); }
  .chip-grid.roots { grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 6px; }
  .chip-grid.roots .chip { min-width: 0; padding: 8px 0; }
  .chip-grid.cats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 700px) {
  .dialog-body { gap: 16px; padding: 18px 16px; }
  .dialog-head h2 { font-size: 26px; }
  .chip-grid.roots .chip { padding: 6px 0; min-width: 0; font-size: 15px; }
  .chip-grid.cats { grid-template-columns: 1fr 1fr; gap: 6px; }
  .chip.cat { padding: 8px 9px; gap: 7px; font-size: 12.5px; line-height: 1.25; }
  .chip.cat small { font-size: 11px; }
  .seg-mini button { font-size: 12.5px; padding: 8px 4px; }
  .dialog-note { font-size: 11px; }
}
@media (max-width: 700px) {
  .chip-grid.roots { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; }
  .chip.cat { white-space: nowrap; min-width: 0; }
  .chip.cat small { display: none; }
  .seg-mini button { white-space: nowrap; font-size: 12px; padding: 8px 2px; }
  .dialog-row { margin-bottom: 8px; }
  .dialog-foot { padding-top: 12px; }
  .dialog-foot .btn { padding: 12px 18px; }
}
@media (max-width: 700px) {
  .chip-grid.cats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .chip.cat { padding: 8px 8px; gap: 6px; }
  .chip.cat span { overflow: hidden; text-overflow: ellipsis; }
  .chip-grid.roots .chip { padding: 5px 0; }
  .dialog-body { gap: 14px; }
}
@media (max-width: 700px) and (max-height: 620px) { .dialog-note { display: none; } }
@media (max-width: 360px) { .chip.cat { font-size: 12px; padding: 8px 6px; gap: 5px; } }

/* ───────── Polish round: nav links, symbols, laptop practice block */
.tab, .brand { text-decoration: none; }
.tab-ico { display: none; }
/* flats/sharps inside chord symbols: use the music font so they sit tight */
.sym, .choice-sym, .slot-sym, .tile-sym { font-family: var(--f-sym), var(--f-music); }

@media (min-width: 1240px) {
  /* side columns run down to the bottom of the answer row: one clean block */
  .toolbar { grid-row: 1 / 4; }
  .stats { grid-row: 1; }
  .mode-hint { grid-row: 2 / 4; }
  .stage { grid-row: 1 / 3; }
  #controls { grid-row: 3; align-self: end; margin-top: 20px; }
  .face { min-height: 440px; }
  .front-spell { min-height: 360px; }
  /* the answer row spans the card's full width */
  #controls .btn.wide, #controls .next { width: 100%; min-width: 0; }
  #controls .btn.miss, #controls .btn.got { flex: 1; min-width: 0; }
  .toolbar .deck-btn small { white-space: normal; }
}

/* ───────── Phone: native-app layout (slim centered top bar + bottom tab bar) */
:root { --bar-bg: rgba(14, 17, 24, 0.94); }
:root[data-theme="light"] { --bar-bg: rgba(240, 234, 222, 0.94); }
@media (max-width: 700px) {
  .top {
    position: sticky; top: 0; z-index: 50;
    display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px;
    padding: max(10px, env(safe-area-inset-top)) 16px 10px;
    background: var(--bar-bg); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--line);
  }
  .brand { grid-column: 2; margin: 0; justify-self: center; }
  .brand-mark { font-size: 22px; padding: 6px 9px 3px; box-shadow: 3px 3px 0 var(--coral); }
  .top-actions { grid-column: 3; justify-self: end; gap: 6px; }
  .top .icon-btn { width: 34px; height: 34px; }
  .install-btn { position: absolute; left: 16px; bottom: 10px; height: 34px; padding: 0 10px; }

  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 60; order: 0; flex: none;
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 0;
    padding: 6px 10px max(8px, env(safe-area-inset-bottom));
    border: 0; border-top: 1px solid var(--line); border-radius: 0;
    background: var(--bar-bg); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  }
  .tab {
    display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 5px 0 3px; flex: none;
    font-size: 11px; font-weight: 600; letter-spacing: 0.01em; color: var(--muted); border-radius: 10px;
  }
  .tab.active, .tab:hover { background: none; color: var(--gold-text); }
  .tab-ico { display: block; width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
  .tab.active .tab-ico { stroke-width: 2.1; }

  main { padding-top: 14px; padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
}
@media (display-mode: standalone) and (max-width: 700px) {
  .top { padding-top: calc(env(safe-area-inset-top) + 8px); }
}
@media (min-width: 701px) and (max-height: 780px) { .vinyl { width: 190px; } }
@media (max-width: 700px) {
  /* a backdrop blur on the header would trap the fixed tab bar inside it, so the top bar is solid */
  .top { -webkit-backdrop-filter: none; backdrop-filter: none; background: var(--ink); }
  .deck-btn .deck-text, .deck-btn .deck-edit { display: none; }
}
/* short phones: keep the main button clear of the bottom tab bar */
@media (max-width: 700px) and (max-height: 640px) {
  .face { min-height: 270px; }
  .front-spell { min-height: 220px; }
  .big-sym { font-size: clamp(64px, 18vw, 110px); }
  main { padding-top: 10px; }
}

/* laptops: fixed-height card; the back scrolls inside instead of stretching the page */
@media (min-width: 1240px) {
  .card.fixed-h .face { height: var(--h); min-height: 0; overflow-y: auto; scrollbar-width: thin; scrollbar-color: rgba(28, 26, 22, 0.25) transparent; }
  .card.fixed-h .front { justify-content: center; }
  .card.fixed-h .front-spell { min-height: 0; }
  /* the colored spine as an inset shadow so it stays put while the back scrolls */
  .card.fixed-h .face::before { display: none; }
  .card.fixed-h .front { box-shadow: inset 12px 0 0 var(--front-c, var(--gold)), 0 1px 0 rgba(255, 255, 255, 0.6) inset, var(--card-shadow); }
  .card.fixed-h .back { box-shadow: inset 12px 0 0 var(--c), 0 1px 0 rgba(255, 255, 255, 0.6) inset, var(--card-shadow); }
}
@media (min-width: 1240px) {
  #controls { min-height: 60px; align-content: start; }
  #controls .btn { height: 56px; }
}
@media (min-width: 1240px) {
  /* Name it / Hear it: "Next card" joins the choices row, so answering doesn't change its height */
  #controls.choices { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; align-items: stretch; }
  #controls.choices.answered { grid-template-columns: minmax(0, 1fr) auto; }
  #controls.choices .choice-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  #controls.choices .next { margin: 0; height: auto; min-width: 0; width: auto; padding: 0 20px; flex-direction: column; gap: 4px; }
  #controls.choices .next kbd { margin: 0; }
  #controls .btn.miss, #controls .btn.got { flex: 1 1 0; }
  #controls:not(.choices) { flex-wrap: nowrap; }
}
/* deck summary: two clean lines instead of a mid-phrase wrap */
.deck-btn small span { display: block; white-space: nowrap; }
.deck-inv { opacity: 0.85; }
@media (max-width: 1239px) { .deck-btn small span { display: inline; } .deck-btn small .deck-inv::before { content: ' · '; } }
@media (min-width: 1240px) {
  /* Hear it: one-line names keep the answer row a constant height */
  #controls .choice { min-height: 96px; }
  #controls .choice-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  /* soft fade at the bottom of the card back when there's more to scroll */
  .card.fixed-h .back.has-more { -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 44px), transparent); mask-image: linear-gradient(to bottom, #000 calc(100% - 44px), transparent); }
}

/* ───────── Evenness pass: no ragged mixed-style rows, no stranded words, single-line labels */
h1, h2, h3, .prog-name, .lib-title { text-wrap: balance; }
p, dd, .desc, small { text-wrap: pretty; }
.btn, .chip, .tag, kbd, th, .tab span, .mini-actions button, .link-btn, .seg button b, .seg button small, .deck-btn b, .equiv, .inv-name { white-space: nowrap; }

/* card back: symbol + title stay side by side on wide cards; description above the play buttons */
@media (min-width: 701px) {
  .back-head { flex-wrap: nowrap; gap: 20px; }
  .back-sym { flex: none; }
  .back-title { min-width: 0; }
  .back-title h2 { font-size: clamp(18px, 2vw, 24px); }
}
.back-foot { flex-direction: column; align-items: flex-start; gap: 12px; }
.back-foot .desc { max-width: none; }

/* Learn tip: badge in its own column, text wraps cleanly beside it */
.fam-tip { display: flex; gap: 12px; align-items: baseline; }
.fam-tip b { flex: none; margin: 0; }
.fam-tip p { margin: 0; }

/* Learn example title: the "≈ equivalent" sits on its own line */
.ex-title .ex-equiv { display: block; margin: 2px 0 0; }

/* deck summary inside the laptop panel wraps as whole phrases */
.deck-btn small span { white-space: normal; }

/* phone polish */
@media (max-width: 360px) { .seg button b { font-size: 12px; } .seg button { padding: 8px 2px 7px; } }
@media (max-width: 700px) {
  .dialog-row { flex-wrap: nowrap; gap: 8px; }
  .mini-actions { gap: 4px; }
  .mini-actions button { padding: 4px 9px; font-size: 11.5px; }
  .dialog-row:has(.dialog-note) { flex-wrap: wrap; }
}
/* tablet header: drop the subtitle where it can't fit on one line */
@media (min-width: 701px) and (max-width: 1100px) { .brand-sub { display: none; } }
/* deck button on laptops: "Edit ›" floats top-right so the summary gets the full width */
@media (min-width: 1240px) {
  .toolbar .deck-btn { grid-template-columns: auto 1fr; }
  .toolbar .deck-edit { position: absolute; top: 14px; right: 12px; }
  .deck-btn small span:first-child { white-space: nowrap; }
}
/* tiny phones: the Deck popup footer buttons fit side by side */
@media (max-width: 360px) {
  .dialog-foot .btn { padding: 11px 14px; font-size: 14px; }
  .dialog-foot .link-btn { font-size: 12px; }
}
@media (max-width: 420px) {
  .detail-card { padding: 22px 16px 18px 26px; }
  .inv-switch { align-self: stretch; }
  .inv-switch button { flex: 1; padding: 6px 4px; }
  .scales ul { grid-template-columns: 1fr; }
}
/* paired with theme.js: invisible until fonts load (never more than ~1s), then a quick fade */
html.fonts-loading body { opacity: 0; }
body { transition: opacity 0.18s ease-out; }
/* inverted Spell cards: a quiet reference for reading slash chords */
.inv-key { margin: 6px 0 0; display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 14px; font-size: 12.5px; color: var(--paper-muted); }
.inv-key span { white-space: nowrap; }
.inv-key b { color: var(--paper-ink); }
/* card back: the inversion answer as a clear badge */
.inv-name.is-inv { display: inline-block; align-self: flex-start; color: var(--paper-ink); background: color-mix(in srgb, var(--c) 22%, transparent); padding: 3px 9px; border-radius: 7px; letter-spacing: 0.05em; }

/* ───────── Library redesign */
.lib-head { margin-bottom: 18px; align-items: flex-end; }
.lib-toolbar {
  display: flex; flex-direction: column; gap: 10px; margin-bottom: 28px; padding: 14px 16px;
  background: var(--ink-2); border: 1px solid var(--line); border-radius: 18px;
}
.lib-tool { display: grid; grid-template-columns: 64px minmax(0, 1fr); align-items: center; gap: 12px; }
.lib-tool-label { font-size: 11px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.lib-toolbar .root-picker { width: 100%; max-width: 640px; }
.lib-fams { display: flex; gap: 6px; flex-wrap: wrap; }
.fam-chip {
  display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; border: 1px solid var(--line); background: transparent;
  color: var(--muted); border-radius: 999px; padding: 6px 12px; font-size: 13px; font-weight: 600; transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.fam-chip i { width: 8px; height: 8px; border-radius: 50%; background: var(--c); flex: none; }
.fam-chip:hover { color: var(--text); border-color: var(--muted); }
.fam-chip.on { background: var(--text); color: var(--ink); border-color: var(--text); }
.fam-chip .lbl-short { display: none; }

.lib-cat { margin-bottom: 30px; }
.lib-cat h3 { margin-bottom: 14px; }
.lib-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.tile {
  padding: 14px 14px 12px; gap: 4px; border-radius: 14px; background: var(--ink-2); border: 1px solid var(--line);
}
.tile::before { display: none; }
.tile:hover { border-color: color-mix(in srgb, var(--c) 70%, transparent); transform: translateY(-2px); }
.tile-sym { font-size: 32px; line-height: 1.15; }
.tile-sym .sym-q { font-size: 0.56em; }
.tile-name { min-height: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 12px; }
.tile .meter { margin-top: 8px; height: 3px; }
.tile .meter.none { visibility: hidden; }
.tile.sel { background: color-mix(in srgb, var(--c) 16%, var(--ink-2)); border-color: var(--c); color: var(--text); box-shadow: 0 0 0 1px var(--c) inset; }
.tile.sel .tile-name { color: var(--text-2); }
:root[data-theme="light"] .tile.sel { background: color-mix(in srgb, var(--c) 14%, var(--paper)); box-shadow: 0 0 0 1px var(--c) inset; }

.sheet-close { display: none; }
.lib-backdrop { display: none; }

/* phones/tablets: chord detail is a bottom sheet over the list */
@media (max-width: 900px) {
  .lib-tool { grid-template-columns: 1fr; gap: 8px; }
  .lib-fams { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px 2px; }
  .lib-fams::-webkit-scrollbar { display: none; }
  .lib-toolbar { padding: 12px 14px; }
  .lib-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }

  .lib-detail {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 75; order: initial; max-height: 86vh; overflow-y: auto; overscroll-behavior: contain;
    border-radius: 22px 22px 0 0; transform: translateY(105%); transition: transform 0.32s cubic-bezier(0.2, 0.9, 0.3, 1); visibility: hidden;
  }
  .lib-detail.open { transform: none; visibility: visible; }
  .lib-detail .detail-card { border-radius: 22px 22px 0 0; padding: 26px 18px calc(22px + env(safe-area-inset-bottom)) 26px; box-shadow: 0 -20px 50px rgba(0, 0, 0, 0.45); }
  .lib-detail .detail-card::after { content: ''; position: absolute; top: 9px; left: 50%; width: 40px; height: 4px; margin-left: -20px; border-radius: 4px; background: rgba(28, 26, 22, 0.2); }
  .sheet-close {
    display: grid; place-items: center; position: absolute; top: 14px; right: 14px; width: 32px; height: 32px; border-radius: 50%;
    border: 0; background: rgba(28, 26, 22, 0.08); color: var(--paper-ink); font-size: 14px; z-index: 2;
  }
  .lib-backdrop { display: block; position: fixed; inset: 0; z-index: 74; background: var(--backdrop); opacity: 0; transition: opacity 0.25s; }
  .lib-backdrop.on { opacity: 1; }
  body.sheet-open { overflow: hidden; }
}
@media (max-width: 700px) {
  .fam-chip .lbl-long { display: none; }
  .fam-chip .lbl-short { display: inline; }
  .lib-sub { font-size: 14px; }
}
.lib-backdrop[hidden] { display: none !important; }
.fam-chip .lbl-long { display: none; }
.fam-chip .lbl-short { display: inline; }
.lib-fams { flex-wrap: nowrap; }
@media (max-width: 900px) { .lib-detail { top: auto; } }
.tile-name {
  white-space: normal; overflow: hidden; text-overflow: clip; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2;
  line-height: 1.35; min-height: 2.7em;
}

/* Phone top bar: logo left-aligned with the page content; actions (Install, theme, sound) on the right */
@media (max-width: 700px) {
  .top { grid-template-columns: auto 1fr; }
  .brand { grid-column: 1; justify-self: start; }
  .top-actions { grid-column: 2; justify-self: end; }
  .install-btn { position: static; height: 34px; padding: 0 11px; }
}
@media (max-width: 360px) { .install-btn span { display: none; } .install-btn { padding: 0 9px; } }

/* ───────── No sideways scrolling on phones: dropdowns instead of swipe rows; cheat sheet as cards */
.toc-select-wrap, .fam-select { display: none; }
.toc-select, .fam-select {
  -webkit-appearance: none; appearance: none; font: 600 15px var(--f-ui); color: var(--text);
  background: var(--ink-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%23a39b8a' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 14px center;
  border: 1px solid var(--line); border-radius: 12px; padding: 11px 40px 11px 14px; width: 100%;
}
@media (min-width: 701px) and (max-width: 1000px) {
  .learn-toc { flex-wrap: wrap; overflow: visible; margin: 0; padding: 0; }
}
@media (min-width: 701px) and (max-width: 900px) {
  .lib-fams { flex-wrap: wrap; overflow: visible; margin: 0; padding: 0; }
}
@media (max-width: 700px) {
  .learn-toc { display: none; }
  .toc-select-wrap { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 10px; position: sticky; top: var(--top-h, 55px); z-index: 5; padding: 8px 0; background: var(--ink); }
  .toc-select-wrap > span { font-size: 11px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
  .lib-fams { display: none; }
  .fam-select { display: block; }

  /* cheat sheet: one card per family */
  .table-wrap { overflow: visible; border: 0; border-radius: 0; }
  .cheat { min-width: 0; background: none; display: block; }
  .cheat thead { display: none; }
  .cheat tbody { display: grid; gap: 10px; }
  .cheat tr { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; padding: 14px 16px; background: var(--ink-2); border: 1px solid var(--line); border-radius: 16px; }
  .cheat td { display: block; padding: 0; border: 0; }
  .cheat td.c-fam { grid-column: 1 / -1; font-size: 15px; }
  .cheat td[data-label]::before { content: attr(data-label); display: block; font: 700 10px var(--f-ui); letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); margin-bottom: 2px; }
}
:root[data-theme="light"] .toc-select-wrap { background: var(--ink); }
/* phones: section jumps stop just below the top bar + sticky "Jump to" bar */
@media (max-width: 700px) { .learn-main > *, .fam { scroll-margin-top: calc(var(--top-h, 55px) + 72px); } }

/* ───────── Prominent playback: the main play button is a solid, colored button everywhere */
.btn.play-main, .btn.play-alt { padding: 11px 18px; font-size: 14.5px; border-radius: 12px; gap: 9px; }
.btn.play-main {
  background: var(--coral); color: #fff; box-shadow: 0 3px 0 #b23a26, 0 8px 18px -8px rgba(232, 85, 61, 0.6);
}
.btn.play-main:hover { background: #f06a52; }
.btn.play-main:active { box-shadow: 0 1px 0 #b23a26; }
.btn.play-main .i { width: 15px; height: 15px; }
.btn.play-main kbd { border-color: rgba(255, 255, 255, 0.6); opacity: 0.8; }
.btn.play-alt { background: transparent; color: var(--paper-ink); border: 1.5px solid rgba(28, 26, 22, 0.25); }
.btn.play-alt:hover { border-color: var(--paper-ink); background: rgba(28, 26, 22, 0.05); }
/* a gentle pulse draws the eye to the play button the first time each card appears */
@keyframes play-hint { 0%, 100% { box-shadow: 0 3px 0 #b23a26, 0 0 0 0 rgba(232, 85, 61, 0.45); } 50% { box-shadow: 0 3px 0 #b23a26, 0 0 0 8px rgba(232, 85, 61, 0); } }
.card.enter .front .btn.play-main, .card.enter .front-hear .btn.play-main { animation: play-hint 1.6s ease-out 0.5s 2; }
@media (prefers-reduced-motion: reduce) { .btn.play-main { animation: none !important; } }
.foot-links a { color: var(--muted); text-decoration: none; }
.foot-links a:hover { color: var(--text); text-decoration: underline; }
/* Roman numerals are case-sensitive (vi = minor, VI = major), so progression titles keep their case */
.prog-name { text-transform: none; letter-spacing: -0.01em; }
