/* Zebbingo Experiment — shared demo shell.
 * Dark first, light via prefers-color-scheme. System fonts only, no assets. */

:root {
  color-scheme: dark;
  --bg: #0e1013;
  --panel: #161a20;
  --panel-2: #1c2129;
  --border: #262c36;
  --border-strong: #363e4b;
  --text: #e7eaef;
  --text-dim: #9aa3b1;
  --text-faint: #6d7684;
  --accent: #7aa2f7;
  --accent-dim: #232d40;
  --live: #3fb950;
  --draft: #d29922;
  --archived: #8b949e;
  --code-bg: #0b0e12;
  --frame-bg: #ffffff;
  --radius: 8px;
  --sidebar-w: 268px;
  --drawer-w: 380px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial,
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #f6f7f9;
    --panel: #ffffff;
    --panel-2: #eef1f5;
    --border: #e1e5ea;
    --border-strong: #c8cfd8;
    --text: #1b1f26;
    --text-dim: #576070;
    --text-faint: #858d9b;
    --accent: #2f5fd0;
    --accent-dim: #e3ebfb;
    --live: #1a7f37;
    --draft: #96690a;
    --archived: #6e7781;
    --code-bg: #f2f4f7;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

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

code, pre, .mono { font-family: var(--mono); font-size: 13px; }

/* ── topbar ─────────────────────────────────────────────────────────────── */

.topbar {
  flex: 0 0 auto;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.topbar-inner {
  padding: 11px 18px;
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
}

.brand {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}

.brand:hover { color: var(--accent); text-decoration: none; }

.brand-note { color: var(--text-faint); font-size: 12.5px; }

/* ── layout: sidebar | stage | (drawer) ─────────────────────────────────── */

.layout {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
}

.layout.is-drawer-open {
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--drawer-w);
}

/* ── sidebar ────────────────────────────────────────────────────────────── */

.sidebar {
  min-height: 0;
  overflow-y: auto;
  border-right: 1px solid var(--border);
  background: var(--panel);
}

.sidebar-search {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 10px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.search {
  width: 100%;
  padding: 7px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 13.5px;
}

.search::placeholder { color: var(--text-faint); }
.search:focus { outline: none; border-color: var(--accent); }

.nav-list { padding: 6px; }

.nav-group {
  padding: 12px 8px 5px;
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
}

.nav-item {
  display: block;
  padding: 7px 9px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  color: var(--text);
}

.nav-item:hover { background: var(--panel-2); text-decoration: none; }
.nav-item.is-active { background: var(--accent-dim); border-color: var(--accent); }
.nav-item.is-nodemo .nav-title { color: var(--text-dim); font-weight: 400; }

.nav-item-top { display: flex; align-items: center; gap: 8px; }

.nav-title {
  font-size: 13.5px;
  font-weight: 500;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.nav-sub {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 2px;
  padding-left: 16px;
  color: var(--text-faint);
  font-size: 11.5px;
}

.nav-tag {
  padding: 0 6px;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 10.5px;
  letter-spacing: 0.03em;
}

.nav-empty { padding: 14px 10px; color: var(--text-faint); font-size: 13px; }

/* ── status dots ────────────────────────────────────────────────────────── */

.dot {
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-faint);
}

.dot-live { background: var(--live); }
.dot-draft { background: var(--draft); }
.dot-archived { background: var(--archived); }

/* ── stage ──────────────────────────────────────────────────────────────── */

.stage {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.stage-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.stage-bar-main { display: flex; align-items: center; gap: 10px; min-width: 0; }

.stage-title {
  font-size: 14.5px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.stage-bar-actions { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }

.stage-body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  overflow: auto;
}

.demo-frame {
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  border: 0;
  background: var(--frame-bg);
}

/* ── notices (empty / error / blocked / server down) ────────────────────── */

.notice {
  margin: 22px;
  padding: 20px 22px;
  max-width: 74ch;
  align-self: flex-start;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--panel);
}

.notice-title { margin: 0 0 8px; font-size: 17px; font-weight: 600; letter-spacing: -0.01em; }
.notice-text { margin: 0 0 12px; color: var(--text-dim); font-size: 14px; max-width: 70ch; }
.notice-hint { margin: 12px 0 0; color: var(--text-faint); font-size: 12.5px; max-width: 70ch; }

.notice-label {
  margin: 14px 0 6px;
  color: var(--text-faint);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.notice > .btn { margin-top: 14px; }
.notice > .btn + .btn { margin-left: 8px; }

/* ── buttons, chips, badges ─────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--panel-2);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  line-height: 1.4;
  cursor: pointer;
}

.btn:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.btn.copied { border-color: var(--live); color: var(--live); }
.btn.is-on { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }

.chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text-dim);
  font-family: inherit;
  font-size: 12px;
  line-height: 1.5;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid transparent;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.badge-live { color: var(--live); background: rgba(63, 185, 80, 0.14); border-color: rgba(63, 185, 80, 0.34); }
.badge-draft { color: var(--draft); background: rgba(210, 153, 34, 0.14); border-color: rgba(210, 153, 34, 0.34); }
.badge-archived { color: var(--archived); background: rgba(139, 148, 158, 0.14); border-color: rgba(139, 148, 158, 0.34); }
.badge-unknown { color: var(--text-dim); background: var(--panel-2); border-color: var(--border); }

@media (prefers-color-scheme: light) {
  .badge-live { background: rgba(26, 127, 55, 0.10); border-color: rgba(26, 127, 55, 0.30); }
  .badge-draft { background: rgba(150, 105, 10, 0.10); border-color: rgba(150, 105, 10, 0.30); }
  .badge-archived { background: rgba(110, 119, 129, 0.10); border-color: rgba(110, 119, 129, 0.30); }
}

/* ── code blocks ────────────────────────────────────────────────────────── */

pre.run,
.md-code {
  margin: 0;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--code-bg);
  color: var(--text);
  overflow-x: auto;
}

.run-row { display: flex; align-items: flex-start; gap: 8px; flex-wrap: wrap; }
.run-row pre.run { flex: 1 1 260px; min-width: 0; }
.copy-btn { flex: 0 0 auto; }

/* ── details drawer ─────────────────────────────────────────────────────── */

.drawer {
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--border);
  background: var(--panel);
}

.drawer-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
}

.drawer-title {
  margin: 0;
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
}

.drawer-close {
  border: 0;
  background: none;
  padding: 0 4px;
  color: var(--text-dim);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.drawer-close:hover { color: var(--text); }

.drawer-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 14px; }

.drawer-meta { display: flex; flex-wrap: wrap; gap: 5px 14px; margin-bottom: 10px; }
.drawer-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 4px; }

.drawer-label {
  margin: 18px 0 7px;
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
}

.drawer-summary { margin: 0; color: var(--text-dim); font-size: 13.5px; }

.drawer-source {
  margin-top: 20px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.meta-item { display: inline-flex; align-items: baseline; gap: 6px; font-size: 12.5px; }
.meta-label { color: var(--text-faint); text-transform: uppercase; font-size: 10.5px; letter-spacing: 0.06em; }
.meta-value { color: var(--text); }

.link-list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 7px; }
.link-list li { display: flex; flex-wrap: wrap; align-items: baseline; gap: 9px; font-size: 13.5px; }
.link-url { color: var(--text-faint); font-size: 12px; word-break: break-all; }
.link-broken { color: var(--draft); font-size: 13px; word-break: break-all; }
.artifact-link { font-family: var(--mono); font-size: 12.5px; word-break: break-all; }

.muted { color: var(--text-dim); }
.small { font-size: 12.5px; }

/* ── rendered Markdown ──────────────────────────────────────────────────── */

.markdown { max-width: 78ch; }

.markdown > *:first-child { margin-top: 0; }
.markdown > *:last-child { margin-bottom: 0; }

.markdown h1,
.markdown h2,
.markdown h3,
.markdown h4,
.markdown h5,
.markdown h6 {
  margin: 20px 0 9px;
  line-height: 1.3;
  letter-spacing: -0.01em;
}

.markdown h1 { font-size: 20px; }
.markdown h2 { font-size: 17px; }
.markdown h3 { font-size: 15.5px; }
.markdown h4, .markdown h5, .markdown h6 { font-size: 14px; }

.markdown p { margin: 0 0 11px; }

.markdown ul,
.markdown ol { margin: 0 0 11px; padding-left: 22px; }
.markdown li { margin: 3px 0; }

.markdown code {
  padding: 1px 5px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--code-bg);
}

.markdown pre.md-code code { padding: 0; border: 0; background: none; }
.markdown strong { font-weight: 650; }

/* ── responsive ─────────────────────────────────────────────────────────── */

@media (max-width: 900px) {
  .layout,
  .layout.is-drawer-open { grid-template-columns: 220px minmax(0, 1fr); }

  /* Too narrow for three columns: the drawer overlays the stage instead of
   * squeezing it, so the demo keeps a usable width. */
  .drawer {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(var(--drawer-w), 84vw);
    border-left-color: var(--border-strong);
  }
}

@media (max-width: 620px) {
  .layout,
  .layout.is-drawer-open { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }

  .sidebar {
    max-height: 34vh;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .notice { margin: 14px; padding: 16px 16px; }
  .stage-bar { padding: 8px 12px; }
  .run-row pre.run { flex: 1 1 100%; }
}
