/* ===========================================================================
   Theme tokens. The PAGE CHROME switches light/dark; the INSTRUMENT (plate,
   comb, note keys) stays bright in both themes so the transparent PNG export
   keeps matching the on-screen harp.
   =========================================================================== */
:root {
  color-scheme: dark;

  /* Warm "blues club" backdrop the instrument is lit against. */
  --bg-0: #14100b;
  --bg-1: #1e1710;
  --glow: rgba(232, 156, 62, 0.20);
  --backdrop:
    radial-gradient(115% 75% at 50% -8%, var(--glow), transparent 55%),
    radial-gradient(80% 55% at 50% 4%, rgba(200, 120, 40, 0.10), transparent 60%),
    linear-gradient(180deg, var(--bg-1), var(--bg-0) 62%);
  --grain-opacity: 0.05;
  --grain-blend: overlay;

  --ink: #f4ecdd;
  --muted: #ab9c85;
  --faint: #7c6f5d;

  /* Signature brass accent — the reed metal of a real harp. */
  --brass: #e8a53f;
  --brass-lit: #f4bd60;
  --brass-soft: rgba(232, 165, 63, 0.14);

  /* Solid CTA brass — same in both themes so buttons/switches stay vivid. */
  --btn-bg: #e79a2b;
  --btn-fg: #2a1600;

  --line: rgba(214, 196, 158, 0.22);
  --fill-1: rgba(255, 255, 255, 0.045); /* raised fill: ghost buttons, pills */
  --fill-2: rgba(255, 255, 255, 0.09);  /* its hover */
  --track-off: rgba(255, 255, 255, 0.16);
  /* Text field surfaces (query input + harp-key combobox). */
  --input-bg: rgba(255, 255, 255, 0.045);
  --input-bg-focus: rgba(255, 255, 255, 0.08);
  --input-shadow: 0 0 transparent;

  --surface: #2a2118;                    /* popover menus */
  --surface-border: rgba(242, 225, 188, 0.16);
  --surface-shadow: 0 18px 44px rgba(0, 0, 0, 0.55);

  --stage-bg:
    radial-gradient(120% 120% at 50% -20%, rgba(232, 165, 63, 0.09), transparent 58%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.035), rgba(0, 0, 0, 0.16));
  --stage-border: rgba(214, 196, 158, 0.12);
  --stage-shadow: 0 34px 70px -34px rgba(0, 0, 0, 0.75), inset 0 1px 0 rgba(255, 255, 255, 0.05);

  --panel-bg: linear-gradient(180deg, rgba(255, 255, 255, 0.035), rgba(0, 0, 0, 0.14));
  --panel-border: var(--line);
  --panel-shadow: 0 20px 44px -28px rgba(0, 0, 0, 0.7);

  /* --- Instrument (shared across themes) --- */
  --plate-hi: #f4ecdd;
  --plate-lo: #e2d8c4;
  --plate-edge: #c9ba9d;
  --comb-hi: #2c2720;
  --comb-lo: #16110c;
  --box-ink: #221b12;

  --reed-fill: #f7f0e2;  --reed-border: #d8caad;
  --bend-fill: #d7e8ed;  --bend-border: #83b3bf;
  --over-fill: #f8e5c3;  --over-border: #d3a45f;

  --match: #1f9d55;  --match-fill: #c9f0d7;
  --tone:  #7fc79b;  --tone-fill:  #e2f5ea;
  --root:  #ec7a12;  --root-fill:  #ffe3c1;

  --radius: 12px;
  --box-h: 46px;
  --reed-h: 62px;
  --num-h: 34px;
  --row-gap: 8px;
  font-synthesis-weight: none;
}

:root[data-theme="light"] {
  color-scheme: light;

  --bg-0: #ece1cf;
  --bg-1: #f6efe1;
  --glow: rgba(230, 150, 55, 0.16);
  --backdrop:
    radial-gradient(115% 72% at 50% -8%, var(--glow), transparent 55%),
    linear-gradient(180deg, var(--bg-1), var(--bg-0) 72%);
  --grain-opacity: 0.035;
  --grain-blend: multiply;

  --ink: #2c2318;
  --muted: #6d6350;
  --faint: #9a8d76;

  --brass: #a9670f;
  --brass-lit: #c9821b;
  --brass-soft: rgba(169, 103, 15, 0.12);

  --line: rgba(74, 56, 26, 0.16);
  --fill-1: rgba(74, 56, 26, 0.05);
  --fill-2: rgba(74, 56, 26, 0.1);
  --input-bg: #fffaf0;   /* lightest card color, so fields read as bright inputs */
  --input-bg-focus: #ffffff;
  --input-shadow: inset 0 1px 2px rgba(74, 56, 26, 0.07);
  --track-off: rgba(74, 56, 26, 0.2);

  --surface: #fffaf0;
  --surface-border: rgba(74, 56, 26, 0.14);
  --surface-shadow: 0 18px 44px rgba(80, 60, 25, 0.22);

  --stage-bg:
    radial-gradient(120% 120% at 50% -20%, rgba(230, 150, 55, 0.1), transparent 58%),
    linear-gradient(180deg, #fffaf0, #f4ead8);
  --stage-border: rgba(74, 56, 26, 0.14);
  --stage-shadow: 0 26px 54px -30px rgba(80, 60, 25, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.6);

  --panel-bg: linear-gradient(180deg, #fffaf0, #f7eede);
  --panel-border: rgba(74, 56, 26, 0.13);
  --panel-shadow: 0 18px 40px -26px rgba(80, 60, 25, 0.32);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Hanken Grotesk', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg-0);
  min-height: 100vh;
  padding: clamp(20px, 4vw, 42px) clamp(12px, 4vw, 40px) 56px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background 0.4s ease, color 0.4s ease;
}

/* Layer 1: warm spotlight washing over the stage + vignette. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -2;
  background: var(--backdrop);
  transition: background 0.4s ease;
}
/* Layer 2: fine film grain for analog texture. */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: var(--grain-opacity);
  mix-blend-mode: var(--grain-blend);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

::selection { background: var(--brass); color: #1a1206; }

/* --- Top-right actions (GitHub link + theme toggle) ------------------------*/
.top-actions {
  position: fixed;
  top: clamp(12px, 2.4vw, 20px);
  right: clamp(12px, 2.4vw, 20px);
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 8px;
}
.theme-toggle, .icon-link {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--fill-1);
  color: var(--brass-lit);
  cursor: pointer;
  overflow: hidden;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  transition: background 0.18s ease, border-color 0.18s ease, transform 0.12s ease, box-shadow 0.18s ease;
}
.icon-link { text-decoration: none; }
.icon-link svg { width: 21px; height: 21px; display: block; }
.theme-toggle:hover, .icon-link:hover { background: var(--fill-2); border-color: var(--brass); box-shadow: 0 0 0 4px var(--brass-soft); }
.theme-toggle:active, .icon-link:active { transform: scale(0.94); }
.theme-toggle:focus-visible, .icon-link:focus-visible { outline: none; border-color: var(--brass); box-shadow: 0 0 0 4px var(--brass-soft); }
.theme-toggle .ic {
  grid-area: 1 / 1;
  font-size: 1.15rem;
  line-height: 1;
  transition: opacity 0.28s ease, rotate 0.4s cubic-bezier(0.2, 0.8, 0.2, 1), scale 0.3s ease;
}
/* Show the icon for the theme you'd switch TO. */
:root[data-theme="dark"]  .ic-sun  { opacity: 1;   rotate: 0deg;   scale: 1;    }
:root[data-theme="dark"]  .ic-moon { opacity: 0;   rotate: -90deg; scale: 0.4;  }
:root[data-theme="light"] .ic-sun  { opacity: 0;   rotate: 90deg;  scale: 0.4;  }
:root[data-theme="light"] .ic-moon { opacity: 1;   rotate: 0deg;   scale: 1;    }

/* --- Header ----------------------------------------------------------------*/
.topbar { text-align: center; margin-bottom: 26px; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  margin: 0 auto 14px;
  border-radius: 16px;
  color: var(--brass);
  background: var(--brass-soft);
  border: 1px solid color-mix(in srgb, var(--brass) 26%, transparent);
}
.brand-mark svg { width: 38px; height: 38px; display: block; }
.topbar h1 {
  margin: 0;
  font-family: 'Fraunces', Georgia, 'Times New Roman', serif;
  font-optical-sizing: auto;
  font-weight: 600;
  font-size: clamp(2rem, 5.2vw, 3.15rem);
  line-height: 1.03;
  letter-spacing: -0.018em;
  background: linear-gradient(168deg, var(--ink) 20%, var(--brass) 118%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
}
.tagline {
  margin: 9px auto 0;
  max-width: 46ch;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.5;
}
.topbar::after {
  content: "";
  display: block;
  width: 66px;
  height: 3px;
  margin: 16px auto 0;
  border-radius: 2px;
  background: linear-gradient(90deg, transparent, var(--brass), transparent);
}

/* --- Controls --------------------------------------------------------------*/
.controls {
  display: flex;
  gap: 14px;
  align-items: flex-end;
  flex-wrap: wrap;
  max-width: 880px;
  margin: 0 auto 14px;
  position: relative;
  z-index: 20; /* keep open dropdowns above the stage card below */
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field.grow { flex: 1 1 320px; }
.field label, .field-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.11em;
}
.field input {
  font: inherit;
  font-size: 1.05rem;
  padding: 12px 14px;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--input-bg);
  color: var(--ink);
  box-shadow: var(--input-shadow);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.field input::placeholder { color: var(--faint); }
.field input:hover { border-color: color-mix(in srgb, var(--brass) 45%, var(--line)); }
.field input:focus {
  outline: none;
  border-color: var(--brass);
  background: var(--input-bg-focus);
  box-shadow: var(--input-shadow), 0 0 0 3px var(--brass-soft);
}

/* --- Custom combobox (harp key) -------------------------------------------*/
.cbx { position: relative; }
.cbx-btn {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  min-width: 100px; height: 48px; padding: 0 12px 0 14px;
  font: inherit; font-size: 1.05rem; font-weight: 600;
  color: var(--ink); background: var(--input-bg);
  border: 1px solid var(--line); border-radius: 12px; cursor: pointer;
  box-shadow: var(--input-shadow);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.cbx-btn:hover { background: var(--input-bg-focus); border-color: color-mix(in srgb, var(--brass) 45%, var(--line)); }
.cbx-btn:focus-visible { outline: none; border-color: var(--brass); box-shadow: var(--input-shadow), 0 0 0 3px var(--brass-soft); }
.cbx-caret { font-size: 1.1rem; color: var(--muted); transition: rotate 0.2s ease, color 0.15s ease; }
.cbx-btn[aria-expanded="true"] .cbx-caret { rotate: 180deg; color: var(--brass); }
.cbx-menu {
  top: calc(100% + 6px); left: 0; right: 0; min-width: 100%;
  max-height: 288px; overflow-y: auto;
  list-style: none; margin: 0;
}
.cbx-opt {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 12px; border-radius: 8px; cursor: pointer;
  color: var(--ink); font-weight: 600; font-size: 1rem;
  transition: background 0.13s ease, color 0.13s ease;
}
.cbx-opt::after { content: ""; font-size: 0.85em; color: var(--brass); }
.cbx-opt[aria-selected="true"]::after { content: "✓"; }
.cbx-opt:hover, .cbx-opt.active { background: var(--brass-soft); color: var(--brass-lit); }

/* --- Shared popover animation ---------------------------------------------*/
.pop {
  position: absolute;
  z-index: 30;
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: 12px;
  box-shadow: var(--surface-shadow);
  padding: 5px;
  opacity: 0;
  visibility: hidden;
  translate: 0 -6px;
  scale: 0.97;
  transform-origin: top center;
  transition:
    opacity 0.16s ease,
    translate 0.16s ease,
    scale 0.16s ease,
    visibility 0s linear 0.16s;
}
.pop.open {
  opacity: 1;
  visibility: visible;
  translate: 0 0;
  scale: 1;
  transition:
    opacity 0.16s ease,
    translate 0.2s cubic-bezier(0.2, 0.8, 0.2, 1),
    scale 0.2s cubic-bezier(0.2, 0.8, 0.2, 1),
    visibility 0s;
}

/* --- Examples --------------------------------------------------------------*/
.examples {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  justify-content: center; max-width: 880px; margin: 0 auto 26px;
  color: var(--muted); font-size: 0.9rem;
}
.examples > span { color: var(--faint); font-weight: 600; letter-spacing: 0.02em; }
.example {
  border: 1px solid var(--line);
  background: var(--fill-1);
  color: var(--ink);
  padding: 6px 13px; border-radius: 999px; cursor: pointer;
  font: inherit; font-size: 0.86rem; font-weight: 600;
  transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease, transform 0.08s ease;
}
.example:hover {
  background: var(--brass-soft);
  border-color: var(--brass);
  color: var(--brass-lit);
  transform: translateY(-1px);
}
.example:active { transform: translateY(0); }

/* --- Harp stage ------------------------------------------------------------*/
.stage {
  position: relative;
  max-width: 1080px;
  margin: 4px auto 0;
  padding: clamp(16px, 3vw, 30px) clamp(8px, 2vw, 22px) clamp(14px, 2.4vw, 24px);
  border-radius: 22px;
  background: var(--stage-bg);
  border: 1px solid var(--stage-border);
  box-shadow: var(--stage-shadow);
  transition: background 0.4s ease, border-color 0.4s ease, box-shadow 0.4s ease;
}
/* The tab line runs the width of the harp, so give the corner share button its
   own band below instead of letting the two overlap. */
.stage:has(#scale-tab:not([hidden])) { padding-bottom: 56px; }
.harp-title {
  text-align: center;
  font-family: 'Fraunces', Georgia, serif;
  font-optical-sizing: auto;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 14px;
  padding: 0 54px; /* clear the corner play / image buttons */
  font-size: clamp(1.1rem, 2.4vw, 1.4rem);
  letter-spacing: 0.005em;
}
/* Accidental glyph inside a serif heading: draw it in the body font (which has a
   properly-sized ♭/♯) tucked close to its note letter. */
.acc {
  font-family: 'Hanken Grotesk', -apple-system, BlinkMacSystemFont, sans-serif;
  font-weight: 600;
  font-size: 0.92em;
  margin-left: -0.03em;
}

/* Heights of the four outer grid rows. They collapse to 0 when every technique
   that lives in them is switched off, so a harp without bends/overblows doesn't
   leave a band of dead space between the title and the reeds. Registered as
   lengths so the collapse animates — the grid tracks, the side labels and the
   fit wrapper's own height are all derived from them. */
@property --row-1 { syntax: "<length>"; inherits: true; initial-value: 54px; }
@property --row-2 { syntax: "<length>"; inherits: true; initial-value: 54px; }
@property --row-6 { syntax: "<length>"; inherits: true; initial-value: 54px; }
@property --row-7 { syntax: "<length>"; inherits: true; initial-value: 54px; }
@property --row-8 { syntax: "<length>"; inherits: true; initial-value: 54px; }

/* Wrapper that clips the harp; JS scales .harp-area down to fit narrow screens
   (a "zoom to fit" instead of a horizontal scrollbar). The vertical padding is
   clip room for the top/bottom rows' hover-lift + shadow. */
.harp-fit {
  overflow: hidden;
  padding: 14px 0;
  /* Each track carries its own gap (the grid's row-gap is 0) so a row that
     collapses takes its gap with it. */
  --row-h: calc(var(--box-h) + var(--row-gap));
  --num-row: calc(var(--num-h) + 2 * var(--row-gap));
  --row-1: var(--row-h);
  --row-2: var(--row-h);
  --row-6: var(--row-h);
  --row-7: var(--row-h);
  --row-8: var(--row-h);
  /* --tab-h is measured by fitHarp(); the rest animates with the row collapse. */
  --harp-h: calc(var(--row-1) + var(--row-2) + var(--reed-h) + var(--num-row)
    + var(--reed-h) + var(--row-6) + var(--row-7) + var(--row-8) + var(--tab-h, 0px));
  transition:
    --row-1 0.26s ease, --row-2 0.26s ease,
    --row-6 0.26s ease, --row-7 0.26s ease, --row-8 0.26s ease;
}
/* Row 1 holds only the deepest blow bend, row 2 also the overblow; mirrored for
   rows 6-8 below the comb. */
.harp-fit.hide-blow-bend { --row-1: 0px; }
.harp-fit.hide-blow-bend.hide-overblow { --row-2: 0px; }
.harp-fit.hide-draw-bend { --row-7: 0px; --row-8: 0px; }
.harp-fit.hide-draw-bend.hide-overdraw { --row-6: 0px; }

.harp-area {
  position: relative;
  padding: 0 30px; /* gutters that hold the side labels */
  container-type: inline-size; /* the tab line sizes its keys off the harp width */
}
.side-label {
  position: absolute;
  width: 26px;
  text-align: center;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.2em;
  color: var(--faint);
  pointer-events: none;
}
.side-label.right { left: auto; right: 0; }
.side-label:not(.right) { left: 0; }
.side-label { display: flex; align-items: center; justify-content: center; height: var(--reed-h); }
.side-blow { top: calc(var(--row-1) + var(--row-2));
  writing-mode: vertical-rl; transform: rotate(180deg); }
.side-draw { top: calc(var(--row-1) + var(--row-2) + var(--reed-h) + var(--num-row));
  writing-mode: vertical-rl; }

.harp {
  display: grid;
  grid-template-columns: repeat(10, minmax(52px, 1fr));
  grid-template-rows:
    var(--row-1)   /* 1 deepest blow bend */
    var(--row-2)   /* 2 blow bend / overblow */
    var(--reed-h)  /* 3 blow */
    var(--num-row) /* 4 number bar */
    var(--reed-h)  /* 5 draw */
    var(--row-6)   /* 6 draw bend / overdraw */
    var(--row-7)   /* 7 draw bend */
    var(--row-8);  /* 8 draw bend */
  column-gap: 8px;
  min-width: 628px;
  position: relative;
  padding: 0 6px; /* absorbs the number bar's -6px overhang */
}

/* Brushed cover plate behind the blow row, number bar and draw row. */
.reed-panel {
  grid-column: 1 / -1;
  grid-row: 3 / 6;
  background: linear-gradient(180deg, var(--plate-hi), var(--plate-lo));
  border: 1px solid var(--plate-edge);
  border-radius: 16px;
  z-index: 0;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.75),
    inset 0 -3px 8px rgba(120, 96, 54, 0.16);
}
/* Dark comb: full-width number bar overlapping the plate's middle. */
.number-bar {
  grid-column: 1 / -1;
  grid-row: 4;
  background: linear-gradient(180deg, var(--comb-hi), var(--comb-lo));
  border-radius: 8px;
  z-index: 1;
  align-self: center;
  height: 30px;
  margin: 0 -6px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.07),
    inset 0 -2px 3px rgba(0, 0, 0, 0.5),
    0 2px 4px rgba(0, 0, 0, 0.4);
}
.hole-num {
  z-index: 2;
  align-self: center;
  justify-self: center;
  color: #f2e7d3;
  background: linear-gradient(180deg, #100c08, #000);
  border-radius: 6px;
  font-size: 0.82rem;
  font-weight: 700;
  min-width: 22px;
  height: 22px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

/* --- Note keys -------------------------------------------------------------*/
.box {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  border: 1.5px solid transparent;
  color: var(--box-ink);
  font: inherit;
  cursor: pointer;
  padding: 0;
  overflow: hidden; /* keeps the label inside while a collapsing row squashes it */
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.55),
    0 1px 2px rgba(0, 0, 0, 0.28);
  /* Independent translate/scale so the hover lift and the show/hide scale
     don't fight over `transform`. */
  transition:
    translate 0.1s ease,
    box-shadow 0.15s ease,
    opacity 0.22s ease,
    scale 0.22s cubic-bezier(0.2, 0.8, 0.2, 1),
    filter 0.14s ease,
    visibility 0s;
}
.box:hover {
  translate: 0 -2px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.6),
    0 8px 16px -5px rgba(0, 0, 0, 0.5);
}
.box:active { translate: 0 0; }
.box:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }
.box .note { font-size: 1.15rem; font-weight: 700; line-height: 1; }
/* Corner-pinned so the note name sits at the same optical centre whether or not
   a degree is shown. */
.box .deg {
  position: absolute; right: 5px; bottom: 3px;
  font-size: 0.62rem; font-weight: 700; opacity: 0.62;
}
.box .tag {
  position: absolute; top: 3px; right: 4px;
  font-size: 0.5rem; font-weight: 800; letter-spacing: 0.03em;
  opacity: 0.5;
}

/* The row gap lives inside the track (see .harp-fit), on the side facing the comb. */
.box.blow-bend, .box.overblow { margin-bottom: var(--row-gap); }
.box.draw-bend, .box.overdraw { margin-top: var(--row-gap); }

.box.reed { background: var(--reed-fill); border-color: var(--reed-border); }
.box.reed .note { font-size: 1.35rem; }
.box.bend { background: var(--bend-fill); border-color: var(--bend-border); }
.box.over { background: var(--over-fill); border-color: var(--over-border); }
/* Over-bar: a line drawn *over* the note marks overblows/overdraws apart from
   bends. Ink-coloured, so unlike the fill and border it survives the highlight
   states — and greyscale. */
.box.over::before {
  content: '';
  position: absolute;
  top: 6px; left: 50%;
  translate: -50% 0;
  width: 28px; height: 2.5px;
  border-radius: 2px;
  background: currentColor;
  opacity: 0.8;
}
/* On a tab key the "°" in the label already says overblow/overdraw, and the bar
   would land on top of it. */
.box.mini.over::before { content: none; }

/* Highlight states — lit keys glow warmly off the dark stage. */
.box.match {
  background: var(--match-fill);
  border-color: var(--match);
  box-shadow:
    inset 0 0 0 2px var(--match),
    inset 0 1px 0 rgba(255, 255, 255, 0.5),
    0 4px 16px -6px rgba(31, 157, 85, 0.55);
}
.box.tone {
  background: var(--tone-fill);
  border-color: var(--tone);
}
.box.tone .note { font-weight: 600; }
.box.root {
  background: var(--root-fill);
  border-color: var(--root);
  box-shadow:
    inset 0 0 0 2.5px var(--root),
    inset 0 1px 0 rgba(255, 255, 255, 0.5),
    0 5px 18px -6px rgba(236, 122, 18, 0.6);
}
.box.dim {
  opacity: 0.28;
  filter: saturate(0.5);
  box-shadow: none;
}
.box.dim:hover { opacity: 0.6; }

/* Animated show/hide of bends & overblows: the keys fade + shrink out while
   their row collapses underneath them. visibility flips after the fade so
   hidden keys leave the tab order. */
.harp-fit.hide-draw-bend .box.draw-bend,
.harp-fit.hide-blow-bend .box.blow-bend,
.harp-fit.hide-overblow  .box.overblow,
.harp-fit.hide-overdraw  .box.overdraw {
  opacity: 0;
  scale: 0.78;
  pointer-events: none;
  visibility: hidden;
  transition:
    translate 0.1s ease,
    box-shadow 0.15s ease,
    opacity 0.22s ease,
    scale 0.22s cubic-bezier(0.2, 0.8, 0.2, 1),
    filter 0.14s ease,
    visibility 0s linear 0.22s;
}

/* --- Tab line (the selection in playing order) -----------------------------*/
/* Sized in cqw against the harp's own width, so the ~24 keys a 7-note scale
   needs always fit one line — and so the keys shrink together with the harp
   when fitHarp() scales it down. Mirrored by the same fractions in exporter.js. */
.scale-tab {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.58cqw;
  margin-top: 2.1cqw;
}
.scale-tab[hidden] { display: none; }
/* Column per key: the stretch keeps the key and its note name on the same box,
   so the name is always exactly below the key it belongs to. */
.tab-key { display: flex; flex-direction: column; }
.tab-name {
  margin-top: 0.35cqw;
  text-align: center;
  font-size: 1.15cqw;
  font-weight: 600;
  line-height: 1.2;
  color: var(--muted);
}
.box.mini {
  min-width: 2.8cqw;
  height: 3.6cqw;
  padding: 0 0.66cqw;
  font-size: 1.45cqw;
  font-weight: 700;
  border-radius: 0.75cqw;
  white-space: nowrap; /* "-2 / 3" stays on one line */
}

/* --- Toggles (animated switches) ------------------------------------------*/
.toggles {
  display: flex; gap: 26px; justify-content: center;
  margin: 22px auto 0; flex-wrap: wrap;
}
.play-hint {
  max-width: 880px;
  margin: 12px auto 0;
  text-align: center;
  color: var(--faint);
  font-size: 0.8rem;
}
.switch { display: inline-flex; align-items: center; gap: 11px; cursor: pointer; user-select: none; }
.switch input {
  position: absolute; opacity: 0; width: 1px; height: 1px; margin: -1px; /* focusable but hidden */
}
.switch-track {
  position: relative;
  flex: none;
  width: 44px; height: 25px;
  border-radius: 999px;
  background: var(--track-off);
  border: 1px solid var(--line);
  transition: background 0.25s ease, border-color 0.25s ease;
}
.switch-thumb {
  position: absolute; top: 2px; left: 2px;
  width: 19px; height: 19px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
  transition: translate 0.26s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.2s ease;
}
.switch input:checked + .switch-track {
  background: var(--btn-bg);
  border-color: transparent;
}
.switch input:checked + .switch-track .switch-thumb { translate: 19px 0; }
.switch input:focus-visible + .switch-track { outline: none; box-shadow: 0 0 0 3px var(--brass-soft); }
.switch-text { color: var(--muted); font-size: 0.92rem; transition: color 0.2s ease; }
.switch:hover .switch-text { color: var(--ink); }

/* --- Card corner controls (play / image) ----------------------------------*/
.card-btn {
  width: 38px; height: 38px; padding: 0;
  display: grid; place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--fill-1);
  color: var(--brass);
  cursor: pointer;
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  transition: background 0.16s ease, color 0.16s ease, border-color 0.16s ease, transform 0.12s ease, box-shadow 0.16s ease;
}
.card-btn:hover { background: var(--brass-soft); border-color: var(--brass); }
.card-btn:active { transform: scale(0.94); }
.card-btn:focus-visible { outline: none; border-color: var(--brass); box-shadow: 0 0 0 3px var(--brass-soft); }
.card-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.card-btn:disabled:hover { background: var(--fill-1); border-color: var(--line); }
.card-btn svg { width: 18px; height: 18px; display: block; }

.card-play { position: absolute; top: 14px; left: 14px; z-index: 6; }
.card-img { position: absolute; top: 14px; right: 14px; z-index: 6; }

/* "Now playing" + "copied/saved" states fill solid brass with a dark glyph. */
.card-play.is-playing, .card-btn.is-done {
  background: var(--btn-bg); color: var(--btn-fg); border-color: transparent;
}
.play-bars rect { transform-origin: center; animation: play-bar-pulse 0.9s ease-in-out infinite; }
.play-bars rect:nth-child(1) { animation-delay: 0s; }
.play-bars rect:nth-child(2) { animation-delay: 0.15s; }
.play-bars rect:nth-child(3) { animation-delay: 0.3s; }
@keyframes play-bar-pulse { 0%, 100% { transform: scaleY(0.4); } 50% { transform: scaleY(1); } }

.img-menu {
  top: calc(100% + 8px); right: 0;
  min-width: 172px; white-space: nowrap;
  display: flex; flex-direction: column; gap: 2px;
}
.img-opt {
  background: none; border: none; cursor: pointer; font: inherit;
  text-align: left; padding: 8px 12px; border-radius: 8px; color: var(--ink);
  transition: background 0.13s ease, color 0.13s ease;
}
.img-opt:hover { background: var(--brass-soft); color: var(--brass-lit); }

/* --- Info panel ------------------------------------------------------------*/
.info {
  max-width: 880px; margin: 24px auto 0;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 16px; padding: 18px 20px;
  box-shadow: var(--panel-shadow);
  transition: background 0.4s ease, border-color 0.4s ease;
}
.info .hint { margin: 0; color: var(--muted); line-height: 1.55; }
.info .hint.warn { color: #e0693f; }
.info code {
  background: var(--brass-soft); color: var(--brass-lit);
  padding: 1px 7px; border-radius: 6px;
  border: 1px solid color-mix(in srgb, var(--brass) 30%, transparent);
  font-size: 0.9em;
}
.detected { display: flex; align-items: baseline; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.detected strong {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 600;
  font-size: 1.4rem;
  color: var(--ink);
}
/* Direct child only, so it can't override the .acc glyph nested inside <strong>. */
.detected > span { color: var(--muted); font-size: 0.9rem; }

/* Copy-link control, tucked into the lower-right of the harp card. */
.card-share {
  position: absolute; bottom: 14px; right: 14px; z-index: 6;
  display: inline-flex; align-items: center; gap: 6px;
  height: 34px; padding: 0 14px;
  font: inherit; font-size: 0.82rem; font-weight: 600;
  border: 1px solid var(--line); border-radius: 999px;
  /* Opaque so it stays legible where it overlaps the harp (e.g. when it scrolls
     horizontally on narrow screens). */
  background: var(--surface); color: var(--muted); cursor: pointer;
  box-shadow: 0 4px 12px -5px rgba(0, 0, 0, 0.35);
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.card-share:hover, .card-share.is-done { background: var(--brass-soft); border-color: var(--brass); color: var(--brass-lit); }
.card-share:focus-visible { outline: none; border-color: var(--brass); box-shadow: 0 0 0 3px var(--brass-soft); }
.card-share svg { width: 15px; height: 15px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
/* Each chip is a button that sounds its note, like the holes on the harp. */
.chip {
  display: inline-flex; align-items: baseline; gap: 5px;
  padding: 5px 12px; border-radius: 999px;
  font: inherit; font-weight: 700; border: 1.5px solid;
  background: none; cursor: pointer;
  transition: translate 0.1s ease, box-shadow 0.15s ease;
}
.chip:hover { translate: 0 -2px; box-shadow: 0 7px 14px -7px rgba(0, 0, 0, 0.55); }
.chip:active { translate: 0 0; box-shadow: none; }
.chip:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }
.chip em { font-style: normal; font-size: 0.7rem; font-weight: 600; opacity: 0.72; }
.chip.match { background: var(--match-fill); border-color: var(--match); color: #12572f; }
.chip.tone { background: var(--tone-fill); border-color: var(--tone); color: #326349; }
.chip.root { background: var(--root-fill); border-color: var(--root); color: #834005; }
.chip.miss { background: var(--fill-1); border-color: var(--line); color: var(--faint); }

.legendline { margin: 0; color: var(--muted); font-size: 0.82rem; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.sw { width: 13px; height: 13px; border-radius: 4px; display: inline-block; border: 1.5px solid; margin-left: 8px; }
.sw.root { background: var(--root-fill); border-color: var(--root); }
.sw.match { background: var(--match-fill); border-color: var(--match); }
.sw.tone { background: var(--tone-fill); border-color: var(--tone); }
.sw.miss { background: var(--fill-1); border-color: var(--line); }

/* --- Cross-promo card (sibling Chord Charts app) ---------------------------*/
.cross-promo {
  display: flex; align-items: center; gap: 16px;
  max-width: 880px; margin: 16px auto 0; padding: 16px 18px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  box-shadow: var(--panel-shadow);
  text-decoration: none; color: inherit;
  transition: border-color 0.18s ease, background 0.4s ease, transform 0.12s ease;
}
.cross-promo:hover { border-color: color-mix(in srgb, var(--brass) 45%, var(--panel-border)); transform: translateY(-1px); }
.cross-promo:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }
.cross-promo-mark {
  display: grid; place-items: center; flex: 0 0 auto;
  width: 52px; height: 52px; border-radius: 14px;
  color: var(--brass); background: var(--brass-soft);
  border: 1px solid color-mix(in srgb, var(--brass) 26%, transparent);
}
.cross-promo-mark svg { width: 34px; height: 34px; }
.cross-promo-body { flex: 1 1 auto; min-width: 0; }
.cross-promo-teaser {
  display: block; font-family: 'Fraunces', Georgia, serif; font-optical-sizing: auto;
  font-size: 1.15rem; font-weight: 600; line-height: 1.15; color: var(--ink);
}
.cross-promo-desc { display: block; margin-top: 5px; font-size: 0.9rem; line-height: 1.45; color: var(--muted); }
.cross-promo-desc b { color: var(--ink); font-weight: 600; }
.cross-promo-go {
  flex: 0 0 auto; display: grid; place-items: center;
  width: 38px; height: 38px; border-radius: 50%;
  color: var(--brass); background: var(--brass-soft);
  border: 1px solid color-mix(in srgb, var(--brass) 26%, transparent);
  transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
}
.cross-promo-go svg { width: 16px; height: 16px; }
.cross-promo:hover .cross-promo-go { background: var(--btn-bg); color: var(--btn-fg); border-color: var(--btn-bg); transform: translateX(2px); }

/* --- Footer ----------------------------------------------------------------*/
.foot {
  max-width: 880px; margin: 40px auto 0; padding-top: 16px;
  border-top: 1px solid var(--line);
  color: var(--muted); font-size: 0.8rem;
}
.foot p { margin: 0; line-height: 1.55; }
.foot-meta {
  display: flex; justify-content: space-between; flex-wrap: wrap;
  gap: 4px 24px; margin-top: 8px;
}
.foot a { color: var(--brass); font-weight: 600; text-decoration: none; transition: color 0.15s ease; }
.foot a:hover { color: var(--brass-lit); text-decoration: underline; text-underline-offset: 2px; }

/* --- Entrance: one calm, staggered reveal on first load --------------------*/
@media (prefers-reduced-motion: no-preference) {
  .topbar, .controls, .examples, .stage, .toggles, .info, .foot {
    animation: rise 0.6s cubic-bezier(0.2, 0.7, 0.2, 1) both;
  }
  .controls { animation-delay: 0.05s; }
  .examples { animation-delay: 0.1s; }
  .stage    { animation-delay: 0.16s; }
  .toggles  { animation-delay: 0.22s; }
  .info     { animation-delay: 0.26s; }
  .foot     { animation-delay: 0.32s; }
  @keyframes rise {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: none; }
  }
}

/* Respect users who prefer no motion — kill transitions/animations. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

@media (max-width: 560px) {
  /* The harp keeps its full-size layout and is scaled to fit by fitHarp(), so no
     per-element shrinking here. */
  .topbar { margin-bottom: 20px; }
  .stage { border-radius: 18px; }
  .theme-toggle, .icon-link { width: 40px; height: 40px; }
}
