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

:root {
  --bg:       #0f1117;
  --surface:  #1a1d27;
  --border:   #2a2d3a;
  --text:     #e1e4eb;
  --text-dim: #8b8fa3;
  --accent:   #FF6F5F;
  --accent-h: #FF8A7D;
  --green:    #4ade80;
  --red:      #f87171;
  --yellow:   #fbbf24;
  --radius:   8px;
  --font:     'Inter', -apple-system, sans-serif;
  --mono:     'JetBrains Mono', 'Fira Code', monospace;
}

[data-theme="light"] {
  --bg:       #f5f5f7;
  --surface:  #ffffff;
  --border:   #d4d4d8;
  --text:     #1a1a2e;
  --text-dim: #6b7280;
  --accent:   #e5544a;
  --accent-h: #d4403a;
  --green:    #16a34a;
  --red:      #dc2626;
  --yellow:   #ca8a04;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
}

/* ── Header ────────────────────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

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

.logo {
  height: 44px;
  width: 44px;
}

header h1 {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.02em;
}

.tagline {
  font-size: 0.82rem;
  color: var(--text-dim);
}

.version {
  font-size: 0.7rem;
  font-family: var(--mono);
  color: var(--text-dim);
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 2px 7px;
  border-radius: 4px;
}

nav { display: flex; gap: 4px; align-items: center; }

.theme-toggle {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 1.1rem;
  width: 34px;
  height: 34px;
  border-radius: var(--radius);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  margin-left: 8px;
}

.theme-toggle:hover { color: var(--accent); border-color: var(--accent); }

.nav-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-dim);
  font-family: var(--font);
  font-size: 0.85rem;
  font-weight: 500;
  padding: 6px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s;
}

.nav-btn:hover { color: var(--text); background: rgba(255, 111, 95, 0.08); }
.nav-btn.active { color: var(--accent); border-color: var(--border); background: var(--bg); }

/* ── Toolbar ───────────────────────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  gap: 16px;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.toolbar label {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-dim);
}

.toolbar select,
.toolbar input[type="text"] {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.82rem;
  padding: 5px 10px;
  border-radius: var(--radius);
  outline: none;
}

.toolbar select:focus,
.toolbar input:focus { border-color: var(--accent); }

#demo-select { min-width: 200px; }
#function-input { width: 140px; }
#mode-select { min-width: 180px; }
#z3-timeout { min-width: 60px; }

.new-btn {
  background: var(--bg);
  color: var(--text-dim);
  font-family: var(--font);
  font-size: 0.78rem;
  font-weight: 500;
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.new-btn:hover { color: var(--accent); border-color: var(--accent); }

.run-btn {
  background: var(--accent);
  color: #fff;
  font-family: var(--font);
  font-size: 0.85rem;
  font-weight: 600;
  border: none;
  padding: 8px 20px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}

.run-btn:hover { background: var(--accent-h); }
.run-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.run-btn.running { background: var(--red); }

/* ── Playground layout: vertical flex fills viewport ──────────── */
#page-playground {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

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

.editor-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  min-width: 0;
  min-height: 0;
}

.editor-pane:last-child { border-right: none; }

.pane-stubs { flex: 0 0 35%; }

.pane-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  flex-shrink: 0;
}

.pane-hint {
  font-weight: 400;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text-dim);
  opacity: 0.6;
}

.editor-container {
  flex: 1;
  min-height: 0;
}

/* ── Output: collapsible panel at bottom ──────────────────────── */
.output-section {
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  transition: height 0.3s ease;
  overflow: hidden;
}

/* Collapsed state: 25% of viewport height */
.output-section.collapsed {
  height: 25vh;
}

/* Expanded state: 50% of viewport height */
.output-section.expanded {
  height: 50vh;
}

.output-section .pane-header {
  cursor: pointer;
  user-select: none;
}

.output-status {
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 400;
}

.output-status.ok { color: var(--green); }
.output-status.leak { color: var(--red); }
.output-status.error { color: var(--yellow); }
.output-status.running { color: var(--accent); }

.output-text {
  padding: 14px 20px;
  font-family: var(--mono);
  font-size: 0.82rem;
  line-height: 1.6;
  background: var(--bg);
  color: var(--text);
  overflow: auto;
  flex: 1;
  min-height: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Highlight LEAK/OK/VIOLATION in output */
.output-text .hl-leak { color: var(--red); font-weight: 600; }
.output-text .hl-ok { color: var(--green); font-weight: 600; }
.output-text .hl-warn { color: var(--yellow); font-weight: 600; }
.output-text .hl-dim { color: var(--text-dim); }

/* ── Documentation pages ───────────────────────────────────────── */
.page-hidden { display: none !important; }

#page-binrevz {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.binrevz-stubs-pane {
  flex: 0 0 30%;
  display: flex;
  flex-direction: column;
  min-height: 120px;
  border-bottom: 1px solid var(--border);
}

.binrevz-stubs-pane .editor-container {
  flex: 1;
  min-height: 0;
}

.binrevz-output-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.binrevz-output-pane .output-text {
  flex: 1;
  overflow: auto;
  margin: 0;
  padding: 0.75em 1em;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

#page-tutorial, #page-docs, #page-about {
  flex: 1;
  overflow-y: auto;
}

.doc-content {
  max-width: 780px;
  margin: 0 auto;
  padding: 40px 24px;
  line-height: 1.7;
}

.doc-content h2 {
  font-size: 1.5rem;
  margin-bottom: 24px;
  color: var(--accent);
}

.doc-content h3 {
  font-size: 1.1rem;
  margin-top: 32px;
  margin-bottom: 12px;
  color: var(--text);
}

.doc-content p {
  margin-bottom: 14px;
  color: var(--text);
}

.doc-content ul, .doc-content ol {
  margin-bottom: 14px;
  padding-left: 24px;
}

.doc-content li {
  margin-bottom: 6px;
}

.doc-content code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--surface);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--accent-h);
}

.doc-content pre {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 14px;
  overflow-x: auto;
}

.doc-content pre code {
  background: transparent;
  padding: 0;
  font-size: 0.84rem;
  line-height: 1.6;
}

.doc-content table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 14px;
}

.doc-content td {
  padding: 6px 12px;
  border: 1px solid var(--border);
  font-size: 0.88rem;
}

.doc-content td:first-child {
  font-family: var(--mono);
  color: var(--accent-h);
  white-space: nowrap;
}

.doc-content strong { color: var(--text); }
.doc-content em { color: var(--text-dim); font-style: italic; }

/* ── Footer ────────────────────────────────────────────────────── */
footer {
  text-align: center;
  padding: 8px 24px;
  font-size: 0.72rem;
  color: var(--text-dim);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  line-height: 1.6;
}

footer strong { color: var(--text); font-weight: 600; }

footer a {
  color: var(--accent);
  text-decoration: none;
}

footer a:hover { text-decoration: underline; }

/* ── Responsive: tablet (≤1024px) ─────────────────────────────── */
/* Viewport-locked at ALL sizes — Monaco needs fixed-height containers.
   Body never scrolls; each panel scrolls internally. */
@media (max-width: 1024px) {
  .tagline { display: none; }
  .version { display: none; }
  header { padding: 8px 16px; }
  .toolbar { padding: 8px 16px; }
  #demo-select { min-width: 130px; }
  #mode-select { min-width: 130px; }
}

/* ── Responsive: mobile (≤768px) ─────────────────────────────── */
@media (max-width: 768px) {
  /* Header: compact single row — logo, title, nav pills, theme toggle */
  header { padding: 6px 10px; gap: 6px; }
  .header-left { gap: 6px; align-items: center; }
  .logo { height: 28px; width: 28px; }
  header h1 { font-size: 1.05rem; }
  .tagline, .version { display: none; }
  nav { gap: 2px; }
  .nav-btn { font-size: 0.7rem; padding: 4px 7px; }
  .theme-toggle { width: 28px; height: 28px; font-size: 0.9rem; margin-left: 4px; }

  /* Toolbar: two-row grid — controls on top, run button below */
  .toolbar {
    padding: 6px 10px;
    gap: 6px;
    flex-wrap: wrap;
  }
  .toolbar-left {
    gap: 6px;
    flex-wrap: wrap;
    width: 100%;
  }
  .toolbar label { font-size: 0.72rem; }
  .toolbar select, .toolbar input[type="text"] {
    font-size: 0.78rem;
    padding: 4px 6px;
  }
  #demo-select { min-width: 0; flex: 1 1 120px; }
  #function-input { width: 0; flex: 1 1 80px; }
  #mode-select { min-width: 0; flex: 1 1 100px; }
  #z3-timeout { min-width: 0; flex: 0 1 50px; }
  .new-btn { padding: 4px 8px; font-size: 0.72rem; }
  .toolbar-right { width: 100%; }
  .run-btn { width: 100%; padding: 8px; font-size: 0.85rem; }

  /* Editors: stack vertically, share the flex space.
     Key: use flex ratios, NOT fixed vh heights.
     The playground is flex:1 filling whatever space header/toolbar/output leave. */
  .editors { flex-direction: column; }
  .editor-pane {
    flex: 3;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .editor-pane:last-child { border-bottom: none; }
  .pane-stubs { flex: 2; }

  /* Output: smaller collapsed height on mobile */
  .output-section.collapsed { height: 20vh; }
  .output-section.expanded { height: 40vh; }

  /* Doc pages */
  .doc-content { padding: 20px 12px; }
  .doc-content h2 { font-size: 1.2rem; }
  .doc-content pre { padding: 8px 10px; font-size: 0.76rem; }

  /* Footer */
  footer { padding: 6px 10px; font-size: 0.65rem; }
}

/* ── Responsive: small phone (≤480px) ────────────────────────── */
@media (max-width: 480px) {
  /* Header: logo + title only, nav wraps to second line */
  header { flex-wrap: wrap; }
  nav { width: 100%; justify-content: space-between; }
  .nav-btn { font-size: 0.65rem; padding: 3px 5px; flex: 1; text-align: center; }

  /* Hide less-critical toolbar labels */
  .toolbar label { display: none; }

  .pane-header { padding: 4px 8px; font-size: 0.68rem; }
  .output-text { padding: 8px 10px; font-size: 0.72rem; }
}

/* ── Responsive: mobile landscape (short + wide) ─────────────── */
/* Phones rotated sideways: plenty of width, very little height.
   Keep editors side-by-side (desktop-like), crush chrome vertically. */
@media (max-height: 500px) and (orientation: landscape) {
  /* Ultra-compact header: single tight row */
  header { padding: 3px 10px; }
  .logo { height: 22px; width: 22px; }
  header h1 { font-size: 0.9rem; }
  .tagline, .version { display: none; }
  .nav-btn { font-size: 0.68rem; padding: 2px 6px; }
  .theme-toggle { width: 24px; height: 24px; font-size: 0.8rem; }

  /* Ultra-compact toolbar: everything on one line */
  .toolbar { padding: 3px 10px; gap: 6px; }
  .toolbar label { font-size: 0.68rem; }
  .toolbar select, .toolbar input[type="text"] {
    font-size: 0.75rem;
    padding: 2px 5px;
  }
  .run-btn { padding: 3px 14px; font-size: 0.78rem; }
  .new-btn { padding: 2px 6px; font-size: 0.68rem; }

  /* Editors: side-by-side (override mobile vertical stacking) */
  .editors { flex-direction: row; }
  .editor-pane {
    flex: 1;
    border-right: 1px solid var(--border);
    border-bottom: none;
  }
  .editor-pane:last-child { border-right: none; }
  .pane-stubs { flex: 0 0 35%; }

  /* Minimal pane headers */
  .pane-header { padding: 2px 8px; font-size: 0.65rem; }

  /* Output: tiny collapsed, modest expanded */
  .output-section.collapsed { height: 15vh; }
  .output-section.expanded { height: 40vh; }
  .output-text { padding: 4px 8px; font-size: 0.72rem; line-height: 1.4; }

  /* Hide footer in landscape — every pixel counts */
  footer { display: none; }
}
