/* ══════════════════════════════════════════════════════════════════════════
   WASMTea — shared design system
   Tokens first, then primitives, then components. Every page imports this.
   ══════════════════════════════════════════════════════════════════════════ */

:root {
  /* ── Surfaces ─────────────────────────────────────────────────────────── */
  --bg:            #14142a;
  --surface:       #1b2447;
  --surface-2:     #16213e;
  --raised:        #223061;
  --line:          #2c3d70;
  --line-soft:     #24325e;

  /* ── Text ─────────────────────────────────────────────────────────────────
     Contrast measured against --surface (#1b2447):
       --text      ≈ 14.4:1   --text-2 ≈ 7.9:1
       --text-3    ≈ 5.1:1    --text-4 ≈ 3.4:1 (non-text / decorative only)
     The old palette used #555 (2.2:1) and #444 (1.8:1) for hints and empty
     states — the exact copy a new user most needs to read. */
  --text:          #eef1f8;
  --text-2:        #b9c2d8;
  --text-3:        #929db8;
  --text-4:        #6d7796;

  /* ── Brand & intent ───────────────────────────────────────────────────────
     Brand red is no longer reused for "failure". Primary actions are blue,
     destructive/negative states are red, positive states are green. */
  --brand:         #ff5c7a;
  --brand-dim:     #c73652;

  --primary:       #3d8bfd;
  --primary-hover: #5a9dff;
  --primary-dim:   #1e5fbf;

  --ok:            #4ade80;
  --ok-dim:        #1e7d43;
  --danger:        #ff6b81;
  --danger-dim:    #b3364b;
  --warn:          #fbbf24;

  /* ── Graph rendering ──────────────────────────────────────────────────── */
  --vertex:        #ff5c7a;
  --vertex-stroke: #ffa0b3;
  --edge:          #5a9dff;

  /* Witness highlight ramp — used to paint analysis results on the canvas */
  --hl-1:          #4ade80;
  --hl-2:          #fbbf24;
  --hl-3:          #c084fc;
  --hl-4:          #38bdf8;
  --hl-5:          #fb923c;
  --hl-6:          #f472b6;

  /* ── Geometry ─────────────────────────────────────────────────────────── */
  --r-sm: 4px;
  --r-md: 6px;
  --r-lg: 10px;
  --sidebar-w: 288px;

  --shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  --focus: 0 0 0 2px var(--bg), 0 0 0 4px var(--primary);

  color-scheme: dark;
}

/* Light theme — opt in via [data-theme="light"], default follows the OS. */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg:            #f4f6fb;
    --surface:       #ffffff;
    --surface-2:     #eef1f8;
    --raised:        #e2e8f5;
    --line:          #cbd5e8;
    --line-soft:     #dde4f1;

    --text:          #131826;
    --text-2:        #3c465e;
    --text-3:        #5b6780;
    --text-4:        #8c96ad;

    --brand:         #d81b47;
    --brand-dim:     #a91435;
    --primary:       #1f6feb;
    --primary-hover: #1a5fd0;
    --primary-dim:   #b9d3f8;
    --ok:            #15803d;
    --ok-dim:        #bbf7d0;
    --danger:        #c62842;
    --danger-dim:    #fbc9d1;
    --warn:          #a16207;

    --vertex:        #d81b47;
    --vertex-stroke: #8f0f2c;
    --edge:          #1f6feb;

    --hl-1: #15803d; --hl-2: #a16207; --hl-3: #7e22ce;
    --hl-4: #0369a1; --hl-5: #c2410c; --hl-6: #be185d;

    --shadow: 0 6px 20px rgba(15, 23, 42, 0.14);
    color-scheme: light;
  }
}

:root[data-theme="light"] {
  --bg:            #f4f6fb;
  --surface:       #ffffff;
  --surface-2:     #eef1f8;
  --raised:        #e2e8f5;
  --line:          #cbd5e8;
  --line-soft:     #dde4f1;

  --text:          #131826;
  --text-2:        #3c465e;
  --text-3:        #5b6780;
  --text-4:        #8c96ad;

  --brand:         #d81b47;
  --brand-dim:     #a91435;
  --primary:       #1f6feb;
  --primary-hover: #1a5fd0;
  --primary-dim:   #b9d3f8;
  --ok:            #15803d;
  --ok-dim:        #bbf7d0;
  --danger:        #c62842;
  --danger-dim:    #fbc9d1;
  --warn:          #a16207;

  --vertex:        #d81b47;
  --vertex-stroke: #8f0f2c;
  --edge:          #1f6feb;

  --hl-1: #15803d; --hl-2: #a16207; --hl-3: #7e22ce;
  --hl-4: #0369a1; --hl-5: #c2410c; --hl-6: #be185d;

  --shadow: 0 6px 20px rgba(15, 23, 42, 0.14);
  color-scheme: light;
}

/* ── Reset ────────────────────────────────────────────────────────────────── */
* { box-sizing: border-box; margin: 0; padding: 0; }

/* Components below set an explicit `display`, which would otherwise beat the
   UA stylesheet's [hidden] { display: none } and leave "hidden" nodes visible. */
[hidden] { display: none !important; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body.app-shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--r-sm); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ── App header ───────────────────────────────────────────────────────────── */
.app-header {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.5rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.app-header h1 {
  font-size: 0.95rem;
  font-weight: 650;
  color: var(--text);
  white-space: nowrap;
  letter-spacing: -0.01em;
}
.app-header h1 .mark { color: var(--brand); }

.app-nav { display: flex; gap: 0.15rem; align-items: center; }

.nav-link {
  padding: 0.32rem 0.7rem;
  border-radius: var(--r-sm);
  font-size: 0.8rem;
  color: var(--text-3);
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.14s, color 0.14s;
}
.nav-link:hover { background: var(--raised); color: var(--text); }
.nav-link[aria-current="page"] { background: var(--raised); color: var(--text); font-weight: 600; }

.header-sep { width: 1px; height: 20px; background: var(--line); flex-shrink: 0; }
.spacer { margin-left: auto; }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.34rem 0.8rem;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--raised);
  color: var(--text-2);
  cursor: pointer;
  font-size: 0.8rem;
  font-family: inherit;
  white-space: nowrap;
  transition: background 0.14s, color 0.14s, border-color 0.14s;
}
.btn:hover:not(:disabled) { background: var(--primary-dim); color: var(--text); border-color: var(--primary); }
.btn:disabled { opacity: 0.45; cursor: default; }

.btn.active   { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.btn.toggled  { background: var(--ok-dim);  border-color: var(--ok);      color: var(--text); }

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 600;
}
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-primary:disabled { background: var(--raised); border-color: var(--line); color: var(--text-4); }

.btn-block { width: 100%; justify-content: center; padding: 0.5rem; font-size: 0.85rem; }

.btn-icon {
  padding: 0.34rem 0.5rem;
  font-size: 0.9rem;
  line-height: 1;
}

.kbd {
  font: 600 0.65rem/1 ui-monospace, monospace;
  color: var(--text-4);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 0.15rem 0.3rem;
  margin-left: 0.15rem;
}

/* ── Badges & status text ─────────────────────────────────────────────────── */
.badge {
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--raised);
  color: var(--text-2);
  border: 1px solid var(--line);
  white-space: nowrap;
  cursor: pointer;
  font-family: inherit;
}
.badge:hover { border-color: var(--primary); color: var(--text); }
.badge.force { background: var(--ok-dim); color: var(--text); border-color: var(--ok); }

.meta   { font-size: 0.76rem; color: var(--text-3); white-space: nowrap; }
.hint   { font-size: 0.76rem; color: var(--text-3); }

/* ── Layout ───────────────────────────────────────────────────────────────── */
.main { display: flex; flex: 1; overflow: hidden; min-height: 0; }

.stage { flex: 1; position: relative; overflow: hidden; min-width: 0; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sidebar.left { border-left: none; border-right: 1px solid var(--line); }

/* ── Tabs ─────────────────────────────────────────────────────────────────── */
.tabs { display: flex; flex-shrink: 0; border-bottom: 1px solid var(--line); }

.tab-btn {
  flex: 1;
  padding: 0.55rem 0.25rem;
  background: none;
  border: none;
  color: var(--text-3);
  font-size: 0.72rem;
  font-weight: 700;
  font-family: inherit;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  cursor: pointer;
  transition: color 0.14s;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

.tab-panel { display: flex; flex-direction: column; flex: 1; overflow: hidden; }
.tab-panel[hidden] { display: none; }

/* ── Collapsible sections ─────────────────────────────────────────────────── */
details.group { margin-bottom: 0.5rem; }

details.group > summary {
  font-size: 0.66rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--primary);
  padding: 0.32rem 0;
  border-bottom: 1px solid var(--line-soft);
  cursor: pointer;
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.4rem;
  user-select: none;
}
details.group > summary::after {
  content: '▸';
  font-size: 0.72rem;
  color: var(--primary);
  transition: transform 0.15s;
  margin-left: auto;
}
details.group[open] > summary::after { transform: rotate(90deg); }
details.group > summary::-webkit-details-marker { display: none; }
details.group > summary .cap {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-4);
  font-size: 0.68rem;
}
.section-body { padding-top: 0.3rem; }

.sec-title {
  font-size: 0.66rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--primary);
  padding-bottom: 0.3rem;
  margin-bottom: 0.5rem;
  border-bottom: 1px solid var(--line-soft);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.sec-title .cap { font-weight: 400; text-transform: none; letter-spacing: 0; color: var(--text-4); font-size: 0.7rem; }
.section { margin-bottom: 1.1rem; }

/* ── Metric rows ──────────────────────────────────────────────────────────── */
.row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.2rem 0.3rem;
  font-size: 0.78rem;
  border-radius: var(--r-sm);
}
.row .lbl { color: var(--text-3); }
.row .val { color: var(--text); font-variant-numeric: tabular-nums; }
.val.yes { color: var(--ok); font-weight: 600; }
.val.no  { color: var(--danger); font-weight: 600; }
.val.na  { color: var(--text-4); font-style: italic; }

/* Rows that can paint a witness onto the canvas */
.row.clickable { cursor: pointer; }
.row.clickable:hover { background: var(--raised); }
.row.clickable .lbl::after {
  content: '◈';
  font-size: 0.62rem;
  color: var(--text-4);
  margin-left: 0.35rem;
  vertical-align: 0.05em;
}
.row.clickable:hover .lbl { color: var(--text); }
.row.clickable:hover .lbl::after { color: var(--primary); }
.row.clickable.showing { background: var(--primary-dim); }
.row.clickable.showing .lbl { color: var(--text); font-weight: 600; }
.row.clickable.showing .lbl::after { content: '◆'; color: var(--primary); }

.seq {
  font-size: 0.72rem;
  color: var(--text-3);
  word-break: break-all;
  line-height: 1.6;
  margin-top: 0.15rem;
  padding: 0 0.3rem;
}

/* ── Form controls ────────────────────────────────────────────────────────── */
.field { margin-bottom: 0.5rem; }
.field label { display: block; font-size: 0.74rem; color: var(--text-3); margin-bottom: 0.22rem; }

input[type="number"], input[type="text"], select, textarea, input[type="file"] {
  width: 100%;
  padding: 0.32rem 0.5rem;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  color: var(--text);
  font-size: 0.8rem;
  font-family: inherit;
}
input[type="number"]:focus, input[type="text"]:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-dim);
}
textarea { resize: vertical; min-height: 3.2rem; font-family: ui-monospace, monospace; line-height: 1.5; }
input[type="file"] { padding: 0.25rem; cursor: pointer; font-size: 0.75rem; }
input[type="range"] { width: 100%; accent-color: var(--primary); }
input[type="checkbox"], input[type="radio"] { accent-color: var(--primary); cursor: pointer; }

.param-row { display: flex; align-items: center; gap: 0.5rem; }
.param-row label { font-size: 0.78rem; color: var(--text-3); flex-shrink: 0; min-width: 4rem; }
.param-row input { flex: 1; text-align: center; }

.radio-row { display: flex; gap: 1rem; margin-bottom: 0.6rem; flex-wrap: wrap; }
.radio-row label {
  font-size: 0.8rem; color: var(--text-2); cursor: pointer;
  display: flex; align-items: center; gap: 0.35rem;
}

/* ── Chips ────────────────────────────────────────────────────────────────── */
.chip-row { display: flex; gap: 0.3rem; align-items: center; flex-wrap: wrap; }

.chip {
  padding: 0.24rem 0.6rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--raised);
  color: var(--text-3);
  font-size: 0.73rem;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.14s, color 0.14s, border-color 0.14s;
}
.chip:hover:not(:disabled) { color: var(--text); border-color: var(--primary); }
.chip:disabled { opacity: 0.4; cursor: default; }
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.chip.active.pass { background: var(--ok-dim); border-color: var(--ok); color: var(--text); }
.chip.active.fail { background: var(--danger-dim); border-color: var(--danger); color: var(--text); }

/* ── Dropdown menu (keyboard accessible) ──────────────────────────────────── */
.menu-wrap { position: relative; display: flex; gap: 0.3rem; }

.menu {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  z-index: 100;
  min-width: 190px;
  box-shadow: var(--shadow);
  padding: 0.25rem;
}
.menu.open { display: block; }

.menu-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.4rem 0.6rem;
  font-size: 0.78rem;
  font-family: inherit;
  color: var(--text-2);
  background: none;
  border: none;
  border-radius: var(--r-sm);
  cursor: pointer;
  white-space: nowrap;
}
.menu-item:hover, .menu-item:focus { background: var(--primary); color: #fff; outline: none; }

/* ── Tables ───────────────────────────────────────────────────────────────── */
.table-wrap { flex: 1; overflow: auto; padding: 0.5rem; min-height: 0; }

table { border-collapse: collapse; font-size: 0.76rem; white-space: nowrap; }

th {
  position: sticky;
  top: 0;
  background: var(--surface);
  padding: 0.4rem 0.65rem;
  text-align: left;
  color: var(--primary);
  font-weight: 700;
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 2px solid var(--line);
  z-index: 1;
}
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); background: var(--raised); }
th.sortable::after { content: '↕'; opacity: 0.35; margin-left: 0.3rem; font-size: 0.7rem; }
th.sortable.asc::after  { content: '↑'; opacity: 1; }
th.sortable.desc::after { content: '↓'; opacity: 1; }

td {
  padding: 0.3rem 0.65rem;
  border-bottom: 1px solid var(--line-soft);
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}
tbody tr { cursor: pointer; }
tbody tr:hover td { background: var(--raised); }

td.g6 {
  font-family: ui-monospace, monospace;
  font-size: 0.72rem;
  color: var(--text-3);
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
}
td.val-true  { color: var(--ok); font-weight: 700; }
td.val-false { color: var(--danger); font-weight: 700; }
td.val-na    { color: var(--text-4); font-style: italic; }

tr.row-pass td:first-child { border-left: 3px solid var(--ok); }
tr.row-fail td:first-child { border-left: 3px solid var(--danger); }
tr.row-err  td:first-child { border-left: 3px solid var(--text-4); }
tr.row-fail td { background: color-mix(in srgb, var(--danger) 9%, transparent); }
tr.selected td { background: var(--primary-dim) !important; }

/* ── Empty states ─────────────────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 2.5rem 1.5rem;
  text-align: center;
  color: var(--text-3);
}
.empty-state .glyph { font-size: 2rem; opacity: 0.5; line-height: 1; }
.empty-state .title { font-size: 0.95rem; font-weight: 600; color: var(--text-2); }
.empty-state .body  { font-size: 0.8rem; color: var(--text-3); max-width: 34ch; line-height: 1.6; }

/* Centred over the drawing stage, click-through so the canvas still works */
.stage-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 5;
}
.stage-empty[hidden] { display: none; }
.stage-empty .inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  padding: 1.5rem 2rem;
  border: 1px dashed var(--line);
  border-radius: var(--r-lg);
  background: color-mix(in srgb, var(--surface) 75%, transparent);
  max-width: 30rem;
}
.stage-empty .glyph { font-size: 2.2rem; opacity: 0.6; }
.stage-empty .title { font-size: 1rem; font-weight: 600; color: var(--text); }
.stage-empty .body  { font-size: 0.82rem; color: var(--text-3); text-align: center; line-height: 1.65; }

/* ── Toasts (replaces alert()) ────────────────────────────────────────────── */
#toast-region {
  position: fixed;
  bottom: 1.1rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  z-index: 9999;
  pointer-events: none;
  align-items: center;
  width: min(30rem, calc(100vw - 2rem));
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  padding: 0.6rem 0.9rem;
  border-radius: var(--r-md);
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 3px solid var(--primary);
  color: var(--text);
  font-size: 0.82rem;
  box-shadow: var(--shadow);
  pointer-events: auto;
  animation: toast-in 0.18s ease-out;
  max-width: 100%;
}
.toast.error { border-left-color: var(--danger); }
.toast.ok    { border-left-color: var(--ok); }
.toast.warn  { border-left-color: var(--warn); }
.toast .glyph { flex-shrink: 0; line-height: 1.4; }
.toast .msg   { flex: 1; line-height: 1.45; }
.toast .close {
  background: none; border: none; color: var(--text-4);
  cursor: pointer; font-size: 1rem; line-height: 1; padding: 0 0.15rem;
  flex-shrink: 0; font-family: inherit;
}
.toast .close:hover { color: var(--text); }
.toast.leaving { animation: toast-out 0.16s ease-in forwards; }

@keyframes toast-in  { from { opacity: 0; transform: translateY(8px); } }
@keyframes toast-out { to   { opacity: 0; transform: translateY(6px); } }

/* ── Progress ─────────────────────────────────────────────────────────────── */
.progress {
  height: 4px;
  background: var(--raised);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 0.5rem;
}
.progress > span {
  display: block;
  height: 100%;
  background: var(--primary);
  transition: width 0.12s linear;
}

/* ── Stale banner ─────────────────────────────────────────────────────────── */
.stale-banner {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.7rem;
  margin-bottom: 0.6rem;
  background: color-mix(in srgb, var(--warn) 15%, transparent);
  border: 1px solid color-mix(in srgb, var(--warn) 45%, transparent);
  border-radius: var(--r-sm);
  font-size: 0.75rem;
  color: var(--text-2);
}
.stale-banner[hidden] { display: none; }
.stale-banner button {
  margin-left: auto; background: none; border: none;
  color: var(--primary); cursor: pointer; font-size: 0.75rem;
  font-weight: 600; font-family: inherit; text-decoration: underline;
}

.is-stale { opacity: 0.5; transition: opacity 0.15s; }

/* ── Legend for witness overlays ──────────────────────────────────────────── */
.legend {
  position: absolute;
  left: 0.75rem;
  bottom: 0.75rem;
  z-index: 6;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  padding: 0.55rem 0.75rem;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow);
  font-size: 0.75rem;
  max-width: 16rem;
}
.legend[hidden] { display: none; }
.legend .head { font-weight: 650; color: var(--text); display: flex; align-items: center; gap: 0.5rem; }
.legend .head button {
  margin-left: auto; background: none; border: none; color: var(--text-4);
  cursor: pointer; font-size: 0.95rem; line-height: 1; font-family: inherit;
}
.legend .head button:hover { color: var(--text); }
.legend .item { display: flex; align-items: center; gap: 0.45rem; color: var(--text-2); }
.legend .swatch { width: 11px; height: 11px; border-radius: 3px; flex-shrink: 0; }

/* ── Screen-reader only ───────────────────────────────────────────────────── */
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* ══════════════════════════════════════════════════════════════════════════
   Responsive — the old layout was fixed at 100vh with rigid sidebars and had
   no media queries at all, which made every page unusable below ~900px.
   ══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 900px) {
  :root { --sidebar-w: 100%; }

  .main { flex-direction: column; }

  .stage { flex: 1 1 55%; min-height: 240px; }

  .sidebar {
    width: 100%;
    max-height: 45%;
    border-left: none;
    border-right: none;
    border-top: 1px solid var(--line);
  }
  .sidebar.left { border-right: none; border-bottom: 1px solid var(--line); border-top: none; }

  /* Sidebar collapses to a drawer toggled from the header */
  .sidebar.collapsed { max-height: 0; border-width: 0; overflow: hidden; }

  .app-header { padding: 0.45rem 0.7rem; gap: 0.4rem; row-gap: 0.4rem; }
  .app-header h1 { font-size: 0.85rem; }
  .hint { display: none; }
  .btn { padding: 0.32rem 0.6rem; font-size: 0.78rem; }

  .drawer-toggle { display: inline-flex !important; }
}

@media (min-width: 901px) {
  .drawer-toggle { display: none !important; }
}

@media (max-width: 560px) {
  .app-header h1 .full { display: none; }
  .badge { display: none; }
  .kbd { display: none; }
}
