@font-face {
  font-family: "Bravura";
  src: url("fonts/Bravura.woff2") format("woff2");
  font-display: block;
}

:root {
  --bg: #f6f4ef;
  --panel: #fffdf8;
  --ink: #1b1a17;
  --ink-soft: #6a6459;
  --rule: #ddd7c9;
  --accent: #7a4b1e;
  --accent-soft: #f0e3d4;
  --highlight: #c9401f;
  --shadow: 0 1px 2px rgba(30, 25, 15, .06), 0 8px 24px rgba(30, 25, 15, .06);
  /* Light only: form controls and scrollbars stay light on a dark-mode device. */
  color-scheme: light;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

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

body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 "Source Serif 4", "Iowan Old Style", Georgia, "Times New Roman", serif;
  -webkit-font-smoothing: antialiased;
}

#app {
  display: grid;
  grid-template-columns: 320px 1fr;
  height: 100%;
}

/* Full screen is for reading: just the music, on a phone or a tablet alike --
   no hymn list, no header. Leaving full screen (a double tap, the back
   gesture, the system's own control) brings them back. */
:root.is-fullscreen #app { grid-template-columns: 1fr; }
:root.is-fullscreen #sidebar,
:root.is-fullscreen .toolbar { display: none; }
:root.is-fullscreen #main {
  padding-top: env(safe-area-inset-top, 0px);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}

/* ---------------------------------------------------------------- sidebar */

#sidebar {
  border-right: 1px solid var(--rule);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.side-head {
  position: relative;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--rule);
}

.book-row {
  display: flex;
  gap: 6px;
  align-items: stretch;
}

/* The book's name is the heading, and the way to the other books. */
.book-btn {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  margin-left: -8px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: .01em;
  text-align: left;
  cursor: pointer;
}

.book-btn:hover { border-color: var(--rule); }
.book-btn #book-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.caret { color: var(--ink-soft); font-size: .8em; }

.menu {
  position: absolute;
  left: 10px;
  right: 10px;
  top: 52px;
  z-index: 6;
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: 9px;
  box-shadow: var(--shadow);
  padding: 4px;
}

.menu button {
  display: block;
  width: 100%;
  padding: 9px 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 15px;
  text-align: left;
  cursor: pointer;
}

.menu button:hover { background: var(--accent-soft); }
.menu button.is-on { color: var(--accent); font-weight: 600; }

.filters {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.filters:empty { display: none; }

.chip {
  border: 1px solid var(--rule);
  background: transparent;
  color: var(--ink-soft);
  border-radius: 999px;
  padding: 2px 10px;
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
}

.chip.is-on {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.list {
  list-style: none;
  margin: 0;
  padding: 6px 0 24px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.list li {
  padding: 7px 16px;
  cursor: pointer;
  border-left: 3px solid transparent;
}

.list li:hover { background: var(--accent-soft); }

.list li.is-sel {
  background: var(--accent-soft);
  border-left-color: var(--accent);
}

.list li.is-head {
  cursor: default;
  padding-top: 14px;
  color: var(--ink-soft);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .07em;
}
.list li.is-head:hover { background: transparent; }

.list .t {
  display: block;
  font-size: 14.5px;
}

.list .s {
  display: block;
  color: var(--ink-soft);
  font-size: 12px;
  margin-top: 1px;
}

.list .num {
  display: inline-block;
  min-width: 2.4em;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
  margin-right: 4px;
}

/* ------------------------------------------------------------------- main */

#main {
  overflow-y: auto;
  min-height: 0;
}

.toolbar {
  position: sticky;
  top: 0;
  z-index: 4;
  display: flex;
  gap: 14px;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  padding: 16px 26px 12px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--rule);
}

/* The hymn number, large, as on a hymn board; press it to go to another. */
.number {
  font-size: 22px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  padding: 2px 10px;
  min-width: 48px;
  line-height: 1.3;
}

.titles { min-width: 0; }

.titles h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
}

.titles p {
  margin: 2px 0 0;
  color: var(--ink-soft);
  font-size: 13.5px;
}

.controls {
  display: flex;
  gap: 18px;
  align-items: center;
}

.group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.group > label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--ink-soft);
}

.verses { display: flex; gap: 4px; }

.verses button {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  border: 1px solid var(--rule);
  background: transparent;
  color: var(--ink-soft);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.verses button.is-on {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.btn {
  border: 1px solid var(--rule);
  background: var(--panel);
  color: var(--ink);
  border-radius: 7px;
  padding: 5px 12px;
  font: inherit;
  font-size: 13.5px;
  cursor: pointer;
}

.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: .4; cursor: default; border-color: var(--rule); color: var(--ink); }

.nav { touch-action: manipulation; }

.tune-btn { max-width: 260px; display: flex; align-items: center; gap: 5px; }
.tune-btn .tune-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--ink-soft);
}
.tune-btn #tune-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.back { display: none; }

/* Full screen is a phone control; on a desk the window is already the size you chose. */
.fullscreen { display: none; }
.fullscreen svg { display: block; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.fullscreen .icon-exit,
:root.is-fullscreen .fullscreen .icon-enter { display: none; }
:root.is-fullscreen .fullscreen .icon-exit { display: block; }

input[type=range] { width: 110px; accent-color: var(--accent); }

.step {
  width: 28px;
  height: 28px;
  flex: none;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--rule);
  border-radius: 50%;
  background: var(--panel);
  color: var(--ink-soft);
  font: inherit;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;   /* no double-tap zoom when tapped quickly */
}

.step:hover { border-color: var(--accent); color: var(--accent); }
.step:active { background: var(--accent-soft); }

.score-wrap {
  padding: 20px 26px 30px;
  /* A double tap on the music is full screen (app.js), not the browser's zoom --
     which matters on a tablet, where this wide layout is what shows. */
  touch-action: manipulation;
}

.score-stage { position: relative; }

/* The neighbouring hymns, beside the page and out of sight until a swipe
   brings them in (app.js). */
.peek {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  pointer-events: none;
  visibility: hidden;
}
.score-stage.is-swiping .peek { visibility: visible; }

/* ------------------------------------------------------------------ words */

/* The hymn as text: the whole of it when there is no music for it, or when
   the words would not fit under the notes; otherwise just the verses that
   would not. Set like a hymn book page. */
.words {
  max-width: 40em;
  margin: 0 auto;
  padding: 10px 26px 40px;
}

.words .why {
  margin: 0 0 14px;
  color: var(--ink-soft);
  font-size: 13px;
  font-style: italic;
}

.words .head {
  text-align: center;
  margin: 0 0 18px;
}

.words .head .n {
  display: block;
  font-size: 30px;
  font-weight: 600;
  line-height: 1.1;
}

.words .head .m {
  color: var(--ink-soft);
  font-size: 13px;
  font-variant: small-caps;
  letter-spacing: .06em;
}

.words .verse {
  display: flex;
  gap: .7em;
  margin: 0 0 1em;
  font-size: 17px;
  line-height: 1.35;
}

.words .verse .vn {
  flex: none;
  min-width: 1.4em;
  text-align: right;
  color: var(--ink-soft);
}

.words .verse .vt { white-space: pre-line; }
.words .verse.refrain .vt { font-style: italic; }
.words .verse .vh { display: block; font-style: italic; color: var(--ink-soft); margin-bottom: .2em; }

.meta {
  padding: 0 26px 60px;
  color: var(--ink-soft);
  font-size: 13px;
  display: flex;
  gap: 26px;
  flex-wrap: wrap;
}

.meta b { font-weight: 600; color: var(--ink); }

/* ------------------------------------------------------------------ sheets */

/* The number pad and the tune list: a panel over the page, dismissed by a
   tap outside it. On a phone it rises from the bottom, where the thumb is. */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
}

.sheet-back {
  position: absolute;
  inset: 0;
  background: rgba(30, 25, 15, .28);
}

.sheet-panel {
  position: relative;
  width: min(360px, calc(100% - 24px));
  max-height: calc(100% - 40px);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(30, 25, 15, .25);
  overflow: hidden;
}

.sheet-panel.tunes { width: min(440px, calc(100% - 24px)); }

.keypad-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 10px 8px 16px;
}

.keypad-book {
  color: var(--ink-soft);
  font-size: 13px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.close { padding: 4px 9px; }

.keypad-shown {
  text-align: center;
  font-size: 46px;
  font-weight: 600;
  line-height: 1.1;
  min-height: 1.1em;
  font-variant-numeric: tabular-nums;
}

.keypad-hint {
  text-align: center;
  min-height: 1.4em;
  font-size: 13px;
  color: var(--ink-soft);
  padding: 0 16px 6px;
}
.keypad-hint.is-bad { color: var(--highlight); }

.keys {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 6px 12px max(12px, env(safe-area-inset-bottom));
}

.keys button {
  height: 52px;
  border: 1px solid var(--rule);
  border-radius: 9px;
  background: var(--bg);
  color: var(--ink);
  font: inherit;
  font-size: 22px;
  cursor: pointer;
  touch-action: manipulation;
}

.keys button:active { background: var(--accent-soft); }
.keys .section-key { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-soft); }
.keys .section-key.is-on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.keys .section-key:disabled { opacity: .35; cursor: default; }
.keys .go {
  grid-column: 1 / -1;
  background: var(--accent);
  border-color: var(--accent);
  color: var(--panel);
  font-size: 17px;
  letter-spacing: .04em;
}

.sheet-hint {
  margin: -4px 16px 6px;
  font-size: 12.5px;
  color: var(--ink-soft);
}

.tune-list { padding: 0 0 max(8px, env(safe-area-inset-bottom)); }
.tune-list li { display: grid; grid-template-columns: auto 1fr auto; column-gap: 10px; align-items: baseline; }
.tune-list .t { grid-column: 2; }
.tune-list .s { grid-column: 2; }
.tune-list .row-play {
  grid-column: 1;
  grid-row: 1 / span 2;
  align-self: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--rule);
  border-radius: 50%;
  background: var(--panel);
  color: var(--accent);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  touch-action: manipulation;
}
.tune-list .row-play:hover { border-color: var(--accent); }
.tune-list li.is-playing .row-play { background: var(--accent); border-color: var(--accent); color: var(--panel); }
.tune-list .fit {
  grid-column: 3;
  grid-row: 1 / span 2;
  align-self: center;
  font-size: 11.5px;
  color: var(--ink-soft);
  text-align: right;
  max-width: 7em;
  line-height: 1.25;
}
.tune-list li.is-own .fit { color: var(--accent); }
.tune-list li.is-bad { opacity: .65; }
.tune-list li.is-bad .fit { color: var(--highlight); }

/* ------------------------------------------------------------------ score */

svg.score {
  display: block;
  margin-inline: auto;       /* a page shrunk below full width sits centred */
  max-width: 100%;
  height: auto;              /* the viewBox scales; without this it squashes */
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: 4px;
  box-shadow: var(--shadow);
}

svg.score text { fill: var(--ink); }
svg.score rect, svg.score circle { fill: var(--ink); }

svg.score .staffline,
svg.score .ledger { fill: var(--ink); opacity: .82; }

svg.score .stem,
svg.score .beam { fill: var(--ink); }

svg.score .tie,
svg.score .slur {
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.6;
  stroke-linecap: round;
}

svg.score .volta path {
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.3;
}

svg.score .mark,
svg.score .measureNumber {
  font-family: "Source Serif 4", Georgia, serif;
  fill: var(--ink-soft);
  font-variant: small-caps;
  letter-spacing: .04em;
}

svg.score .scoreTitle,
svg.score .scoreSub,
svg.score .scoreCredit,
svg.score .scoreNumber {
  font-family: "Source Serif 4", "Iowan Old Style", Georgia, "Times New Roman", serif;
}

svg.score .scoreTitle { font-weight: 600; letter-spacing: .005em; }
svg.score .scoreSub { fill: var(--ink-soft); font-variant: small-caps; letter-spacing: .06em; }
svg.score .scoreCredit { fill: var(--ink-soft); font-style: italic; }
svg.score .scoreNumber { fill: var(--ink-soft); font-variant-numeric: tabular-nums; }

svg.score .lyric {
  font-family: "Source Serif 4", "Iowan Old Style", Georgia, "Times New Roman", serif;
}

svg.score .lyric.italic { font-style: italic; }
svg.score .verseNumber { font-weight: 600; }

svg.score .hyphen,
svg.score .extender { fill: var(--ink); opacity: .8; }

svg.score .notehead.is-playing { fill: var(--highlight); }

/* The passage the by-ear search matched, so you can see what it heard. */
svg.score .notehead.is-matched { fill: var(--accent); }
svg.score .is-matched.stem { stroke: var(--accent); }

svg.score .notehead { transition: fill .08s linear; }

/* ------------------------------------------------------------------- ear */

.mic {
  white-space: nowrap;
  padding: 6px 11px;
  flex: none;
}

.mic span {
  color: var(--highlight);
  font-size: 11px;
  vertical-align: 1px;
}

.mic.is-on {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--panel);
}

.mic.is-on:hover { color: var(--panel); }
.mic.is-on span { color: var(--panel); animation: pulse 1.1s ease-in-out infinite; }

@keyframes pulse { 50% { opacity: .25; } }

.ear {
  border-bottom: 1px solid var(--rule);
  padding: 10px 16px 6px;
  background: var(--accent-soft);
}

.ear-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 7px;
}

.ear-state {
  font-size: 13px;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.ear-trace {
  display: block;
  width: 100%;
  height: 92px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--panel);
}

.ear-hint {
  margin: 7px 0 4px;
  font-size: 12px;
  line-height: 1.35;
  color: var(--ink-soft);
}

.ear-results {
  max-height: 38vh;
  margin: 0 -16px;          /* the panel is padded; the rows should not be */
  padding-bottom: 2px;
}

/* Title on the left, score on the right, subtitle under both, and a bar along
   the bottom edge for the score again -- readable at a glance from a pew. */
.ear-results li {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  column-gap: 10px;
  align-items: baseline;
}

.ear-results .t { grid-column: 1; }
.ear-results .s { grid-column: 1; }

.ear-results .pc {
  grid-column: 2;
  grid-row: 1;
  font-size: 12px;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

.ear-results li.is-sure {
  background: var(--panel);
  border-left-color: var(--accent);
}

.ear-results li.is-sure .t { font-weight: 600; }
.ear-results li.is-sure .pc { color: var(--accent); }

.ear-results .bar {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 2px;
  background: var(--accent);
  opacity: .45;
}

/* On the hymn page: a band under the toolbar while listening for which of
   this hymn's tunes is being sung. */
.ear-here {
  border-bottom: 1px solid var(--rule);
  padding: 10px 26px 6px;
}
.ear-here .ear-trace { height: 70px; }
.ear-here .ear-results { margin: 0; max-height: 30vh; }
.ear-here .ear-results li { padding: 6px 10px; }
.ear-here .ear-results li.is-sel { background: var(--panel); border-left-color: var(--accent); }

/* "Tune Sheet has been updated": a line at the foot of the page, not in the way. */
.toast {
  position: fixed;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: calc(100% - 24px);
  padding: 8px 10px 8px 14px;
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: var(--shadow);
  font-size: 14px;
}
.toast .btn { white-space: nowrap; }

@media print {
  #sidebar, .toolbar, .meta, .sheet, .toast { display: none !important; }
  #app { display: block; }
  #main { overflow: visible; }
  .score-wrap { padding: 0; }
  svg.score { border: 0; box-shadow: none; background: none; }
  body { background: #fff; }
}

@media (max-width: 820px) {
  /* One column, and two pages within it: the hymn (with its music) and the
     list of hymns in the book (with the by-ear results). `is-score` says which
     one you are on; the Hymns button in the toolbar is how you get to the
     list, and choosing a hymn is how you get back. */
  #app {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    height: 100dvh;
  }

  #sidebar { border-right: 0; }
  #main { padding-bottom: env(safe-area-inset-bottom); }

  #app.is-score #sidebar { display: none; }
  #app:not(.is-score) #main { display: none; }

  .back {
    display: block;
    margin-right: 2px;
    padding: 6px 10px;
  }

  .side-head {
    padding: max(12px, env(safe-area-inset-top)) 14px 8px;
  }

  .book-btn { font-size: 17px; }
  .menu { top: calc(max(12px, env(safe-area-inset-top)) + 40px); }

  .mic { padding: 9px 13px; }

  /* Thumbs, not cursors. */
  .list li { padding: 11px 14px; }
  .chip { padding: 4px 11px; }

  .ear { padding: 10px 14px 6px; }
  .ear-trace { height: 110px; }
  .ear-results { margin: 0 -14px; max-height: none; }
  .ear-here { padding: 8px 12px 4px; }
  .ear-here .ear-trace { height: 60px; }
  .ear-here .ear-results { margin: 0; max-height: 36vh; }

  .toolbar {
    gap: 8px 10px;
    align-items: center;
    padding: max(8px, env(safe-area-inset-top)) 12px 8px;
    /* Moved by app.js as the music scrolls, the way a browser's own bar is. */
    will-change: transform;
  }

  .number { font-size: 19px; padding: 3px 8px; min-width: 40px; }

  .fullscreen:not([hidden]) {
    display: grid;
    place-items: center;
    width: 36px;
    height: 34px;
    padding: 0;
    flex: none;
    touch-action: manipulation;
  }

  .titles { flex: 1; min-width: 0; }
  .titles h2 {
    font-size: 17px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .titles p { font-size: 12px; }

  .controls {
    order: 3;
    width: 100%;
    gap: 10px;
    overflow-x: auto;          /* rather than wrapping into a tall stack */
    padding-bottom: 2px;
  }
  .controls .group { flex: none; }
  .group > label { display: none; }
  /* Every verse is always shown on a phone; toggling them is a desk thing. */
  #verse-group { display: none !important; }
  input[type=range] { width: 82px; }
  .step { width: 32px; height: 32px; }   /* a comfortable thumb target */
  /* Arrows only, sized for a thumb: the words cost width the slider needs. */
  .nav span { display: none; }
  .nav { min-width: 36px; height: 32px; font-size: 20px; line-height: 1; padding: 0 8px; }
  .tune-btn { max-width: 150px; height: 32px; }
  /* The whole row must fit a phone's width: prev, next, tune, play, listen. */
  .controls { gap: 8px; }
  .controls .group { gap: 6px; }
  .toolbar .mic { height: 32px; padding: 0 9px; }
  .toolbar .mic .mic-label { display: none; }
  .toolbar .mic span { font-size: 13px; vertical-align: 0; }

  .score-wrap {
    padding: 8px 8px 24px;
    /* Pinching and sideways swipes are ours (app.js); the browser only scrolls. */
    touch-action: pan-y;
  }
  /* The page scaled up mid-pinch, and the neighbours waiting either side,
     stay inside the stage rather than widening or lengthening the page. */
  .score-stage { overflow: clip; }
  svg.score { border-radius: 3px; }

  .words { padding: 8px 18px 30px; }
  .words .verse { font-size: 16px; }

  /* The credits are already in the score's own header; the footer repeating
     them is only scroll on a phone. */
  .meta { display: none; }

  /* Sheets rise from the bottom, under the thumb. */
  .sheet { place-items: end center; }
  .sheet-panel, .sheet-panel.tunes {
    width: 100%;
    max-height: 85dvh;
    border-radius: 16px 16px 0 0;
    border-bottom: 0;
  }
  .keys button { height: 58px; }
}

/* Phones proper: the score is worth more than the chrome around it. */
@media (max-width: 500px) {
  #print { display: none; }

  /* The page runs edge to edge: no gutter round it, no card edges. */
  .score-wrap { padding: 0 0 20px; }
  svg.score {
    border-width: 1px 0;
    border-radius: 0;
    box-shadow: none;
  }

  .titles p {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}
