/* ── Self-hosted fonts (IBM Plex — Apache 2.0 license) ── */
@font-face {
  font-family: 'IBM Plex Mono';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/ibm-plex-mono-400.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'IBM Plex Sans';
  font-style: normal;
  font-weight: 400 500;
  font-display: swap;
  src: url('fonts/ibm-plex-sans-400.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ── Reset ── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
:where(button, input, select, textarea) { font: inherit; color: inherit; }
:where(fieldset) { border: none; min-width: 0; }

/* ── Design tokens ── */
:root {
  /* Colors — light */
  --bg:            #eef3f8;
  --bg-glow:       rgba(37,99,235,0.07);
  --surface:       #ffffff;
  --surface-alt:   rgba(246,249,252,0.95);
  --surface-card:  rgba(255,255,255,0.92);
  --border:        rgba(90,115,145,0.18);
  --border-strong: rgba(70,95,125,0.32);
  --text:          #0f1f35;
  --text-dim:      #4e6880;
  --text-xdim:     #8aa0b4;
  --accent:        #2563eb;
  --accent-dim:    rgba(37,99,235,0.12);
  --accent-hover:  #1d54d4;
  --ok:            #047857;
  --ok-bg:         rgba(4,120,87,0.1);
  --warn:          #b45309;
  --warn-bg:       rgba(180,83,9,0.08);
  --danger:        #be123c;
  --danger-bg:     rgba(190,18,60,0.08);
  --code-bg:       #0e1a2b;
  --code-text:     #c8ddf2;

  /* Typography */
  --mono: 'IBM Plex Mono', 'Cascadia Code', 'Fira Code', 'Menlo', monospace;
  --sans: 'IBM Plex Sans', 'Inter', 'Segoe UI', 'Helvetica Neue', sans-serif;

  /* Shape */
  --r-sm:  8px;
  --r-md:  12px;
  --r-lg:  18px;
  --r-xl:  24px;
  --r-pill: 999px;
  --shadow-lg: 0 20px 56px rgba(14,25,45,0.14), 0 4px 16px rgba(14,25,45,0.06);
  --shadow-sm: 0 2px 8px rgba(14,25,45,0.08);

  /* Layout */
  --container-w: 61.8vw;
  --frame-gap: 2rem;
  --panel-pad: 1.25rem;
  --min-touch: 44px;
}

/* ── Dark mode ── */
@media (prefers-color-scheme: dark) {
  :root {
    --bg:            #0b1626;
    --bg-glow:       rgba(59,130,246,0.06);
    --surface:       #101e30;
    --surface-alt:   rgba(14,24,40,0.97);
    --surface-card:  rgba(16,28,46,0.95);
    --border:        rgba(60,100,160,0.18);
    --border-strong: rgba(60,100,160,0.3);
    --text:          #dde8f4;
    --text-dim:      #5d83a8;
    --text-xdim:     #3d5a7a;
    --accent:        #3b82f6;
    --accent-dim:    rgba(59,130,246,0.12);
    --accent-hover:  #5094f8;
    --ok:            #34d399;
    --ok-bg:         rgba(52,211,153,0.1);
    --warn:          #fbbf24;
    --warn-bg:       rgba(251,191,36,0.08);
    --danger:        #f87171;
    --danger-bg:     rgba(248,113,113,0.08);
    --code-bg:       #070e1a;
    --code-text:     #b8d4ef;
    --shadow-lg: 0 20px 56px rgba(0,0,0,0.4), 0 4px 16px rgba(0,0,0,0.2);
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.2);
  }
}

/* ── Portrait / narrow ── */
@media (orientation: portrait), (max-width: 800px) {
  :root {
    --container-w: 100%;
    --frame-gap: 0px;
    --panel-pad: 1rem;
  }
}

/* ── Base ── */
html, body {
  min-height: 100%;
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  font-family: var(--sans);
  font-size: 14px;
  color: var(--text);
  background:
    radial-gradient(ellipse 80% 40% at 50% 0%, var(--bg-glow) 0%, transparent 70%),
    var(--bg);
  line-height: 1.5;
}

a { color: var(--accent); }

code {
  font-family: var(--mono);
  font-size: 0.85em;
  background: var(--accent-dim);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}

/* ── Header ── */
.page-header {
  border-bottom: 1px solid var(--border);
  background: var(--surface-alt);
}

.header-inner {
  max-width: calc(var(--container-w) + 4rem);
  margin: 0 auto;
  padding: 1.25rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-hex {
  font-size: 2rem;
  line-height: 1;
  color: var(--accent);
  flex-shrink: 0;
}

.brand-kicker {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 2px;
}

.brand-title {
  font-size: clamp(1.3rem, 3vw, 2rem);
  font-weight: 700;
  letter-spacing: -0.04em;
  line-height: 1;
}

.brand-sub {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-top: 2px;
}

.bbx-credit-header {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  text-decoration: none;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-pill);
  padding: 6px 14px;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s;
}

.bbx-credit-header:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.bbx-credit-header strong { color: var(--accent); }

.header-links {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}

.header-link {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  padding: 5px 11px;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s;
}

.header-link:hover { color: var(--accent); border-color: var(--accent); }

.header-link[aria-current="page"] {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-dim);
}

.header-link-pricing {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-dim);
  font-weight: 700;
}

.header-link-pricing:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ── Layout ── */
.demo-root {
  display: flex;
  justify-content: center;
  padding: 1.5rem 0 3rem;
}

.demo-container {
  width: var(--container-w);
  max-width: 1600px;
  min-width: min(var(--container-w), 100%);
  display: flex;
  flex-direction: column;
  gap: 0;
}

/* ── Session bar ── */
.session-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  border-bottom: none;
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  box-shadow: var(--shadow-sm);
}

.sbar-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
}

/* ── Mode toggle ── */
.mode-toggle {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-pill);
  overflow: hidden;
  background: var(--surface-alt);
  flex-shrink: 0;
}

.mode-btn {
  min-height: var(--min-touch);
  padding: 0 14px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}

.mode-btn.active {
  background: var(--accent);
  color: #fff;
}

.mode-btn:not(.active):hover { background: var(--accent-dim); color: var(--accent); }

/* ── Field ── */
.sfield {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.sfield-label {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.sfield-input {
  min-height: var(--min-touch);
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  color: var(--text);
  font-family: var(--mono);
  font-size: 12.5px;
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
}

.sfield-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.sfield-key { flex: 1 1 220px; }
.sfield-region { flex: 0 1 140px; }

.key-hint {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-xdim);
  letter-spacing: 0.04em;
  margin-top: 2px;
}

.sfield-address {
  flex: 1 1 300px;
}

/* ── Buttons ── */
.btn {
  min-height: var(--min-touch);
  padding: 8px 16px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-pill);
  background: var(--surface);
  color: var(--text);
  font-family: var(--mono);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.1s, border-color 0.15s, background 0.15s, box-shadow 0.15s;
}

.btn:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--accent-dim);
  color: var(--accent);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.btn:active:not(:disabled) { transform: translateY(0); }

.btn:disabled {
  opacity: 0.4;
  cursor: default;
  transform: none;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #fff;
}

/* Connect CTA — shimmer while idle (not connected) */
@keyframes btn-shimmer {
  0%   { background-position: -200% center; }
  100% { background-position:  200% center; }
}
.btn-connect-cta:not(:disabled) {
  background: linear-gradient(
    110deg,
    var(--accent) 0%,
    var(--accent) 38%,
    #6baeff       48%,
    #fff          52%,
    #6baeff       56%,
    var(--accent) 66%,
    var(--accent) 100%
  );
  background-size: 200% auto;
  animation: btn-shimmer 2.6s linear infinite;
  box-shadow: 0 0 0 3px rgba(37,99,235,0.22), 0 2px 10px rgba(37,99,235,0.3);
}
.btn-connect-cta:not(:disabled):hover {
  box-shadow: 0 0 0 3px rgba(37,99,235,0.36), 0 4px 18px rgba(37,99,235,0.45);
  animation-duration: 1.4s;
}
.btn-connect-cta:disabled {
  /* connected state — back to solid accent, no shimmer */
  background: var(--accent);
  animation: none;
  box-shadow: none;
}

.icon-btn {
  min-width: var(--min-touch);
  padding: 8px 10px;
  font-size: 14px;
}

.btn-link {
  background: none;
  border: none;
  color: var(--accent);
  font-family: var(--mono);
  font-size: 11px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--r-sm);
}

.btn-link:hover { background: var(--accent-dim); }

/* Status badge */
.status-badge {
  font-family: var(--mono);
  font-size: 11px;
  padding: 6px 12px;
  border-radius: var(--r-pill);
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text-dim);
  letter-spacing: 0.06em;
  margin-left: auto;
}

.status-badge.status-connecting { background: var(--warn-bg); color: var(--warn); border-color: var(--warn); }
.status-badge.status-connected  { background: var(--ok-bg);   color: var(--ok);   border-color: var(--ok); }
.status-badge.status-error      { background: var(--danger-bg); color: var(--danger); border-color: var(--danger); }

.nav-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}

/* ── Viewport ── */
.viewport-wrap {
  background: var(--surface);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.viewport-meta {
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  min-height: 56px;
}

.vmeta-left {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.vmeta-title {
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 60ch;
}

.vmeta-url {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
  overflow-wrap: anywhere;
  line-height: 1.3;
}

.vmeta-pills {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
  align-items: flex-start;
  flex-wrap: wrap;
}

.vpill {
  font-family: var(--mono);
  font-size: 10px;
  padding: 5px 10px;
  border-radius: var(--r-pill);
  border: 1px solid var(--border);
  background: var(--accent-dim);
  color: var(--accent);
  letter-spacing: 0.04em;
  white-space: nowrap;
}

/* The viewport frame — golden ratio + device AR */
.viewport-frame {
  position: relative;
  width: 100%;
  overflow: hidden;
  background: linear-gradient(160deg, #0a1628 0%, #0e1f38 100%);

  /* Landscape: aspect-ratio from device screen */
  aspect-ratio: var(--screen-w, 16) / var(--screen-h, 9);

  /* Fallback / cap */
  max-height: 80vh;
  min-height: 280px;
}

/* Portrait / narrow: fixed 61.8% of viewport height */
@media (orientation: portrait), (max-width: 800px) {
  .viewport-frame {
    aspect-ratio: auto;
    height: 61.8vh;
    min-height: 280px;
    max-height: none;
  }
}

.viewport-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  color: rgba(180, 210, 255, 0.4);
  font-family: var(--mono);
  text-align: center;
  padding: 2rem;
}

.ph-icon {
  font-size: 3rem;
  line-height: 1;
  animation: ph-pulse 3s ease-in-out infinite;
}

@keyframes ph-pulse {
  0%, 100% { opacity: 0.3; transform: scale(1); }
  50% { opacity: 0.7; transform: scale(1.06); }
}

.ph-head {
  font-size: 15px;
  color: rgba(180, 210, 255, 0.55);
  font-weight: 600;
}

.ph-hint {
  font-size: 12px;
  color: rgba(150, 185, 240, 0.35);
  max-width: 380px;
  line-height: 1.6;
}

.ph-hint strong { color: rgba(150, 185, 240, 0.55); }

.viewport-frame hyper-frame {
  display: block;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* ── Perf HUD overlay ── */
.perf-hud {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 10;
  background: rgba(7, 14, 26, 0.82);
  border: 1px solid rgba(80, 140, 255, 0.25);
  border-radius: var(--r-md);
  padding: 8px 12px;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.7;
  color: rgba(180, 215, 255, 0.9);
  pointer-events: none;
  backdrop-filter: blur(4px);
  min-width: 130px;
}

.perf-hud[hidden] { display: none; }

.perf-hud-row {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 0 6px;
}

.perf-hud-label { color: rgba(100, 150, 220, 0.7); }
.perf-hud-value { color: rgba(200, 230, 255, 0.95); font-weight: 600; }
.perf-hud-value.ok   { color: #34d399; }
.perf-hud-value.warn { color: #fbbf24; }

.btn-hud-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  padding: 4px 8px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  white-space: nowrap;
}

.btn-hud-toggle:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }
.btn-hud-toggle.active { border-color: var(--ok); color: var(--ok); background: var(--ok-bg); }

/* ── Status rail ── */
.status-rail {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--frame-gap);
}

.srail-cell {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0.6rem 1rem;
  border-right: 1px solid var(--border);
}

.srail-cell:last-child { border-right: none; }

.srail-label {
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-xdim);
}

.srail-cell strong {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  overflow-wrap: anywhere;
}

/* ── Controls segment ── */
.controls-segment {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

@media (orientation: portrait), (max-width: 800px) {
  .controls-segment {
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-top: none;
  }

  .status-rail {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    margin-bottom: 0;
    border-left: none;
    border-right: none;
  }

  .session-bar {
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-top: none;
  }

  .viewport-wrap {
    border-left: none;
    border-right: none;
  }
}

/* ── Tab bar ── */
.tab-bar {
  display: flex;
  overflow-x: auto;
  scrollbar-width: none;
  border-bottom: 1px solid var(--border);
  background: var(--surface-alt);
  -webkit-overflow-scrolling: touch;
}

.tab-bar::-webkit-scrollbar { display: none; }

.tab-btn {
  flex-shrink: 0;
  min-height: 44px;
  padding: 0 1.1rem;
  border: none;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  white-space: nowrap;
  margin-bottom: -1px;
}

.tab-btn:hover:not(.active) {
  color: var(--text);
  background: var(--accent-dim);
}

.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background: var(--surface);
}

/* ── Tab panels ── */
.tab-panel {
  padding: var(--panel-pad);
}

.tab-panel[hidden] { display: none; }

/* ── Panel grid (Surface, Policy) ── */
.panel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
  align-items: start;
}

/* ── Control group ── */
.ctrl-group {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 0.9rem;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
}

.ctrl-group-span {
  grid-column: 1 / -1;
}

.ctrl-group-title {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-xdim);
  margin-bottom: 0.1rem;
}

.ctrl-group-hint {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0.04em;
  font-size: 9px;
  color: var(--text-xdim);
}

/* ── Individual control ── */
.ctrl {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ctrl-wide { width: 100%; }

.ctrl-label {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.ctrl-input {
  min-height: var(--min-touch);
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  color: var(--text);
  font-family: var(--mono);
  font-size: 12px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  width: 100%;
}

.ctrl-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.ctrl-textarea {
  min-height: 120px;
  resize: vertical;
  line-height: 1.5;
  font-size: 11.5px;
}

.ctrl-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.ctrl-hint {
  font-size: 11px;
  color: var(--text-xdim);
  line-height: 1.5;
  font-family: var(--mono);
}

/* ── Capture preview ── */
.capture-preview {
  margin-top: 1rem;
  padding: 1rem;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
}

.capture-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
  font-family: var(--mono);
  font-size: 11px;
}

.capture-head a {
  color: var(--accent);
  text-decoration: none;
}

.capture-head a:hover { text-decoration: underline; }

.capture-preview img {
  width: 100%;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  display: block;
}

/* ── Direct API layout ── */
.api-layout {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 1rem;
  align-items: start;
}

@media (max-width: 1100px) {
  .api-layout { grid-template-columns: 1fr; }
}

.api-methods {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* ── API group ── */
.api-group {
  padding: 0.85rem 1rem;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.api-group-title {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-xdim);
  margin-bottom: 0.15rem;
}

.api-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.api-row-btns {
  flex-wrap: wrap;
}

.api-row-tall {
  align-items: flex-start;
}

.api-input {
  flex: 1 1 160px;
  min-width: 0;
  min-height: 36px;
  padding: 6px 10px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  color: var(--text);
  font-family: var(--mono);
  font-size: 11.5px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.api-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.api-input-num {
  flex: 0 0 72px;
  min-width: 0;
}

.api-textarea {
  min-height: 60px;
  resize: vertical;
  line-height: 1.4;
  flex: 1 1 160px;
}

.api-textarea-args { min-height: 44px; }

.api-raw-inputs {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex: 1 1 160px;
  min-width: 0;
}

.api-btn {
  flex-shrink: 0;
  min-height: 36px;
  padding: 6px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s, background 0.15s, color 0.15s, transform 0.1s;
}

.api-btn:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--accent-dim);
  color: var(--accent);
  transform: translateY(-1px);
}

.api-btn:active:not(:disabled) { transform: translateY(0); }

.api-btn:disabled { opacity: 0.38; cursor: default; }

.api-btn-tall { align-self: stretch; }

/* ── API output ── */
.api-output-col {
  display: flex;
  flex-direction: column;
  gap: 0;
  position: sticky;
  top: 1rem;
}

.api-output-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 0.75rem;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--r-lg) var(--r-lg) 0 0;
}

.api-output-label {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-xdim);
}

.api-output {
  min-height: 280px;
  max-height: 60vh;
  overflow: auto;
  padding: 1rem;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 0 0 var(--r-lg) var(--r-lg);
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.6;
  color: var(--code-text);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* ── Events ── */
.events-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.events-count {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
}

.event-log {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  max-height: 420px;
  overflow: auto;
  padding-right: 0.25rem;
}

.ev-item {
  padding: 0.55rem 0.8rem;
  border-radius: var(--r-md);
  display: grid;
  grid-template-columns: 80px 1fr 1fr;
  gap: 0 0.6rem;
  align-items: start;
  border-left: 3px solid var(--accent-dim);
  background: rgba(37,99,235,0.04);
  font-family: var(--mono);
  font-size: 11px;
}

.ev-item.ev-warn {
  border-left-color: var(--warn);
  background: var(--warn-bg);
}

.ev-item.ev-error {
  border-left-color: var(--danger);
  background: var(--danger-bg);
}

.ev-time { color: var(--text-xdim); font-size: 10px; }
.ev-type { color: var(--accent); font-weight: 600; }
.ev-detail { color: var(--text-dim); white-space: pre-wrap; overflow-wrap: anywhere; }

/* ── Embed ── */
.embed-panel {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.embed-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.embed-desc {
  font-size: 12.5px;
  color: var(--text-dim);
  max-width: 60ch;
}

.embed-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.embed-snippet {
  overflow: auto;
  padding: 1.1rem;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.7;
  color: var(--code-text);
  white-space: pre;
  tab-size: 2;
}

/* ── Footer ── */
.page-footer {
  text-align: center;
  padding: 2rem 1rem 2.5rem;
  border-top: 1px solid var(--border);
  background: var(--surface-alt);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

.footer-purchase {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: center;
}

.footer-buy-btn {
  display: inline-block;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 10px 22px;
  border-radius: var(--r-pill);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  transition: transform 0.1s, border-color 0.15s, background 0.15s, color 0.15s, box-shadow 0.15s;
}

.footer-buy-btn:hover {
  border-color: var(--accent);
  background: var(--accent-dim);
  color: var(--accent);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.footer-buy-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.footer-buy-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #fff;
}

.footer-split-hint {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--text-xdim);
  letter-spacing: 0.04em;
}

.bbx-credit-footer {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
  text-decoration: none;
  letter-spacing: 0.06em;
  transition: color 0.15s;
}

.bbx-credit-footer:hover { color: var(--accent); }
.bbx-credit-footer strong { color: var(--accent); }

/* ── Utility ── */
.is-hidden { display: none !important; }

/* ── Small mobile (<520px) ── */
@media (max-width: 520px) {
  .header-inner {
    padding: 1rem;
    flex-wrap: wrap;
    align-items: flex-start;
  }

  .header-brand {
    flex: 1 1 190px;
    min-width: 0;
  }

  .header-links {
    order: 3;
    width: 100%;
  }

  .bbx-credit-header {
    padding: 5px 9px;
    font-size: 10px;
  }

  .demo-root { padding: 0; }

  .session-bar {
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-top: none;
  }

  .sbar-row {
    flex-direction: column;
    align-items: stretch;
  }

  .status-badge { margin-left: 0; }

  .mode-toggle { width: 100%; }

  .nav-actions { gap: 0.35rem; }

  .viewport-meta {
    flex-direction: column;
    align-items: stretch;
  }

  .vmeta-title {
    max-width: none;
  }

  .vmeta-pills {
    width: 100%;
  }

  .status-rail {
    grid-template-columns: repeat(2, 1fr);
  }

  .tab-panel { padding: 0.85rem; }

  .panel-grid { grid-template-columns: 1fr; }

  .api-layout { grid-template-columns: 1fr; }

  .embed-head { flex-direction: column; align-items: flex-start; }

  .ev-item { grid-template-columns: 70px 1fr; }
  .ev-detail { grid-column: 1 / -1; }
}
