/* ============================================================
   FRETBOARD
   ------------------------------------------------------------
   One stylesheet. The palette is the Collect Workshop's and
   Psalm Drone's, which is thecommonwild.org's -- cream stock,
   warm near-black, one earth accent -- taken over wholesale, so
   the workshop tools are recognisably one set of hands.

   --accent marks the root: the root's dot on the board, the root
   ring in a scale, the root in a list of chord tones. That is the
   one thing colour means here, so a reader learns it once.

   Wider than the drone's column, because a fretboard on its side
   wants the room. The text keeps to a readable measure inside it.
   ============================================================ */

:root {
  --paper: #f5f1e8;
  --paper-2: #efeade;
  --paper-3: #e7e1d2;
  --ink: #211c17;
  --ink-muted: #6f665b;
  --ink-faint: #9a9084;
  --rule: #d8d1c1;
  --accent: #8a3b1e;
  --accent-deep: #6e2f17;
  /* The fretboard's own: a string is a little warmer than a rule, and a
     fret wire a little lighter than a string. */
  --wire: #b9b0a0;
  --string: #7d7366;

  /* The page is as wide as is useful to the board and the cards beside
     it; only running text is held to a reading measure. */
  --measure: 90rem;
  --text: 34rem;
  --gutter: clamp(1rem, 4vw, 2rem);
  --serif: ui-serif, "Iowan Old Style", "Palatino Linotype", Palatino,
           "Book Antiqua", Charter, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;

  color-scheme: light;
}

/* Lit from the other side. Only the neutrals move, as in the siblings. */
:root[data-theme="dark"] {
  --paper: #171512;
  --paper-2: #1e1b17;
  --paper-3: #26221d;
  --ink: #e8e2d6;
  --ink-muted: #a49a8c;
  --ink-faint: #756c60;
  --rule: #35302a;
  --accent: #d98a63;
  --accent-deep: #e8a884;
  --wire: #4a443c;
  --string: #8c8273;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

main {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 1.8rem var(--gutter) calc(3rem + env(safe-area-inset-bottom));
}

a { color: var(--accent); }
a:hover { color: var(--accent-deep); }

.titlerow { display: flex; align-items: center; gap: .75rem; }
h1 {
  font-size: 1.05rem; font-weight: 600; letter-spacing: .01em;
  margin: 0; flex: 1 1 auto;
}
.standfirst { margin: .15rem 0 1.2rem; color: var(--ink-muted); font-size: .95rem; max-width: var(--text); }

.themebtn {
  font-family: var(--sans); font-size: .72rem; letter-spacing: .04em;
  border: 1px solid var(--rule); border-radius: 999px;
  padding: .15rem .6rem; background: none; color: var(--ink-faint);
  cursor: pointer; flex: 0 0 auto;
}
.themebtn:hover { color: var(--accent); border-color: var(--accent); }

/* --- the columns -------------------------------------------------------- */
/* One column on a phone. From 64rem the saved chords, keys and scales go
   to the right, wide enough for their cards, and the title and the
   instrument sit in a short band above the chord and the board. From 84rem
   that band becomes a narrow rail on the left, so the chord's name and
   the board start at the top of the page; the middle column keeps enough
   width for twelve frets lying across. */
@media (min-width: 64rem) {
  .layout {
    display: grid; align-items: start;
    grid-template-columns: minmax(0, 1fr) minmax(20rem, 26rem);
    grid-template-rows: auto 1fr;
    grid-template-areas: "setup study" "play study";
    gap: 0 clamp(2rem, 4vw, 3.5rem);
  }
  .col-setup { grid-area: setup; }
  .col-play { grid-area: play; }
  .col-study {
    grid-area: study;
    border-left: 1px solid var(--rule);
    padding-left: clamp(1.25rem, 2.5vw, 2rem);
    min-height: 100%;
  }
}
@media (min-width: 84rem) {
  .layout {
    grid-template-columns: 12.5rem minmax(0, 1fr) minmax(20rem, 24rem);
    grid-template-rows: auto;
    grid-template-areas: "setup play study";
    column-gap: clamp(1.75rem, 2.5vw, 2.75rem);
  }
  .col-setup .standfirst { font-size: .85rem; margin-bottom: 1.4rem; }
  .col-setup .setup { flex-direction: column; align-items: stretch; gap: .9rem; }
  .col-setup .select { width: 100%; }
  .col-setup .tuning-pick { flex-direction: column; align-items: flex-start; gap: .3rem; }
  .col-setup .custom-strings { grid-template-columns: 1fr 1fr; }
}

/* --- control groups ------------------------------------------------------ */
section { margin-bottom: 1.9rem; }
.label {
  font-family: var(--sans); font-size: .78rem; letter-spacing: .04em;
  color: var(--ink-muted); margin: 0 0 .5rem;
}
/* The instrument and its tuning: two small groups side by side, which
   wrap on a phone and stack in the rail. */
.setup { display: flex; flex-wrap: wrap; gap: .7rem 1.6rem; align-items: flex-end; }
.setup .label { display: block; margin-bottom: .35rem; }
.setup-wide { flex: 1 0 100%; margin-top: 0; }
.tuning-pick { display: flex; align-items: center; gap: .7rem; }
.strings-out { font-family: var(--sans); font-size: .76rem; letter-spacing: .06em; color: var(--ink-faint); white-space: nowrap; }
.select {
  font: inherit; font-size: .95rem; color: var(--ink); background: var(--paper);
  border: 1px solid var(--rule); border-radius: 2px; padding: .3rem .4rem;
  min-width: 9rem; cursor: pointer;
}
.select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.readout { color: var(--ink-faint); float: right; font-weight: 400; }
.hint {
  font-family: var(--sans); font-size: .74rem; color: var(--ink-faint);
  margin: .45rem 0 0; max-width: var(--text);
}

.row { display: flex; flex-wrap: wrap; gap: .3rem; align-items: center; }
.row + .row { margin-top: .35rem; }

.chip {
  font: inherit; font-size: .95rem;
  color: var(--ink); background: transparent;
  border: 1px solid var(--rule); border-radius: 2px;
  padding: .42rem .6rem; min-width: 2.6rem; cursor: pointer;
}
.chip:hover:not([disabled]) { border-color: var(--ink-muted); }
.chip[aria-pressed="true"], .chip[aria-checked="true"] {
  background: var(--ink); border-color: var(--ink); color: var(--paper);
}
.chip[disabled] { opacity: .4; cursor: not-allowed; }
.chip.small { font-family: var(--sans); font-size: .76rem; padding: .3rem .5rem; min-width: 0; }

.linkish {
  font: inherit; font-size: inherit; color: var(--accent);
  background: none; border: none; padding: 0; cursor: pointer;
  text-decoration: underline; text-underline-offset: .15em;
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* --- the custom tuning ---------------------------------------------------- */
.custom { margin-top: .8rem; padding: .7rem .8rem; background: var(--paper-2); border: 1px solid var(--rule); border-radius: 2px; }
.custom-strings {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(6.2rem, 1fr));
  gap: .4rem; margin-bottom: .6rem;
}
.custom-string { display: flex; flex-direction: column; gap: .15rem; }
.custom-string span { font-family: var(--sans); font-size: .7rem; color: var(--ink-faint); }
.custom-string select {
  font: inherit; font-size: .95rem; color: var(--ink); background: var(--paper);
  border: 1px solid var(--rule); border-radius: 2px; padding: .3rem .3rem;
}

/* --- the chord, named ----------------------------------------------------- */
.chord { margin-bottom: 1rem; min-height: 8.5rem; }
.chord-name {
  font-size: clamp(3.2rem, 14vw, 4.6rem);
  line-height: 1; letter-spacing: -.01em;
  font-variant-numeric: lining-nums;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  min-height: 1em;
}
.chord-name .tail { font-size: .62em; margin-left: .03em; }
.chord-name .slash { font-size: .62em; color: var(--ink-muted); margin-left: .08em; }
.chord-name .dash { color: var(--ink-faint); padding: 0 .1em; }
.chord-name .placeholder { font-size: .5em; color: var(--ink-faint); font-style: italic; }
/* Two lines kept for the description, which often runs to a second line
   on an inversion; see also chordTall in main.js. */
.chord-long { margin: .35rem 0 .5rem; color: var(--ink-muted); max-width: var(--text); min-height: 2lh; }
.chord-note { font-family: var(--sans); font-size: .74rem; color: var(--ink-faint); margin: .4rem 0 0; max-width: var(--text); }
.chord-alts { font-family: var(--sans); font-size: .82rem; margin-top: .45rem; color: var(--ink-faint); }
.alts-label { color: var(--ink-faint); margin-right: .2rem; }

/* With the room, the name on the left and what it is made of beside it,
   rather than all of it stacked above the board. The split is fixed, so
   the details stay where they are as the name grows and shrinks. */
@media (min-width: 64rem) {
  .chord {
    display: grid; align-items: start;
    grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
    gap: 0 1.5rem; min-height: 0;
  }
  .chord-name { font-size: 4.2rem; }
  .chord-long { margin-top: .15rem; }
}
.chord-alts.empty { visibility: hidden; }

/* A list of notes, each with its interval under it: the chord's tones,
   or a scale's. The root's interval reads R and is set in the accent, as
   the root is on the board. */
.chord-tones, .scale-notes { display: flex; flex-wrap: wrap; gap: .25rem .9rem; margin: 0; }
/* One row kept for the tones even before there are any, so the first two
   notes do not push the board down. */
.chord-tones { min-height: 2.45rem; }
.tone { display: inline-flex; flex-direction: column; align-items: center; min-width: 1.6rem; }
.tone-name { font-size: 1.2rem; line-height: 1.15; }
.tone-label { font-family: var(--sans); font-size: .68rem; color: var(--ink-faint); }
.tone.root .tone-label { color: var(--accent); }
.tone.outside .tone-name { color: var(--accent); font-style: italic; }

/* --- the scale bar -------------------------------------------------------- */
.overlay-bar {
  margin: 0 0 .9rem; padding: .6rem .7rem .7rem;
  border: 1px solid var(--rule); border-left: 3px solid var(--accent);
  background: var(--paper-2); border-radius: 2px;
  scroll-margin-top: 1rem;
}
.overlay-head { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; margin-bottom: .5rem; }
.overlay-title { margin: 0; flex: 1 1 auto; font-size: 1.05rem; }
.overlay-kicker { font-family: var(--sans); font-size: .7rem; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-faint); margin-right: .3rem; }
.shapes .chip { font-size: .85rem; padding: .3rem .5rem; min-width: 0; }
.shape-fret { font-family: var(--sans); font-size: .7em; color: var(--ink-faint); margin-left: .3em; }
.chip[aria-pressed="true"] .shape-fret { color: inherit; opacity: .75; }

/* --- the board ------------------------------------------------------------ */
.board-sec { margin-bottom: 2.4rem; }
.board {
  width: 100%; margin: 0 0 .9rem;
  border-radius: 3px;
  /* The board is an instrument: no text selection, no callout under a
     held finger, no double-tap zoom. Scrolling still works. */
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.board:focus { outline: none; }
.board:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
.fb { display: block; max-width: 100%; height: auto; overflow: visible; }

.fb-string { stroke: var(--string); }
.fb-fret { stroke: var(--wire); stroke-width: 1.4; }
.fb-nut { stroke: var(--ink); stroke-width: 5; stroke-linecap: square; }
.fb-inlay { fill: var(--paper-3); }
:root[data-theme="dark"] .fb-inlay { fill: var(--rule); }
.fb-num { font-family: var(--sans); font-size: 11px; fill: var(--ink-faint); }
.fb-num-mark { fill: var(--ink-muted); }
.fb-label { font-family: var(--serif); font-size: 15px; fill: var(--ink-muted); }

.fb-dot circle { fill: var(--ink); }
.fb-dot text { font-family: var(--sans); font-size: 12px; font-weight: 600; fill: var(--paper); }
.fb-dot-root circle { fill: var(--accent); }
.fb-barre { fill: var(--ink); opacity: .22; }
.fb-open circle { fill: var(--paper); stroke: var(--ink); stroke-width: 1.8; }
.fb-open text { font-family: var(--sans); font-size: 9.5px; font-weight: 600; fill: var(--ink); }
.fb-open-root circle { stroke: var(--accent); stroke-width: 2.4; }
.fb-open-root text { fill: var(--accent); }
.fb-mute { stroke: var(--ink-muted); stroke-width: 2; stroke-linecap: round; fill: none; }
.fb-ignore { fill: var(--ink-faint); }
.fb-off {
  font-family: var(--sans); font-size: 9.5px; font-weight: 600; fill: var(--accent);
  stroke: var(--paper); stroke-width: 3px; paint-order: stroke; stroke-linejoin: round;
}

.fb-scale circle { fill: var(--paper); stroke: var(--ink-muted); stroke-width: 1.3; }
.fb-scale text { font-family: var(--sans); font-size: 10px; fill: var(--ink-muted); }
.fb-scale-root circle { stroke: var(--accent); stroke-width: 2.4; }
.fb-scale-root text { fill: var(--accent); font-weight: 600; }

.fb-hit { fill: transparent; cursor: pointer; }
@media (hover: hover) {
  .fb-hit:hover { fill: var(--ink); fill-opacity: .06; }
}
.fb-hit-label { cursor: pointer; }
.fb-cursor { fill: none; stroke: var(--accent); stroke-width: 2; stroke-dasharray: 4 3; }

/* --- the tools under the board ------------------------------------------- */
.tools {
  display: grid; gap: .8rem 1.6rem;
  grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
  margin-bottom: 1rem;
}
.tool { display: flex; flex-direction: column; gap: .3rem; }
.tool .row + .row { margin-top: 0; }
.tool-label { font-family: var(--sans); font-size: .72rem; color: var(--ink-faint); letter-spacing: .03em; }
.tool .chip { font-family: var(--sans); font-size: .82rem; padding: .35rem .5rem; min-width: 2.2rem; }
.pos { font-family: var(--sans); font-size: .85rem; min-width: 3.6rem; text-align: center; color: var(--ink-muted); }

.actions { display: flex; flex-wrap: wrap; gap: .4rem; align-items: stretch; }
.primary {
  font: inherit; font-size: 1.05rem;
  color: var(--paper); background: var(--ink);
  border: none; border-radius: 2px; cursor: pointer;
  padding: .6rem 1.4rem;
}
.primary:hover:not([disabled]) { background: var(--accent); }
.primary[disabled] { opacity: .4; cursor: not-allowed; }

.for-keys { display: none; }
@media (hover: hover) and (pointer: fine) {
  .for-keys { display: revert; }
  .for-touch { display: none; }
}

/* --- saved chords --------------------------------------------------------- */
.saved { display: flex; flex-wrap: wrap; gap: .45rem; }
.card {
  display: flex; flex-direction: column; align-items: center; gap: .1rem;
  min-width: 5.2rem; padding: .45rem .4rem .4rem;
  font: inherit; color: var(--ink); background: var(--paper-2);
  border: 1px solid var(--rule); border-radius: 3px; cursor: pointer;
}
.card:hover { border-color: var(--ink-muted); }
.card.loaded { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.card-name { font-size: 1.05rem; line-height: 1.2; max-width: 7rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-num { font-family: var(--serif); font-size: .82rem; color: var(--accent); }
.card-tuning { font-family: var(--sans); font-size: .62rem; color: var(--ink-faint); max-width: 6.5rem; text-align: center; line-height: 1.2; }
.mini { display: block; }
.mini .mn-string, .mini .mn-fret { stroke: var(--string); stroke-width: .8; }
.mini .mn-fret { stroke: var(--wire); }
.mini .mn-nut { stroke: var(--ink); stroke-width: 2.4; }
.mini .mn-dot { fill: var(--ink); }
.mini .mn-barre { fill: var(--ink); opacity: .3; }
.mini .mn-open { fill: none; stroke: var(--ink); stroke-width: .9; }
.mini .mn-mute { stroke: var(--ink-muted); stroke-width: .9; }
.mini .mn-pos { font-family: var(--sans); font-size: 7px; fill: var(--ink-faint); }

.saved-edit { margin-top: .6rem; }
.saved-actions { margin-top: .8rem; }
.saved-actions .chip { font-family: var(--sans); font-size: .82rem; padding: .35rem .6rem; }
.status { font-family: var(--sans); font-size: .78rem; color: var(--accent); margin-left: .3rem; }

/* The two panels under the saved chords: chords added from text, and the
   title for a printed chart. */
.panel {
  margin-top: .9rem; padding: .8rem .85rem .9rem;
  border: 1px solid var(--rule); border-radius: 3px; background: var(--paper-2);
}
.panel .label { display: block; }
.panel .row { margin-top: .6rem; }
.textbox, .textline {
  display: block; width: 100%; box-sizing: border-box;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .88rem;
  color: var(--ink); background: var(--paper);
  border: 1px solid var(--rule); border-radius: 2px; padding: .45rem .5rem;
}
.textbox { resize: vertical; min-height: 8.5rem; line-height: 1.45; }
.textline { font-family: inherit; font-size: 1rem; }
.textbox:focus-visible, .textline:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.textbox::placeholder, .textline::placeholder { color: var(--ink-faint); }
.import-read { margin: .55rem 0 0; font-size: .95rem; }
.import-read:empty { display: none; }
.import-problems {
  margin: .4rem 0 0; padding-left: 1.1rem;
  font-family: var(--sans); font-size: .76rem; color: var(--accent);
}
.import-problems li + li { margin-top: .2rem; }
.panel code, .hint code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .95em;
  color: var(--ink-muted); white-space: nowrap;
}

/* --- keys ----------------------------------------------------------------- */
.keys { display: grid; gap: .45rem; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); }
.keys-none { grid-column: 1 / -1; margin: 0 0 .2rem; }
.key {
  display: flex; flex-direction: column; align-items: flex-start; gap: .25rem;
  text-align: left; font: inherit; color: var(--ink);
  background: transparent; border: 1px solid var(--rule); border-radius: 3px;
  padding: .6rem .7rem; cursor: pointer;
}
.key:hover { border-color: var(--ink-muted); }
.key.chosen { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); background: var(--paper-2); }
.key-title { font-size: 1.15rem; }
.key-nums { display: flex; flex-wrap: wrap; gap: .15rem .55rem; color: var(--accent); font-size: .98rem; }
.key-why { font-family: var(--sans); font-size: .74rem; color: var(--ink-muted); }
.key-notes { font-family: var(--sans); font-size: .74rem; color: var(--ink-faint); letter-spacing: .02em; }

/* --- scales --------------------------------------------------------------- */
.scales { display: grid; gap: .6rem; }
.scale { border-top: 1px solid var(--rule); padding-top: .7rem; }
.scale:first-child { border-top: none; padding-top: 0; }
.scale.on .scale-title::before { content: "● "; color: var(--accent); font-size: .7em; vertical-align: .15em; }
.scale-title { font-size: 1.1rem; margin: 0 0 .3rem; }
.scale-notes { margin-bottom: .4rem; }
.scale-why { margin: 0 0 .25rem; color: var(--ink-muted); font-size: .95rem; max-width: var(--text); }
.scale-about { font-family: var(--sans); font-size: .74rem; color: var(--ink-faint); margin: 0 0 .5rem; max-width: var(--text); }

/* --- footer --------------------------------------------------------------- */
footer {
  margin-top: 2.4rem; padding-top: 1rem; border-top: 1px solid var(--rule);
  color: var(--ink-faint); font-family: var(--sans); font-size: .78rem;
}
footer p { margin: 0 0 .7rem; max-width: var(--text); }
footer kbd {
  font-family: var(--sans); font-size: .95em;
  border: 1px solid var(--rule); border-radius: 3px;
  padding: 0 .3em; color: var(--ink-muted);
}

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}
[hidden] { display: none !important; }

/* ============================================================
   THE PRINTED CHART
   ------------------------------------------------------------
   Not on screen at all. On paper, when there are saved chords,
   it is the only thing printed: the page around it is controls,
   which are no use on paper. Black on white whatever the theme,
   and in the browser's serif, like the page.
   ============================================================ */

.sheet { display: none; }

@media print {
  @page { margin: 14mm 12mm; }
  body.printing-chart { background: #fff !important; color: #000; }
  body.printing-chart > *:not(.sheet) { display: none !important; }
  body.printing-chart .sheet { display: block; }
  .sheet { font-family: var(--serif); color: #000; }
  .sheet-head { border-bottom: 1px solid #000; padding-bottom: 3mm; margin-bottom: 6mm; }
  .sheet-head h1 { font-size: 22pt; font-weight: 400; margin: 0 0 1mm; }
  .sheet-head p { font-size: 10.5pt; margin: 0; color: #333; }
  .sheet-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(38mm, 1fr)); gap: 7mm 4mm; }
  .sheet-card { margin: 0; text-align: center; break-inside: avoid; }
  .sheet-name { font-size: 16pt; line-height: 1.1; margin-bottom: 1mm; }
  .sheet-card .chart { display: block; margin: 0 auto; width: auto; height: 34mm; }
  .sheet-under { margin: 1mm 0 0; font-size: 9pt; }
  .sheet-num { font-size: 11pt; }
  .sheet-shape { font-family: ui-monospace, Menlo, Consolas, monospace; color: #444; }
  .sheet-tuning { margin: .5mm 0 0; font-family: var(--sans); font-size: 7pt; color: #555; }
  .sheet-foot { margin-top: 8mm; font-family: var(--sans); font-size: 7.5pt; color: #777; }
  .chart .ch-string, .chart .ch-fret { stroke: #000; stroke-width: 1; }
  .chart .ch-fret { stroke: #777; }
  .chart .ch-nut { stroke: #000; stroke-width: 4; }
  .chart .ch-dot { fill: #000; }
  .chart .ch-finger { fill: #fff; font-family: var(--sans); font-size: 10px; font-weight: 600; }
  .chart .ch-open { fill: none; stroke: #000; stroke-width: 1.3; }
  .chart .ch-mute { stroke: #000; stroke-width: 1.3; }
  .chart .ch-pos { fill: #000; font-family: var(--sans); font-size: 11px; }
  .chart .ch-name { fill: #444; font-family: var(--sans); font-size: 9px; }
}
