/* ============================================================
   INTERVALS
   ------------------------------------------------------------
   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. The
   board's rules are Fretboard's, since the board is Fretboard's.

   --accent marks the first note heard: its dot on the board and
   its name. That, and a right answer, is what colour means here.
   The piano's keys have fixed colours of their own, at the end.
   ============================================================ */

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

  /* Wide enough for the question and the record side by side; the
     hints keep to a reading measure. */
  --measure: 80rem;
  --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 question, then what to practise, then the
   record. From 64rem the question on the left and the rest beside it. */
.layout { display: flex; flex-direction: column; }
.col-drill { min-width: 0; }
.col-side { min-width: 0; margin-top: 1rem; }
@media (min-width: 64rem) {
  .layout {
    display: grid; align-items: start;
    grid-template-columns: minmax(0, 1fr) 24rem;
    column-gap: clamp(1.75rem, 3vw, 3rem);
  }
  .col-side { margin-top: 0; border-left: 1px solid var(--rule); padding-left: clamp(1.25rem, 2.5vw, 2rem); }
}

/* --- controls, as in Fretboard ----------------------------------------- */
section { margin-bottom: 1.6rem; }
.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; }
.select {
  font: inherit; font-size: .95rem; color: var(--ink); background: var(--paper);
  border: 1px solid var(--rule); border-radius: 2px; padding: .3rem .4rem;
}
.select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.link {
  font: inherit; font-family: var(--sans); font-size: .76rem; color: var(--accent);
  background: none; border: none; padding: 0; margin-top: .6rem; cursor: pointer;
  text-decoration: underline; text-underline-offset: 2px;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.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; }
kbd {
  font-family: var(--sans); font-size: .92em; padding: 0 .3em;
  border: 1px solid var(--rule); border-radius: 3px; background: var(--paper-2);
}

/* --- the question ---------------------------------------------------------- */
.kicker {
  font-family: var(--sans); font-size: .72rem; letter-spacing: .08em; text-transform: uppercase;
  color: var(--accent); margin: 0 0 .2rem; min-height: 1.1rem;
}
.prompt { font-size: 1.45rem; font-weight: 400; line-height: 1.3; margin: 0 0 1rem; max-width: var(--text); }
.go-row { gap: .5rem; margin-bottom: 1.1rem; }
.go-row .primary { min-width: 6.5rem; }
/* Waiting for an answer, Next skips: quieter, so it is not pressed by habit. */
.go-row .primary.waiting { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1px var(--rule); }
.go-row .primary.waiting:hover { box-shadow: inset 0 0 0 1px var(--ink-muted); background: transparent; }

/* The answers: big enough to hit without looking, short name over long. */
.answers {
  display: grid; gap: .45rem;
  grid-template-columns: repeat(auto-fill, minmax(6.6rem, 1fr));
  margin-bottom: 1.1rem; max-width: 46rem;
}
.answer {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: .05rem;
  font: inherit; color: var(--ink); background: var(--paper-2);
  border: 1px solid var(--rule); border-radius: 3px;
  padding: .55rem .4rem .5rem; cursor: pointer; min-height: 3.6rem;
  touch-action: manipulation;
}
.answer:hover:not([disabled]) { border-color: var(--ink-muted); }
.answer[disabled] { cursor: default; color: var(--ink-faint); }
.ashort { font-size: 1.25rem; line-height: 1.1; }
.aname { font-family: var(--sans); font-size: .7rem; color: var(--ink-muted); }
.akey { position: absolute; top: .2rem; left: .35rem; font-family: var(--sans); font-size: .62rem; color: var(--ink-faint); }
.answer.is-right { color: var(--paper); background: var(--ink); border-color: var(--ink); }
.answer.is-right .aname, .answer.is-right .akey { color: var(--paper); opacity: .8; }
.answer.is-wrong { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); color: var(--accent); }
.answer.is-wrong .aname { color: var(--accent); }

.verdict {
  border-left: 3px solid var(--accent); background: var(--paper-2);
  padding: .6rem .8rem .7rem; margin-bottom: 1rem; max-width: 46rem; border-radius: 2px;
}
.verdict.ok { border-left-color: var(--ink); }
.verdict-line { margin: 0 0 .5rem; }

.neck { margin-bottom: 1rem; }
.neck-say { margin: 0 0 .6rem; color: var(--ink-muted); max-width: var(--text); }
.place-count { font-family: var(--sans); font-size: .74rem; color: var(--ink-faint); }

.session { font-family: var(--sans); font-size: .82rem; color: var(--ink-muted); margin: .4rem 0 0; min-height: 1.2rem; }
/* No keyboard on a phone, so no keys. */
@media (hover: none) and (pointer: coarse) { .keys { display: none; } }

/* --- what to practise ------------------------------------------------------ */
.settings .label { margin-top: 1.1rem; }
.settings .label:first-child { margin-top: 0; }
.intervals { display: grid; grid-template-columns: repeat(auto-fill, minmax(5.4rem, 1fr)); gap: .3rem; }
.ichip { display: flex; flex-direction: column; align-items: center; padding: .3rem .25rem; line-height: 1.2; }
.ichip .ishort { font-family: var(--serif); font-size: .98rem; }
.ichip .iname { font-size: .64rem; opacity: .8; }
.ladder-row { margin-top: .5rem; }
.hint.ready { color: var(--accent); }

/* --- the record ------------------------------------------------------------ */
.days { display: flex; gap: 3px; margin-bottom: .35rem; }
.day { width: 1.1rem; height: 1.1rem; border-radius: 2px; background: var(--paper-3); }
:root[data-theme="dark"] .day { background: var(--rule); }
.day.l1 { background: color-mix(in srgb, var(--accent) 35%, var(--paper)); }
.day.l2 { background: color-mix(in srgb, var(--accent) 65%, var(--paper)); }
.day.l3, :root[data-theme="dark"] .day.l3 { background: var(--accent); }
:root[data-theme="dark"] .day.l1 { background: color-mix(in srgb, var(--accent) 35%, var(--paper)); }
:root[data-theme="dark"] .day.l2 { background: color-mix(in srgb, var(--accent) 65%, var(--paper)); }
.days-say { font-family: var(--sans); font-size: .74rem; color: var(--ink-faint); margin: 0 0 .8rem; }

.table-wrap { overflow-x: auto; }
.record-table { border-collapse: collapse; width: 100%; font-family: var(--sans); font-size: .76rem; }
.record-table th, .record-table td { text-align: left; padding: .3rem .4rem .3rem 0; border-bottom: 1px solid var(--rule); vertical-align: middle; white-space: nowrap; }
.record-table thead th { font-weight: 500; color: var(--ink-faint); font-size: .7rem; }
.record-table tbody th { font-weight: 400; }
.record-table .ishort { font-family: var(--serif); font-size: .95rem; display: inline-block; min-width: 1.6rem; }
.record-table .iname { color: var(--ink-faint); font-size: .68rem; }
.record-table tr.out { opacity: .55; }
.record-table .none { color: var(--ink-faint); }
.record-table .mix { color: var(--ink-muted); }
.meter { display: inline-block; vertical-align: middle; width: 2.2rem; height: .32rem; background: var(--paper-3); border-radius: 2px; margin-right: .3rem; overflow: hidden; }
:root[data-theme="dark"] .meter { background: var(--rule); }
.meter > span { display: block; height: 100%; background: var(--ink-muted); }
.frac { color: var(--ink); }
.of { color: var(--ink-faint); font-size: .9em; }
@media (max-width: 26rem) { .record-table .iname { display: none; } }

/* --- the board ------------------------------------------------------------ */
.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 keyboard ---------------------------------------------------------- */
/* A piano's keys keep their colours in either theme. */
.kb { display: block; max-width: 100%; height: auto; }
.kb-key { cursor: pointer; }
.kb-white { fill: #fbf8f1; stroke: #9a9084; stroke-width: 1; }
.kb-black { fill: #231e19; stroke: #231e19; stroke-width: 1; }
:root[data-theme="dark"] .kb-white { fill: #e4ddcf; stroke: #4a443c; }
:root[data-theme="dark"] .kb-black { fill: #0e0d0b; stroke: #0e0d0b; }
@media (hover: hover) {
  .kb-white:hover { fill: #efe8da; }
  .kb-black:hover { fill: #3b332b; }
}
.kb-c { font-family: var(--sans); font-size: 10px; fill: var(--ink-faint); }
.kb-c-middle { fill: var(--ink-muted); font-weight: 600; }
.kb-mark { pointer-events: none; }
.kb-mark text { font-family: var(--sans); font-size: 11px; font-weight: 600; }
.kb-first circle { fill: #8a3b1e; }
.kb-first text { fill: #fbf8f1; }
.kb-second circle { fill: #211c17; }
.kb-second text { fill: #fbf8f1; }
.kb-second.on-black circle { fill: #fbf8f1; }
.kb-second.on-black text { fill: #211c17; }
.kb-ring circle { fill: none; stroke: #8a3b1e; stroke-width: 2; stroke-dasharray: 3 2; }
.kb-ring text { fill: #8a3b1e; }
.kb-ring.on-black circle { stroke: #e8a884; }
.kb-ring.on-black text { fill: #e8a884; }
