/* ============================================================
   Frankenroom — design system: "the laboratory at night"
   Surfaces: charcoal #121417, panels #1a1d21, raised #22262b
   Ink: bone #e8e2d4, muted #9a968c
   Accents: green #8fbf8a, amber #d6a14a, blood #c0574b
   ============================================================ */

/* ---- Reset & base ----------------------------------------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #121417;
  --panel:       #1a1d21;
  --raised:      #22262b;
  --border:      #2e3238;
  --ink:         #e8e2d4;
  --muted:       #9a968c;
  --green:       #8fbf8a;
  --amber:       #d6a14a;
  --blood:       #c0574b;
  --focus:       #d6a14a;
  --radius:      4px;
  --font-mono:   ui-monospace, 'Cascadia Code', 'Fira Mono', monospace;
  --font-ui:     system-ui, -apple-system, 'Segoe UI', sans-serif;
  --lamp-glow:   radial-gradient(ellipse 60% 18% at 50% 0%, rgba(214,161,74,.13) 0%, transparent 100%);
}

html { font-size: 15px; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  line-height: 1.5;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Faint lamp glow at top of page */
body::before {
  content: '';
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 180px;
  background: var(--lamp-glow);
  pointer-events: none;
  z-index: 0;
}

/* ---- Accessibility helpers --------------------------------- */
.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;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* ---- LIGHTNING FLASH --------------------------------------- */
#lightning {
  position: fixed;
  inset: 0;
  z-index: 1000;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding-top: 56px;
  opacity: 0;
  transition: opacity 0.08s ease-in;
}

#lightning.active {
  opacity: 1;
}

.lightning-bolt {
  width: 100%;
  height: 3px;
  background: linear-gradient(90deg, transparent 0%, var(--green) 20%, #fff 50%, var(--green) 80%, transparent 100%);
  box-shadow: 0 0 18px 4px var(--green), 0 0 40px 8px rgba(143,191,138,.4);
  transform: scaleX(0);
  transform-origin: left center;
}

#lightning.active .lightning-bolt {
  animation: bolt-sweep 0.35s cubic-bezier(.2,.8,.4,1) forwards;
}

.lightning-text {
  margin-top: 10px;
  font-family: var(--font-ui);
  font-size: 1.1rem;
  font-style: italic;
  color: var(--green);
  text-shadow: 0 0 12px var(--green);
  letter-spacing: 0.04em;
  opacity: 0;
}

#lightning.active .lightning-text {
  animation: text-appear 0.4s ease-out 0.25s forwards;
}

@keyframes bolt-sweep {
  from { transform: scaleX(0); opacity: 1; }
  80%  { transform: scaleX(1); opacity: 1; }
  to   { transform: scaleX(1); opacity: 0; }
}

@keyframes text-appear {
  from { opacity: 0; transform: translateY(-4px); }
  40%  { opacity: 1; transform: translateY(0); }
  80%  { opacity: 1; }
  to   { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  #lightning.active .lightning-bolt,
  #lightning.active .lightning-text {
    animation: none;
    opacity: 0;
  }
  /* Still show brief flash via opacity for reduced-motion users */
  #lightning.active {
    opacity: 0.6;
    transition: opacity 0s;
  }
}

/* ---- HEADER ----------------------------------------------- */
#header {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 14px 20px 12px;
  border-bottom: 1px dashed var(--border);
  background: var(--panel);
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: baseline;
  gap: 16px;
  flex-wrap: wrap;
}

.wordmark {
  display: flex;
  align-items: center;
  gap: 8px;
}

.bolt-mark { flex-shrink: 0; }

h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.tagline {
  font-size: 0.82rem;
  color: var(--muted);
  font-style: italic;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.aurmada-brand {
  font-size: 0.75rem;
  color: var(--muted);
  letter-spacing: 0.02em;
}

/* Pulse dot */
.pulse-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.pulse-idle    { background: var(--muted); }
.pulse-ok      { background: var(--green); box-shadow: 0 0 6px var(--green); animation: pulse-beat 2s ease-in-out infinite; }
.pulse-warn    { background: var(--amber); box-shadow: 0 0 6px var(--amber); }
.pulse-error   { background: var(--blood); box-shadow: 0 0 6px var(--blood); }

@keyframes pulse-beat {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

@media (prefers-reduced-motion: reduce) {
  .pulse-ok { animation: none; }
}

/* ---- MAIN LAYOUT ------------------------------------------ */
#main-layout {
  display: grid;
  grid-template-columns: 280px 1fr 300px;
  grid-template-rows: 1fr;
  gap: 0;
  flex: 1;
  min-height: 0;      /* allow shrink below content size */
  overflow: hidden;
  position: relative;
  z-index: 1;
}

/* Suture dividers between columns */
#stitches-panel {
  border-right: 1px dashed var(--border);
}
#right-panel {
  border-left: 1px dashed var(--border);
}

/* ---- SHARED PANEL STYLES ---------------------------------- */
#stitches-panel {
  overflow-y: auto;
  padding: 16px;
}

#right-panel {
  overflow-y: auto;
  padding: 16px;
}

/* Center column is a flex column: timeline grows, composer is pinned at bottom */
#room-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  padding: 16px 16px 0;
}

.panel-title {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-subtitle {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 14px;
  line-height: 1.4;
}

/* ---- STITCH CARDS ----------------------------------------- */
.stitch-card {
  display: flex;
  background: var(--raised);
  border-radius: var(--radius);
  border: 1px dashed var(--border);
  margin-bottom: 10px;
  overflow: hidden;
  transition: border-color 0.15s;
}

.stitch-card:hover { border-color: var(--muted); }

/* Coloured source tabs */
.stitch-tab {
  width: 4px;
  flex-shrink: 0;
}

.stitch-human  { background: var(--green); }
.stitch-mcp    { background: var(--amber); }
.stitch-a2a    { background: #7ab3c8; }   /* teal-ish, no purple/neon */
.stitch-ticket { background: var(--blood); }
.stitch-sensor { background: #b8a86a; }   /* warm tan */
.stitch-warden { background: var(--green); }  /* galvanic green — alive */
.stitch-system { background: var(--muted); }

.stitch-body {
  padding: 10px 12px;
  flex: 1;
  min-width: 0;
}

.stitch-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 3px;
}

.stitch-name {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink);
}

.stitch-count {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  background: var(--bg);
  color: var(--muted);
  border-radius: 10px;
  padding: 1px 7px;
  min-width: 26px;
  text-align: center;
  flex-shrink: 0;
}

.stitch-count.has-events {
  color: var(--green);
  background: rgba(143,191,138,.12);
}

.stitch-proto {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--muted);
  margin-bottom: 4px;
}

.stitch-desc {
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.4;
}

.stitch-desc code, .stitch-proto code {
  font-family: var(--font-mono);
  font-size: 0.75em;
  color: var(--amber);
}

.stitch-endpoint {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.endpoint-path {
  font-family: var(--font-mono);
  font-size: 0.69rem;
  color: var(--amber);
  word-break: break-all;
  flex: 1;
  min-width: 0;
}

/* Copy / Try buttons */
.btn-copy {
  font-size: 0.69rem;
  padding: 2px 8px;
  background: transparent;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  cursor: pointer;
  font-family: var(--font-mono);
  flex-shrink: 0;
  transition: border-color 0.1s, color 0.1s;
}

.btn-copy:hover, .btn-copy:focus-visible {
  border-color: var(--amber);
  color: var(--amber);
}

.btn-copy.copied {
  border-color: var(--green);
  color: var(--green);
}

.try-details {
  margin-top: 8px;
  border-top: 1px dashed var(--border);
  padding-top: 8px;
}

.try-summary {
  font-size: 0.75rem;
  color: var(--muted);
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 4px;
  outline: none;
}
.try-summary::-webkit-details-marker { display: none; }
.try-summary::before { content: '▸'; font-size: 0.65rem; transition: transform 0.15s; }
details[open] .try-summary::before { transform: rotate(90deg); }
.try-summary:focus-visible { outline: 2px solid var(--focus); border-radius: 2px; }
.try-summary:hover { color: var(--ink); }

.try-payload {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--muted);
  background: var(--bg);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 8px;
  overflow-x: auto;
  white-space: pre;
  margin: 8px 0 6px;
  max-height: 160px;
}

.btn-try {
  font-size: 0.75rem;
  padding: 4px 12px;
  background: transparent;
  border: 1px solid var(--muted);
  border-radius: var(--radius);
  color: var(--ink);
  cursor: pointer;
  font-family: var(--font-ui);
  transition: background 0.1s, border-color 0.1s;
}

.btn-try:hover, .btn-try:focus-visible {
  background: var(--raised);
  border-color: var(--amber);
  color: var(--amber);
}

.try-result {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  margin-top: 6px;
  padding: 6px 8px;
  border-radius: var(--radius);
  display: none;
  word-break: break-all;
}

.try-result.ok   { display: block; color: var(--green); background: rgba(143,191,138,.08); border: 1px dashed var(--green); }
.try-result.fail { display: block; color: var(--blood); background: rgba(192,87,75,.08);   border: 1px dashed var(--blood); }

/* ---- TIMELINE --------------------------------------------- */
#room-panel .panel-title { flex-shrink: 0; }

#timeline {
  flex: 1;
  overflow-y: auto;
  min-height: 0;      /* must shrink inside flex parent */
  margin-bottom: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-bottom: 8px;
}

.timeline-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.6;
  padding: 32px;
}

/* Event rows */
.event-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius);
  position: relative;
}

.event-row:hover { background: rgba(255,255,255,.025); }

/* Suture line between events */
.event-row + .event-row::before {
  content: '';
  position: absolute;
  left: 11px; top: -1px;
  width: 1px; height: 3px;
  border-left: 1px dashed var(--border);
}

.event-tab {
  width: 3px;
  min-height: 100%;
  border-radius: 2px;
  flex-shrink: 0;
  align-self: stretch;
  min-height: 18px;
}

.event-tab.src-human  { background: var(--green); }
.event-tab.src-mcp    { background: var(--amber); }
.event-tab.src-a2a    { background: #7ab3c8; }
.event-tab.src-ticket { background: var(--blood); }
.event-tab.src-sensor { background: #b8a86a; }
.event-tab.src-warden { background: var(--green); }  /* galvanic green */
.event-tab.src-system { background: var(--muted); }

.event-content { flex: 1; min-width: 0; }

.event-meta {
  display: flex;
  align-items: baseline;
  gap: 7px;
  margin-bottom: 1px;
  flex-wrap: wrap;
}

.event-actor {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 160px;
}

.event-time {
  font-size: 0.68rem;
  color: var(--muted);
  flex-shrink: 0;
  font-family: var(--font-mono);
}

.event-body {
  font-size: 0.82rem;
  color: var(--ink);
  word-break: break-word;
  line-height: 1.4;
}

/* Chip for ticket/signal/action key data */
.event-chip {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  padding: 1px 7px;
  border-radius: 10px;
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.chip-ticket { background: rgba(192,87,75,.15);  color: var(--blood); border: 1px solid rgba(192,87,75,.3); }
.chip-signal { background: rgba(184,168,106,.12); color: #c8b878; border: 1px solid rgba(184,168,106,.3); }
.chip-action { background: rgba(143,191,138,.12); color: var(--green); border: 1px solid rgba(143,191,138,.3); }
.chip-warden { background: rgba(143,191,138,.12); color: var(--green); border: 1px solid rgba(143,191,138,.3); }

/* Anomaly rows */
.event-row.anomaly-warn .event-body { color: var(--amber); }
.event-row.anomaly-crit .event-body { color: var(--blood); }

/* Grouped sensor row */
.event-row.sensor-group {
  background: rgba(255,255,255,.015);
  border: 1px dashed var(--border);
}

.sensor-group-data {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: #c8b878;
  margin-top: 2px;
  flex-wrap: wrap;
  display: flex;
  gap: 10px;
}

.sensor-datum { white-space: nowrap; }
.sensor-datum.door-open { color: var(--amber); }
.sensor-datum.temp-warn { color: var(--amber); }
.sensor-datum.temp-crit { color: var(--blood); }

/* ---- COMPOSER --------------------------------------------- */
#composer {
  flex-shrink: 0;
  border-top: 1px dashed var(--border);
  padding: 12px 0 14px;
  background: var(--bg);
}

.composer-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.composer-row input[type="text"] {
  background: var(--raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--ink);
  padding: 7px 10px;
  font-family: var(--font-ui);
  font-size: 0.85rem;
  transition: border-color 0.15s;
}

.composer-row input[type="text"]:focus {
  outline: none;
  border-color: var(--amber);
  box-shadow: 0 0 0 2px rgba(214,161,74,.2);
}

#composer-name { width: 110px; flex-shrink: 0; }
#composer-body { flex: 1; min-width: 0; }

.btn-primary {
  background: var(--green);
  color: #0e1210;
  border: none;
  border-radius: var(--radius);
  padding: 7px 18px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, box-shadow 0.15s;
}

.btn-primary:hover, .btn-primary:focus-visible {
  background: #a0d49a;
  box-shadow: 0 0 10px rgba(143,191,138,.35);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.composer-hint {
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 5px;
}

.composer-hint code {
  font-family: var(--font-mono);
  color: var(--amber);
}

/* ---- ROOM BADGE ------------------------------------------- */
.room-badge {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  background: var(--bg);
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 1px 8px;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
}

/* ---- DEVICE CARD ------------------------------------------ */
#device-card {
  background: var(--raised);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
}

.device-temp-row {
  display: flex;
  align-items: baseline;
  gap: 4px;
  margin-bottom: 8px;
}

.device-temp {
  font-size: 2.4rem;
  font-family: var(--font-mono);
  font-weight: 300;
  color: var(--ink);
  line-height: 1;
}

.device-temp.temp-warn { color: var(--amber); }
.device-temp.temp-crit { color: var(--blood); }

.device-temp-unit {
  font-size: 1rem;
  color: var(--muted);
  align-self: flex-start;
  margin-top: 6px;
}

.device-setpoint {
  font-size: 0.72rem;
  font-family: var(--font-mono);
  color: var(--muted);
  margin-left: 6px;
}

#sparkline {
  display: block;
  width: 100%;
  height: 60px;
  background: var(--bg);
  border-radius: var(--radius);
  border: 1px dashed var(--border);
  margin-bottom: 10px;
}

.device-stats {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.device-stat {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
}

.stat-label {
  color: var(--muted);
  min-width: 80px;
  flex-shrink: 0;
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--ink);
}

.stat-fault {
  color: var(--blood);
  font-weight: 600;
}

.load-bar-track {
  flex: 1;
  height: 6px;
  background: var(--bg);
  border-radius: 3px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.load-bar-fill {
  height: 100%;
  background: var(--green);
  border-radius: 3px;
  width: 0%;
  transition: width 0.4s ease, background 0.3s;
}

.load-bar-fill.load-warn { background: var(--amber); }
.load-bar-fill.load-crit { background: var(--blood); }

.fault-buttons {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.btn-fault {
  font-size: 0.72rem;
  padding: 4px 10px;
  background: transparent;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  cursor: pointer;
  font-family: var(--font-ui);
  transition: border-color 0.15s, color 0.15s;
}

.btn-fault:hover, .btn-fault:focus-visible {
  border-color: var(--amber);
  color: var(--amber);
}

.btn-fault-crit:hover, .btn-fault-crit:focus-visible {
  border-color: var(--blood);
  color: var(--blood);
}

.btn-fault-clear:hover, .btn-fault-clear:focus-visible {
  border-color: var(--green);
  color: var(--green);
}

/* ---- PROPOSALS -------------------------------------------- */
#proposals-section {
  background: var(--raised);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

.proposals-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 700;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 10px;
  background: var(--amber);
  color: #0e0c08;
  text-transform: none;
  letter-spacing: 0;
}

.proposals-empty {
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
  padding: 16px 0 8px;
}

.proposal-card {
  background: var(--bg);
  border: 1px dashed var(--amber);
  border-radius: var(--radius);
  padding: 11px 12px;
  margin-bottom: 10px;
  animation: proposal-appear 0.25s ease-out;
}

@keyframes proposal-appear {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.proposal-by {
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.proposal-by-badge {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  padding: 1px 6px;
  border-radius: 8px;
  background: rgba(214,161,74,.15);
  color: var(--amber);
  border: 1px solid rgba(214,161,74,.3);
}

.proposal-action {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 4px;
}

.proposal-rationale {
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.4;
  margin-bottom: 10px;
}

.proposal-buttons {
  display: flex;
  gap: 8px;
}

.btn-approve {
  flex: 1;
  padding: 6px 12px;
  background: rgba(143,191,138,.15);
  border: 1px solid var(--green);
  border-radius: var(--radius);
  color: var(--green);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-approve:hover, .btn-approve:focus-visible {
  background: rgba(143,191,138,.3);
}

.btn-deny {
  flex: 1;
  padding: 6px 12px;
  background: rgba(192,87,75,.12);
  border: 1px solid var(--blood);
  border-radius: var(--radius);
  color: var(--blood);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-deny:hover, .btn-deny:focus-visible {
  background: rgba(192,87,75,.25);
}

.btn-approve:disabled, .btn-deny:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.proposal-decided {
  font-size: 0.75rem;
  font-family: var(--font-mono);
  padding: 3px 0;
  text-align: center;
}

.proposal-decided.approved { color: var(--green); }
.proposal-decided.denied   { color: var(--blood); }

/* ---- FOOTER ----------------------------------------------- */
footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  padding: 10px 20px;
  border-top: 1px dashed var(--border);
  font-size: 0.72rem;
  color: var(--muted);
  flex-shrink: 0;
  flex-wrap: wrap;
}

footer a {
  color: var(--muted);
  text-decoration: none;
  transition: color 0.1s;
}

footer a:hover, footer a:focus-visible {
  color: var(--ink);
}

.footer-sep {
  margin: 0 8px;
  opacity: 0.4;
}

/* ---- RESPONSIVE ------------------------------------------- */
@media (max-width: 1024px) {
  #main-layout {
    grid-template-columns: 240px 1fr 260px;
  }
}

@media (max-width: 800px) {
  .header-left { flex-direction: column; gap: 2px; }
  .tagline { display: none; }
}

@media (max-width: 480px) {
  #header { flex-direction: column; align-items: flex-start; }
  .header-right { align-self: flex-end; }
  .composer-row { flex-wrap: wrap; }
  #composer-name { width: 100%; }
}

/* 800 px and below: single-column stacked layout.
   The first screen is header + timeline + composer (composer pinned at the
   viewport bottom); stitches and the device panel stack below. */
@media (max-width: 800px) {
  body { overflow: auto; }

  #main-layout {
    display: flex;
    flex-direction: column;
    overflow: visible;
  }
  #main-layout > * { flex-shrink: 0; }
  #right-panel { overflow: visible; max-height: none; height: auto; }

  #room-panel {
    /* Header is ~60 px; the room fills the rest of the first screen so the
       composer lands exactly at the viewport bottom. */
    height: calc(78dvh - 62px);
    min-height: 420px;
    display: flex;
    flex-direction: column;
  }
  #room-panel #timeline { flex: 1 1 auto; min-height: 0; overflow-y: auto; }

  #stitches-panel {
    border-right: none;
    border-bottom: 1px dashed var(--border);
    max-height: none;
    overflow-y: visible;
  }

  #right-panel {
    border-left: none;
    border-top: 1px dashed var(--border);
  }

  /* Composer always visible at the bottom on narrow screens */
  #composer {
    position: static;
    flex-shrink: 0;
    background: var(--bg);
    z-index: 20;
    padding-bottom: max(14px, env(safe-area-inset-bottom));
    border-top: 1px dashed var(--border);
  }
}

/* 490 px and below (390 px phones): room timeline first, then device and
   proposals, then the stitches reference; composer at the bottom of the room card;
   the freezer card peeks below the first screen. */
@media (max-width: 490px) {
  #room-panel     { order: 1; }
  #right-panel    { order: 2; }
  #stitches-panel { order: 3; }

  #header { flex-direction: column; align-items: flex-start; }
  .header-right { align-self: flex-end; }

  .composer-row { flex-wrap: wrap; }
  #composer-name { width: 100%; }

  .header-left { gap: 4px; }
}

/* ---- DEVICE TIME SCALE ------------------------------------ */
.device-time-scale {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--muted);
  letter-spacing: 0.03em;
  margin-left: 4px;
  opacity: 0.85;
}

/* ---- JUMP TO LATEST --------------------------------------- */
.jump-to-latest {
  position: sticky;
  bottom: 8px;
  align-self: center;
  display: block;
  margin: 4px auto 0;
  padding: 5px 16px;
  background: var(--raised);
  color: var(--amber);
  border: 1px dashed var(--amber);
  border-radius: 999px;
  font-size: 0.75rem;
  font-family: var(--font-ui);
  cursor: pointer;
  opacity: 0.9;
  transition: opacity 0.15s, background 0.15s;
  z-index: 5;
  flex-shrink: 0;
}

.jump-to-latest:hover, .jump-to-latest:focus-visible {
  background: rgba(214,161,74,.12);
  opacity: 1;
}

.jump-to-latest[hidden] { display: none; }
.device-stat[hidden] { display: none; }
