/* ============================================================
   Interactive Multiscale Viewer v7 — viewer.css
   Design tokens match public/Burns/Burn Knowledge Map.html
   ============================================================ */

:root {
  --teal: #059598;
  --teal-dark: #013f54;
  --orange: #f69318;
  --surface: #f4fafa;
  --bg: #f8fafc;
  --ink: #1a2733;
  --ink-soft: #4a5b6b;
  --ink-mute: #8094a3;
  --rule: #e3ecef;
  --rule-soft: #eef2f4;

  --macro: #2b6cb0;
  --macro-bg: #f0f5fa;
  --meso: #2f855a;
  --meso-bg: #f0fff4;
  --micro: #c53030;
  --micro-bg: #fff5f5;
  --systemic: #b7791f;
  --systemic-bg: #fffaf0;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; }
body {
  font-family: 'Inter', -apple-system, system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ===== APP GRID ===== */
.app {
  display: grid;
  grid-template-columns: 400px 1fr;
  grid-template-rows: 1fr 120px;
  height: 100vh;
  width: 100vw;
}

/* ===== SIDEBAR ===== */
.sidebar {
  grid-row: 1 / 3;
  background: #fff;
  border-right: 1px solid var(--rule);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.side-header {
  background: var(--teal-dark);
  color: #fff;
  padding: 20px 22px 18px;
  flex-shrink: 0;
}
.brand-mark {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: #fff;
  opacity: 0.85;
  margin-bottom: 8px;
}
.side-title {
  font-family: 'Merriweather', Georgia, serif;
  font-size: 20px;
  font-weight: 700;
  color: #fff;
  line-height: 1.25;
  letter-spacing: -0.01em;
  margin-bottom: 10px;
}
.side-sub {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--orange);
  display: flex;
  align-items: center;
  gap: 6px;
}
.side-sub::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--orange);
}

/* ===== MODE TOGGLE ===== */
.mode-toggle {
  display: flex;
  padding: 12px 16px;
  background: #fff;
  border-bottom: 1px solid var(--rule);
  gap: 4px;
  flex-shrink: 0;
}
.mode-pill {
  flex: 1;
  border: 1px solid var(--rule);
  background: #fff;
  color: var(--ink-soft);
  padding: 7px 6px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  border-radius: 999px;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.mode-pill:hover { border-color: var(--teal); color: var(--teal); }
.mode-pill.active {
  background: var(--teal-dark);
  color: #fff;
  border-color: var(--teal-dark);
}

/* ===== SIDEBAR BODY ===== */
.side-body {
  overflow-y: auto;
  flex: 1;
  padding: 20px 22px 30px;
}
.side-body { scrollbar-width: thin; scrollbar-color: var(--rule) transparent; }
.side-body::-webkit-scrollbar { width: 6px; }
.side-body::-webkit-scrollbar-thumb { background: var(--rule); border-radius: 3px; }

/* ===== OVERVIEW / LEGEND ===== */
.overview-title {
  font-family: 'Merriweather', Georgia, serif;
  font-size: 17px;
  font-weight: 700;
  color: var(--ink);
  margin: 0 0 8px;
  line-height: 1.3;
}
.overview-abstract {
  font-size: 13px;
  color: var(--ink-soft);
  line-height: 1.6;
  margin-bottom: 22px;
}

.legend-block { margin-bottom: 22px; }
.legend-block h4 {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-mute);
  margin: 0 0 10px;
}
.legend-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 0;
  font-size: 12.5px;
  color: var(--ink-soft);
}
.legend-row .label-strong { color: var(--ink); font-weight: 500; }
.swatch {
  width: 28px;
  height: 16px;
  border-radius: 3px;
  border: 1.5px solid;
  flex-shrink: 0;
}
.swatch.macro    { border-color: var(--macro);    background: var(--macro-bg); }
.swatch.meso     { border-color: var(--meso);     background: var(--meso-bg); }
.swatch.micro    { border-color: var(--micro);    background: var(--micro-bg); }
.swatch.systemic { border-color: var(--systemic); background: var(--systemic-bg); border-style: dashed; }

.layer-swatch {
  width: 28px;
  height: 12px;
  border-radius: 2px;
  border: 1px solid var(--rule);
  flex-shrink: 0;
}

.edge-svg { width: 38px; height: 14px; flex-shrink: 0; }

.usage-tips {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 12px;
  color: var(--ink-soft);
  line-height: 1.6;
}
.usage-tips strong { color: var(--ink); font-weight: 600; }
.usage-tips ul { margin: 6px 0 0; padding-left: 18px; }
.usage-tips li { margin: 3px 0; }

/* ===== DETAIL PANEL ===== */
.detail .scale-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  border: 1px solid;
  margin-bottom: 14px;
}
.badge-meso  { color: var(--meso);  border-color: var(--meso);  background: var(--meso-bg); }
.badge-macro { color: var(--macro); border-color: var(--macro); background: var(--macro-bg); }
.badge-micro { color: var(--micro); border-color: var(--micro); background: var(--micro-bg); }
.badge-systemic { color: var(--systemic); border-color: var(--systemic); background: var(--systemic-bg); }
.badge-abm {
  display: inline-block;
  background: var(--teal-dark);
  color: #fff;
  padding: 3px 8px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.14em;
}

.detail-title {
  font-family: 'Merriweather', Georgia, serif;
  font-size: 22px;
  font-weight: 700;
  margin: 0 0 6px;
  line-height: 1.2;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 10px;
}
.detail-title .emoji { font-size: 24px; }
.detail-context {
  font-size: 12px;
  color: var(--ink-mute);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.detail-context .dot {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--ink-mute);
}
.detail-summary {
  font-size: 13.5px;
  color: var(--ink-soft);
  line-height: 1.65;
  margin-bottom: 22px;
}

.panel-sub {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-mute);
  margin: 22px 0 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--rule-soft);
}

/* ===== STOCKS & FLOWS GRID ===== */
.sf-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.sf-card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 10px 12px;
}
.sf-card .sf-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--teal);
  margin-bottom: 4px;
}
.sf-card .sf-value {
  font-size: 12.5px;
  color: var(--ink);
  line-height: 1.4;
}
.sf-card.flows .sf-label { color: var(--orange); }

/* ===== CONNECTIONS ===== */
.connection {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 0;
  border-bottom: 1px dashed var(--rule-soft);
  font-size: 13px;
}
.connection:last-child { border-bottom: none; }
.connection .rel {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 3px;
  flex-shrink: 0;
}
.rel-activates    { color: var(--meso);     background: var(--meso-bg); }
.rel-recruits     { color: #b08016;         background: #fffaf0; }
.rel-secretes     { color: #6b46c1;         background: #f7f3ff; }
.rel-differentiates { color: var(--macro);  background: var(--macro-bg); }
.rel-cross        { color: var(--teal);     background: #e6f7f7; }
.rel-inhibits     { color: var(--micro);    background: var(--micro-bg); }
.rel-degrades     { color: #9b2226; background: #fff0f0; }
.rel-couples      { color: #059598; background: #e6f7f7; }
.connection .arrow { color: var(--ink-mute); }
.connection .ref-node { color: var(--ink); font-weight: 500; }

/* ===== REFERENCES ===== */
.reference {
  font-size: 11.5px;
  color: var(--ink-soft);
  line-height: 1.5;
  padding: 8px 0;
  border-bottom: 1px solid var(--rule-soft);
}
.reference:last-child { border-bottom: none; }
.reference .ref-num {
  display: inline-block;
  width: 18px;
  height: 18px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 50%;
  text-align: center;
  font-size: 10px;
  font-weight: 600;
  color: var(--teal);
  margin-right: 6px;
  line-height: 16px;
}
.reference .ref-title  { color: var(--ink);      font-weight: 500; }
.reference .ref-meta   { color: var(--ink-mute); font-style: italic; }

/* ===== MODEL CARD ===== */
.model-card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 10px;
}
.model-card .mc-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.model-card .mc-name {
  font-weight: 600;
  color: var(--ink);
  font-size: 13px;
}

/* ===== EQUATION BLOCK ===== */
.equation-block {
  background: #0d2935;
  color: #c4e8e8;
  padding: 12px 14px;
  border-radius: 5px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12.5px;
  margin: 10px 0;
  overflow-x: auto;
  line-height: 1.6;
}
.equation-block .eq-var { color: var(--orange); }
.equation-block .eq-op  { color: #7fb8ce; }

/* ===== SOFTWARE CHIPS ===== */
.software-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.chip {
  background: #fff;
  border: 1px solid var(--rule);
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 11px;
  color: var(--ink-soft);
  font-weight: 500;
}
.chip::before {
  content: '◇';
  color: var(--teal);
  margin-right: 4px;
  font-size: 9px;
}

/* ===== PATIENT CALLOUT ===== */
.patient-callout {
  background: linear-gradient(180deg, #fff8ec 0%, #fff 100%);
  border: 1px solid #f5dca5;
  border-left: 3px solid var(--orange);
  border-radius: 6px;
  padding: 14px 16px;
  margin: 14px 0;
}
.patient-callout h5 {
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--orange);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.patient-callout p {
  margin: 0;
  font-size: 13px;
  line-height: 1.6;
  color: var(--ink);
}

/* ===== HEALING ROW ===== */
.healing-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 12px 14px;
  margin-top: 12px;
}
.healing-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--teal);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 18px;
  flex-shrink: 0;
}
.healing-row .ht {
  font-size: 12.5px;
  color: var(--ink);
  font-weight: 500;
}
.healing-row .hs {
  font-size: 11px;
  color: var(--ink-mute);
}

/* ===== BACK BUTTON ===== */
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-mute);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0 0 14px;
  font-family: inherit;
  transition: color 0.15s ease;
}
.back-btn:hover { color: var(--teal); }
.back-btn::before { content: '←'; font-size: 13px; }

/* ===== CANVAS WRAP ===== */
.canvas-wrap {
  position: relative;
  background: var(--bg);
  overflow: hidden;
}

/* ===== TISSUE BANDS ===== */
.layer-bg {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  z-index: 0;
}
.tissue-band {
  flex: 1;
  position: relative;
  border-bottom: 1px dashed rgba(0, 0, 0, 0.06);
  display: flex;
  align-items: center;
}
.tissue-band:last-child { border-bottom: none; }
.tissue-band .layer-label {
  position: absolute;
  left: 18px;
  top: 12px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: rgba(0, 0, 0, 0.42);
}
.tissue-band .layer-depth {
  position: absolute;
  left: 18px;
  top: 28px;
  font-size: 9px;
  font-family: 'JetBrains Mono', monospace;
  color: rgba(0, 0, 0, 0.32);
  letter-spacing: 0.02em;
}
.band-epidermis  { background: #f5e6d3; }
.band-dermis     { background: #fce4ec; flex: 1.4; }
.band-hypodermis { background: #fff3e0; }
.band-vasculature{ background: #e3f2fd; flex: 0.8; }
.band-systemic   { background: #f5f5f5; flex: 0.9; }

/* ===== JACKSON ZONE OVERLAY ===== */
.zones-overlay {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(
      ellipse 55% 60% at 30% 30%,
      rgba(60, 20, 20, 0.32) 0%,
      rgba(60, 20, 20, 0.18) 18%,
      rgba(217, 119, 6, 0.18) 38%,
      rgba(244, 114, 182, 0.10) 60%,
      transparent 78%
    );
  pointer-events: none;
  z-index: 1;
  mix-blend-mode: multiply;
}

/* ===== CANVAS GRAIN ===== */
.canvas-grain {
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(
      90deg,
      transparent 0,
      transparent 80px,
      rgba(1, 63, 84, 0.025) 80px,
      rgba(1, 63, 84, 0.025) 81px
    );
  pointer-events: none;
  z-index: 1;
}

/* ===== CYTOSCAPE CONTAINER ===== */
#cy {
  position: absolute;
  inset: 0;
  z-index: 2;
}

/* ===== ZONE KEY (top-left of canvas) ===== */
.zone-key {
  position: absolute;
  top: 16px;
  left: 18px;
  z-index: 5;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 10px;
  font-weight: 500;
  color: var(--ink-soft);
  display: flex;
  gap: 12px;
  align-items: center;
}
.zone-key .zk-title {
  font-weight: 600;
  color: var(--ink);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-size: 9px;
  margin-right: 2px;
}
.zone-key .zk-item { display: flex; align-items: center; gap: 5px; }
.zone-key .zk-dot  {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}
.zk-coag { background: #4a2424; }
.zk-stas { background: #d97706; }
.zk-hyp  { background: #f472b6; }

/* ===== CANVAS HEADER (top-right) ===== */
.canvas-header {
  position: absolute;
  top: 16px;
  right: 18px;
  z-index: 5;
  text-align: right;
  color: var(--teal-dark);
}
.canvas-header .ch-title {
  font-family: 'Merriweather', serif;
  font-size: 13px;
  font-weight: 700;
}
.canvas-header .ch-sub {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-mute);
  margin-top: 2px;
}

/* ===== TIMELINE ===== */
.timeline {
  grid-column: 2;
  background: #fff;
  border-top: 1px solid var(--rule);
  padding: 16px 32px 14px;
  display: grid;
  grid-template-columns: 230px 1fr 180px;
  gap: 28px;
  align-items: center;
  position: relative;
  z-index: 5;
}

.tl-current {
  display: flex;
  flex-direction: column;
}
.tl-current .tl-label {
  font-size: 10px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-mute);
  font-weight: 600;
}
.tl-current .tl-phase {
  font-family: 'Merriweather', serif;
  font-size: 22px;
  font-weight: 700;
  color: var(--teal-dark);
  line-height: 1.1;
  margin-top: 4px;
}
.tl-current .tl-time {
  font-size: 11px;
  color: var(--ink-mute);
  font-family: 'JetBrains Mono', monospace;
  margin-top: 2px;
}

.tl-track-wrap {
  position: relative;
  padding: 18px 0 22px;
}
.tl-axis {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 2px;
  background: var(--rule);
  border-radius: 1px;
  transform: translateY(-50%);
}
.tl-axis-active {
  position: absolute;
  left: 0;
  top: 50%;
  height: 2px;
  background: var(--teal);
  border-radius: 1px;
  transform: translateY(-50%);
  transition: width 0.3s ease;
}
.tl-stops {
  position: relative;
  display: flex;
  justify-content: space-between;
}
.tl-stop {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  z-index: 2;
}
.tl-stop .tl-marker {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--rule);
  transition: all 0.2s ease;
}
.tl-stop:hover .tl-marker { border-color: var(--teal); }
.tl-stop.active .tl-marker {
  background: var(--teal);
  border-color: var(--teal-dark);
  box-shadow: 0 0 0 4px rgba(5, 149, 152, 0.18);
}
.tl-stop.passed .tl-marker {
  background: var(--teal);
  border-color: var(--teal);
}
.tl-stop .tl-stop-label {
  position: absolute;
  top: 22px;
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-soft);
  white-space: nowrap;
}
.tl-stop.active .tl-stop-label { color: var(--teal-dark); font-weight: 600; }
.tl-stop .tl-stop-time {
  position: absolute;
  top: -22px;
  font-size: 9px;
  color: var(--ink-mute);
  font-family: 'JetBrains Mono', monospace;
  white-space: nowrap;
}

/* ===== TIMELINE ACTIONS / TOGGLE SWITCH ===== */
.tl-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
}
.tl-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--ink-soft);
  cursor: pointer;
  user-select: none;
}
.tl-toggle input {
  opacity: 0;
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
}
.tl-toggle .switch {
  width: 30px;
  height: 16px;
  border-radius: 999px;
  background: var(--rule);
  position: relative;
  transition: background 0.2s;
}
.tl-toggle .switch::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 12px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}
.tl-toggle input:checked + .switch { background: var(--teal); }
.tl-toggle input:checked + .switch::after { transform: translateX(14px); }

.tl-disclaimer {
  grid-column: 1 / -1;
  font-size: 10px;
  color: var(--ink-mute);
  font-style: italic;
  text-align: center;
  margin: 0;
  padding: 4px 0 0;
  line-height: 1.4;
}

/* ===== MODEL TYPE BADGE ===== */
.model-type-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.type-ODE       { background: #ebf8ff; color: #2b6cb0; border: 1px solid #bee3f8; }
.type-PDE       { background: #f0fff4; color: #276749; border: 1px solid #9ae6b4; }
.type-ABM       { background: #faf5ff; color: #6b46c1; border: 1px solid #d6bcfa; }
.type-Boolean   { background: #fffaf0; color: #b7791f; border: 1px solid #fbd38d; }
.type-auxiliary { background: var(--surface); color: var(--ink-mute); border: 1px solid var(--rule); }

.model-notes {
  font-size: 12px;
  color: var(--ink-soft);
  line-height: 1.55;
  margin: 6px 0 0;
}

/* ===== UTILITY ===== */
.hidden { display: none !important; }

/* ── Semantic zoom levels ───────────────────────────────────────── */
/* Applied by Cytoscape style selectors, not HTML classes */

.zoom-hint {
  position: absolute;
  bottom: 14px;
  right: 18px;
  z-index: 5;
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(6px);
  border: 1px solid var(--rule);
  border-radius: 20px;
  padding: 5px 12px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-mute);
  pointer-events: none;
  transition: opacity 0.3s ease;
}

/* ── Focus visible ──────────────────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}
button:focus-visible,
.mode-pill:focus-visible,
.tl-stop:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 3px;
  border-radius: 4px;
}
#cy:focus-visible {
  outline: 3px solid var(--teal);
  outline-offset: -3px;
}

/* ===== REDUCED MOTION ===== */
@media (prefers-reduced-motion: reduce) {
  .mode-pill,
  .tl-axis-active,
  .tl-stop .tl-marker,
  .tl-toggle .switch,
  .tl-toggle .switch::after {
    transition: none;
  }
}

/* ===== MOBILE SIDEBAR DRAWER ===== */

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.42);
  z-index: 40;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity 0.25s ease;
}
.sidebar-backdrop.active {
  opacity: 1;
}

.sidebar-toggle {
  display: none;
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 60;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--teal-dark);
  border: none;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.28);
  transition: background 0.15s ease;
}
.sidebar-toggle:hover { background: var(--teal); }
.sidebar-toggle:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 3px;
}

/* Hamburger → X icon */
.sidebar-toggle-icon,
.sidebar-toggle-icon::before,
.sidebar-toggle-icon::after {
  display: block;
  width: 18px;
  height: 2px;
  background: #fff;
  border-radius: 1px;
  transition: transform 0.22s ease, opacity 0.22s ease;
}
.sidebar-toggle-icon { position: relative; margin: auto; }
.sidebar-toggle-icon::before,
.sidebar-toggle-icon::after {
  content: '';
  position: absolute;
  left: 0;
}
.sidebar-toggle-icon::before { top: -6px; }
.sidebar-toggle-icon::after  { top:  6px; }

/* When sidebar is open: X */
.sidebar-toggle[aria-expanded="true"] .sidebar-toggle-icon { background: transparent; }
.sidebar-toggle[aria-expanded="true"] .sidebar-toggle-icon::before { transform: rotate(45deg) translate(4px, 4px); }
.sidebar-toggle[aria-expanded="true"] .sidebar-toggle-icon::after  { transform: rotate(-45deg) translate(4px, -4px); }

/* ===== RESPONSIVE LAYOUT ===== */

@media (max-width: 768px) {

  /* Single-column full-screen app */
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
  }

  /* Sidebar becomes an off-canvas drawer */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: min(85vw, 340px);
    height: 100dvh;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 4px 0 28px rgba(0, 0, 0, 0.22);
  }
  .sidebar.mobile-open {
    transform: translateX(0);
  }

  /* Backdrop visible on mobile */
  .sidebar-backdrop {
    display: block;
    pointer-events: none;
  }
  .sidebar-backdrop.active {
    pointer-events: auto;
  }

  /* Toggle button visible on mobile */
  .sidebar-toggle {
    display: flex;
  }

  /* Canvas fills full screen */
  .canvas-wrap {
    grid-column: 1;
    grid-row: 1;
  }

  /* Timeline collapses to a compact strip */
  .timeline {
    grid-column: 1;
    grid-row: 2;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
    padding: 10px 16px 12px;
    gap: 8px;
  }

  .tl-current {
    flex-direction: row;
    align-items: baseline;
    gap: 10px;
  }
  .tl-current .tl-phase { font-size: 16px; }
  .tl-current .tl-time  { margin-top: 0; }

  /* Horizontal timeline track takes full width */
  .tl-track-wrap { padding: 14px 0 18px; }

  /* Actions row inline */
  .tl-actions {
    justify-content: flex-start;
  }

  /* Disclaimer on its own row */
  .tl-disclaimer { text-align: left; }

  /* Canvas overlays: shrink and reposition to avoid toggle button */
  .zone-key {
    top: 14px;
    left: 62px;   /* clear the toggle button */
    flex-wrap: wrap;
    gap: 8px;
    max-width: calc(100vw - 80px);
    font-size: 9px;
  }

  .canvas-header {
    display: none;  /* too cramped on phone */
  }

  .zoom-hint { bottom: 10px; right: 12px; }
}

@media (max-width: 400px) {
  .sidebar { width: 92vw; }
  .zone-key { display: none; }  /* too cramped on very small phones */
}
