/* Transfer function: what is its own on top of the shared plot-first page
   (shared/css/stage.css). |H| gets most of the room, the coherence a strip
   under it, the phase (when asked for) the middle; under the plots one
   row of legend chips, which are also how the lines are shown, faded or
   hidden. The measurement cards sit in the deck where it is a column
   beside the plots (a laptop), and are a sheet that ≡ opens elsewhere. */

.plots { grid-template-rows: minmax(0, 1.7fr) minmax(0, 0.85fr); grid-auto-rows: unset; }
.plots.with-phase { grid-template-rows: minmax(0, 1.5fr) minmax(0, 0.9fr) minmax(0, 0.8fr); }
/* γ² put away: |H| (and the phase) take its room */
.plots.no-coh { grid-template-rows: minmax(0, 1fr); }
.plots.with-phase.no-coh { grid-template-rows: minmax(0, 1.6fr) minmax(0, 1fr); }

/* messages over the |H| plot (nothing measured yet, no microphone, nothing heard) */
#pw-mag .hint {
  top: 38%; left: 3.2rem; right: 1rem; text-align: center;
  font-size: 0.9rem; color: var(--text-dim);
}
#pw-mag .hint.warn { color: var(--danger); }
/* what was measured, or how far it has got: the coherence plot's top line, right */
.status {
  position: absolute; right: 0.6rem; top: 0.25rem; left: 2.6rem; margin: 0; pointer-events: none;
  font: 500 0.7rem/1.2 var(--font-mono); color: var(--text-faint); text-align: right;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.status.warn { color: var(--danger); }
/* with γ² put away, at the foot of the lowest plot, just above its frequencies */
.status.foot { top: auto; bottom: 1.4rem; left: auto; max-width: calc(100% - 4rem); padding: 0.1rem 0.35rem; background: var(--plot-tag-bg); border-radius: var(--radius-sm); }
/* a warning about the whole result (the delay moved; nothing steady at all) is said in full, over the top of γ², where it is plainest */
.status.warn.long { white-space: normal; text-align: left; line-height: 1.35; padding: 0.3rem 0.45rem; background: var(--plot-tag-bg); border: 1px solid var(--plot-tag-border); border-radius: var(--radius-sm); }

#strip .btn { white-space: nowrap; }
#btn-measure { min-width: 6.4rem; }
#btn-measure.on { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
/* the microphone's level, a hairline along the foot of Measure while the page is listening */
#btn-measure { position: relative; overflow: hidden; }
.lvl { position: absolute; left: 0; right: 0; bottom: 0; height: 2px; pointer-events: none; }
.lvl i { display: block; height: 100%; width: 0; background: currentColor; opacity: 0.55; transition: width 0.15s linear; }
#kind label, #mass label { padding: 0.35rem 0.6rem; }

/* ---------- the legend: a line's swatch and number, tapped round on → faded → off ---------- */
#legend { display: flex; align-items: center; gap: 0.35rem; padding-top: 0.4rem; min-height: 2.15rem; }
#chips { display: flex; gap: 0.3rem; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
#chips::-webkit-scrollbar { display: none; }
/* more chips than room: the row fades at its right end, so it reads as one that scrolls */
#chips.more-right { -webkit-mask-image: linear-gradient(to right, var(--text) calc(100% - 1.5rem), transparent); mask-image: linear-gradient(to right, var(--text) calc(100% - 1.5rem), transparent); }
.lg {
  flex: none; display: inline-flex; align-items: center; gap: 0.35rem;
  font: 500 0.75rem/1 var(--font-mono); color: var(--text-dim);
  background: var(--bg-raised); border: 1px solid var(--line); border-radius: 999px;
  padding: 0.3rem 0.6rem; cursor: pointer; white-space: nowrap; user-select: none;
}
.lg:hover { border-color: var(--line-strong); }
.lg.latest { color: var(--text); font-weight: 700; }
.lg.faded { color: var(--text-faint); }
.lg.off { color: var(--text-faint); text-decoration: line-through; border-style: dashed; }
.lg.more { margin-left: auto; color: var(--accent); border-color: var(--accent-border); }
/* H₂ of a one-frame result: a word that it is H₁, nothing to switch */
.lg.same { cursor: default; color: var(--text-faint); }
.lg.same:hover { border-color: var(--line); }
#legend .lg-empty { flex: 1; font: 500 0.72rem/1 var(--font-ui); color: var(--text-faint); padding-left: 0.2rem; }
#legend:not(.empty) .lg-empty { display: none; }
#legend.empty #chips { display: none; }
/* the swatch: a short piece of the line, in its look (the colour is set from the token by main.js) */
.sw { flex: none; display: inline-block; width: 1.1rem; height: 0; border-top: 2.5px solid; }
.sw.thin { border-top-width: 1px; }
.sw.band { border-top-width: 5px; opacity: 0.35; }
.sw.broad { border-top-width: 4px; opacity: 0.5; }
.faded .sw { opacity: 0.35; }
.off .sw { opacity: 0.15; }

/* ---------- the cards ---------- */
#tray header { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; }
#tray header .btn { white-space: nowrap; }
/* the buttons wrap among themselves: in one unbroken row, draft mode's Save sound made the row
   wider than the deck, which then scrolled sideways and took the cards' ✕ off the screen (Tore,
   9 Oct, on a projector); a 360 px phone lost the sheet's ✕ the same way without it */
.tray-acts { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; margin-left: auto; }
/* (and one column no wider than the deck, so nothing in the header can stretch the cards past it) */
#deck #tray { grid-template-columns: minmax(0, 1fr); }
.tick { display: inline-flex; align-items: center; gap: 0.25rem; font-size: 0.78rem; color: var(--text-dim); white-space: nowrap; cursor: pointer; }
#tray h2 { margin: 0 auto 0 0; font: 600 0.85rem/1 var(--font-ui); color: var(--text-dim); }
#btn-tray-close { display: none; }
#cards { list-style: none; margin: 0.5rem 0 0; padding: 0; display: grid; gap: 0.3rem; }
.card { display: flex; align-items: stretch; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--bg-raised); }
.card .cv {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 0.5rem; text-align: left;
  background: none; border: 0; color: inherit; padding: 0.4rem 0.2rem 0.4rem 0.55rem; cursor: pointer; font: inherit;
}
.card .no { font: 600 0.82rem/1 var(--font-mono); color: var(--text-dim); min-width: 1.1rem; }
.card.latest .no { color: var(--text); font-weight: 700; }
.card .tx { display: grid; min-width: 0; gap: 0.15rem; }
.card .nm, .card .sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .nm { font: 500 0.8rem/1.2 var(--font-ui); color: var(--text); }
.card .sub { font: 500 0.68rem/1.2 var(--font-mono); color: var(--text-faint); }
.card.faded .nm, .card.faded .no { color: var(--text-faint); }
.card.off .nm, .card.off .no { color: var(--text-faint); text-decoration: line-through; }
.card.off { border-style: dashed; }
.card .del { flex: none; width: 2.4rem; background: none; border: 0; border-left: 1px solid var(--line); color: var(--text-faint); cursor: pointer; font-size: 0.85rem; }
.card .del:hover { color: var(--danger); }
/* (draft mode: saves the sound, so a word, not ♪, which on these pages plays one) */
.card .del[data-wav] { width: 2.4rem; padding: 0; font: 500 0.7rem/1 var(--font-mono); }
.card .del[data-wav]:hover { color: var(--accent); }
.card .flag { color: var(--danger); }
.card { flex-wrap: wrap; }
.card .why { flex-basis: 100%; margin: 0; padding: 0 0.6rem 0.45rem 2.9rem; font-size: 0.74rem; line-height: 1.35; color: var(--text-dim); }
.card .why.bad { color: var(--danger); }
.card .alt { flex-basis: 100%; text-align: left; background: none; border: 0; border-top: 1px dashed var(--line); padding: 0.4rem 0.6rem; font: 500 0.75rem/1.2 var(--font-ui); color: var(--accent); cursor: pointer; }
#tray-empty { margin: 0.5rem 0 0; font-size: 0.8rem; line-height: 1.4; color: var(--text-faint); }

/* the ? sheet's second part, behind one line: the chirp, the delay, devices and phones, for whoever wants them */
#help-more { margin: 0.9rem 0 0.5rem; border-top: 1px solid var(--line); }
#help-more summary { cursor: pointer; padding: 0.75rem 0 0.3rem; font-weight: 600; color: var(--accent); }

/* ---------- the level check: over the plots for its 10 s, with its own level slider ---------- */
#check {
  position: fixed; z-index: 40; top: calc(4.2rem + var(--sat, 0px)); left: 50%; transform: translateX(-50%); width: min(24rem, calc(100% - 2rem));
  padding: 0.5rem 0.75rem 0.65rem; background: var(--sheet); border: 1px solid var(--line-strong); border-radius: var(--radius); box-shadow: var(--sheet-shadow);
}
#check header { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.3rem; }
#check h3 { flex: 1; margin: 0; font: 600 0.95rem/1.2 var(--font-ui); }
#ck-time { font: 500 0.78rem/1 var(--font-mono); color: var(--text-dim); }
.ck { display: grid; grid-template-columns: 3rem minmax(0, 1fr) 5.2rem; align-items: center; gap: 0.6rem; min-height: 1.9rem; }
.ck > :first-child { font: 600 0.85rem/1 var(--font-ui); color: var(--text-dim); }
.ck .ro { text-align: right; font: 500 0.8rem/1 var(--font-mono); }
.ck input[type='range'] { width: 100%; }
.ckbar { position: relative; height: 0.75rem; border-radius: 0.375rem; background: var(--bg-inset); border: 1px solid var(--line); overflow: hidden; }
.ckbar i { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: var(--trace-main); transition: width 0.15s linear; }
#ck-out { background: var(--trace-peak); }
.ckbar i.hot { background: var(--gold); }
.ckbar i.clip { background: var(--danger); }
/* (−10 dBFS on a −60…0 scale: the most for noise) */
.ckbar b { position: absolute; top: 0; bottom: 0; left: 83.3%; width: 2px; background: var(--text-faint); }
#ck-say { margin: 0.4rem 0 0; min-height: 2.3em; font-size: 0.82rem; line-height: 1.4; color: var(--text-dim); }
#ck-say.warn { color: var(--danger); }
#ck-say.good { color: var(--text); }

#toast {
  position: fixed; z-index: 45; left: 50%; bottom: calc(1rem + var(--sab)); transform: translateX(-50%);
  display: flex; align-items: center; gap: 0.8rem; padding: 0.45rem 0.5rem 0.45rem 0.9rem;
  background: var(--sheet); border: 1px solid var(--line-strong); border-radius: var(--radius); box-shadow: var(--sheet-shadow);
  font-size: 0.85rem; white-space: nowrap;
}
#btn-undo { color: var(--accent); }

#deck select { max-width: none; width: 100%; }
/* a choice with no readout takes the readout's column too */
.row.wide > :nth-child(2) { grid-column: 2 / 4; justify-self: start; }
.row.wide > select:nth-child(2) { justify-self: stretch; }
.row label { font-size: 0.85rem; }
.row .seg label { font: 500 0.82rem/1.2 var(--font-ui); }
#ro-frame { font-size: 0.72rem; }
.fpair { display: flex; align-items: center; gap: 0.35rem; }
.fpair input { width: 5rem; }
.fpair input[aria-invalid='true'] { border-color: var(--danger); }
#in-start { width: 6rem; }
/* devices: out of the way, under the frame row; open on a laptop, closed on a phone (main.js) */
#devs { margin-top: 0.3rem; }
#devs summary { cursor: pointer; font: 600 0.85rem/1 var(--font-ui); color: var(--text-dim); padding: 0.5rem 0; }
#devs[open] summary { margin-bottom: 0.3rem; }
#devs .row + .row { margin-top: 0.35rem; }
.devnote { margin: 0.3rem 0 0; font-size: 0.8rem; line-height: 1.4; color: var(--text-dim); }
.card .note { color: var(--text-dim); }
.devinfo { margin: 0.4rem 0 0; font: 500 0.72rem/1.35 var(--font-mono); color: var(--text-faint); }
.filebtn { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: center; font-weight: 500; }

/* ---------- a laptop: the deck a little wider, the cards under the settings ---------- */
@media (min-aspect-ratio: 1/1) and (min-width: 640px) and (min-height: 521px) {
  #app { grid-template-columns: minmax(0, 1fr) 20.5rem; }
  #tray { margin-top: 1.1rem; padding-top: 0.8rem; border-top: 1px solid var(--line); }
  #btn-tray { display: none; }
}
/* ---------- everywhere else (phones, a tablet upright): the cards are a sheet ---------- */
@media not all and (min-aspect-ratio: 1/1) and (min-width: 640px) and (min-height: 521px) {
  /* (#deck #tray: stage.css lays every deck section out as a grid, which would spread the cards down a tall sheet) */
  #deck #tray {
    position: fixed; z-index: 30; left: 0; right: 0; bottom: 0; max-height: 46dvh;
    display: flex; flex-direction: column; padding: 0.7rem 0.8rem calc(0.7rem + var(--sab));
    background: var(--sheet); border-top: 1px solid var(--line-strong); border-radius: var(--radius) var(--radius) 0 0;
    box-shadow: var(--sheet-shadow); transform: translateY(105%); visibility: hidden; transition: transform 0.2s, visibility 0.2s;
  }
  #app.tray-open #deck #tray { transform: none; visibility: visible; }
  /* the heading and its ✕ on the top line, the buttons under them; the ✕ keeps its full size to
     tap but reaches into the gaps round it, so the line is no taller than the heading's */
  #btn-tray-close { display: inline-flex; margin: -0.55rem -0.45rem -0.55rem 0; }
  .tray-acts { flex-basis: 100%; margin-left: 0; }
  #cards { overflow-y: auto; min-height: 0; }
}

@media (max-width: 420px) {
  #kind label { padding: 0.35rem 0.42rem; }
  #btn-measure { min-width: 0; padding: 0.35rem 0.6rem; }
  #strip { gap: 0.35rem; }
  #tabs button { padding: 0.45rem 0.5rem; }
}
/* a phone lying down: a little more deck than stage.css gives, for the 16 px
   selects (theme.css: smaller ones make iOS zoom in on focus); the sheet
   comes in from the side, over the deck, leaving the plots in view */
@media (max-height: 520px) and (min-aspect-ratio: 1/1) {
  #app { grid-template-columns: minmax(0, 1fr) 18rem; }
  #legend { padding-top: 0.3rem; min-height: 1.9rem; }
  .lg { padding: 0.25rem 0.55rem; }
  #deck #tray { left: auto; top: 0; width: min(21.5rem, 60vw); max-height: none; border-top: 0; border-left: 1px solid var(--line-strong); border-radius: 0; padding-top: calc(0.6rem + var(--sat)); transform: translateX(105%); }
}
/* phones upright: the deck as short as it can be, scrolling past about a
   quarter of the screen, so the plots keep most of it (Measure, the signal
   and the legend are above it, always in view) */
@media (max-width: 860px) and (max-aspect-ratio: 1/1) {
  #deck { max-height: 22dvh; overflow-y: auto; }
  #legend { padding-top: 0.35rem; min-height: 2rem; }
  .lg { padding: 0.28rem 0.5rem; gap: 0.3rem; }
  .sw { width: 0.95rem; }
  #deck section { gap: 0.1rem; }
  #deck .row { min-height: 38px; }
  #strip { min-height: 2.8rem; padding: 0.35rem 0 0.3rem; }
}
