/* MarGoth: the sleeve, the console, and the words under them.
 *
 * One stylesheet for both music pages: the design tokens, the page chrome and
 * the parameter section. The panel keeps its own scoped CSS inside ui.js --
 * it has to work wherever it is injected -- and reads these tokens with
 * fallbacks, so the panel is legible on a page that never links this file.
 *
 * No webfonts: both pages must work offline, and nothing else on this site
 * loads an external asset. The type is the reader's own Iowan/Palatino and
 * SF Mono.
 */

:root {
  color-scheme: dark;

  --paper: #0b0b0d;
  --surface: #121216;
  --surface-2: #17171d;
  --ink: #e9e7ec;
  --dim: #8d8a97;
  --faint: #5f5c6a;
  --line: #272733;
  --rule: #1d1d26;

  --accent: #e0b366;   /* gold: the locked, current path */
  --cold: #86a7b6;     /* steel: a live edge on the signal side */
  --warm: #e07373;     /* armed, or refused */
  --good: #8fbfa6;
  --meter-fill: var(--accent);

  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Times New Roman", ui-serif, serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  /* The room: a cold glow off the top of the paper, a warm one behind the
     title, and the corners falling away. Tokens, not literals, so light mode
     can invert the mood instead of tinting black onto cream. */
  --haze-cold: color-mix(in srgb, var(--cold) 9%, transparent);
  --haze-warm: color-mix(in srgb, var(--accent) 11%, transparent);
  --vignette: color-mix(in srgb, #000 55%, transparent);
  --lift: color-mix(in srgb, var(--ink) 7%, transparent);

  /* The sleeve uses the screen it is on: a fluid column that stops at 1440 so a
     very wide display does not stretch the line measure past reading, and
     shrinks to the gutters on a laptop. 94vw keeps a hair of margin either side
     so the paper edge is visible. */
  --page: min(1440px, 94vw);
  --gutter: 24px;
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;

    --paper: #f6f4f0;
    --surface: #fffdf8;
    --surface-2: #efece5;
    --ink: #1a191c;
    --dim: #5f5c66;
    --faint: #8c8892;
    --line: #d9d4ca;
    --rule: #e4dfd5;

    --accent: #8a6a2f;
    --cold: #3d6373;
    --warm: #a8443f;
    --good: #3f7059;

    --haze-cold: color-mix(in srgb, var(--cold) 8%, transparent);
    --haze-warm: color-mix(in srgb, var(--accent) 13%, transparent);
    --vignette: color-mix(in srgb, #6b5a38 9%, transparent);
    --lift: color-mix(in srgb, #fff 70%, transparent);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  font: 15px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
  overflow-wrap: break-word;
  background-color: var(--paper);
  /* three layers: steel off the top, gold behind the masthead, and the paper
     falling into shadow at the corners */
  background-image:
    radial-gradient(120% 46% at 50% -14%, var(--haze-warm), transparent 66%),
    radial-gradient(90% 34% at 50% -2%, var(--haze-cold), transparent 72%),
    radial-gradient(130% 110% at 50% 22%, transparent 46%, var(--vignette) 100%);
  background-repeat: no-repeat;
}

body > header,
body > main,
body > footer {
  max-width: var(--page);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

/* --------------------------------------------------------------- the sleeve */
/* Centred, like a sleeve title: a mark, a tracked-out kicker flanked by
   hairlines, the name in display serif with a faint warm bloom, the blurb in
   italic serif, and a rule with a gold centre to close the header. */
.mg-top {
  padding-top: 58px;
  padding-bottom: 54px;
  text-align: center;
}

/* the mark: a small gold lozenge, the only filled shape above the fold */
.mg-top::before {
  content: "";
  display: block;
  width: 7px;
  height: 7px;
  margin: 0 auto 26px;
  background: var(--accent);
  transform: rotate(45deg);
  opacity: .85;
  box-shadow: 0 0 18px 2px var(--haze-warm);
}

/* the closing rule: hairline in from both sides, gold at the centre */
.mg-top::after {
  content: "";
  display: block;
  width: min(460px, 76%);
  height: 1px;
  margin: 40px auto 0;
  background: linear-gradient(90deg,
    transparent, var(--line) 14%, var(--accent) 50%, var(--line) 86%, transparent);
  opacity: .8;
}

.mg-kicker {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  margin: 0;
  font: 11px/1 var(--mono);
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--dim);
}

.mg-kicker::before,
.mg-kicker::after {
  content: "";
  width: 36px;
  height: 1px;
}

.mg-kicker::before { background: linear-gradient(90deg, transparent, var(--line)); }
.mg-kicker::after { background: linear-gradient(90deg, var(--line), transparent); }

h1 {
  margin: 20px 0 0;
  font: 400 clamp(32px, 4.4vw, 50px)/1.06 var(--serif);
  letter-spacing: .004em;
  color: var(--ink);
  text-wrap: balance;
  /* a bloom, not a glow: enough to lift the name off the paper, not to halo it */
  text-shadow: 0 1px 34px var(--haze-warm);
}

h2 {
  margin: 0 0 6px;
  font: 400 20px/1.2 var(--serif);
  letter-spacing: -0.005em;
}

/* the epithet: the band's subtitle, set between the name and the description so
   the description stays a description. Centred by .mg-top like the rest of the
   masthead. --ink, not --accent: gold already means "the current path" in the
   chain view, and a subtitle is not a musical claim. */
.mg-subtitle {
  margin: 14px auto 0;
  max-width: 44ch;
  font: italic clamp(18px, 2.2vw, 23px)/1.32 var(--serif);
  letter-spacing: .004em;
  color: var(--ink);
  text-wrap: balance;
}

.mg-sub {
  margin: 18px auto 0;
  max-width: 50ch;
  font: italic 17px/1.55 var(--serif);
  color: var(--dim);
  text-wrap: pretty;
}

/* -------------------------------------------------------------- the console */
/* Centred like a rack front panel: the action, the three dials, then the level
   behind a hairline. Depth comes from one inset highlight and one shadow, so
   the bar reads as a strip of metal rather than a coloured box. */
.mg-bar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 12px 22px;
  margin: 0;
  padding: 12px max(var(--gutter), calc((100% - var(--page)) / 2));
  background: color-mix(in srgb, var(--paper) 74%, transparent);
  border-bottom: 1px solid var(--line);
  box-shadow:
    inset 0 1px 0 var(--lift),
    0 18px 40px -26px var(--haze-warm);
  backdrop-filter: blur(12px) saturate(115%);
}

.mg-bar button {
  font: 11px/1 var(--mono);
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 8px 14px;
  cursor: pointer;
  box-shadow: inset 0 1px 0 var(--lift);
  transition: border-color .15s linear, color .15s linear, box-shadow .15s linear;
}

.mg-bar button:hover {
  border-color: var(--accent);
  color: var(--ink);
  box-shadow: inset 0 1px 0 var(--lift), 0 0 16px -4px var(--haze-warm);
}
.mg-bar button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.mg-jump {
  font: 11px/1 var(--mono);
  letter-spacing: .1em;
  padding: 8px 12px;
  color: var(--cold);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 3px;
  text-decoration: none;
  white-space: nowrap;
}

.mg-jump:hover { border-color: var(--accent); color: var(--accent); }
.mg-jump:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.mg-bar button[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: inset 0 0 12px -6px var(--haze-warm);
}

.mg-hint {
  font: 11px/1.4 var(--mono);
  color: var(--faint);
  max-width: 34ch;
  text-align: center;
}

/* A dial on a real rack is labelled twice: the name stencilled on the panel and
   the scale beside the knob. Each control is that shape -- name and gloss on one
   line, slider and value under it -- and the gloss (a plain word plus its range)
   is filled from explain.js at boot, so the label cannot drift from the rule. */
.mg-ctl {
  display: grid;
  gap: 5px;
  justify-items: start;
}

.mg-ctl-head {
  display: flex;
  align-items: baseline;
  gap: 7px;
  white-space: nowrap;
}

.mg-ctl-name {
  font: 11px/1 var(--mono);
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--ink);
}

.mg-ctl-hint {
  font: 10px/1 var(--mono);
  letter-spacing: .08em;
  /* --dim, not --faint: this word is the whole reason the control is readable,
     and 10px of --faint on paper is about 3:1 */
  color: var(--dim);
}

.mg-ctl-hint:empty { display: none; }

.mg-ctl-row {
  display: flex;
  align-items: center;
  gap: 9px;
}

.mg-ctl input[type="range"] {
  width: 88px;
  margin: 0;
  accent-color: var(--accent);
}

.mg-ctl output {
  min-width: 2.8em;
  font: 11px/1 var(--mono);
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  text-align: right;
}

/* the level sits behind a hairline, the way a meter does on a real panel */
.mg-level {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-left: 22px;
  border-left: 1px solid var(--rule);
}

#meter {
  width: 150px;
  height: 3px;
  background: var(--line);
  border-radius: 2px;
  overflow: hidden;
}

#meterbar {
  height: 100%;
  width: 0%;
  background: var(--meter-fill);
  box-shadow: 0 0 10px -2px var(--haze-warm);
  transition: width .06s linear;
}

/* Fixed width, not min-width: the readout changes every animation frame, and in
   a centred row an auto-width box re-centres the whole console up to 60 times a
   second -- measured 26.5px of slide between "-8.0 / -1.0 dBFS" and
   "-26.7 / -20.2 dBFS". 18ch is the longest string the format can produce
   ("-38.0 / -38.0 dBFS"), and mono with tabular-nums makes ch exact, so the box
   never moves; right-aligned, the digits grow leftward inside it. */
#meter-text {
  font: 11px/1 var(--mono);
  font-variant-numeric: tabular-nums;
  color: var(--dim);
  width: 18ch;
  text-align: right;
  white-space: nowrap;
}

/* The transport hides its export button with an attribute, and the UA rule for
   [hidden] is a bare tag selector: any class rule that sets a display beats it. */
.mg-bar [hidden],
main [hidden] { display: none; }

/* ------------------------------------------------------------------- the stage */
main { padding-block: 26px 8px; }
main > section + section { margin-top: 26px; }
#mount:empty { display: none; }

/* ------------------------------------------------------------------ the desk */
/* The centre of the page: three cards, each with a drawing of the thing it
   controls. Not a settings row -- this is where the piece is composed, so it gets
   the page's width and the masthead's axis. */
.mg-stage {
  max-width: min(1120px, 94vw);
  margin: 0 auto;
  padding: 34px var(--gutter) 40px;
  text-align: center;
  scroll-margin-top: 90px;   /* clears the sticky transport when jumped to */
}

.mg-stage-title {
  margin: 0 0 8px;
  font: 400 22px/1.2 var(--serif);
  color: var(--ink);
  letter-spacing: -0.005em;
}

.mg-stage-sub {
  margin: 0 auto 26px;
  max-width: 64ch;
  color: var(--dim);
  font-size: 14px;
  text-wrap: pretty;
}

.mg-stage-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  background: var(--rule);
  border: 1px solid var(--rule);
  border-radius: 12px;
  overflow: hidden;
}

.mg-card {
  display: grid;
  gap: 9px;
  justify-items: center;
  align-content: start;
  min-width: 0;
  padding: 22px 18px 20px;
  background: var(--surface);
}

.mg-card-title {
  margin: 0;
  font: 400 17px/1.25 var(--serif);
  color: var(--ink);
}

.mg-card-gloss {
  margin: 0;
  max-width: 30ch;
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--dim);
  text-wrap: pretty;
}

/* the drawings: one line art each, in the panel's own stroke language */
.mg-glyph {
  width: 100%;
  max-width: 168px;
  height: 60px;
  color: var(--dim);
}

.mg-glyph svg { display: block; width: 100%; height: 100%; overflow: visible; }
.mg-head { fill: none; stroke: var(--line); stroke-width: 1.4; }
.mg-head[data-on="true"] { stroke: var(--cold); }
.mg-arc { fill: none; stroke: var(--line); stroke-width: 1.4; stroke-dasharray: 3 3; }
.mg-arc[data-on="true"] { stroke: var(--accent); stroke-dasharray: none; }
.mg-elec { fill: none; stroke: var(--line); stroke-width: 1.2; stroke-dasharray: 2 2; }
.mg-elec[data-known="true"] { stroke: var(--dim); }
.mg-elec[data-lit="true"] { fill: var(--accent); stroke: var(--accent); stroke-dasharray: none; }
.mg-mid { stroke: var(--rule); stroke-width: 1; }
.mg-wave { fill: none; stroke: var(--accent); stroke-width: 1.6; stroke-linejoin: round; }
.mg-ladder { fill: none; stroke: var(--cold); stroke-width: 1.4; }
.mg-ladder-dot { fill: var(--surface); stroke: var(--cold); stroke-width: 1.4; }
.mg-ladder-dot[data-root="true"] { fill: var(--accent); stroke: var(--accent); }

.mg-seat-choices {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin-top: 2px;
}

/* a chip is a radio: chosen reads gold, refused reads warm, auto is dashed */
.mg-choice {
  font: 11px/1 var(--mono);
  letter-spacing: .08em;
  color: var(--dim);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  cursor: pointer;
  transition: border-color .15s linear, color .15s linear;
}

.mg-choice:hover { border-color: var(--accent); color: var(--ink); }
.mg-choice:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.mg-choice[aria-checked="true"] { border-color: var(--accent); color: var(--accent); }
.mg-choice[data-kind="auto"] { border-style: dashed; }
.mg-choice[data-kind="refused"] { color: var(--warm); }
.mg-choice[data-stale="true"] { opacity: .6; }
.mg-seat-choices[hidden] { display: none; }

/* One line per seat saying what it is actually doing: the choice is remembered,
   so when a head goes it says so here rather than leaving a chip that cannot
   light. */
.mg-seat-state {
  margin: 0;
  font: 11px/1.5 var(--mono);
  color: var(--dim);
}

.mg-seat-state[data-lost="true"] { color: var(--warm); }

/* ----------------------------------------------------------------- the keys */
.mg-keys {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px;
}

.mg-key {
  display: grid;
  justify-items: center;
  gap: 3px;
  min-width: 42px;
  padding: 7px 6px 6px;
  font: 11px/1 var(--mono);
  color: var(--dim);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  cursor: pointer;
  transition: border-color .08s linear, color .08s linear, background .08s linear;
}

.mg-key b {
  font: 12px/1 var(--mono);
  font-weight: 500;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ink);
}

.mg-key span {
  font: 10px/1 var(--mono);
  font-variant-numeric: tabular-nums;
  color: var(--faint);
}

/* a key that is sounding: the same gold the current path uses */
.mg-key[data-down="true"] {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 16%, var(--surface-2));
}
.mg-key[data-down="true"] b { color: var(--accent); }

@media (prefers-reduced-motion: reduce) {
  .mg-choice, .mg-key { transition: none; }
}

#label {
  margin: 18px 0 0;
  color: var(--accent);
  font: 13px/1.5 var(--mono);
}

/* --------------------------------------------------------- what the numbers mean */
.mg-params {
  padding-top: 30px;
  border-top: 1px solid var(--rule);
}

.mg-params-sub {
  margin: 0 0 22px;
  max-width: 66ch;
  color: var(--dim);
  font-size: 14px;
}

.mg-params-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 30px;
  align-items: start;
}

.mg-param {
  border-bottom: 1px solid var(--rule);
  padding: 10px 0 12px;
}

.mg-param > summary {
  display: flex;
  align-items: baseline;
  gap: 10px;
  cursor: pointer;
  list-style: none;
  font: 15px/1.4 var(--serif);
  color: var(--ink);
}

.mg-param > summary::-webkit-details-marker { display: none; }
.mg-param > summary::after {
  content: "+";
  margin-left: auto;
  font: 12px/1 var(--mono);
  color: var(--faint);
}

.mg-param[open] > summary::after { content: "−"; }
.mg-param > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.mg-param-label { flex: 0 0 auto; }

.mg-param-gloss {
  flex: 0 0 auto;
  font: italic 14px/1.3 var(--serif);
  color: var(--dim);
}

.mg-chip {
  font: 10px/1 var(--mono);
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--faint);
  white-space: nowrap;
}

.mg-param-body {
  margin: 8px 0 0;
  max-width: 58ch;
  color: var(--dim);
  font-size: 14px;
}

/* The arithmetic: a hairline on the left, each line its own claim, numerals in
   the mono face so the formulas line up and can be read at a glance. */
.mg-how {
  margin: 10px 0 0;
  padding: 0 0 0 14px;
  max-width: 62ch;
  list-style: none;
  border-left: 1px solid var(--rule);
  display: grid;
  gap: 6px;
}

.mg-how > li {
  font: 13px/1.5 var(--mono);
  font-variant-numeric: tabular-nums;
  color: var(--muted, var(--dim));
  text-wrap: pretty;
}

.mg-how > li::before {
  content: "";
  display: inline-block;
  width: 4px;
  height: 4px;
  margin-right: 8px;
  vertical-align: middle;
  background: var(--accent);
  opacity: .55;
  transform: rotate(45deg);
}

.mg-src {
  margin: 6px 0 0;
  font: 11px/1.5 var(--mono);
  color: var(--faint);
}

/* ------------------------------------------------------------------- the foot */
#status {
  max-width: var(--page);
  margin: 0 auto;
  padding: 0 var(--gutter);
  min-height: 1.6em;
  color: var(--dim);
  font: 11px/1.6 var(--mono);
  letter-spacing: .02em;
}

footer {
  padding-top: 14px;
  padding-bottom: 52px;
  color: var(--faint);
  font: 11px/1.7 var(--mono);
  border-top: 1px solid var(--rule);
  margin-top: 26px;
}

footer a { color: var(--cold); text-decoration: none; border-bottom: 1px solid transparent; }
footer a:hover { border-bottom-color: var(--cold); }
footer a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

@media (min-width: 1180px) {
  .mg-params-list { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  .mg-stage-grid { grid-template-columns: minmax(0, 1fr); }
  .mg-stage { padding-top: 28px; }
  .mg-card { padding: 18px 16px 16px; }
  .mg-glyph { max-width: 150px; height: 52px; }
}

@media (max-width: 1000px) {
  .mg-bar { gap: 10px 16px; }
  .mg-ctl { gap: 7px; letter-spacing: .12em; }
  .mg-ctl input[type="range"] { width: 68px; }
  .mg-level { padding-left: 16px; gap: 8px; }
  #meter { width: 104px; }
}

@media (max-width: 720px) {
  :root { --gutter: 16px; }
  .mg-top { padding-top: 38px; padding-bottom: 38px; }
  .mg-top::after { margin-top: 28px; }
  h1 { font-size: clamp(28px, 8.4vw, 34px); }
  .mg-subtitle { font-size: 17px; max-width: 30ch; }
  .mg-sub { font-size: 15px; max-width: 34ch; }
  .mg-kicker::before,
  .mg-kicker::after { width: 18px; }
  .mg-params-list { grid-template-columns: minmax(0, 1fr); }
  .mg-bar { gap: 10px 14px; padding-block: 10px; }
  .mg-level { padding-left: 0; border-left: 0; }
  .mg-ctl input[type="range"] { width: 72px; }
  #meter { width: 104px; }
}

@media (prefers-reduced-motion: reduce) {
  #meterbar { transition: none; }
  .mg-bar button { transition: none; }
}
