/* Shared styles for interactive labs — /heap-lab and /stack-lab.
   Single-viewport layout: compact hero + control bar + 3-col interactive.
   Source code + comparison live in collapsible <details> below. */

.lab-hero {
  padding: 1.75rem 0 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface-soft);
}
.lab-hero h1 {
  font-size: 1.85rem;
  letter-spacing: -0.02em;
  margin: 0.2rem 0 0.4rem;
}
.lab-hero .lede {
  font-size: 0.98rem;
  max-width: 80ch;
  margin: 0;
}

.lab-shell {
  padding: 1.25rem 0 2rem;
}

/* ── Control bar ────────────────────────────────────────────────────── */
.lab-bar {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 1px 2px rgba(15,23,42,.04);
  margin-bottom: 1rem;
  overflow: hidden;
}

.lab-bar-nav {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 1rem;
  align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}
.lab-step-info { text-align: center; min-width: 0; }
.lab-step-pos {
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.lab-step-title {
  font-size: 1.05rem;
  font-weight: 650;
  color: var(--ink);
  margin-top: 0.1rem;
}
.lab-step-text {
  font-size: 0.86rem;
  color: var(--muted);
  margin-top: 0.15rem;
  line-height: 1.4;
}

.lab-bar-actions {
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  gap: 0.9rem;
  align-items: center;
  padding: 0.7rem 1rem;
}
.lab-bar-buttons { display: flex; gap: 0.45rem; }

.lab-slider-wrap {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  min-width: 0;
  padding: 0 0.5rem;
}
.lab-slider-label {
  font-family: var(--mono);
  font-size: 0.76rem;
  color: var(--muted);
  white-space: nowrap;
}
.lab-slider-label b { color: var(--ink); font-weight: 700; }
.lab-range {
  flex: 1;
  accent-color: var(--accent);
  min-width: 80px;
}

.lab-state-inline {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--ink-soft);
}
.lab-state-inline code {
  font-family: var(--mono);
  background: var(--surface-soft);
  padding: 0.12em 0.4em;
  border-radius: 4px;
}

/* Buttons — smaller, icon-first */
.lab-btn {
  font-family: var(--sans);
  font-weight: 600;
  font-size: 0.84rem;
  padding: 0.5rem 0.9rem;
  border-radius: 7px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform .08s, background-color .15s, color .15s, border-color .15s;
  white-space: nowrap;
}
.lab-btn:active { transform: translateY(1px); }
.lab-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.lab-btn-primary { background: var(--accent); color: #fff; }
.lab-btn-primary:hover:not(:disabled) { background: var(--accent-deep); }
.lab-btn-ghost {
  background: #fff;
  border-color: var(--border);
  color: var(--ink-soft);
}
.lab-btn-ghost:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.lab-btn-nav {
  background: transparent;
  border-color: var(--border);
  color: var(--ink-soft);
  padding: 0.55rem 0.95rem;
}
.lab-btn-nav:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }

.lab-badge {
  font-family: var(--mono);
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.25rem 0.55rem;
  border-radius: 4px;
  letter-spacing: 0.08em;
}
.lab-badge-safe   { background: var(--safe-soft); color: var(--safe); }
.lab-badge-danger { background: var(--danger-soft); color: var(--danger); animation: lab-pulse 1.4s ease-in-out infinite; }
@keyframes lab-pulse { 50% { transform: scale(1.04); } }

/* Alias classes still used on /chain */
.hv-btn, .hv-btn-primary, .hv-btn-ghost {
  font-family: var(--sans);
  font-weight: 600;
  font-size: 0.88rem;
  padding: 0.55rem 1rem;
  border-radius: 7px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform .08s, background-color .15s, color .15s;
}
.hv-btn-primary { background: var(--accent); color: #fff; }
.hv-btn-primary:hover { background: var(--accent-deep); }
.hv-btn-ghost { background: #fff; border-color: var(--border); color: var(--ink-soft); }
.hv-btn-ghost:hover { border-color: var(--accent); color: var(--accent); }

/* ── Terminals (stacked vertically, full width) ─────────────────────── */
.lab-terminals {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.lab-terminals .lab-pane {
  max-height: 360px;
}

.lab-pane {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
  min-width: 0;   /* prevent grid item from expanding past 1fr */
}
.lab-pane-dark {
  background: #0b1220;
  border-color: #1e293b;
  color: #e2e8f0;
}
.lab-pane-head {
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  flex-shrink: 0;
}
.lab-pane-dark .lab-pane-head {
  border-color: #1e293b;
  color: #94a3b8;
}
.lab-pane-head code {
  font-family: var(--mono);
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.82rem;
  background: var(--surface-soft);
  padding: 0.1em 0.4em;
  border-radius: 4px;
  color: var(--ink);
  margin-left: 0.5rem;
  font-weight: 500;
}
.lab-pane-dark .lab-pane-head code {
  background: rgba(148,163,184,0.12);
  color: #fde68a;
}
.lab-pane-body {
  flex: 1;
  min-height: 0;
  overflow-x: auto;
  overflow-y: auto;
  padding: 0.85rem 0.9rem;
}
.lab-pane-body::-webkit-scrollbar { width: 8px; }
.lab-pane-body::-webkit-scrollbar-thumb { background: #334155; border-radius: 4px; }
.lab-pane:not(.lab-pane-dark) .lab-pane-body::-webkit-scrollbar-thumb { background: #cbd5e1; }

/* ── Terminal transcript ────────────────────────────────────────────── */
.lab-term-body {
  font-family: var(--mono);
  font-size: 0.78rem;
  line-height: 1.55;
  color: #d1d5db;
  white-space: pre;
}
.gdb-line { white-space: pre; }
.gdb-prompt { color: #60a5fa; font-weight: 600; }
.gdb-cmd    { color: #fde68a; font-weight: 500; }
.gdb-body   { color: #e2e8f0; }
.gdb-dim    { color: #64748b; }
.gdb-comment { color: #64748b; }
.gdb-danger { color: #f87171; font-weight: 600; }
.gdb-ok     { color: #34d399; }

/* ── gdb x/gx memory ────────────────────────────────────────────────── */
.lab-mem {
  font-family: var(--mono);
  font-size: 0.82rem;
  line-height: 1.75;
  color: #cbd5e1;
  background: transparent;
  padding: 0;
  margin: 0;
  white-space: pre;
}
.mem-row {
  display: block;
  padding: 0 0.3rem;
  border-radius: 3px;
  transition: background-color .25s;
}
.mem-row.write    { background: rgba(96, 165, 250, 0.14); }
.mem-row.overflow { background: rgba(239, 68, 68, 0.18); }
.mem-addr { color: #60a5fa; }
.mem-word { color: #e2e8f0; }
.mem-word.changed  { color: #fde68a; font-weight: 600; }
.mem-word.overflow { color: #fca5a5; font-weight: 600; }
.mem-section-label {
  color: #64748b;
  margin-left: 1.5ch;
}
.mem-section-label.is-name    { color: #6ee7b7; }
.mem-section-label.is-auth    { color: #fbbf24; }
.mem-section-label.is-service { color: #a5b4fc; }
.mem-section-label.is-meta    { color: #64748b; }

/* Legend strip under memory */
.lab-legend {
  padding: 0.5rem 1rem;
  border-top: 1px solid #1e293b;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  font-family: var(--mono);
  font-size: 0.7rem;
  color: #94a3b8;
  flex-shrink: 0;
}
.lab-legend .lg { display: inline-flex; align-items: center; gap: 0.35rem; }
.lab-legend .sw { display: inline-block; width: 11px; height: 11px; border-radius: 2px; }
.sw-meta    { background: #64748b; }
.sw-name    { background: #34d399; }
.sw-auth    { background: #fbbf24; }
.sw-service { background: #a5b4fc; }
.sw-overflow { background: #ef4444; }
.sw-ret     { background: #f472b6; }
.sw-rbp     { background: #fb923c; }
.sw-buf     { background: #34d399; }

/* ── Horizontal memory strip (under terminals) ──────────────────────── */
.lab-viz {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.2rem 1.2rem;
  margin-top: 1rem;
  box-shadow: 0 1px 2px rgba(15,23,42,.04);
}
.lab-viz-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.8rem;
}
.lab-viz-title {
  font-size: 0.82rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.lab-viz-sub {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--ink-soft);
}

.lab-strip {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface-soft);
  position: relative;
  min-height: 64px;
}
.lab-strip-region {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0.55rem 0.7rem;
  border-right: 1px dashed rgba(148,163,184,0.35);
  min-width: 0;
  overflow: hidden;
  background: #fff;
  transition: background-color .3s;
}
.lab-strip-region:last-child { border-right: 0; }
.lab-strip-region .sr-label {
  font-family: var(--mono);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  position: relative;
  z-index: 2;
}
.lab-strip-region .sr-size {
  font-family: var(--mono);
  font-size: 0.74rem;
  color: var(--muted);
  margin-top: 0.2rem;
  position: relative;
  z-index: 2;
}
.lab-strip-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  z-index: 1;
  transition: width .28s ease, background-color .28s;
}
.lab-strip-region.r-meta    .lab-strip-fill { background: rgba(100,116,139,0.30); }
.lab-strip-region.r-name    .lab-strip-fill { background: rgba(52,211,153,0.35); }
.lab-strip-region.r-auth    .lab-strip-fill { background: rgba(251,191,36,0.45); }
.lab-strip-region.r-service .lab-strip-fill { background: rgba(165,180,252,0.45); }
.lab-strip-region.r-buf     .lab-strip-fill { background: rgba(52,211,153,0.35); }
.lab-strip-region.r-rbp     .lab-strip-fill { background: rgba(251,146,60,0.45); }
.lab-strip-region.r-ret     .lab-strip-fill { background: rgba(244,114,182,0.45); }
.lab-strip-region.is-overflowed .lab-strip-fill { background: rgba(239,68,68,0.45) !important; }
.lab-strip-region.is-overflowed .sr-label { color: var(--danger); }

/* Boundary separator between chunk A and chunk B */
.lab-strip-region.boundary-start {
  border-left: 3px solid var(--danger);
}

.lab-strip-axis {
  display: flex;
  margin-top: 0.5rem;
  font-family: var(--mono);
  font-size: 0.76rem;
  color: var(--muted);
}
.lab-strip-axis-tick { padding: 0 0.3rem; border-left: 1px solid var(--border); }
.lab-strip-axis-tick:first-child { border-left: 0; }

.lab-viz-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.1rem;
  margin-top: 0.8rem;
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--ink-soft);
}
.lab-viz-legend .lg { display: inline-flex; align-items: center; gap: 0.35rem; }
.lab-viz-legend .sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; }

/* Inline info cards (replaces collapsed details) */
.lab-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-top: 1rem;
  box-shadow: 0 1px 2px rgba(15,23,42,.04);
  overflow: hidden;
}
.lab-card-head {
  padding: 0.7rem 1.2rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  background: var(--surface-soft);
}
.lab-card-head code {
  font-family: var(--mono);
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.84rem;
  color: var(--ink);
  margin-left: 0.4rem;
  font-weight: 500;
}
.lab-card-body { padding: 1rem 1.2rem 1.2rem; }
.lab-card-body pre {
  margin: 0;
  max-height: 360px;
  overflow-y: auto;
  overflow-x: hidden;
  white-space: pre-wrap;
  word-break: break-word;
}
.lab-card-body pre[class*="language-"] {
  font-size: 0.86rem !important;
  line-height: 1.6 !important;
}

.lab-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 1rem;
}
@media (max-width: 900px) { .lab-grid-2 { grid-template-columns: 1fr; } }

/* ── Heap chunk diagram (legacy — retained) ─────────────────────────── */
.lab-diagram {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.lab-chunk {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.8rem;
  background: var(--surface-soft);
}
.lab-chunk-header {
  display: flex;
  justify-content: space-between;
  font-family: var(--mono);
  font-size: 0.74rem;
  color: var(--muted);
  margin-bottom: 0.5rem;
}
.lab-chunk-name { font-weight: 600; color: var(--ink-soft); }
.lab-chunk-addr { color: var(--accent); }
.lab-chunk-fields { display: flex; flex-direction: column; gap: 0.35rem; }
.lab-field-label {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--ink-soft);
  margin-bottom: 0.15rem;
}
.lab-field-vis {
  height: 18px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 4px;
  position: relative;
  overflow: hidden;
}
.lab-field-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  background: var(--accent);
  transition: width .28s ease, background-color .28s;
}
.lab-field-name .lab-field-fill    { background: #34d399; }
.lab-field-auth .lab-field-fill    { background: #fbbf24; }
.lab-field-meta .lab-field-fill    { background: #64748b; }
.lab-field-service .lab-field-fill { background: #a5b4fc; }
.lab-field.is-overflowed .lab-field-fill { background: #ef4444; }

.lab-chunk-arrow {
  align-self: center;
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--danger);
}

/* ── Details drawer ─────────────────────────────────────────────────── */
.lab-details {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-top: 1rem;
}
.lab-details + .lab-details { margin-top: 0.75rem; }
.lab-details > summary {
  padding: 0.75rem 1.2rem;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--ink);
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.lab-details > summary::-webkit-details-marker { display: none; }
.lab-details > summary::after {
  content: "+";
  font-family: var(--mono);
  color: var(--muted);
  font-weight: 400;
  font-size: 1.1rem;
}
.lab-details[open] > summary::after { content: "−"; }
.lab-details[open] > summary { border-bottom: 1px solid var(--border); }
.lab-details > .lab-details-body {
  padding: 1rem 1.2rem 1.2rem;
}
.lab-details pre { margin: 0; max-height: 360px; overflow: auto; }

/* Compare table */
.compare-table {
  width: 100%;
  font-family: var(--mono);
  font-size: 0.84rem;
  border-collapse: collapse;
}
.compare-table th, .compare-table td {
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}
.compare-table th {
  font-family: var(--sans);
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
}
.compare-table tr:last-child td { border-bottom: 0; }
.compare-table td code {
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--ink);
}
.lab-cell-same {
  font-weight: 600;
  color: var(--accent);
  text-align: center !important;
  background: var(--accent-soft);
}
