/* One stylesheet for the whole UI. Order: fonts, palette, primitives (fields,
   buttons, pills, tabs), then the three places with a layout of their own —
   the studio columns, the library list, the guide — and the phone
   breakpoint last. */

@font-face { font-family: "IBM Plex Sans"; font-weight: 400; font-style: normal; font-display: swap;
             src: url("/static/fonts/IBMPlexSans-Regular.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Sans"; font-weight: 600; font-style: normal; font-display: swap;
             src: url("/static/fonts/IBMPlexSans-SemiBold.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Mono"; font-weight: 400; font-style: normal; font-display: swap;
             src: url("/static/fonts/IBMPlexMono-Regular.woff2") format("woff2"); }

:root {
  --bg: #f4f5f8;
  --panel: #ffffff;
  --sunken: #f8f9fb;
  --border: #dfe3ea;
  --text: #1b2430;
  --muted: #6b7484;
  --accent: #4f46e5;
  --accent-soft: #ebeaff;
  --danger: #d33a3a;
  --danger-soft: #fdeeee;
  --ver-v: #c9cfd8;
  --ver-n: #0d9488;
  --ver-n-soft: #e8f6f4;
  /* o wears what a selected row used to, and a selected row the button's fill. */
  --ver-o: var(--accent);
  --ver-o-soft: var(--accent-soft);
  /* --muted is 4.2:1 on the n and o tints; this keeps small text above 4.5. */
  --muted-tinted: #5e6777;
  /* A line that still shows on the n and o tints, where --border all but vanishes. */
  --rule: color-mix(in srgb, var(--text) 28%, transparent);
  --on-color: #ffffff;
  /* The analysis strip in the people's colours: notes orange, gaps dark grey, those in the tables
     red and black, and a dark joint so two notes in a row never read as one. */
  --an-note: #ff9f0a;
  --an-note-long: #e0202a;
  --an-gap: #474c53;
  --an-gap-long: #000000;
  --an-joint: #000000;
  --key-low: #2563eb;
  --key-mid: #16a34a;
  --key-high: #facc15;
  /* A minute of the analysis strip, whatever the window: one scale for every score. */
  --minute: 960px;
  --radius: 10px;
  --font: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", ui-sans-serif, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --panel: #1c2027;
    --sunken: #181b21;
    --border: #2c323c;
    --text: #e6e9ef;
    --muted: #949cab;
    --accent: #8b87f5;
    --accent-soft: #272a45;
    --danger: #ef6b6b;
    --danger-soft: #3a2323;
    --ver-v: #424955;
    --ver-n: #2dd4bf;
    --ver-n-soft: #18302d;
    --muted-tinted: #949cab;
    /* White on the lighter dark-theme accent is 2.9:1; dark text is over 6. */
    --on-color: #14171c;
  }
}

/* Native controls — the audio players above all — follow the theme too. */
:root { color-scheme: light dark; }

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
}

h1, h2, h3 { font-weight: 600; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.note { margin: 0 0 10px; font-size: .82rem; color: var(--muted); }
.error { color: var(--danger); font-size: .85rem; }

/* --- primitives ---------------------------------------------------------- */

.group {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 12px;
}

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
/* display: flex above beats the browser's own [hidden] rule, and the library
   hides its player whole when a song's audio has been deleted. */
.field[hidden] { display: none; }
.field:last-child { margin-bottom: 0; }
.label { font-size: .8rem; font-weight: 600; display: flex; align-items: baseline; gap: 8px; }
.label output { font-variant-numeric: tabular-nums; color: var(--accent); font-weight: 400; }
.label a { font-size: .75rem; font-weight: 400; }
.info { font-size: .72rem; color: var(--muted); }

textarea, input[type="text"], input[type="number"], input[type="search"],
input[type="password"], select {
  width: 100%;
  font-family: inherit;
  font-size: .88rem;
  color: var(--text);
  background: var(--sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 9px;
}
textarea { resize: vertical; line-height: 1.5; }
textarea:focus, input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea[readonly] { color: var(--muted); }
#log, #abc { font-family: var(--mono); font-size: .76rem; line-height: 1.4; }

input[type="range"] { width: 100%; accent-color: var(--accent); margin: 2px 0; }

button {
  font-family: inherit;
  font-size: .88rem;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 12px;
  cursor: pointer;
}
button:hover { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-color); }
button.stop { background: var(--danger); border-color: var(--danger); color: var(--on-color); }
button.big { width: 100%; min-height: 54px; font-size: 1rem; }
button.small { font-size: .78rem; padding: 5px 10px; }

.split { display: flex; gap: 8px; align-items: flex-start; }
.split > * { flex: 1; }
.split > .stop { flex: 0 0 auto; }

.with-button { display: flex; gap: 6px; align-items: stretch; }
.with-button input, .with-button select { flex: 1; min-width: 0; }
.with-button button { flex: 0 0 auto; }

/* The preset panel is one dropdown and the two rare actions on it. Naming a
   preset and confirming a deletion both fold out under that row, one at a
   time, so the panel is a single line until something is asked of it. */
#preset-form, #preset-confirm { margin-top: 8px; }
#preset-form-note { display: block; margin-top: 4px; }

.pills { display: flex; flex-wrap: wrap; gap: 6px; }
.pills label { cursor: pointer; }
.pills input { position: absolute; opacity: 0; pointer-events: none; }
.pills span {
  display: inline-block;
  font-size: .8rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 11px;
  background: var(--sunken);
}
.pills label:has(:checked) span { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.pills label:has(:focus-visible) span { outline: 2px solid var(--accent); }
.pills label:has(:disabled) { cursor: default; }
.pills label:has(:disabled) span { opacity: .45; }
#versions span { min-width: 30px; padding: 3px 0; text-align: center; }

details.group > summary { cursor: pointer; font-size: .85rem; font-weight: 600; }
details.group[open] > summary { margin-bottom: 10px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.tab { background: none; border: none; border-bottom: 2px solid transparent; border-radius: 0;
       color: var(--muted); font-weight: 600; padding: 8px 12px; }
.tab:hover { border-color: transparent; color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.panel { display: none; }
.panel.active { display: block; }
.tabs.inner { margin-bottom: 10px; }

/* --- page ---------------------------------------------------------------- */

#page { max-width: 1240px; margin-inline: auto; padding: 14px 18px 40px; }

#topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
#brand { flex: 1; min-width: 0; }
#brand h1 { margin: 0; font-size: 1.5rem; letter-spacing: -0.01em; }
#brand p { margin: 0; font-size: .78rem; color: var(--muted); }
#corner { text-align: right; }
#engine { font-size: .95rem; font-variant-numeric: tabular-nums; white-space: pre-line; }
#disk { font-size: .85rem; font-variant-numeric: tabular-nums; }
#who { font-size: .8rem; color: var(--muted); }

.row { display: flex; gap: 14px; align-items: flex-start; }
.row > .field { flex: 1; min-width: 0; }
.col { min-width: 0; }
.col.wide { flex: 3; }
.col.narrow { flex: 2; }

#estimate { margin: 0 0 8px; font-size: .78rem; color: var(--muted); }
#stop { margin-top: 0; }
#lib-player, .result audio { width: 100%; }
#results-field { margin-top: 14px; }
.result + .result { margin-top: 10px; }
.result-head { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; font-size: .85rem; }
.result-head .song-head { flex: 1; min-width: 0; }

/* In the list, on the card and beside a result alike: a title up to 9999-n and a
   length up to 6:00 take one width, so what follows them stands in one column. */
.song-head { display: flex; flex-wrap: wrap; align-items: baseline; column-gap: .75em;
             font-variant-numeric: tabular-nums; }
.song-head .title { min-width: 6.5ch; font-weight: 600; }
.song-head .length { min-width: 4ch; }
/* Ten digits have to be readable whole: a clipped seed reads as a different
   number, and the point of a seed is that it is copied exactly. ch against the
   mono face sizes the field to the longest one the 🎲 can produce, and the
   spinners are dropped because stepping by 1 through 2**31 is not a gesture. */
.field.seed { flex: 0 0 auto; }
.with-button #seed {
  /* ch is the width of a digit in the mono face; the padding is border-box and
     has to be added or the last digit still clips. */
  flex: 0 0 calc(11ch + 24px);
  font-family: var(--mono);
  font-size: .8rem;
  appearance: textfield;
}
#seed::-webkit-outer-spin-button, #seed::-webkit-inner-spin-button { appearance: none; margin: 0; }

#progress { margin: 8px 0 12px; }
#progress-bar { height: 5px; width: 0; background: var(--accent); border-radius: 3px; transition: width .2s; }
#progress-text { display: block; font-family: var(--mono); font-size: .7rem; color: var(--muted);
                 margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* The library list: one song per row, the style on a second line. A dropdown
   showed one clipped line, and what got clipped was the style — the one thing
   that tells two songs apart. */
#past { list-style: none; margin: 10px 0; padding: 0; max-height: 32rem; overflow-y: auto; }
#past li { margin-bottom: 4px; }
/* A version's 4px stripe takes 3px more than a plain border, and the padding gives
   them back, so every row's text starts at the same place. */
#past button {
  display: block; width: 100%; text-align: left; padding: 6px 9px 6px 12px;
  background: var(--panel); border-color: var(--border);
}
#past button.ver-n, #past button.ver-o { padding-left: 9px; }
#past button.ver-n, #details.ver-n { background: var(--ver-n-soft); border-left: 4px solid var(--ver-n); }
#past button.ver-o, #details.ver-o { background: var(--ver-o-soft); border-left: 4px solid var(--ver-o); }
#past button.selected { background: var(--accent); border-color: var(--accent); color: var(--on-color); }
#past button.selected.ver-n { border-left-color: var(--ver-n); }
/* o's stripe is the fill's own colour, so on a selected row it takes the tint instead. */
#past button.selected.ver-o { border-left-color: var(--ver-o-soft); }
#past .head { font-size: .85rem; }
#past .style { display: block; font-size: .76rem; color: var(--muted); line-height: 1.35; }
#past button.gone .head { color: var(--muted); }
#past button.ver-n .style, #past button.ver-o .style, #past button.ver-n.gone .head,
#past button.ver-o.gone .head, #details.ver-n .muted, #details.ver-o .muted { color: var(--muted-tinted); }
#past button.selected .style, #past button.selected.gone .head { color: var(--on-color); }
.gone-note { color: var(--danger); font-size: .85rem; }
#summary { font-size: .8rem; white-space: pre-line; }

/* Every card wears a version's stripe, v's included, so its text never moves. */
#details { background: var(--panel); border: 1px solid var(--border); border-left: 4px solid var(--ver-v);
           border-radius: var(--radius); padding: 12px 12px 12px 9px; margin-bottom: 12px;
           max-height: 30rem; overflow-y: auto; }
#details h3 { margin: 0 0 .5em; font-size: 1rem; font-weight: 400; overflow-wrap: anywhere; column-gap: 1em; }
#details p { margin: .25em 0; font-size: .85rem; }
#details p b { font-weight: 600; }
#details .sum { font-variant-numeric: tabular-nums; }
/* The rule ends where the «Карта:» line does: what the song took above it, how it
   was made below. */
#details .spend { margin-bottom: .5em; }
#details .spend > :last-child { width: fit-content; padding-bottom: .5em;
                                border-bottom: 1px solid var(--rule); }
#details h4 { margin: 1em 0 .3em; font-size: .85rem; }
#details pre { background: var(--sunken); border-radius: var(--radius); padding: 8px;
               font-family: var(--mono); font-size: .76rem; overflow-x: auto; white-space: pre-wrap;
               margin: .2em 0 .8em; }
#confirm { border: 1px solid var(--danger); background: var(--danger-soft);
           border-radius: var(--radius); padding: 10px; margin-top: 10px; }
#confirm p { margin: 0 0 8px; font-size: .85rem; }
#details .series { display: flex; flex-wrap: wrap; gap: 6px; margin: .3em 0 .6em; }
#details .series button { min-width: 30px; padding: 3px 8px; border-radius: 999px; font-size: .8rem; }
#details .series .ver-v { border-color: var(--ver-v); }
#details .series .ver-n { background: var(--ver-n-soft); border-color: var(--ver-n); }
#details .series .ver-o { background: var(--ver-o-soft); border-color: var(--ver-o); }
/* The 🗑 glyph is taller than a line of text; the row keeps one height anyway. */
#lib-actions { align-items: stretch; }

/* --- the score window and the analysis ------------------------------------ */

dialog.sheet { max-height: 85vh; padding: 0; border: 1px solid var(--border); border-radius: var(--radius);
               background: var(--panel); color: var(--text); box-shadow: 0 12px 40px rgba(0, 0, 0, .35); }
dialog.sheet::backdrop { background: rgba(0, 0, 0, .45); }
/* The frame takes what the window leaves inside its border: a frame as tall as the window overflowed it
   by 2px, and the window scrolled beside the frame's own scrollbar. */
dialog.sheet[open] { display: flex; flex-direction: column; }
.sheet-frame { display: flex; flex-direction: column; gap: 10px; flex: 1; min-height: 0; padding: 12px 14px 14px; }
.sheet-head { display: flex; align-items: center; gap: 10px; }
.sheet-head h2 { flex: 1; margin: 0; font-size: .95rem; overflow-wrap: anywhere; }
button.close { flex: 0 0 auto; width: 30px; height: 30px; }
button.close svg { display: block; }
#score-view { width: min(900px, calc(100vw - 32px)); }
/* Bars are not wrapped: a bar broken across two lines reads as two. */
#score-text { flex: 1; min-height: 0; overflow: auto; margin: 0; padding: 10px; white-space: pre;
              background: var(--sunken); border-radius: var(--radius);
              font-family: var(--mono); font-size: .78rem; line-height: 1.45; }

/* One size whatever the score. The width is a minute of strip, room either side for the scale's labels,
   and a scrollbar's gutter, kept even when there is no scrollbar so the strips never lose their end. */
#analysis-view { width: min(calc(var(--minute) + 96px), calc(100vw - 32px)); height: 92vh; max-height: 92vh; }
#analysis-body { flex: 1; min-height: 0; overflow: auto; scrollbar-gutter: stable; font-size: .88rem; }
#analysis-body b { font-weight: 600; }
.an-head { display: flex; flex-wrap: wrap; align-items: baseline; column-gap: 2.5em; row-gap: 6px; margin: 0 0 8px;
           font-variant-numeric: tabular-nums; }
#analysis-range { width: auto; margin-left: .3em; padding: 3px 6px; cursor: pointer; }
#analysis-result { transition: opacity .15s; }
#analysis-result[aria-busy="true"] { opacity: .45; transition-delay: .2s; }
.an-facts { display: grid; grid-template-columns: max-content max-content 1fr; column-gap: .4em; row-gap: 3px;
            align-items: baseline; margin-bottom: 14px; }
.an-facts .tones { display: flex; flex-wrap: wrap; gap: 4px; }
.tone { min-width: 2.2em; padding: 1px 5px; border: 1px solid rgba(0, 0, 0, .3); border-radius: 3px;
        color: #111111; font-family: var(--mono); font-size: .82rem; text-align: center; }
.tone.on-dark { color: #ffffff; }
.an-colors { display: inline-flex; align-items: center; align-self: center; gap: .35em; cursor: pointer; }
.an-colors input { width: auto; margin: 0; }
#analysis-result.colored .an-strip .note:not(.long) { background: var(--tone); }
/* overflow-y is spelled out: left to follow overflow-x, a label a pixel too low gave the strips a scrollbar of their own. */
.an-strips { display: flex; flex-direction: column; align-items: flex-start; gap: 14px;
             overflow-x: auto; overflow-y: hidden; padding: 0 24px; margin-bottom: 16px; }
.an-row { flex: none; }
.an-marks { position: relative; height: 14px; font-size: .68rem; line-height: 14px;
            font-variant-numeric: tabular-nums; }
.an-marks span { position: absolute; transform: translateX(-50%); white-space: nowrap; }
.an-strip { position: relative; height: 10px; }
.an-strip span { position: absolute; height: 100%; }
.an-strip .gap { background: var(--an-gap); }
.an-strip .note { background: var(--an-note); }
.an-strip .gap.long { background: var(--an-gap-long); }
.an-strip .note.long { background: var(--an-note-long); }
.an-strip .note.joined { border-left: 1px solid var(--an-joint); }
.an-scale { position: relative; height: 17px; border-top: 1px solid var(--border); color: var(--muted);
            font-size: .62rem; line-height: 1; font-variant-numeric: tabular-nums; }
.an-scale span { position: absolute; top: 0; padding-top: 6px; transform: translateX(-50%); white-space: nowrap; }
.an-scale span::before { content: ""; position: absolute; top: 0; left: 50%; height: 4px;
                         border-left: 1px solid var(--muted); }
.an-tables { display: flex; gap: 16px; align-items: flex-start; }
.an-tables table { flex: 1 1 0; max-width: 22rem; border-collapse: collapse; font-size: .85rem; font-variant-numeric: tabular-nums; }
.an-tables caption { text-align: left; font-weight: 600; padding-bottom: 4px; }
.an-tables th, .an-tables td { border: 1px solid var(--border); padding: 3px 8px; text-align: left; }
.an-tables th { font-weight: 600; background: var(--sunken); }
.an-tables th:nth-child(3), .an-tables td:nth-child(3) { text-align: right; }

#analysis-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
#analysis-note, #score-note { margin: 0; }
#analysis-split { flex: none; min-width: 10rem; }

#analysis-help { font-size: .95rem; font-weight: 600; }
#keys-view { width: min(calc(var(--minute) + 96px), calc(100vw - 32px)); }
#keys-view .info { margin: 0; font-size: .8rem; }
#keys-view code { font-family: var(--mono); }
#keys { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 8px; }
#keys .octave { position: relative; display: flex; gap: 2px; flex: none; }
#keys .key { display: flex; align-items: flex-end; justify-content: center; width: 36px; height: 130px;
             padding-bottom: 8px; border: 1px solid rgba(0, 0, 0, .25); border-radius: 0 0 5px 5px;
             color: #111111; font-family: var(--mono); font-size: .78rem; }
#keys .key.on-dark { color: #ffffff; }
/* --after is how many white keys stand left of it: the black key sits on that gap, 38px a key. */
#keys .key.black { position: absolute; top: 0; left: calc(var(--after) * 38px - 13px); z-index: 1;
                   flex-direction: column; justify-content: flex-end; align-items: center; width: 24px; height: 80px; padding-bottom: 6px;
                   border-color: rgba(0, 0, 0, .65); box-shadow: 0 2px 4px rgba(0, 0, 0, .35);
                   font-size: .66rem; line-height: 1.1; }

/* --- the editor ---------------------------------------------------------- */

#editor-foot { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
#editor-foot > div { display: flex; flex-direction: column; gap: 4px; }
#editor-error { margin: 0; }
#editor-analyze { flex: none; min-width: 10rem; }
#editor-text { height: calc(100vh - 260px); min-height: 22rem; resize: vertical; white-space: pre;
               font-family: var(--mono); font-size: .8rem; line-height: 1.45; }

/* --- the guide ---------------------------------------------------------- */

#help-layout { display: flex; gap: 28px; align-items: flex-start; }
#help-toc { flex: 0 0 240px; position: sticky; top: 12px; max-height: calc(100vh - 24px); overflow-y: auto; }
#help-toc ol { list-style: none; margin: 0; padding: 0; }
#help-toc li { margin: 0; }
#help-toc a { display: block; padding: 3px 8px; border-radius: 6px; font-size: .82rem;
              color: var(--text); text-decoration: none; }
#help-toc a:hover { background: var(--accent-soft); color: var(--accent); }
#help-toc li.h2 { margin-top: 8px; }
#help-toc li.h2:first-child { margin-top: 0; }
#help-toc li.h2 a { font-weight: 600; }
#help-toc li.h3 a { padding-left: 20px; color: var(--muted); }
#help-body { flex: 1; min-width: 0; }
#help-body > :not(table) { max-width: 80ch; }
#help-body hr { margin: 2em 0; border: none; border-top: 1px solid var(--border); }
#help-body h2, #help-body h3 { scroll-margin-top: 12px; }

/* One glyph in a circle: the padding buttons inherit is what pushed it off
   centre, so this places it itself. */
button.close {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0; line-height: 1; border-radius: 50%;
}
#help-body h1 { font-size: 1.3rem; margin: 0 0 .3em; }
#help-body h2 { font-size: 1.1rem; margin-top: 1.6em; }
#help-body h3 { font-size: .98rem; margin-top: 1.2em; }
#help-body h4 { font-size: .9rem; margin-top: 1em; }
#help-body p, #help-body li, #help-body td, #help-body th { font-size: .88rem; line-height: 1.6; }
#help-body table { width: 100%; border-collapse: collapse; }
#help-body th, #help-body td { border: 1px solid var(--border); padding: 4px 7px; text-align: left; }
#help-body code { font-family: var(--mono); font-size: .82rem; background: var(--sunken);
                  border-radius: 4px; padding: 1px 4px; }
#help-body pre { background: var(--sunken); border-radius: var(--radius); padding: 10px; overflow-x: auto; }
#help-body pre code { background: none; padding: 0; }

/* --- toasts and login ---------------------------------------------------- */

#toasts { position: fixed; right: 14px; bottom: 14px; z-index: 50;
          display: flex; flex-direction: column; gap: 8px; max-width: min(420px, calc(100vw - 28px)); }
.toast { background: var(--panel); border: 1px solid var(--border); border-left: 4px solid var(--accent);
         border-radius: var(--radius); padding: 9px 12px; font-size: .85rem;
         box-shadow: 0 6px 20px rgba(0, 0, 0, .13); }
.toast.bad { border-left-color: var(--danger); }

.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
#login { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
         padding: 22px; width: 100%; max-width: 340px; }
#login h1 { margin: 0; font-size: 1.5rem; }
#login p { margin: 0 0 16px; font-size: .8rem; }

/* --- phones -------------------------------------------------------------- */

@media (max-width: 768px) {
  #page { padding: 10px 12px 30px; }
  .row, .split { flex-direction: column; }
  .row > *, .split > * { width: 100%; }
  .split > .stop { flex: 1 1 auto; }
  /* In one column the last field of a split loses the gap the row used to give it. */
  .group > .split + .field, .row + .row, #reset { margin-top: 12px; }
  .field.seed { flex: 1 1 auto; }
  /* One column: the field has the whole width and no reason to be 12ch. */
  .with-button #seed { flex: 1 1 auto; }
  /* Three controls do not fit one line at this width: the dropdown (and the
     name field under it) take the whole width, their buttons sit below. */
  #preset-bar .with-button { flex-wrap: wrap; }
  #preset-bar .with-button > :first-child { flex: 1 1 100%; }
  /* Two short buttons, and the question they answer is one line long. */
  #confirm .split { flex-direction: row; }
  /* A finger needs 44px; the desktop's 22px pills are a mis-tap waiting to happen. */
  .pills { gap: 8px; }
  .pills span { display: inline-flex; align-items: center; min-height: 44px; padding: 0 16px; font-size: 1rem; }
  #versions span { justify-content: center; min-width: 48px; padding: 0; }
  #details .series button { min-width: 44px; min-height: 44px; font-size: .95rem; }

  /* Four tabs fit one line at 390px only with narrower sides; the height is a finger's. */
  #tabs .tab { padding: 12px 8px; }

  #topbar { flex-wrap: wrap; }
  #brand { flex: 1 1 100%; order: 1; }
  #brand h1 { font-size: 1.25rem; }
  #corner { flex: 1; order: 2; text-align: left; }
  #engine { font-size: 1rem; }
  #disk { font-size: .9rem; }

  /* Safari zooms the page when a focused field's text is under 16px and never
     zooms back out. Read-only fields cannot be typed into, so they stay small. */
  input, textarea, select { font-size: 16px !important; }
  #log { font-size: .72rem !important; }

  /* A scroll container inside a scrolling page is unusable on a touchscreen,
     so these give up their own; full-height text areas get one instead. */
  #past, #details { max-height: none; overflow-y: visible; }
  #lyrics { max-height: 40vh; }
  #abc { max-height: 30vh; overflow-y: auto; }
  #log { max-height: 26vh; }

  /* Stretched, or the text takes the width of its longest unbreakable line. */
  #help-layout { flex-direction: column; align-items: stretch; gap: 14px; }
  #help-body code { overflow-wrap: anywhere; }
  #help-toc { position: static; flex: none; width: 100%; max-height: none; overflow: visible;
              border-bottom: 1px solid var(--border); padding-bottom: 10px; }
  #help-toc a { padding: 9px 8px; font-size: .95rem; }
  #help-toc li.h3 a { padding-left: 22px; }
  #help-body table { display: block; overflow-x: auto; }
  #toasts { left: 12px; right: 12px; max-width: none; }

  #score-view, #analysis-view { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh;
                                margin: 0; border: none; border-radius: 0; }
  #keys-view { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: var(--radius) var(--radius) 0 0; }
  .sheet-frame { padding: 10px 12px 14px; }
  button.close { width: 44px; height: 44px; }
  #score-actions { flex-direction: row; flex-wrap: wrap; }
  #score-actions > button { flex: 1 1 0; width: auto; }
  #score-actions button, #analysis-range, #analysis-split, #editor-analyze { min-height: 44px; }
  #analysis-foot { flex-direction: column; align-items: stretch; }
  #score-actions #score-analyze { flex: 1 1 100%; }
  .an-strips { padding: 0 14px 10px; }
  .an-tables { gap: 10px; }
  .an-tables th, .an-tables td { padding: 3px 5px; }
  #editor-text { height: 60vh; min-height: 0; }
  #editor-foot { flex-direction: column; align-items: stretch; }
}
