/* Layout: one-column reference page; sticky instrument bar, chart as a dense grid of
   note cards (staff over key diagram), tap opens a bottom sheet with the large view. */
:root {
  --paper: #f3f5f8;      /* staff-paper ground, cool */
  --card: #ffffff;
  --ink: #17223a;        /* band-uniform navy: pressed keys, noteheads, text */
  --muted: #5a6478;
  --line: #cfd5df;
  --tube: #e9edf3;
  --brass: #a8740f;      /* lacquer brass: focus, play, accents */
  --brass-soft: #f4e8cc;
  --scrim: rgba(12, 18, 30, .45);
  --display: "Instrument Serif", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --body: "Atkinson Hyperlegible", "Segoe UI", system-ui, -apple-system, sans-serif;
  --music: "Noto Music", "Segoe UI Symbol", "Apple Symbols", "Atkinson Hyperlegible", serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0f141d; --card: #171e2b; --ink: #e7ebf2; --muted: #9ba5b7; --line: #343f54;
    --tube: #1e2635; --brass: #e2b04f; --brass-soft: #3a2f17; --scrim: rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #0f141d; --card: #171e2b; --ink: #e7ebf2; --muted: #9ba5b7; --line: #343f54;
  --tube: #1e2635; --brass: #e2b04f; --brass-soft: #3a2f17; --scrim: rgba(0, 0, 0, .6);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 16px/1.5 var(--body);
}
a { color: inherit; }
:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }

/* ---- top bar */
.bar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5;
  display: flex; align-items: center; gap: 14px;
  padding: 10px 16px; background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.mark { font-family: var(--display); font-size: 1.35rem; text-decoration: none; white-space: nowrap; line-height: 1; }
.mark .m1 { font-style: italic; color: var(--brass); }
.inav { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; min-width: 0; }
.inav::-webkit-scrollbar { display: none; }
.inav a {
  text-decoration: none; font-size: .9rem; white-space: nowrap;
  padding: 6px 10px; border-radius: 999px; color: var(--muted);
}
.inav a:hover { color: var(--ink); }
.inav a[aria-current="page"] { background: var(--ink); color: var(--paper); }

/* ---- page frame */
main { max-width: 1040px; margin: 0 auto; padding: 0 16px; }
.ihead, .hhead { padding-block: 28px 8px; max-width: 42rem; }
.eyebrow { margin: 0 0 4px; font-size: .78rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
h1 {
  font-family: var(--display); font-weight: 400; font-size: clamp(2.2rem, 7vw, 3.4rem);
  line-height: 1.02; margin: 0 0 12px; text-wrap: balance; letter-spacing: -.01em;
}
.lede { margin: 0 0 8px; font-size: 1.05rem; }
.pitch { margin: 0; font-size: .9rem; color: var(--muted); }
h2 { font-size: 1rem; font-weight: 700; margin: 0 0 10px; text-wrap: balance; }

/* ---- chart grid */
.grp { padding-block: 22px 4px; }
.grp h2 { display: flex; align-items: baseline; gap: 10px; }
.grp h2::after { content: ""; flex: 1; border-bottom: 1px solid var(--line); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 8px; }
.note {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 4px 8px; background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent;
  transition: border-color .15s, transform .15s;
}
.note:hover { border-color: var(--brass); }
.note:active { transform: scale(.97); }
.note.sel { border-color: var(--brass); box-shadow: 0 0 0 2px var(--brass-soft); }
.note .st { width: 100%; height: auto; }
.note .nm { font-weight: 700; font-size: .85rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.note .dg { width: 74%; height: auto; }
.note .ft { font-size: .72rem; color: var(--muted); text-align: center; line-height: 1.2; }
.note .badge {
  position: absolute; top: 4px; right: 4px; font-size: .6rem; letter-spacing: .06em; text-transform: uppercase;
  padding: 1px 5px; border-radius: 4px; background: var(--brass-soft); color: var(--ink);
}

/* ---- svg parts (shared by cards and sheet) */
.dg .tube { fill: var(--tube); }
.dg .split { stroke: var(--line); stroke-width: .8; stroke-dasharray: 2 2; }
.dg .k > * { fill: var(--card); stroke: var(--ink); stroke-width: .9; }
.dg .k.on > * { fill: var(--ink); }
.dg .lbl { display: none; font: 700 4.1px var(--body); fill: var(--muted); }
.dg .lbi { display: none; font: 700 2.6px var(--body); fill: var(--ink); }
.dg .lbi.on { fill: var(--card); }
.dg .vn { font: 700 9px var(--body); fill: var(--ink); }
.dg .vn.on { fill: var(--card); }
.dg .slide { stroke: var(--line); stroke-width: 3; stroke-linecap: round; }
.dg .tick { stroke: var(--muted); stroke-width: .8; }
.dg .pn { font: 400 6.4px var(--body); fill: var(--muted); }
.dg .pn.cur { font-weight: 700; fill: var(--ink); }
.dg .arrow { stroke: var(--brass); stroke-width: 1.4; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.st .sl, .st .ll { stroke: var(--muted); stroke-width: .55; }
.st .nh { fill: var(--ink); }
.st .acc { font: 9px var(--music); fill: var(--ink); }

/* ---- prose */
.notes-text { max-width: 40rem; padding-block: 32px 8px; }
.notes-text h2 { margin-top: 18px; }
.notes-text p { margin: 0 0 10px; color: var(--ink); }

/* ---- home */
.igrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; padding-block: 16px; }
.icard {
  display: grid; grid-template-columns: 44px 1fr; grid-template-rows: auto auto; column-gap: 12px; align-items: center;
  padding: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; text-decoration: none;
}
.icard:hover { border-color: var(--brass); }
.icard .dg { grid-row: span 2; width: 44px; height: 88px; }
.icard .iname { font-family: var(--display); font-size: 1.5rem; line-height: 1; align-self: end; }
.icard .irange { font-size: .8rem; color: var(--muted); align-self: start; }

.foot { max-width: 1040px; margin: 40px auto 0; padding: 20px 16px 36px; border-top: 1px solid var(--line); font-size: .85rem; color: var(--muted); }
.foot p { margin: 0 0 4px; }
.foot strong { color: var(--ink); font-weight: 700; }

/* ---- bottom sheet */
.scrim { position: fixed; inset: 0; background: var(--scrim); z-index: 20; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21;
  max-height: 92vh; max-height: 92dvh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--card); border-radius: 18px 18px 0 0;
  padding: 10px 16px calc(18px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -8px 30px rgba(0, 0, 0, .18);
  animation: up .22s ease-out;
}
@keyframes up { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } .note { transition: none; } }
@media (min-width: 700px) {
  .sheet { left: 50%; right: auto; bottom: 50%; width: 460px; transform: translate(-50%, 50%); border-radius: 18px; animation: none; }
}
.sh-top { display: flex; align-items: center; gap: 6px; }
.sh-title { flex: 1; text-align: center; min-width: 0; }
.sh-name { font-family: var(--display); font-size: 2.1rem; line-height: 1.05; }
.sh-sub { font-size: .85rem; color: var(--muted); }
.sh-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: var(--card);
  color: var(--ink); font-size: 1.5rem; line-height: 1; cursor: pointer; flex: none;
}
.sh-x { border-color: transparent; font-size: 1.7rem; }
.sh-body { display: grid; grid-template-columns: 0.8fr 1fr; gap: 12px; align-items: center; padding-block: 8px 4px; }
.sh-staff svg { width: 100%; height: auto; }
.sh-dg svg { width: 100%; height: auto; max-height: 48vh; display: block; margin: 0 auto; }
.sh-dg .lbl, .alt .lbl, .sh-dg .lbi, .alt .lbi { display: block; }
.sh-ft { text-align: center; font-weight: 700; min-height: 0; }
.sh-ft:empty { display: none; }
.play {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
  margin: 10px 0 4px; padding: 12px; border: 0; border-radius: 12px;
  background: var(--brass); color: var(--card); font: 700 1rem var(--body); cursor: pointer;
}
.play svg { width: 18px; height: 18px; fill: currentColor; }
.play.on { filter: brightness(1.1); }
.sh-more .tip { margin: 12px 0 0; padding: 10px 12px; border-radius: 10px; background: var(--brass-soft); font-size: .95rem; }
.sh-more .alts-h { margin: 16px 0 8px; font-size: .78rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.sh-more .alts { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.alt { margin: 0; padding: 8px; border: 1px solid var(--line); border-radius: 10px; text-align: center; }
.alt svg { width: 70%; height: auto; }
.alt figcaption { font-size: .85rem; font-weight: 700; line-height: 1.25; }
.alt figcaption span { display: block; font-weight: 400; color: var(--muted); }
.sh-brand { margin: 14px 0 0; text-align: center; font-size: .75rem; letter-spacing: .04em; color: var(--muted); }
body.locked { overflow: hidden; }

/* ---- instrument sub-navigation */
.sub { display: flex; gap: 6px; flex-wrap: wrap; padding-block: 14px 0; }
.sub a {
  text-decoration: none; font-size: .9rem; padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--muted); background: var(--card);
}
.sub a:hover { color: var(--ink); border-color: var(--brass); }
.sub a[aria-current="page"] { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.also { margin-top: 18px; }
.also a, .notes-text a { color: var(--ink); text-decoration-color: var(--brass); text-underline-offset: 3px; }

/* ---- scales */
.keyjump { display: flex; flex-wrap: wrap; gap: 4px; padding-block: 16px 0; }
.keyjump a {
  min-width: 40px; text-align: center; text-decoration: none; font-weight: 700; font-size: .9rem;
  padding: 6px 8px; border-radius: 8px; background: var(--card); border: 1px solid var(--line);
}
.keyjump a:hover { border-color: var(--brass); }
.scale { scroll-margin-top: 64px; }
.scale h2 { flex-wrap: wrap; }
.scale .wk { font-weight: 400; color: var(--muted); font-size: .9rem; }
.pscale {
  display: inline-flex; align-items: center; gap: 6px; margin: 0 0 10px; padding: 6px 12px;
  border: 1px solid var(--brass); border-radius: 999px; background: transparent; color: var(--ink);
  font: 700 .85rem var(--body); cursor: pointer;
}
.pscale svg { width: 12px; height: 12px; fill: var(--brass); }
.pscale.on { background: var(--brass-soft); }
.grid.g8 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (min-width: 720px) { .grid.g8 { grid-template-columns: repeat(8, minmax(0, 1fr)); } }

/* ---- trills */
.legend { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 6px 0 0; font-size: .9rem; color: var(--muted); }
.legend .sw { display: inline-block; width: 14px; height: 14px; border-radius: 50%; border: 1.5px solid var(--ink); background: var(--card); }
.legend .sw.on { background: var(--ink); }
.legend .sw.tr { background: var(--brass); border-color: var(--brass); margin-left: 10px; }
.dg .k.tr > * { fill: var(--card); stroke: var(--brass); stroke-width: 1.6; }
.dg .k.tr.on > * { fill: var(--brass); }

/* ---- half-hole, valve labels */
.dg .half { fill: var(--ink); }
.dg .vn.sm { font-size: 6.5px; }

/* ---- transposition page */
.tpage .conv { padding-block: 16px 0; }
.convrow { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.convrow label { font-weight: 700; }
.convrow select {
  font: 1rem var(--body); padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); min-width: 0; max-width: 100%;
}
.tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--line); border-radius: 10px; background: var(--card); }
.convgrid, .tt { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
.convgrid th, .convgrid td { padding: 8px 6px; text-align: center; border-bottom: 1px solid var(--line); white-space: nowrap; }
.convgrid th { text-align: left; font-size: .8rem; color: var(--muted); font-weight: 700; padding-left: 10px; }
.convgrid tr.wr td { font-weight: 700; font-size: 1.05rem; color: var(--brass); }
.convgrid tr:last-child > * { border-bottom: 0; }
.tt th, .tt td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tt thead th { font-size: .78rem; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.tt tbody tr:last-child > * { border-bottom: 0; }
.tt a { text-decoration: none; }
.tt a:hover { text-decoration: underline; text-decoration-color: var(--brass); }
.tt .iv { color: var(--muted); white-space: normal; min-width: 14rem; }

/* ---- home reference card */
.icard.ref { grid-template-columns: 1fr; }
.icard.ref .iname { font-size: 1.35rem; }

/* ---- popular notes */
.popular { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding-block: 12px 0; font-size: .85rem; }
.popular span { color: var(--muted); }
.popular a { text-decoration: none; padding: 3px 9px; border-radius: 999px; background: var(--brass-soft); color: var(--ink); }
.popular a:hover { text-decoration: underline; }

/* ---- songs */
.songbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding-block: 14px 0; }
.songbar .pscale { margin: 0; }
.songbar .pitch { margin: 0; }
.songlist { display: grid; gap: 8px; }
.songrow {
  display: flex; flex-direction: column; gap: 2px; padding: 12px 14px; text-decoration: none;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
}
.songrow:hover { border-color: var(--brass); }
.songrow .sname { font-family: var(--display); font-size: 1.45rem; line-height: 1.1; }
.songrow .snotes { font-size: .85rem; color: var(--muted); }

/* ---- single-note page */
.onenote {
  display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; margin-top: 18px; padding: 16px;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
}
@media (min-width: 640px) { .onenote { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: center; } }
.on-fig { display: grid; grid-template-columns: 0.8fr 1fr; gap: 10px; align-items: center; }
.on-staff svg { width: 100%; height: auto; }
.on-dg svg { width: 100%; height: auto; max-height: 380px; }
.on-dg .lbl, .on-dg .lbi, .alts .lbl, .alts .lbi { display: block; }
.on-name { font-family: var(--display); font-size: 3rem; line-height: 1; margin: 0 0 8px; }
.on-words { margin: 0 0 10px; font-size: 1.02rem; }
.on-txt .tip { margin: 0 0 12px; padding: 10px 12px; border-radius: 10px; background: var(--brass-soft); font-size: .95rem; }
.alts { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.alts figcaption span { font-size: .8rem; }

/* ---- printables */
.pgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; padding-block: 16px; }
.pcard { margin: 0; background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.pcard img { display: block; width: 100%; height: auto; aspect-ratio: 11 / 8.5; object-fit: cover; background: #fff; border-bottom: 1px solid var(--line); }
.pcard figcaption { display: flex; flex-direction: column; gap: 2px; padding: 8px 10px 10px; }
.pcard .iname { font-family: var(--display); font-size: 1.25rem; line-height: 1.1; }
.pcard .pitch { font-size: .78rem; }
.dl { font-weight: 700; color: var(--ink); text-decoration-color: var(--brass); text-underline-offset: 3px; font-size: .9rem; }
.printfig figure { margin: 0; }
.printfig img { display: block; width: 100%; height: auto; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.printfig figcaption { font-size: .85rem; color: var(--muted); margin-top: 6px; }
