/* ============================================================
   SONG SHEET
   ------------------------------------------------------------
   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 a chord: over the words, and on the chord chosen
   to place. That is the one thing colour means here.

   Fretboard's palette and type, so the two read as one pair of
   tools. The words are the page's text, in the page's serif.
   ============================================================ */

: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 chord charts' strings and frets, as in Fretboard. */
  --wire: #b9b0a0;
  --string: #7d7366;

  /* Wide, so the words and the sheet can sit side by side; the hints
     keep 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: the song, then the list of songs. From 64rem the
   title and the list sit in a rail on the left and the song beside them. */
.layout { display: flex; flex-direction: column; }
.col-head { order: 0; }
.col-song { order: 1; min-width: 0; }
.col-songs { order: 2; margin-top: 1.5rem; }
@media (min-width: 64rem) {
  .layout {
    display: grid; align-items: start;
    grid-template-columns: 13rem minmax(0, 1fr);
    grid-template-rows: auto 1fr;
    grid-template-areas: "head song" "songs song";
    column-gap: clamp(1.75rem, 3vw, 3rem);
  }
  .col-head { grid-area: head; }
  .col-song { grid-area: song; }
  .col-songs { grid-area: songs; margin-top: 0; }
  .col-head .standfirst { font-size: .85rem; }
}

/* --- controls, as in Fretboard ----------------------------------------- */
section { margin-bottom: 1.5rem; }
.label {
  font-family: var(--sans); font-size: .78rem; letter-spacing: .04em;
  color: var(--ink-muted); margin: 0 0 .5rem;
}
.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);
}
.hint.warn { color: var(--accent); }
.hint code, .panel code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .95em;
  color: var(--ink-muted); white-space: nowrap;
}
.row { display: flex; flex-wrap: wrap; gap: .3rem; align-items: center; }
.row + .row { margin-top: .35rem; }
.chip {
  font: inherit; font-family: var(--sans); font-size: .82rem;
  color: var(--ink); background: transparent;
  border: 1px solid var(--rule); border-radius: 2px;
  padding: .38rem .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-size: .76rem; padding: .28rem .5rem; }
.primary {
  font: inherit; font-size: 1rem;
  color: var(--paper); background: var(--ink);
  border: none; border-radius: 2px; cursor: pointer;
  padding: .5rem 1.2rem;
}
.primary.small { font-size: .92rem; padding: .4rem 1rem; }
.primary:hover:not([disabled]) { background: var(--accent); }
.primary[disabled] { opacity: .4; cursor: not-allowed; }
.status { font-family: var(--sans); font-size: .78rem; color: var(--accent); margin-left: .3rem; }

.panel {
  margin-top: .8rem; 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 {
  display: block; width: 100%; resize: vertical; min-height: 7rem; line-height: 1.45;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .86rem;
  color: var(--ink); background: var(--paper);
  border: 1px solid var(--rule); border-radius: 2px; padding: .45rem .5rem;
}
.textbox:focus-visible, .words:focus-visible, .details input:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
::placeholder { color: var(--ink-faint); opacity: 1; }
.read { margin: .55rem 0 0; font-size: .95rem; }
.read:empty { display: none; }
.problems { margin: .4rem 0 0; padding-left: 1.1rem; font-family: var(--sans); font-size: .76rem; color: var(--accent); }
.problems:empty { display: none; }
.problems li + li { margin-top: .2rem; }
.file-pick { position: relative; overflow: hidden; display: inline-block; }
.file-pick input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.file-pick:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }

/* --- Fretboard's chords, arriving ------------------------------------------ */
.inbox {
  border: 1px solid var(--accent); border-radius: 3px; background: var(--paper-2);
  padding: .7rem .85rem .8rem;
}
.inbox-what { margin: 0 0 .5rem; }

/* --- the song's details ------------------------------------------------------ */
.details input {
  font: inherit; color: var(--ink); background: transparent;
  border: none; border-bottom: 1px solid var(--rule); border-radius: 0;
  padding: .15rem 0;
}
.title-in { display: block; width: 100%; font-size: 1.9rem !important; line-height: 1.2; font-style: italic; }
.title-in:not(:placeholder-shown) { font-style: normal; }
.detail-row { display: flex; flex-wrap: wrap; gap: .5rem 1.2rem; margin-top: .6rem; }
.detail { display: flex; align-items: baseline; gap: .45rem; flex: 1 1 12rem; }
.detail.short { flex: 0 1 7.5rem; }
.detail span { font-family: var(--sans); font-size: .74rem; color: var(--ink-faint); letter-spacing: .03em; }
.detail input { width: 100%; min-width: 0; font-size: .98rem; }

/* --- the chords, kept in view ---------------------------------------------- */
.chords-sec { background: var(--paper); padding: .4rem 0 .5rem; margin-bottom: 1rem; z-index: 2; }
.chords-sec.stuck { position: sticky; top: 0; }
.chords-head { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem .6rem; margin-bottom: .45rem; }
.chords-head .label { margin: 0; flex: 0 0 auto; }
.palette { display: flex; gap: .4rem; overflow-x: auto; padding-bottom: .2rem; scrollbar-width: thin; }
.palette:empty { display: none; }
.pcard {
  flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; gap: .05rem;
  min-width: 4rem; padding: .35rem .35rem .3rem;
  font: inherit; color: var(--ink); background: var(--paper-2);
  border: 1px solid var(--rule); border-radius: 3px; cursor: pointer;
}
.pcard:hover { border-color: var(--ink-muted); }
.pcard[aria-checked="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.pcard[aria-checked="true"] .pcard-name { color: var(--accent); }
.pcard.unshaped { border-style: dashed; background: transparent; }
.pcard-name { font-family: var(--sans); font-weight: 600; font-size: .9rem; line-height: 1.2; white-space: nowrap; }
.noshape {
  display: flex; align-items: center; justify-content: center; height: 3.3rem;
  font-family: var(--sans); font-size: .62rem; color: var(--ink-faint);
}
.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); }

/* --- words and sheet ------------------------------------------------------- */
/* One at a time, by the switch, until there is room for both. */
.panes[data-view="write"] .pane-place, .panes[data-view="place"] .pane-write { display: none; }
@media (min-width: 72rem) {
  .view-switch { display: none; }
  .panes { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); gap: clamp(1.25rem, 2.5vw, 2.25rem); align-items: start; }
  .panes .pane-place, .panes .pane-write { display: block !important; }
}
.view-switch { margin-bottom: .9rem; }
.words {
  display: block; width: 100%; min-height: 26rem; resize: vertical;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .9rem; line-height: 1.6;
  color: var(--ink); background: var(--paper-2);
  border: 1px solid var(--rule); border-radius: 3px; padding: .7rem .8rem;
}
@media (min-width: 72rem) { .words { min-height: 34rem; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: .6rem; margin-bottom: .5rem; }
.sheet-head .label { margin: 0; }
.held-bar {
  font-family: var(--sans); font-size: .76rem; color: var(--ink-muted);
  display: flex; flex-wrap: wrap; align-items: center; gap: .35rem .5rem;
  min-height: 4.2rem; align-content: flex-start; margin-bottom: .3rem;
}
.held-btns { display: inline-flex; gap: .35rem; }
@media (max-width: 40rem) { .held-bar { min-height: 4.8rem; } }
.sheet-empty { color: var(--ink-faint); font-style: italic; }

/* The sheet, also the printed one: each word a little column with its
   chord, if any, above it, so a chord stays over its letter however the
   line wraps. */
.ln { margin: 0; }
.ln.lyric { display: flex; flex-wrap: wrap; align-items: flex-end; }
.ln.blank { height: .9em; display: flex; }
.ln.head {
  font-family: var(--sans); font-size: .76rem; font-weight: 600; letter-spacing: .06em;
  text-transform: uppercase; color: var(--ink-muted); margin: 1.1em 0 .3em;
}
.sec:first-child .ln.head:first-child { margin-top: 0; }
.ln.note { font-style: italic; color: var(--ink-muted); margin: .1em 0 .25em; }
.pc { display: inline-flex; flex-direction: column; }
.cd {
  font-family: var(--sans); font-weight: 600; font-size: .82em; color: var(--accent);
  min-height: 1.35em; line-height: 1.35; padding-right: .45em; white-space: nowrap;
}
.cd.unshaped { text-decoration: underline dotted; text-underline-offset: .2em; }
.ly { white-space: pre; line-height: 1.45; font-size: 1.05rem; }
.chords-only .ly { display: none; }
.chords-only .cd { padding-right: .9em; }
.end { flex: 1 0 2rem; align-self: stretch; min-height: 1.4em; }

.sheet { padding: .2rem 0 1rem; }
.sheet [data-o], .sheet [data-at] { cursor: pointer; }
.sheet.placing [data-o]:hover { background: var(--paper-3); box-shadow: inset 2px 0 0 var(--accent); }
.sheet.placing .end:hover { box-shadow: inset 2px 0 0 var(--accent); background: transparent; }
.sheet .cd[data-at]:hover { background: var(--paper-3); }
.sheet .cd.held { background: var(--accent); color: var(--paper); border-radius: 2px; padding: 0 .3em; margin-right: .15em; }

.song-actions { border-top: 1px solid var(--rule); padding-top: 1rem; }

/* --- the list of songs ------------------------------------------------------ */
.songs { display: flex; flex-direction: column; gap: .2rem; margin-bottom: .6rem; }
.song-btn {
  display: flex; justify-content: space-between; align-items: baseline; gap: .6rem;
  text-align: left; font: inherit; color: var(--ink); background: transparent;
  border: none; border-left: 2px solid transparent; padding: .25rem .5rem; cursor: pointer;
}
.song-btn:hover { background: var(--paper-2); }
.song-btn[aria-current="true"] { border-left-color: var(--accent); background: var(--paper-2); }
.song-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.song-when { font-family: var(--sans); font-size: .68rem; color: var(--ink-faint); flex: 0 0 auto; }
.songs-actions .chip { font-size: .74rem; }

/* --- 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);
}
.for-keys { display: none; }
@media (hover: hover) and (pointer: fine) { .for-keys { display: revert; } }

.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 SONG CHART
   ------------------------------------------------------------
   Not on screen. On paper it is the only thing printed: title
   and details, the chord charts in a row across the top in the
   order they are first played, then the words with the chords
   over them, in one column or two. Black on white whatever the
   theme. A section is kept on one page where it fits.
   ============================================================ */

.print { display: none; }

@media print {
  @page { margin: 13mm 12mm; }
  body.printing-song { background: #fff !important; color: #000; }
  body.printing-song > *:not(.print) { display: none !important; }
  body.printing-song .print { display: block; }
  .print { font-family: var(--serif); color: #000; font-size: 11pt; }
  .pr-head { border-bottom: 1px solid #000; padding-bottom: 2.5mm; margin-bottom: 4mm; }
  .pr-head h1 { font-size: 20pt; font-weight: 400; margin: 0 0 1mm; }
  .pr-head p { margin: 0; font-size: 10pt; color: #333; }
  .pr-chords { display: flex; flex-wrap: wrap; gap: 2mm 3mm; margin-bottom: 5mm; }
  .pr-chord { margin: 0; text-align: center; break-inside: avoid; }
  .pr-chord figcaption { font-family: var(--sans); font-weight: 600; font-size: 10pt; }
  .pr-chord .chart { display: block; height: 26mm; width: auto; }
  .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; }
  .pr-words.two { columns: 2; column-gap: 9mm; }
  .print .ln, .print .sec { break-inside: avoid; }
  .print .ln.head { color: #000; break-after: avoid; font-size: 8.5pt; }
  .print .ln.note { color: #333; }
  .print .cd { color: #000; font-size: 9pt; text-decoration: none; }
  .print .ly { font-size: 11pt; }
}
