:root {
  --navy-900: #0b132b;
  --navy-800: #121c38;
  --navy-700: #1a2747;
  --navy-600: #243355;
  --navy-line: #2e3f63;
  --brass-400: #e6b65a;
  --brass-300: #f0c878;
  --brass-500: #cf9f3e;
  --brass-600: #b3862f;
  --ink: #2a2014;
  --parchment: #f5efde;
  --parchment-shade: #ece4cf;
  --text: #e8edf7;
  --text-dim: #9fb0d1;
  --text-faint: #6f80a3;
  --good: #7ee0a0;
  --shadow: 0 18px 48px rgba(0,0,0,0.45);
  --radius: 16px;
  --font-ui: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: "Cormorant Garamond", Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: var(--font-ui);
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(207,159,62,0.10), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(46,63,99,0.55), transparent 60%),
    linear-gradient(160deg, var(--navy-900) 0%, var(--navy-800) 60%, var(--navy-900) 100%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.app {
  max-width: 1080px;
  margin: 0 auto;
  padding: 40px 24px 56px;
}

/* ---------- Hero ---------- */
.hero {
  text-align: center;
  margin-bottom: 34px;
}
.hero-mark {
  font-size: 34px;
  color: var(--brass-400);
  line-height: 1;
  margin-bottom: 8px;
  filter: drop-shadow(0 0 14px rgba(230,182,90,0.4));
}
.hero h1 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(34px, 6vw, 54px);
  margin: 0 0 10px;
  letter-spacing: 0.5px;
  background: linear-gradient(180deg, #fff 0%, var(--brass-300) 130%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.subtitle {
  color: var(--text-dim);
  font-size: 15px;
  max-width: 620px;
  margin: 0 auto;
  line-height: 1.6;
}
.subtitle strong { color: var(--brass-300); font-weight: 600; }

/* ---------- Controls ---------- */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: flex-end;
  justify-content: center;
  background: linear-gradient(180deg, var(--navy-700), var(--navy-800));
  border: 1px solid var(--navy-line);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow);
}
.control {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 150px;
  flex: 1 1 150px;
  max-width: 220px;
}
.control-narrow {
  min-width: 130px;
  flex: 0 1 130px;
  max-width: 150px;
}
.control-toggle {
  min-width: 120px;
  flex: 0 0 auto;
  max-width: 150px;
  align-items: flex-start;
  padding-top: 2px;
}

/* ---------- Toggle switch ---------- */
.switch {
  position: relative;
  display: inline-block;
  cursor: pointer;
  height: 44px;
  display: flex;
  align-items: center;
}
.switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.switch-track {
  width: 52px;
  height: 28px;
  border-radius: 999px;
  background: var(--navy-900);
  border: 1px solid var(--navy-line);
  position: relative;
  transition: background 0.22s ease, border-color 0.22s ease;
  flex-shrink: 0;
}
.switch-thumb {
  position: absolute;
  top: 50%;
  left: 3px;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--text-faint);
  transition: transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.22s ease;
}
.switch input:checked + .switch-track {
  background: linear-gradient(180deg, var(--brass-300), var(--brass-500));
  border-color: var(--brass-600);
}
.switch input:checked + .switch-track .switch-thumb {
  transform: translateY(-50%) translateX(24px);
  background: var(--navy-900);
}
.switch input:focus-visible + .switch-track {
  outline: none;
  box-shadow: 0 0 0 3px rgba(230,182,90,0.22);
}
.control label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--brass-300);
}

/* ---------- Settings toggle ---------- */
.settings-toggle {
  display: none;
  align-items: center;
  gap: 8px;
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  background: var(--navy-800);
  border: 1px solid var(--navy-line);
  border-radius: 10px;
  padding: 12px 16px;
  cursor: pointer;
  letter-spacing: 0.5px;
  transition: color 0.18s ease, border-color 0.18s ease, background 0.18s ease;
  align-self: flex-end;
  height: 44px;
}
.settings-toggle:hover {
  color: var(--brass-300);
  border-color: var(--brass-600);
  background: var(--navy-700);
}
.settings-toggle[aria-expanded="true"] {
  color: var(--brass-300);
  border-color: var(--brass-600);
  background: var(--navy-700);
}
.settings-icon { font-size: 15px; }
.settings-caret {
  font-size: 10px;
  transition: transform 0.25s ease;
}
.settings-toggle[aria-expanded="true"] .settings-caret {
  transform: rotate(180deg);
}

/* ---------- Advanced controls panel ---------- */
.advanced-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: flex-end;
  width: 100%;
}

/* Hide mobile-only octave controls on desktop */
.octave-control-mobile { display: none; }
.select-wrap {
  position: relative;
}
.select-wrap select {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  font-family: var(--font-ui);
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  background: var(--navy-900);
  border: 1px solid var(--navy-line);
  border-radius: 10px;
  padding: 12px 36px 12px 14px;
  cursor: pointer;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}
.select-wrap select:hover {
  border-color: var(--brass-600);
  background: #0d1730;
}
.select-wrap select:focus {
  outline: none;
  border-color: var(--brass-400);
  box-shadow: 0 0 0 3px rgba(230,182,90,0.22);
}
.select-wrap select option {
  background: var(--navy-900);
  color: var(--text);
}
.select-caret {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--brass-400);
  pointer-events: none;
  font-size: 12px;
}

/* ---------- Play button ---------- */
.play-btn {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-family: var(--font-ui);
  font-size: 15px;
  font-weight: 600;
  color: var(--navy-900);
  background: linear-gradient(180deg, var(--brass-300), var(--brass-500));
  border: none;
  border-radius: 10px;
  padding: 12px 22px;
  cursor: pointer;
  letter-spacing: 0.3px;
  box-shadow: 0 6px 18px rgba(207,159,62,0.28);
  transition: transform 0.12s ease, box-shadow 0.18s ease, filter 0.18s ease;
  align-self: flex-end;
  height: 44px;
}
.play-btn:hover { filter: brightness(1.06); box-shadow: 0 8px 22px rgba(207,159,62,0.4); }
.play-btn:active { transform: translateY(1px); }
.play-btn:disabled { opacity: 0.5; cursor: default; filter: grayscale(0.3); box-shadow: none; }
.play-icon { font-size: 11px; }
.play-btn.playing .play-icon { font-size: 12px; }

/* ---------- Info bar ---------- */
.info-bar {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin: 22px 0 6px;
  flex-wrap: wrap;
}
.info-chip {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.5px;
  color: var(--brass-300);
  background: rgba(230,182,90,0.08);
  border: 1px solid rgba(230,182,90,0.2);
  border-radius: 999px;
  padding: 6px 14px;
}
.info-chip.muted { color: var(--text-faint); background: rgba(159,176,209,0.06); border-color: rgba(159,176,209,0.16); }

/* ---------- Notation ---------- */
.notation {
  margin-top: 18px;
  background: linear-gradient(180deg, var(--parchment) 0%, var(--parchment-shade) 100%);
  border: 1px solid #d9cfb4;
  border-radius: var(--radius);
  padding: 26px 18px 18px;
  min-height: 240px;
  box-shadow: var(--shadow), inset 0 0 0 1px rgba(255,255,255,0.4);
  position: relative;
  overflow-x: auto;
}
.notation::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  pointer-events: none;
  box-shadow: inset 0 60px 70px -50px rgba(120,100,50,0.25);
}
#vexflow-output {
  display: flex;
  justify-content: center;
}
#vexflow-output svg {
  max-width: 100%;
  height: auto;
  display: block;
}
.notation-hint {
  text-align: center;
  color: var(--ink);
  opacity: 0.6;
  font-size: 14px;
  margin-top: 14px;
}
.hidden { display: none !important; }

/* ---------- Note names strip ---------- */
.note-names {
  text-align: center;
  margin: 14px auto 0;
  padding: 14px 18px;
  max-width: 100%;
  line-height: 2.4;
  font-size: 15px;
  font-weight: 500;
  color: var(--text-dim);
  background: linear-gradient(180deg, var(--navy-700), var(--navy-800));
  border: 1px solid var(--navy-line);
  border-radius: 12px;
  letter-spacing: 0.3px;
  word-break: break-word;
  position: relative;
  max-height: 8em; /* ~3 lines */
  overflow: hidden;
  transition: max-height 0.35s ease;
}
.note-names.expanded {
  max-height: 9999px;
}

/* Gradient fade at bottom when collapsed */
.note-names.has-overflow:not(.expanded)::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3em;
  background: linear-gradient(to bottom, transparent, var(--navy-800));
  pointer-events: none;
  border-radius: 0 0 11px 11px;
}

/* Show more / less toggle button */
.note-toggle {
  display: none;
  position: absolute;
  bottom: 6px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2;
  padding: 6px 16px;
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 600;
  color: var(--brass-300);
  background: var(--navy-700);
  border: 1px solid rgba(230,182,90,0.25);
  border-radius: 8px;
  cursor: pointer;
  letter-spacing: 0.3px;
  transition: background 0.18s ease, border-color 0.18s ease;
}
.note-toggle:hover {
  background: rgba(230,182,90,0.10);
  border-color: var(--brass-500);
}
.note-names.has-overflow .note-toggle { display: block; }
.note-name {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 6px;
  transition: transform 0.14s ease, background 0.14s ease, color 0.14s ease, box-shadow 0.14s ease;
  font-family: var(--font-ui);
}
.note-name.active {
  background: linear-gradient(180deg, var(--brass-300), var(--brass-500));
  color: var(--navy-900);
  transform: scale(1.18);
  box-shadow: 0 3px 12px rgba(207,159,62,0.5);
  font-weight: 700;
}
.note-sep {
  color: var(--text-faint);
  opacity: 0.4;
  margin: 0 1px;
}

/* ---------- Footer ---------- */
.foot {
  margin-top: 26px;
  text-align: center;
  font-size: 12px;
  color: var(--text-faint);
  letter-spacing: 0.3px;
}

/* ---------- Responsive ---------- */
/* Tablet & small desktop: compact controls but full layout */
@media (max-width: 860px) {
  .controls { gap: 12px; padding: 16px 18px; }
  .control { min-width: 130px; flex: 1 1 140px; max-width: 200px; }
  .control-narrow { min-width: 110px; flex: 0 1 120px; max-width: 140px; }
  .control-toggle { min-width: 110px; max-width: 140px; }
  .play-btn { padding: 12px 18px; }
}

/* Mobile: collapsed advanced panel, 2-col grid, inline toggles */
@media (max-width: 640px) {
  .app { padding: 24px 12px 36px; }
  .hero { margin-bottom: 22px; }
  .hero h1 { font-size: clamp(28px, 8vw, 44px); }
  .subtitle { display: none; }

  .controls {
    gap: 10px;
    padding: 14px 12px;
    justify-content: stretch;
  }

  /* Primary controls in a 2-column grid */
  .control {
    flex: 1 1 calc(50% - 5px);
    min-width: 0;
    max-width: none;
    gap: 6px;
  }
  .control-narrow {
    flex: 1 1 calc(50% - 5px);
    min-width: 0;
    max-width: none;
  }
  .control label { font-size: 12px; letter-spacing: 1.1px; }
  .select-wrap select { font-size: 15px; padding: 10px 32px 10px 12px; }
  .select-caret { right: 10px; font-size: 10px; }

  /* Play button beside Settings toggle */
  .play-btn {
    flex: 1 1 calc(50% - 5px);
    min-width: 0;
    max-width: none;
    width: auto;
    justify-content: center;
    order: 98;
  }

  /* Settings toggle beside Play button */
  .settings-toggle {
    display: flex;
    flex: 1 1 calc(50% - 5px);
    min-width: 0;
    max-width: none;
    justify-content: center;
    order: 99;
  }

  /* Hide main octave controls, show mobile duplicates */
  .octave-control { display: none; }
  .octave-control-mobile { display: flex; }

  /* Advanced controls collapsible on mobile */
  .advanced-controls {
    gap: 10px;
    overflow: hidden;
    transition: max-height 0.35s ease, opacity 0.25s ease, margin-top 0.3s ease;
    max-height: 500px;
    opacity: 1;
  }
  .advanced-controls .control label { font-size: 12px; letter-spacing: 1.1px; }
  .advanced-controls.collapsed {
    max-height: 0;
    opacity: 0;
    pointer-events: none;
  }
  .advanced-controls .control,
  .advanced-controls .control-narrow {
    flex: 1 1 calc(50% - 5px);
    min-width: 0;
    max-width: none;
  }

  /* Toggles inline: label beside switch */
  .advanced-controls .control-toggle {
    flex: 1 1 100%;
    max-width: none;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding-top: 0;
    gap: 0;
  }
  .advanced-controls .control-toggle label:first-of-type {
    font-size: 13px;
    letter-spacing: 0.8px;
  }

  .info-bar { display: none; }
  .info-chip { font-size: 12px; padding: 5px 10px; }
  .notation { padding: 18px 10px 12px; min-height: 180px; }
  .note-names { font-size: 13px; padding: 10px 14px; }
  .foot { font-size: 11px; margin-top: 18px; }
}

/* Mobile landscape: 3-column grid, Play button inline beside Settings */
@media (max-width: 900px) and (orientation: landscape) {
  .app { padding: 16px 14px 28px; }
  .hero { margin-bottom: 12px; }
  .hero h1 { font-size: clamp(22px, 5vw, 36px); }
  .subtitle { display: none; }

  .controls {
    gap: 8px;
    padding: 12px 14px;
    justify-content: stretch;
  }

  /* Primary controls in a 3-column grid */
  .control,
  .control-narrow {
    flex: 1 1 calc(33.33% - 6px);
    min-width: 0;
    max-width: none;
    gap: 4px;
  }
  .control label { font-size: 11px; letter-spacing: 1px; }
  .select-wrap select { font-size: 14px; padding: 8px 28px 8px 10px; }
  .select-caret { right: 8px; font-size: 9px; }

  /* Play button inline beside Settings toggle */
  .play-btn {
    flex: 1 1 calc(33.33% - 6px);
    min-width: 0;
    max-width: none;
    width: auto;
    padding: 8px 12px;
    height: 38px;
    font-size: 13px;
    order: 98;
  }

  /* Settings toggle visible on mobile */
  .settings-toggle {
    display: flex;
    flex: 1 1 calc(33.33% - 6px);
    min-width: 0;
    max-width: none;
    padding: 8px 12px;
    height: 38px;
    font-size: 12px;
    order: 99;
  }

  /* Hide main octave controls, show mobile duplicates */
  .octave-control { display: none; }
  .octave-control-mobile { display: flex; }

  /* Advanced controls: 3-col for dropdowns, toggles in a row */
  .advanced-controls {
    gap: 8px;
    overflow: hidden;
    transition: max-height 0.35s ease, opacity 0.25s ease, margin-top 0.3s ease;
    max-height: 400px;
    opacity: 1;
  }
  .advanced-controls.collapsed {
    max-height: 0;
    opacity: 0;
    pointer-events: none;
  }
  .advanced-controls .control,
  .advanced-controls .control-narrow {
    flex: 1 1 calc(33.33% - 6px);
    min-width: 0;
    max-width: none;
  }

  /* Toggles: 3 across in a single row */
  .advanced-controls .control-toggle {
    flex: 1 1 calc(33.33% - 6px);
    max-width: none;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding-top: 0;
    gap: 0;
  }
  .advanced-controls .control-toggle label:first-of-type {
    font-size: 12px;
    letter-spacing: 0.6px;
  }

  .info-bar { display: none; }
  .info-chip { font-size: 11px; padding: 3px 8px; }
  .notation { padding: 12px 8px 8px; min-height: 130px; }
  .note-names { font-size: 12px; padding: 8px 12px; line-height: 2; }
  .foot { font-size: 10px; margin-top: 10px; }
}
