/* ==========================================================================
   Themes
   All five share the same variable set, so every rule below the :root block
   is theme-agnostic. Default is "stage" (the original backstage-dark look).
   ========================================================================== */
:root, [data-theme="stage"] {
  --bg: #14131a;
  --surface: #1e1d26;
  --surface-2: #262530;
  --surface-3: #2f2e3a;
  --brass: #c9a227;
  --brass-light: #e5c157;
  --teal: #3a9e98;
  --ink: #f2ede2;
  --ink-dim: #a9a5b0;
  --ink-faint: #726e7c;
  --danger: #c0503a;
  --danger-light: #e2735a;
  --on-accent: #1a1608;
  --on-teal: #08201f;
  --overlay: rgba(10, 9, 13, 0.7);
  --radius-s: 6px;
  --radius-m: 12px;
  --radius-l: 20px;
  --font-display: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* Daylight — manuscript-paper practice room: warm ivory page, deep ink,
   engraved-brass accent. */
[data-theme="daylight"] {
  --bg: #f6f1e4;
  --surface: #fffdf8;
  --surface-2: #efe8d6;
  --surface-3: #e2d8bf;
  --brass: #8a5a1f;
  --brass-light: #b3792f;
  --teal: #2f6e68;
  --ink: #241f14;
  --ink-dim: #5c5546;
  --ink-faint: #8b8371;
  --danger: #a23f2c;
  --danger-light: #c65a3f;
  --on-accent: #fff8ec;
  --on-teal: #eafaf6;
  --overlay: rgba(60, 52, 34, 0.35);
}

/* Chalkboard — practice-room slate: chalk yellow/blue on green-black board. */
[data-theme="chalkboard"] {
  --bg: #1b2620;
  --surface: #22302a;
  --surface-2: #2a3a33;
  --surface-3: #33463d;
  --brass: #d8c98a;
  --brass-light: #ecdfab;
  --teal: #8fb6c9;
  --ink: #eef2ea;
  --ink-dim: #a9b8ac;
  --ink-faint: #748077;
  --danger: #c96a4f;
  --danger-light: #e08a6d;
  --on-accent: #22301a;
  --on-teal: #0f242c;
  --overlay: rgba(10, 16, 12, 0.7);
}

/* Concert Hall — velvet and gold: deep wine, aged-gold brass, emerald teal. */
[data-theme="concert-hall"] {
  --bg: #1f1116;
  --surface: #2b1a20;
  --surface-2: #3a232b;
  --surface-3: #492c35;
  --brass: #c9a24a;
  --brass-light: #e6c56f;
  --teal: #4f8f6b;
  --ink: #f3e9dd;
  --ink-dim: #c2a9a0;
  --ink-faint: #8f7770;
  --danger: #a83c3c;
  --danger-light: #cc5c53;
  --on-accent: #241505;
  --on-teal: #08160f;
  --overlay: rgba(20, 10, 13, 0.72);
}

/* Marquee — gig stage lighting: indigo-navy with hot-pink/cyan double accent,
   built for high contrast in both bright and dark stage-lighting conditions. */
[data-theme="marquee"] {
  --bg: #12102a;
  --surface: #1b1840;
  --surface-2: #241f52;
  --surface-3: #2d2763;
  --brass: #ff4fa3;
  --brass-light: #ff7ec0;
  --teal: #38e0e6;
  --ink: #f5f3ff;
  --ink-dim: #b6b0d6;
  --ink-faint: #7e78a3;
  --danger: #ff5c5c;
  --danger-light: #ff8686;
  --on-accent: #2a0416;
  --on-teal: #012326;
  --overlay: rgba(8, 6, 20, 0.75);
}

/* Walnut — the instrument itself: wound-up wooden-case metronome, walnut
   casing, aged brass pendulum, verdigris patina in place of teal. */
[data-theme="walnut"] {
  --bg: #2b1d13;
  --surface: #362519;
  --surface-2: #423020;
  --surface-3: #4f3b28;
  --brass: #b8752f;
  --brass-light: #d99a52;
  --teal: #7a9483;
  --ink: #f5ead5;
  --ink-dim: #c2ae8e;
  --ink-faint: #927e63;
  --danger: #9c4a2e;
  --danger-light: #c06844;
  --on-accent: #241505;
  --on-teal: #10201a;
  --overlay: rgba(20, 12, 6, 0.72);
}

/* ==========================================================================
   Base
   ========================================================================== */
* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
body {
  min-height: 100vh;
  min-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
}
#app { max-width: 640px; margin: 0 auto; padding: 0 16px 40px; }

/* ---------- trial / free-week banner (shell.js) ---------- */
.tfm-banner {
  margin: 10px 0 -4px;
  padding: 6px 12px;
  border-radius: var(--radius-s);
  background: color-mix(in srgb, var(--teal) 16%, transparent);
  color: var(--teal);
  border: 1px solid color-mix(in srgb, var(--teal) 35%, transparent);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: .01em;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
[data-contrast="high"] .tfm-banner { border-width: 2px; }

/* ---------- generic "part of the paid features" note (shared by any
   light-DOM locked panel — mirrors the shadow-DOM .sheet-note the tuner and
   recorder each keep their own scoped copy of) ---------- */
.locked-note { font-size: 13px; color: var(--ink-dim); margin: 8px 0 0; }
.locked-note a { color: var(--brass-light); }

/* ---------- debug-mode panel (shell.js, only while /debug.txt exists) ---------- */
.tfm-debug-panel { position: fixed; right: 12px; bottom: 12px; z-index: 500; }
.tfm-debug-dot {
  width: 14px; height: 14px; border-radius: 50%;
  background: color-mix(in srgb, var(--ink-faint) 55%, transparent);
  border: none; padding: 0; cursor: pointer; opacity: .55;
}
.tfm-debug-dot:hover { opacity: 1; }
.tfm-debug-card {
  width: 220px; padding: 12px; border-radius: var(--radius-m);
  background: var(--surface-2); border: 1px solid var(--surface-3);
  box-shadow: 0 6px 24px rgba(0,0,0,.35);
}
.tfm-debug-title {
  display: flex; align-items: center; justify-content: space-between;
  font-family: var(--font-display); font-size: 12px; letter-spacing: .04em;
  text-transform: uppercase; color: var(--ink-dim); margin-bottom: 6px;
}
.tfm-debug-close { background: none; border: none; color: var(--ink-faint); cursor: pointer; font-size: 13px; }
.tfm-debug-current { font-size: 12px; color: var(--ink-dim); margin: 0 0 8px; }
.tfm-debug-rows { display: flex; flex-direction: column; gap: 6px; }
.tfm-debug-row { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-dim); }
.tfm-debug-days { width: 44px; padding: 2px 4px; }
.tfm-debug-rows .btn-secondary { font-size: 12.5px; padding: 6px 10px; text-align: left; }

/* ---------- topbar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 0 8px;
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--brass-light); }
.brand-mark { width: 22px; height: 22px; }
.brand-name { font-family: var(--font-display); font-size: 18px; letter-spacing: 0.06em; text-transform: uppercase; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

.icon-btn {
  display: flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: 50%;
  background: transparent; border: 1px solid var(--surface-3); color: var(--ink-dim);
  cursor: pointer;
}
.icon-btn:hover { color: var(--ink); border-color: var(--ink-faint); }
.icon-btn:active { background: var(--surface-2); }

.pill {
  font-size: 11px; letter-spacing: .03em; padding: 4px 9px; border-radius: 999px;
  background: color-mix(in srgb, var(--teal) 15%, transparent); color: var(--teal);
  border: 1px solid color-mix(in srgb, var(--teal) 35%, transparent);
  white-space: nowrap;
}
.pill-muted {
  background: color-mix(in srgb, var(--ink-faint) 15%, transparent); color: var(--ink-dim);
  border-color: color-mix(in srgb, var(--ink-faint) 35%, transparent);
}

.btn-ghost {
  background: transparent; border: 1px solid var(--surface-3); color: var(--ink-dim);
  font-family: var(--font-body); font-size: 13px; padding: 7px 12px; border-radius: var(--radius-s);
  cursor: pointer; text-decoration: none; display: inline-block;
}
.btn-ghost:hover { color: var(--ink); border-color: var(--ink-faint); }

.btn-secondary {
  background: var(--surface-2); border: 1px solid var(--surface-3); color: var(--ink);
  font-family: var(--font-body); font-weight: 600; font-size: 14px; padding: 10px 16px;
  border-radius: var(--radius-m); cursor: pointer;
}
.btn-secondary:active { background: var(--surface-3); }

/* ---------- piece banner ---------- */
.piece-banner {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface); border: 1px solid var(--surface-3); border-radius: var(--radius-m);
  padding: 10px 14px; margin-bottom: 10px;
}
.piece-banner[hidden] { display: none; }
.piece-banner-label { font-size: 11px; color: var(--ink-faint); text-transform: uppercase; letter-spacing: .06em; }
.piece-banner-title { font-size: 15px; font-weight: 600; }

/* ---------- stage ---------- */
.stage {
  background: radial-gradient(ellipse at 50% -10%, color-mix(in srgb, var(--brass) 10%, transparent), transparent 60%), var(--surface);
  border: 1px solid var(--surface-3);
  border-radius: var(--radius-l);
  padding: 20px 18px 24px;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  margin-top: 8px;
}
.time-sig-readout {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-family: Georgia, "Times New Roman", "Iowan Old Style", serif;
  font-weight: 700; color: var(--ink); line-height: 0.82;
  font-variant-numeric: tabular-nums; letter-spacing: -0.01em;
}
.time-sig-num { display: block; font-size: 30px; }

/* Time signature + tempo marking sit side by side at the top of the stage —
   the same two independent pieces of information you'd see printed at the
   start of a line of music. Wraps on narrow screens rather than overflowing. */
.stage-readouts { display: flex; align-items: center; justify-content: center; gap: 22px; flex-wrap: wrap; }
.tempo-mark-readout {
  display: flex; align-items: center; gap: 5px;
  font-family: Georgia, "Times New Roman", "Iowan Old Style", serif;
  font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums;
}
.tempo-mark-glyph { display: flex; align-items: center; color: var(--ink); }
.tempo-mark-glyph svg { width: 22px; height: 25px; }
.tempo-mark-eq { font-size: 22px; }
.tempo-mark-bpm { font-size: 26px; }

.bpm-display { display: flex; align-items: center; gap: 14px; }
.bpm-step {
  width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--surface-3);
  background: var(--surface-2); color: var(--ink); font-size: 22px; line-height: 1;
  cursor: pointer;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  touch-action: none;
}
.bpm-step:active { background: var(--surface-3); }
.bpm-readout { display: flex; align-items: baseline; gap: 6px; }
.bpm-number {
  width: 3.4ch; background: transparent; border: none; color: var(--brass-light);
  font-family: var(--font-display); font-size: 56px; font-weight: 700; text-align: right;
  -moz-appearance: textfield;
}
.bpm-number::-webkit-outer-spin-button, .bpm-number::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.bpm-unit { font-family: var(--font-display); font-size: 15px; color: var(--ink-faint); letter-spacing: .05em; }

.bpm-slider { width: 100%; max-width: 320px; accent-color: var(--brass); }

.stage-label {
  align-self: center; font-size: 11px; color: var(--ink-faint);
  text-transform: uppercase; letter-spacing: .06em; margin: -4px 0 -6px;
}

.beat-row { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.beat-btn {
  width: 34px; height: 34px; border-radius: var(--radius-s); border: 1px solid var(--surface-3);
  background: var(--surface-2); color: var(--ink-dim); font-family: var(--font-display); font-size: 13px;
  cursor: pointer;
}
.beat-btn.accent { background: var(--brass); color: var(--on-accent); border-color: var(--brass-light); font-weight: 700; }
.beat-btn.muted { background: transparent; color: var(--ink-faint); border-style: dashed; }
.beat-btn.playing { box-shadow: 0 0 0 2px var(--teal); }

.start-stop {
  width: 100%; max-width: 320px; height: 74px; border-radius: var(--radius-l);
  border: none; background: var(--brass); color: var(--on-accent); font-family: var(--font-body);
  font-size: 20px; font-weight: 700; letter-spacing: .02em; cursor: pointer;
  box-shadow: 0 6px 18px color-mix(in srgb, var(--brass) 25%, transparent);
}
.start-stop:active { transform: translateY(1px); }
.start-stop.is-running { background: var(--danger); box-shadow: 0 6px 18px color-mix(in srgb, var(--danger) 30%, transparent); }

/* ---------- panels ---------- */
.panel {
  background: var(--surface); border: 1px solid var(--surface-3); border-radius: var(--radius-l);
  padding: 16px 18px; margin-top: 14px;
}
.panel-title {
  font-family: var(--font-display); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em;
  color: var(--ink-dim); margin: 0 0 12px; cursor: default;
  display: flex; align-items: center; justify-content: flex-end;
}
details.collapsible > summary.panel-title { cursor: pointer; list-style: none; justify-content: space-between; }
details.collapsible > summary.panel-title::-webkit-details-marker { display: none; }
details.collapsible > summary.panel-title::before { content: "▸ "; color: var(--brass); }
details.collapsible[open] > summary.panel-title::before { content: "▾ "; }
details.collapsible[open] > summary.panel-title { margin-bottom: 12px; }
.panel-title-text { flex: none; }

/* A scoped "Reset to defaults" + a quiet hint that something in the panel
   was changed from its built-in default — same pattern as the tuner's
   Sensitivity card (tuner/tuner.js), reused here for light-DOM panels. */
.mod-hint {
  font: 600 10px var(--font-display); letter-spacing: .05em; text-transform: uppercase;
  padding: 2px 7px; border-radius: 999px; color: var(--ink-dim);
  background: color-mix(in srgb, var(--ink-faint) 15%, transparent);
  border: 1px solid color-mix(in srgb, var(--ink-faint) 35%, transparent);
}
.reset-row { display: flex; justify-content: flex-end; margin-top: 4px; }
.reset-row .seg-btn:disabled { opacity: .45; cursor: default; }

.hint { font-size: 12px; color: var(--ink-faint); margin: 8px 0 0; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 480px) { .grid-3 { grid-template-columns: 1fr; } }

/* Time signature + Subdivision on one row — kept deliberately narrow
   (rather than the 50/50 grid columns used elsewhere) so both fit on one
   line even on phone-width screens: the select only needs to fit "12/8" or
   "3/16", and the subdivision buttons are icon-only, not full-width segments. */
.time-fields { display: flex; align-items: flex-start; gap: 14px; flex-wrap: nowrap; }
.time-fields .field-compact { flex: 0 0 auto; }
.time-fields .field-compact select { width: 8ch; flex: none; }
.time-fields .field-grow { flex: 1 1 auto; min-width: 0; }
#tempoUnitGroup.segmented { gap: 5px; justify-content: center; }
#tempoUnitGroup .seg-btn { padding: 6px 8px; }
#subdivisionGroup.segmented { gap: 5px; }
#subdivisionGroup .seg-btn { padding: 8px 8px; }
.swing-presets.segmented { gap: 5px; flex-wrap: nowrap; }
.swing-presets .seg-btn { padding: 6px 6px; font-size: 12px; flex: 1 1 0; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Gradual tempo ramp's three fields (Start BPM / End BPM / Bars per step) —
   kept on one line at every width, including phone-width screens, rather
   than the 480px collapse-to-one-column behavior grid-3 uses elsewhere: a
   short 2-3 digit number field reads awkwardly full-width and stacked.
   Label and number are both centered since a narrow column with
   left-aligned text/digits looks lopsided. */
.ramp-fields { display: flex; gap: 8px; }
.ramp-fields .field { flex: 1 1 0; min-width: 0; text-align: center; }
.ramp-fields .field input[type="number"] { width: 100%; text-align: center; }

/* Tempo marking — small, secondary to the BPM number it labels. Purely
   descriptive (see index.html comment); kept visually subordinate so it
   doesn't compete with the actual functional BPM control above it. */
.tempo-marking-block { display: flex; flex-direction: column; align-items: center; gap: 6px; margin-top: -6px; }

.silent-mode-row { margin-top: 14px; margin-bottom: 0; }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--ink-dim); }
.field input[type="number"], .field input[type="text"], .field select {
  background: var(--surface-2); border: 1px solid var(--surface-3); color: var(--ink);
  border-radius: var(--radius-s); padding: 9px 10px; font-family: var(--font-body); font-size: 14px;
}
.field input[type="range"] { accent-color: var(--brass); }
/* Native range sliders otherwise claim any touch that starts on them, so a
   vertical swipe meant to scroll the page past a slider drags its thumb
   instead. touch-action: pan-y tells the browser a vertical drag here is a
   page scroll, not a slider drag, while a horizontal drag still works.
   Applied app-wide (every range input, including the tuner's — see
   tuner/tuner.js's own scoped copy of this rule for its Shadow DOM). */
input[type="range"] { touch-action: pan-y; }
.field-label { display: block; font-size: 13px; color: var(--ink-dim); margin-bottom: 8px; }

.segmented { display: flex; flex-wrap: wrap; gap: 6px; }
.seg-btn {
  display: flex; align-items: center; justify-content: center;
  background: var(--surface-2); border: 1px solid var(--surface-3); color: var(--ink-dim);
  padding: 8px 12px; border-radius: var(--radius-s); font-size: 13px; cursor: pointer;
}
.seg-btn.is-active { background: var(--teal); border-color: var(--teal); color: var(--on-teal); font-weight: 600; }

.subpanel { padding: 10px 0; border-top: 1px solid var(--surface-2); }
.subpanel:first-of-type { border-top: none; padding-top: 0; }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 14px; margin-bottom: 8px; cursor: pointer; }
.switch { position: relative; width: 36px; height: 20px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track { position: absolute; inset: 0; background: var(--surface-3); border-radius: 999px; transition: background 120ms; }
.switch .thumb { position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; background: var(--ink); border-radius: 50%; transition: transform 120ms, background 120ms; }
.switch input:checked + .track { background: var(--brass); opacity: 0.5; }
.switch input:checked ~ .thumb { transform: translateX(16px); background: var(--brass-light); }
.switch input:focus-visible ~ .track { outline: 2px solid var(--teal); outline-offset: 2px; }
.switch input:disabled + .track, .switch input:disabled ~ .thumb { opacity: .5; }
[data-disabled="true"] { opacity: .4; pointer-events: none; }

.loop-steps { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.loop-step-row { display: flex; gap: 8px; align-items: center; background: var(--surface-2); border-radius: var(--radius-s); padding: 8px; }
.loop-step-row input { width: 70px; background: var(--surface-3); border: 1px solid var(--surface-3); color: var(--ink); border-radius: var(--radius-s); padding: 6px 8px; }
.loop-step-remove { margin-left: auto; background: none; border: none; color: var(--danger-light); cursor: pointer; font-size: 16px; }

.status-line { margin-top: 10px; }

.preset-save-row { display: flex; gap: 8px; }
.preset-save-row input { flex: 1; background: var(--surface-2); border: 1px solid var(--surface-3); color: var(--ink); border-radius: var(--radius-s); padding: 9px 10px; }
.preset-list { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.preset-item { display: flex; align-items: center; gap: 8px; background: var(--surface-2); border: 1px solid var(--surface-3); border-radius: var(--radius-s); padding: 10px 12px; }
.preset-item-main { flex: 1; cursor: pointer; }
.preset-item-name { font-weight: 600; font-size: 14px; }
.preset-item-meta { font-size: 12px; color: var(--ink-faint); font-family: var(--font-display); }
.preset-item button { background: none; border: none; color: var(--ink-faint); cursor: pointer; font-size: 15px; }
.preset-item button:hover { color: var(--danger-light); }
.preset-empty { color: var(--ink-faint); font-size: 13px; }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; background: var(--overlay); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px; }
.modal[hidden] { display: none; }
.modal-card { background: var(--surface); border: 1px solid var(--surface-3); border-radius: var(--radius-m); padding: 20px; max-width: 340px; max-height: 85vh; overflow-y: auto; }
.modal-actions { display: flex; gap: 10px; margin-top: 14px; justify-content: flex-end; }

/* ---------- settings dialog ---------- */
.settings-card { width: 100%; max-width: 380px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.modal-header .panel-title { margin: 0; }
.settings-note { font-size: 12px; color: var(--ink-faint); margin: -4px 0 0; }

.theme-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.theme-swatch {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  background: var(--surface-2); border: 1px solid var(--surface-3); border-radius: var(--radius-s);
  padding: 8px 6px; cursor: pointer;
}
.theme-swatch.is-active { border-color: var(--teal); box-shadow: 0 0 0 1px var(--teal); }
.theme-swatch-preview { width: 100%; height: 32px; border-radius: var(--radius-s); border: 1px solid rgba(0,0,0,0.15); }
.theme-swatch-label { font-size: 11px; color: var(--ink-dim); }

[data-theme-preview="stage"] { background: linear-gradient(135deg, #14131a 50%, #c9a227 50%); }
[data-theme-preview="daylight"] { background: linear-gradient(135deg, #f6f1e4 50%, #8a5a1f 50%); }
[data-theme-preview="chalkboard"] { background: linear-gradient(135deg, #1b2620 50%, #d8c98a 50%); }
[data-theme-preview="concert-hall"] { background: linear-gradient(135deg, #1f1116 50%, #c9a24a 50%); }
[data-theme-preview="marquee"] { background: linear-gradient(135deg, #12102a 50%, #ff4fa3 50%); }
[data-theme-preview="walnut"] { background: linear-gradient(135deg, #2b1d13 50%, #b8752f 50%); }

/* ==========================================================================
   Tools for Music — shell additions
   Everything above is the metronome's stylesheet, unchanged. Everything
   below is new: the app switcher in the header, the Home screen, the
   account card, and the page footnote used by every tool.
   ========================================================================== */

.footnote { text-align: center; color: var(--ink-faint); font-size: 12px; margin-top: 22px; }
.page-intro {
  background: var(--surface); border: 1px solid var(--surface-3); border-radius: var(--radius-m);
  color: var(--ink-dim); font-size: 12.5px; line-height: 1.5; padding: 10px 12px; margin-top: 14px;
}
.topbar { position: relative; }
[hidden] { display: none !important; }

/* ---------- app switcher (brand button + dropdown) ---------- */
.brand-switch {
  display: flex; align-items: center; gap: 8px;
  background: none; border: 0; margin: 0 0 0 -8px; padding: 6px 8px;
  font: inherit; color: var(--brass-light); cursor: pointer;
  border-radius: var(--radius-s);
}
.brand-switch:hover, .brand-switch[aria-expanded="true"] { background: var(--surface); }
.brand-switch:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
.brand-switch .chev {
  width: 12px; height: 12px; margin-left: 2px; color: var(--ink-faint);
  transition: transform 120ms;
}
.brand-switch[aria-expanded="true"] .chev { transform: rotate(180deg); }

.app-menu {
  position: absolute; top: calc(100% - 2px); left: -8px; z-index: 40;
  min-width: 230px; padding: 6px;
  background: var(--surface); border: 1px solid var(--surface-3);
  border-radius: var(--radius-m);
  box-shadow: 0 14px 36px var(--overlay);
}
.app-menu-label {
  font-size: 11px; letter-spacing: .06em; text-transform: uppercase;
  color: var(--ink-faint); padding: 8px 12px 4px;
}
.app-menu a {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 12px; border-radius: var(--radius-s);
  color: var(--brass-light); text-decoration: none;
}
.app-menu a:hover, .app-menu a:focus-visible { background: var(--surface-2); outline: none; }
.app-menu a .brand-mark { flex: none; }

/* ---------- Home ---------- */
.home-hero { padding: 18px 0 6px; }
.home-title {
  margin: 0; font-family: var(--font-display); font-size: 26px; font-weight: 700;
  letter-spacing: .04em; text-transform: uppercase; color: var(--brass-light);
}
.home-lede { margin: 8px 0 0; color: var(--ink-dim); font-size: 14px; line-height: 1.5; }

.tool-grid { display: flex; flex-direction: column; gap: 10px; margin: 18px 0 14px; }
.tool-card {
  display: flex; align-items: center; gap: 16px;
  background: var(--surface); border: 1px solid var(--surface-3);
  border-radius: var(--radius-l); padding: 16px 18px;
  color: var(--ink); text-decoration: none;
}
.tool-card:hover { border-color: var(--brass); }
.tool-card:active { background: var(--surface-2); }
.tool-card:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
.tool-card-mark {
  flex: none; width: 52px; height: 52px; border-radius: var(--radius-m);
  display: flex; align-items: center; justify-content: center;
  background: var(--surface-2); color: var(--brass-light);
}
.tool-card-mark .brand-mark { width: 30px; height: 30px; }
.tool-card-text { flex: 1; min-width: 0; }
.tool-card-name {
  font-family: var(--font-display); font-size: 17px; letter-spacing: .06em;
  text-transform: uppercase; color: var(--brass-light);
}
.tool-card-desc { font-size: 13px; color: var(--ink-dim); margin-top: 3px; line-height: 1.4; }
.tool-card-go { flex: none; color: var(--ink-faint); font-size: 20px; }

/* ---------- account card (Home only) ---------- */
.account-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.account-email { font-size: 14px; word-break: break-all; }
.account-note { font-size: 12px; color: var(--ink-faint); margin: 10px 0 0; line-height: 1.5; }
.auth-tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.auth-form { display: flex; flex-direction: column; gap: 10px; }
.auth-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--ink-dim); }
.auth-form input {
  background: var(--surface-2); border: 1px solid var(--surface-3); color: var(--ink);
  border-radius: var(--radius-s); padding: 10px; font-size: 15px; font-family: var(--font-body);
}
.auth-form input:focus-visible { outline: 2px solid var(--teal); outline-offset: 1px; }
.auth-error { font-size: 13px; color: var(--danger-light); min-height: 1em; margin: 0; }
.btn-primary {
  background: var(--brass); color: var(--on-accent); border: none;
  font-family: var(--font-body); font-weight: 700; font-size: 14px;
  padding: 11px 16px; border-radius: var(--radius-m); cursor: pointer;
}
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { opacity: .6; cursor: default; }
.pill-brass {
  background: color-mix(in srgb, var(--brass) 15%, transparent); color: var(--brass-light);
  border-color: color-mix(in srgb, var(--brass) 40%, transparent);
}

/* ==========================================================================
   High contrast — one switch for every tool, layered on whichever theme is
   active. Values are precomputed per theme so that normal text is at least
   WCAG AAA (7:1) on the surfaces it sits on and control edges are at least 3:1
   against their background. Because these are custom properties they also
   reach the tuner and recorder (shadow DOM).
   ========================================================================== */
html[data-contrast="high"]:not([data-theme]),
html[data-theme="stage"][data-contrast="high"] {
  --ink: #ffffff;
  --ink-dim: #eae9ec;
  --ink-faint: #b3b1b8;
  --surface-3: #696971;
  --brass: #c9a227;
  --brass-light: #e5c157;
  --teal: #79bdb9;
  --on-teal: #08201f;
  --danger: #c6624e;
  --danger-light: #e2735a;
}
html[data-theme="daylight"][data-contrast="high"] {
  --ink: #000000;
  --ink-dim: #27241d;
  --ink-faint: #4f4b40;
  --surface-3: #918a7a;
  --brass: #754c1a;
  --brass-light: #66451b;
  --teal: #24544f;
  --on-teal: #eafaf6;
  --danger: #a23f2c;
  --danger-light: #a84c36;
}
html[data-theme="chalkboard"][data-contrast="high"] {
  --ink: #ffffff;
  --ink-dim: #ffffff;
  --ink-faint: #c3c8c5;
  --surface-3: #6c7a73;
  --brass: #d8c98a;
  --brass-light: #ecdfab;
  --teal: #aecad8;
  --on-teal: #0f242c;
  --danger: #d07d66;
  --danger-light: #e08a6d;
}
html[data-theme="concert-hall"][data-contrast="high"] {
  --ink: #ffffff;
  --ink-dim: #f0eae8;
  --ink-faint: #c0b3af;
  --surface-3: #7a656c;
  --brass: #c9a24a;
  --brass-light: #e6c56f;
  --teal: #99bea9;
  --on-teal: #08160f;
  --danger: #bc6969;
  --danger-light: #d4766f;
}
html[data-theme="marquee"][data-contrast="high"] {
  --ink: #ffffff;
  --ink-dim: #e8e7f2;
  --ink-faint: #b2aec8;
  --surface-3: #68638f;
  --brass: #ff69b1;
  --brass-light: #ff8bc6;
  --teal: #38e0e6;
  --on-teal: #012326;
  --danger: #ff5c5c;
  --danger-light: #ff8686;
}
html[data-theme="walnut"][data-contrast="high"] {
  --ink: #ffffff;
  --ink-dim: #faf8f5;
  --ink-faint: #cbc1b4;
  --surface-3: #7f7062;
  --brass: #cb9a67;
  --brass-light: #e5ba89;
  --teal: #b7c5bc;
  --on-teal: #10201a;
  --danger: #b2725c;
  --danger-light: #ce8b6f;
}
html[data-contrast="high"] { --focus-w: 3px; }   /* read by components inside Shadow DOM (they can't see the rule below) */
html[data-contrast="high"] :focus-visible { outline: 3px solid var(--teal); outline-offset: 2px; }

/* ---------- Home: sign-in / unlock panel ---------- */
.unlock-title { margin: 0 0 6px; font-family: var(--font-display); font-size: 14px; letter-spacing: .06em; text-transform: uppercase; color: var(--brass-light); }
.unlock-text { margin: 0 0 12px; font-size: 13px; line-height: 1.5; color: var(--ink-dim); }
.unlock-form { display: flex; flex-direction: column; gap: 10px; }
.unlock-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--ink-dim); }
.unlock-form input {
  background: var(--surface-2); border: 1px solid var(--surface-3); color: var(--ink);
  border-radius: var(--radius-s); padding: 11px 10px; font-size: 16px; font-family: var(--font-body);
}
.unlock-form input.code-input { font-family: var(--font-display); font-size: 20px; letter-spacing: .18em; text-transform: uppercase; text-align: center; }
.unlock-form input:focus-visible { outline: 2px solid var(--teal); outline-offset: 1px; }
.unlock-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.unlock-msg { font-size: 13px; min-height: 1em; margin: 0; color: var(--ink-dim); }
.unlock-msg.is-error { color: var(--danger-light); }
.unlock-list { margin: 0 0 12px; padding-left: 18px; font-size: 13px; line-height: 1.6; color: var(--ink-dim); }
.placeholder-tag {
  display: inline-block; font-family: var(--font-display); font-size: 10px; letter-spacing: .08em; text-transform: uppercase;
  padding: 2px 7px; border-radius: 999px; margin-left: 6px; vertical-align: middle;
  color: var(--ink-dim); border: 1px dashed var(--ink-faint);
}
.linklike { background: none; border: 0; padding: 0; font: inherit; font-size: 13px; color: var(--ink-dim); text-decoration: underline; cursor: pointer; }
.linklike:hover { color: var(--ink); }

/* ---------- Home: email row (input + icon button), hidden labels ---------- */
.visually-hidden { position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.unlock-row { display: flex; gap: 8px; align-items: stretch; }
.unlock-row input { flex: 1; min-width: 0; }
.icon-send {
  flex: none; width: 48px; display: flex; align-items: center; justify-content: center;
  background: var(--brass); color: var(--on-accent); border: none; border-radius: var(--radius-s); cursor: pointer;
}
.icon-send svg { width: 22px; height: 22px; }
.icon-send:active { transform: translateY(1px); }
.icon-send:disabled { opacity: .6; cursor: default; }
.icon-send:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }

/* ---------- Home: compact vertical layout (fits one phone screen) ---------- */
.is-home .topbar { padding-top: 10px; padding-bottom: 4px; }
.is-home .home-hero { padding: 8px 0 0; }
.is-home .home-title { font-size: 22px; }
.is-home .home-lede { margin-top: 3px; font-size: 13px; }
.is-home .tool-grid { gap: 8px; margin: 12px 0 10px; }
.is-home .tool-card { padding: 9px 14px; gap: 12px; border-radius: var(--radius-m); }
.is-home .tool-card-mark { width: 40px; height: 40px; border-radius: var(--radius-s); }
.is-home .tool-card-mark .brand-mark { width: 24px; height: 24px; }
.is-home .tool-card-name { font-size: 15px; }
.is-home .tool-card-desc { font-size: 12.5px; margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.is-home .panel { padding: 12px 14px; margin-top: 0; }
.is-home .unlock-title { margin-bottom: 4px; }
.is-home .unlock-text { margin-bottom: 8px; }
.is-home .unlock-form { gap: 6px; }
.unlock-msg:empty { display: none; }
a.linklike { text-decoration: underline; }
/* the Paid features page reuses the same look */
.btn-primary { display: inline-block; text-decoration: none; }
