/* ── Fonts ───────────────────────────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Lora:ital,wght@0,400;0,600;1,400&family=Inter:wght@300;400;500;600&display=swap');

/* ── Reset ───────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Design tokens — light theme ─────────────────────────────────────────────── */
:root {
  /* Backgrounds */
  --bg:     #faf8f4;
  --bg-alt: #f3f0ea;

  /* Text */
  --text:       #1c1814;
  --text-dim:   #7a6f65;
  --text-faint: #bbb0a4;

  /* Borders */
  --sep: #e4ddd5;

  /* Accent (links, hover highlights) */
  --accent: #c45c2e;

  /* Layout */
  --header-h: 60px;
  --left-w:   440px;

  /* Fonts */
  --font-sans:  'Inter', system-ui, -apple-system, sans-serif;
  --font-serif: 'Lora', Georgia, serif;

  /* Note colour system — --nh is set per .note-cell by JS */
  --nh:     0;      /* hue for the current note */
  --cb-s:   62%;    /* colorbar / flower saturation */
  --cb-l:   44%;    /* colorbar / flower lightness  */
  --pill-s: 50%;    /* strip pill gradient saturation */
}

/* ── Dark mode hook ───────────────────────────────────────────────────────────
   To activate: add data-theme="dark" to <html>.
   Only colour tokens need overriding — layout, sizing, font variables stay. */
[data-theme="dark"] {
  --bg:         #0f0f13;
  --bg-alt:     #13131a;
  --text:       #c8c8d4;
  --text-dim:   #52526a;
  --text-faint: #3a3a52;
  --sep:        #1e1e2a;
  --accent:     #f5a623;
}

/* ── Base ────────────────────────────────────────────────────────────────────── */
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

/* ── Site header ─────────────────────────────────────────────────────────────── */
.site-header {
  position: fixed; top: 0; left: 0; right: 0; height: var(--header-h);
  display: flex; align-items: center; padding: 0 40px;
  background: rgba(250,248,244,0.93);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--sep);
  z-index: 100;
}

[data-theme="dark"] .site-header {
  background: rgba(15,15,19,0.93);
}

.logo-wrap {
  display: flex; align-items: center; gap: 9px;
  flex-shrink: 0; text-decoration: none; color: inherit;
}
.logo {
  font-family: var(--font-sans);
  font-size: 14px; font-weight: 500; letter-spacing: 0.01em;
  color: var(--text);
}

nav { display: flex; gap: 2px; flex: 1; }
.nav-btn {
  padding: 5px 14px; background: none; border: none;
  font-family: var(--font-sans); font-size: 12.5px;
  color: var(--text-dim); cursor: pointer; border-radius: 5px;
  transition: color 0.15s, background 0.15s;
}
.nav-btn:hover { color: var(--text); background: rgba(0,0,0,0.04); }
[data-theme="dark"] .nav-btn:hover { background: rgba(255,255,255,0.05); }

.header-right { display: flex; gap: 6px; }
.icon-btn {
  width: 30px; height: 30px; background: none;
  border: 1px solid var(--sep); border-radius: 5px; cursor: pointer;
  font-size: 12px; color: var(--text-dim);
  display: flex; align-items: center; justify-content: center;
  transition: border-color 0.2s, color 0.2s;
}
.icon-btn:hover { border-color: #ccc8c0; color: var(--text); }

/* ── Header three-zone layout ─────────────────────────────────────────────────── */
.hdr-left  { display: flex; align-items: center; gap: 24px; flex: 1; min-width: 0; }
.hdr-center {
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  display: flex; align-items: center;
}
.hdr-nav   { display: flex; gap: 2px; }

/* ── Dropdowns ────────────────────────────────────────────────────────────────── */
.hdr-dropdown { position: relative; }
.hdr-dropdown-btn::after { content: ' ▾'; font-size: 9px; vertical-align: 1px; opacity: 0.6; }
.hdr-menu {
  display: none;
  position: absolute; top: calc(100% + 6px); left: 0;
  background: var(--bg); border: 1px solid var(--sep);
  border-radius: 8px; padding: 5px;
  min-width: 152px;
  box-shadow: 0 8px 24px rgba(28,24,20,0.1);
  z-index: 300;
}
.hdr-menu.open { display: block; }
.hdr-menu-item {
  display: block; padding: 7px 11px; border-radius: 5px;
  text-decoration: none; font-size: 13px; color: var(--text-dim);
  transition: background 0.12s, color 0.12s;
}
.hdr-menu-item:hover { background: var(--bg-alt); color: var(--text); }
.hdr-menu-item.active { color: var(--accent); font-weight: 500; }
.hdr-menu-empty { display: block; padding: 7px 11px; font-size: 12px; color: var(--text-faint); font-style: italic; }

/* ── Center about button ──────────────────────────────────────────────────────── */
.hdr-center-btn {
  background: none; border: none; cursor: pointer; padding: 5px;
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  transition: opacity 0.2s;
}
.hdr-center-btn:hover { opacity: 0.65; }

/* ── Right icon groups ────────────────────────────────────────────────────────── */
.hdr-right { display: flex; align-items: center; gap: 0; }
.hdr-icon-group { display: flex; align-items: center; gap: 3px; }
.hdr-icon-sep   { width: 1px; height: 18px; background: var(--sep); margin: 0 5px; flex-shrink: 0; }

/* Icon group wrap — icons above, label below */
.hdr-group-wrap {
  display: flex; flex-direction: column; align-items: center;
  gap: 3px; position: relative; padding: 0 6px;
}
.hdr-group-label {
  font-size: 7.5px; font-weight: 600;
  letter-spacing: 0.11em; text-transform: uppercase;
  color: var(--text-faint); white-space: nowrap;
  line-height: 1; user-select: none;
}

/* Vertical separator between groups */
.hdr-vert-sep {
  width: 1px; height: 26px;
  background: var(--sep); margin: 0 2px;
  align-self: center; flex-shrink: 0;
}

/* ── Icon dropdowns (right panel) ─────────────────────────────────────────────── */
.hdr-icon-dd { position: relative; }

.hdr-icon-menu {
  display: none;
  position: absolute; top: calc(100% + 10px); right: 0;
  background: var(--bg); border: 1px solid var(--sep);
  border-radius: 10px; padding: 10px;
  min-width: 190px;
  box-shadow: 0 8px 28px rgba(28,24,20,0.12);
  z-index: 300;
}
.hdr-icon-menu.open { display: block; }
.hdr-icon-menu--root { min-width: 200px; }

[data-theme="dark"] .hdr-icon-menu {
  box-shadow: 0 8px 28px rgba(0,0,0,0.45);
}

/* ── Icon dropdown content (hdm = header dropdown menu) ──────────────────────── */
.hdm-sep { height: 1px; background: var(--sep); margin: 8px 0; }

.hdm-section { margin: 0; }

.hdm-label {
  display: block; font-size: 9px; font-weight: 600;
  letter-spacing: 0.11em; text-transform: uppercase;
  color: var(--text-faint); margin-bottom: 6px;
}
.hdm-label-row {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 6px;
}
.hdm-capo-val {
  font-size: 10px; color: var(--text-dim);
}

.hdm-radio-row { display: flex; gap: 4px; }
.hdm-radio {
  display: flex; align-items: center; justify-content: center;
  padding: 4px 10px; border-radius: 5px;
  border: 1px solid var(--sep);
  font-size: 12px; color: var(--text-dim); cursor: pointer;
  transition: border-color 0.12s, background 0.12s, color 0.12s;
  flex: 1; user-select: none; gap: 0;
}
.hdm-radio input { position: absolute; opacity: 0; pointer-events: none; width: 0; height: 0; }
.hdm-radio:has(input:checked) {
  background: var(--bg-alt);
  border-color: #ccc8c0;
  color: var(--text);
}
[data-theme="dark"] .hdm-radio:has(input:checked) {
  background: rgba(255,255,255,0.06);
  border-color: #3a3a52;
}

.hdm-select {
  width: 100%; padding: 5px 8px;
  border: 1px solid var(--sep); border-radius: 6px;
  background: var(--bg); color: var(--text);
  font-size: 12px; font-family: var(--font-sans); cursor: pointer;
}
.hdm-select:focus { outline: none; border-color: var(--accent); }

/* Tuning radio list */
.hdm-tune-list { display: flex; flex-direction: column; gap: 2px; }
.hdm-tune-opt {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 8px; border-radius: 5px;
  border: 1px solid transparent; cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
  user-select: none;
}
.hdm-tune-opt input { position: absolute; opacity: 0; pointer-events: none; width: 0; height: 0; }
.hdm-tune-opt:has(input:checked) { background: var(--bg-alt); border-color: var(--sep); }
.hdm-tune-opt:hover { background: var(--bg-alt); }
.hdm-tune-name { font-size: 12px; color: var(--text-dim); flex-shrink: 0; min-width: 52px; }
.hdm-tune-opt:has(input:checked) .hdm-tune-name { color: var(--text); }
.hdm-tune-notes { font-size: 10.5px; color: var(--text-faint); letter-spacing: 0.04em; font-variant-numeric: tabular-nums; }

/* Capo slider — thumb styled as a capo bar */
.hdm-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 3px;
  background: var(--sep);
  border-radius: 2px;
  cursor: pointer;
  outline: none;
}
.hdm-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 7px; height: 20px;
  background: var(--text-dim);
  border-radius: 2px;
  cursor: pointer;
  transition: background 0.15s;
}
.hdm-slider::-webkit-slider-thumb:hover { background: var(--text); }
.hdm-slider::-moz-range-thumb {
  width: 7px; height: 20px;
  background: var(--text-dim);
  border: none; border-radius: 2px;
  cursor: pointer;
}

/* Palette options */
.hdm-palette-opt {
  display: flex; align-items: center; gap: 9px;
  padding: 6px 8px; border-radius: 6px; cursor: pointer;
  transition: background 0.12s; user-select: none;
}
.hdm-palette-opt:hover { background: var(--bg-alt); }
.hdm-palette-opt--soon { opacity: 0.42; cursor: default; pointer-events: none; }
.hdm-palette-opt input { position: absolute; opacity: 0; pointer-events: none; width: 0; height: 0; }
.hdm-palette-name { font-size: 12px; color: var(--text-dim); }
.hdm-palette-name em { font-size: 10px; color: var(--text-faint); margin-left: 4px; font-style: normal; }

.hdm-palette-swatch {
  width: 24px; height: 14px; border-radius: 3px; flex-shrink: 0;
  border: 1px solid rgba(0,0,0,0.08);
}
.hdm-palette-swatch--default {
  background: linear-gradient(90deg, hsl(0,62%,52%), hsl(120,62%,44%), hsl(240,62%,52%));
}
.hdm-palette-swatch--cb {
  background: linear-gradient(90deg, hsl(210,62%,52%), hsl(30,70%,50%), hsl(280,50%,55%));
}

/* Muted sound button state */
.icon-btn--off { opacity: 0.38; }
.icon-btn--off:hover { opacity: 0.75; border-color: #ccc8c0; color: var(--text); }

/* ── About modal ──────────────────────────────────────────────────────────────── */
.about-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(28,24,20,0.42); backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity 0.22s;
}
.about-overlay.open { opacity: 1; pointer-events: all; }

.about-card {
  background: var(--bg); border: 1px solid var(--sep);
  border-radius: 14px; padding: 42px 46px 38px;
  max-width: 500px; width: 90%; position: relative;
  box-shadow: 0 24px 64px rgba(28,24,20,0.18);
  max-height: 88vh; overflow-y: auto;
}
.about-close {
  position: absolute; top: 14px; right: 16px;
  width: 27px; height: 27px; border-radius: 50%;
  background: none; border: 1px solid var(--sep); cursor: pointer;
  font-size: 16px; color: var(--text-dim); line-height: 1;
  display: flex; align-items: center; justify-content: center;
  transition: border-color 0.2s, color 0.2s;
}
.about-close:hover { border-color: #ccc8c0; color: var(--text); }

.about-intro {
  font-family: var(--font-serif);
  font-size: 14.5px; font-weight: 400; font-style: italic;
  color: var(--text); line-height: 1.65; margin-bottom: 30px;
}
.about-flower-wrap { display: flex; justify-content: center; margin-bottom: 26px; }
.about-body {
  font-size: 13px; color: var(--text-dim); line-height: 1.9; margin-bottom: 24px;
}
.about-body svg { display: inline-block; vertical-align: middle; margin: 0 2px 2px; }
.about-footer { font-size: 13px; color: var(--text-dim); line-height: 1.72; }
.about-footer a { color: var(--accent); text-decoration: none; }
.about-footer a:hover { text-decoration: underline; }

/* ── Note colour pills ────────────────────────────────────────────────────────── */
/* --nh must be set inline on the parent .note-cell by JS: style="--nh:${hue}" */

.note-cell {
  display: flex; align-items: center; justify-content: center;
  width: 28px; height: 26px;
  flex-shrink: 0; position: relative;
}

.note-pill {
  display: flex; align-items: center; justify-content: center;
  width: 25px; height: 21px;
  border-radius: 4px;
  font-size: 10px; font-weight: 600;
  letter-spacing: -0.02em;
  position: relative;
  transition: transform 0.1s;
  cursor: default;
}

/* inactive — note exists in chromatic context but not in current scale/chord */
.note-pill.inactive {
  font-size: 9px; font-weight: 400;
  color: var(--text-faint);
  background: none;
}

/* ctx — small context label (interval name, Roman numeral) */
.note-pill.ctx {
  font-size: 8px; color: var(--text-faint);
  background: none; width: 20px;
}

/* root — tonic of the current chord or scale */
.note-pill.root {
  background: hsl(var(--nh), 52%, 90%);
  color: hsl(var(--nh), 52%, 28%);
  border: 1px solid hsl(var(--nh), 52%, 72%, 0.8);
  box-shadow: 0 0 8px hsl(var(--nh), 52%, 60%, 0.25);
  font-weight: 700;
  cursor: pointer;
}

/* active — note is in the current scale or chord */
.note-pill.active {
  background: linear-gradient(135deg, #f0ede8 62%, hsl(var(--nh), 22%, 87%));
  color: hsl(var(--nh), 22%, 46%);
  border: 1px solid hsl(var(--nh), 10%, 84%);
  cursor: pointer;
}

/* secondary — present but subordinate (e.g. extension) */
.note-pill.secondary {
  background: linear-gradient(135deg, #f0ede8 62%, hsl(var(--nh), 22%, 87%));
  color: hsl(var(--nh), 22%, 46%);
  border: 1px solid hsl(var(--nh), 10%, 84%);
  cursor: pointer;
}

/* borrowed — from parallel key or modal mixture */
.note-pill.borrowed {
  background: linear-gradient(135deg, #f0ede8 62%, hsl(var(--nh), 22%, 87%));
  color: hsl(var(--nh), 22%, 46%);
  border: 1px dashed hsl(var(--nh), 10%, 80%);
  cursor: pointer;
}

/* optional seventh — rendered at reduced opacity */
.note-pill.seventh { border-style: dashed !important; opacity: 0.72; }

.note-pill:not(.inactive):not(.ctx):hover { transform: scale(1.12); z-index: 20; }

/* ── Dark mode pill overrides ─────────────────────────────────────────────────
   Apply when <html data-theme="dark"> is set. */
[data-theme="dark"] .note-pill.inactive { color: #4e4e68; }
[data-theme="dark"] .note-pill.ctx      { color: #181828; }
[data-theme="dark"] .note-pill.root {
  background: hsl(var(--nh), var(--cb-s), 18%);
  color: hsl(var(--nh), var(--cb-s), 74%);
  border: 1px solid hsl(var(--nh), var(--cb-s), 52%, 0.7);
  box-shadow: 0 0 10px hsl(var(--nh), var(--cb-s), 42%, 0.45);
}
[data-theme="dark"] .note-pill.active,
[data-theme="dark"] .note-pill.secondary,
[data-theme="dark"] .note-pill.borrowed {
  background: linear-gradient(135deg, #16161e 62%, hsl(var(--nh), var(--pill-s), 22%));
  color: #7a7a94;
  border-color: #252535;
}
[data-theme="dark"] .note-pill.borrowed { border-style: dashed; }

/* ── Tooltip ──────────────────────────────────────────────────────────────────── */
.tip {
  position: absolute; bottom: calc(100% + 7px); left: 50%;
  transform: translateX(-50%);
  background: #fff; border: 1px solid var(--sep);
  border-radius: 6px; padding: 6px 10px;
  font-size: 11px; color: var(--text);
  white-space: nowrap; pointer-events: none;
  opacity: 0; transition: opacity 0.12s;
  z-index: 1000; box-shadow: 0 4px 16px rgba(28,24,20,0.12);
  line-height: 1.5;
}
.note-pill:hover .tip { opacity: 1; }
.tip-note  { font-weight: 700; color: var(--text); }
.tip-enh   { font-size: 9px; color: var(--text-faint); margin-left: 5px; }
.tip-spell { display: block; font-size: 9px; color: var(--text-faint); margin-top: 2px; font-style: italic; }
.tip-int   { color: var(--text-dim); font-size: 10px; }
.tip-deg   { color: hsl(var(--nh), 60%, 38%); font-size: 10px; }

[data-theme="dark"] .tip {
  background: #1c1c2a; border-color: #2e2e42;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}
[data-theme="dark"] .tip-note  { color: #fff; }
[data-theme="dark"] .tip-deg   { color: hsl(var(--nh), 80%, 68%); }

/* ── Colorbar ─────────────────────────────────────────────────────────────────── */
.note-colorbar {
  flex-shrink: 0; width: 80px; height: 6px;
  align-self: center; margin-left: 8px;
  border-radius: 3px; opacity: 0.7;
}

/* ── Strip layout (story pages) ───────────────────────────────────────────────── */
/* Positioned by the strip engine; story pages add this class to strip wrappers. */
.strip-item {
  position: absolute;
  width: 100%;
  max-width: 600px;
  left: 50%;
  transform: translateX(-50%);
  transition: top 0.42s cubic-bezier(0.25, 0.1, 0.25, 1), opacity 0.35s ease;
}
.strip-item.traveling,
.strip-item.traveling-out { transition: opacity 0.15s ease; }
.strip-item.leaving       { transition: opacity 0.32s ease; pointer-events: none; }
.strip-item.dim     { opacity: 0.45; }
.strip-item.dim:hover   { opacity: 1; transition: top 0.42s cubic-bezier(0.25, 0.1, 0.25, 1), opacity 0.1s; }
.strip-item.muted   { opacity: 0.25; }
.strip-item.muted:hover { opacity: 0.7;  transition: top 0.42s cubic-bezier(0.25, 0.1, 0.25, 1), opacity 0.1s; }

.strip-row   { display: flex; align-items: center; }
.strip-label {
  width: 130px; flex-shrink: 0;
  text-align: right; padding-right: 14px;
  line-height: 1.25; cursor: pointer; user-select: none;
}
.strip-label strong { display: block; font-size: 11px; font-weight: 500; color: var(--text); }
.strip-label .sub   { display: block; font-size: 9px; color: var(--text-dim); margin-top: 1px; }

.strip { display: flex; align-items: center; flex: 1; min-width: 0; }

/* ── Inline flower (spinning or static, used in body text) ───────────────────── */
@keyframes flowerSpin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}
.flower-spin {
  transform-box: fill-box; transform-origin: 50% 50%;
  animation: flowerSpin 28s linear infinite;
}

/* ── Inline chord label (flower + text in running prose) ─────────────────────── */
.inline-chord {
  cursor: pointer; display: inline-flex; align-items: center;
  gap: 2px; padding: 1px 5px 1px 2px; border-radius: 4px;
  transition: background 0.1s; white-space: nowrap;
}
.inline-chord:hover { background: rgba(28,24,20,0.05); }
[data-theme="dark"] .inline-chord:hover { background: rgba(255,255,255,0.06); }
