:root {
  --bg: #12151a;
  --bg2: #1a1f27;
  --bg3: #242a34;
  --border: #3a4250;
  --text: #e8eaed;
  --muted: #9aa0a6;
  --accent: #6ee7a8;
  --accent2: #a3d977;
  --link: #c6f6d5;
  --hot: #fb923c;
  --spec: #ddd6fe;
  --warn: #fdba74;
  --hold: #fdba74;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; height: 100dvh; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  font-size: 15px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
body.is-schematic {
  overflow: hidden;
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
}
a { color: var(--link); }
code {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.9em;
  background: var(--bg3);
  padding: 1px 5px;
  border-radius: 3px;
}

.banners { flex-shrink: 0; }
.banner {
  padding: 7px 16px;
  font-size: 12px;
  text-align: center;
  border-bottom: 1px solid;
}
.banner strong { color: #fff; }
.banner.note { background: #1a1f27; border-color: #3a4250; color: var(--muted); }
.banner.draft { background: #1a2420; border-color: #245c45; color: #d7fbe8; }
.banner.draft strong { color: var(--accent); }

header.doc-header {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px 0;
  flex-shrink: 0;
  z-index: 20;
}
.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
header.doc-header h1 { font-size: 1.15rem; font-weight: 700; color: #fff; }
header.doc-header .meta { color: var(--muted); font-size: 12px; margin: 2px 0 8px; }
.hub-back {
  display: inline-flex;
  align-items: center;
  color: var(--link);
  text-decoration: none;
  font-size: 13px;
  font-weight: 700;
  min-height: 36px;
  border-radius: 6px;
}
.hub-back:hover, .hub-back:focus-visible { text-decoration: underline; color: #fff; }
.hub-back:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.status-row { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 8px; }
.badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.badge.draft { background: #163528; color: var(--accent); }
.badge.lock { background: #24301c; color: var(--accent2); }
.badge.hold { background: #3b2416; color: var(--hold); }

nav.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 2px;
  border-bottom: 1px solid var(--border);
}
nav.tabs button {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  border-radius: 6px 6px 0 0;
  font-family: inherit;
}
nav.tabs button:hover { color: var(--text); background: var(--bg3); }
nav.tabs button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  color: var(--text);
}
nav.tabs button[aria-selected="true"] {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background: var(--bg3);
}

main { flex: 1 1 auto; min-height: 0; overflow: auto; }
main:not(.is-3d) {
  max-width: 900px;
  margin: 0 auto;
  padding: 20px 16px 72px;
  width: 100%;
}
main.is-3d {
  max-width: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel { display: none !important; }
.panel.active { display: block !important; }
#panel-action.panel.active {
  display: flex !important;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  height: auto;
}

h2 { font-size: 1.25rem; margin: 0 0 10px; color: #fff; }
h3 {
  font-size: 0.78rem;
  margin: 18px 0 8px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
p, li { margin-bottom: 8px; }
ul, ol { padding-left: 1.25em; margin-bottom: 12px; }
.muted { color: var(--muted); }

.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 12px;
}
.card h2, .card h3 { margin-top: 0; }
.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}
.split .card h3 { margin-bottom: 8px; }
.pull {
  border-left: 3px solid var(--accent);
  padding: 8px 12px;
  margin: 0 0 14px;
  color: #fff;
  font-size: 15px;
}

.callout {
  background: #14241c;
  border: 1px solid #245c45;
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 14px;
}
.callout .k {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 4px;
}
.callout strong { color: #fff; display: block; margin-bottom: 4px; }
.callout p { margin: 0; color: var(--muted); font-size: 13px; }

.step {
  margin-bottom: 10px;
  padding: 12px 14px;
  border-left: 3px solid var(--border);
  background: var(--bg2);
  border-radius: 0 8px 8px 0;
}
.step.now { border-left-color: var(--accent); }
.step.next { border-left-color: var(--warn); }
.step.later { border-left-color: #3a4250; }
.step h4 { font-size: 14px; color: #fff; margin-bottom: 4px; }
.step p { margin: 0 0 4px; font-size: 14px; }
.gate { font-size: 12px; color: var(--accent); }

.check { list-style: none; padding: 0; margin: 0; }
.check li {
  position: relative;
  padding: 8px 4px 8px 28px;
  border-bottom: 1px solid #2a3140;
  margin: 0;
}
.check li::before {
  content: "";
  position: absolute;
  left: 2px;
  top: 11px;
  width: 14px;
  height: 14px;
  border: 2px solid #6b7280;
  border-radius: 3px;
}
.group-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  margin: 12px 0 4px;
}

.wrap { width: 100%; overflow-x: auto; margin-bottom: 14px; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 520px; }
table.data th, table.data td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
table.data th {
  color: var(--accent);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: var(--bg2);
}
.pills { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 12px; }
.pill {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
}
.formula {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 13px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin: 0 0 8px;
  color: var(--accent);
}
details.footnotes { margin-top: 8px; }
details.footnotes summary { cursor: pointer; color: var(--link); font-weight: 600; }
details.footnotes ol { margin-top: 8px; }
details.footnotes li { font-size: 13px; color: var(--muted); }

.toolbar {
  flex-shrink: 0;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 8px 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.toolbar button, .deeper-btn {
  background: #2c3440;
  color: var(--text);
  border: 1px solid #4b5568;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  min-height: 36px;
  font-family: inherit;
}
.toolbar button:hover, .deeper-btn:hover { background: #384252; }
.toolbar button:focus-visible, .deeper-btn:focus-visible,
.chip:focus-visible, .phases button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.toolbar label.toggle {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  user-select: none;
  min-height: 36px;
}
.hint { font-size: 11px; color: var(--muted); margin-left: auto; }

.phases {
  flex-shrink: 0;
  display: flex;
  align-items: stretch;
  gap: 6px;
  padding: 8px 12px;
  overflow-x: auto;
  background: #151a21;
  border-bottom: 1px solid var(--border);
}
.phases button {
  flex: 1 0 7.5rem;
  min-height: 44px;
  text-align: left;
  background: var(--bg2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
  cursor: pointer;
  font-family: inherit;
}
.phases button .ph-id {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
}
.phases button .ph-q {
  display: block;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.25;
}
.phases button[aria-pressed="true"] {
  border-color: var(--accent);
  background: #163528;
}
.phases button[aria-pressed="true"] .ph-q { color: #d7fbe8; }
.phases .ph-arrow {
  align-self: center;
  color: #5c6b7a;
  font-size: 14px;
  flex: 0 0 auto;
}
.phases .parallel { color: #c4b5fd; letter-spacing: -0.08em; }

.view3d-wrap {
  flex: 1 1 auto;
  display: flex;
  position: relative;
  min-height: 240px;
  background:
    radial-gradient(ellipse at 30% 40%, rgba(110, 231, 168, 0.08), transparent 55%),
    #12151a;
}
#canvas-wrap {
  flex: 1 1 auto;
  position: relative;
  min-width: 0;
  min-height: 240px;
}
#canvas-wrap canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
#three-error {
  display: none;
  position: absolute;
  inset: 12px;
  z-index: 20;
  background: #3a1a1a;
  border: 1px solid #c44;
  border-radius: 10px;
  padding: 16px 18px;
  color: #ffc9c9;
  font-size: 14px;
  line-height: 1.45;
  overflow: auto;
}
#three-error.visible { display: block; }
#three-error strong { color: #fff; }
#three-loading {
  position: absolute;
  inset: 0;
  z-index: 15;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #12151a;
  color: var(--muted);
  font-size: 14px;
}
#three-loading.hidden { display: none; }

.hud-lock {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 8;
  background: rgba(18, 21, 26, 0.82);
  border: 1px solid #245c45;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 11px;
  line-height: 1.35;
  color: #d7fbe8;
  pointer-events: none;
  max-width: min(70%, 260px);
}
.hud-lock strong { color: #fff; display: block; font-size: 12px; }

#sidebar-3d {
  width: 360px;
  max-width: 42vw;
  flex-shrink: 0;
  background: var(--bg2);
  border-left: 1px solid var(--border);
  overflow: auto;
  padding: 14px 16px 32px;
}
#sidebar-3d h2 { font-size: 1rem; }
#sidebar-3d h3 {
  font-size: 0.72rem;
  margin: 16px 0 6px;
}
.legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid #2a3140;
}
.legend-copy { font-size: 12px; color: var(--muted); flex: 1 1 140px; }

.tag {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  border-radius: 999px;
  padding: 2px 8px;
  margin: 0 4px 4px 0;
}
.tag.proven { color: #052e1a; background: #6ee7a8; }
.tag.speculative { color: #2e1065; background: #ddd6fe; }
.tag.plan { color: #1a2e12; background: #a3d977; }
.tag.hold { color: #431407; background: #fdba74; }

#story p { font-size: 13px; color: var(--text); margin: 0 0 8px; }
#detail {
  margin-top: 8px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #141a22;
  border: 1px solid #2f3b4a;
}
#detail h2 { font-size: 15px; margin-bottom: 6px; }
#detail-summary { font-size: 13.5px; color: var(--text); margin: 0 0 8px; }
#detail-deeper { margin: 8px 0 0; padding-left: 1.15em; }
#detail-deeper li { font-size: 13px; color: #d5dbe3; margin-bottom: 6px; }
.deeper-btn { margin-top: 2px; }
.deeper-btn[aria-expanded="true"] { border-color: var(--accent); color: var(--accent); }

.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 10px;
  min-height: 36px;
  cursor: pointer;
}
.chip:hover { border-color: #6b7c70; }
.chip[aria-pressed="true"] {
  border-color: var(--accent);
  background: #163528;
  color: #fff;
}
.chip.spec[aria-pressed="true"] {
  border-color: #c4b5fd;
  background: #2a2440;
}

#btn-expand { min-height: 36px; font-weight: 700; }
#fs-hud { display: none; }
body.fs-3d { padding: 0; overflow: hidden; }
body.fs-3d .banners,
body.fs-3d header.doc-header,
body.fs-3d .toolbar,
body.fs-3d .phases,
body.fs-3d #sidebar-3d { display: none !important; }
body.fs-3d main.is-3d,
body.fs-3d #panel-action.panel.active,
body.fs-3d .view3d-wrap,
body.fs-3d #canvas-wrap {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100dvh;
  max-height: none;
  min-height: 0;
  z-index: 50;
  border: none;
}
body.fs-3d #fs-hud { display: block; z-index: 60; pointer-events: none; }
#fs-hud .fs-top {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 10px 8px;
  background: linear-gradient(to bottom, rgba(18, 21, 26, 0.92), rgba(18, 21, 26, 0));
  pointer-events: auto;
}
#fs-hud .fs-top .hub-back { margin: 0; color: #fff; min-height: 44px; }
#fs-hud .fs-top button {
  min-height: 44px;
  padding: 8px 12px;
  font-weight: 700;
  cursor: pointer;
  background: var(--bg2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
}
.fs-detail {
  position: fixed;
  left: 10px;
  right: 10px;
  bottom: calc(10px + env(safe-area-inset-bottom));
  max-width: 520px;
  background: rgba(18, 21, 26, 0.92);
  border: 1px solid #245c45;
  border-radius: 10px;
  padding: 8px 12px;
  pointer-events: none;
}
.fs-detail strong { display: block; color: #fff; font-size: 13px; }
.fs-detail p {
  margin: 2px 0 0;
  color: #d7fbe8;
  font-size: 12px;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

@media (max-width: 860px) {
  html, body.is-schematic {
    height: auto;
    max-height: none;
    overflow: auto;
  }
  body.is-schematic main.is-3d {
    overflow: visible;
    display: block;
    flex: none;
  }
  #panel-action.panel.active {
    display: block !important;
    flex: none;
  }
  .banner.note { font-size: 11px; padding: 5px 10px; }
  .banner.draft { display: none; }
  header.doc-header { padding: 4px 10px 0; }
  header.doc-header h1 { font-size: 1.02rem; }
  header.doc-header .meta { display: none; }
  .status-row { margin-bottom: 4px; }
  nav.tabs button { padding: 8px 10px; font-size: 12px; min-height: 44px; }
  .phases { padding: 6px 8px; }
  .phases button { flex-basis: 6.2rem; }
  .phases .ph-q { display: none; }
  .toolbar { padding: 6px 8px; }
  .hint { display: none; }
  .view3d-wrap { flex-direction: column; min-height: 0; }
  #canvas-wrap {
    flex: none;
    width: 100%;
    height: 54vh;
    height: 54dvh;
    min-height: 280px;
  }
  #sidebar-3d {
    width: 100%;
    max-width: none;
    max-height: none;
    overflow: visible;
    border-left: none;
    border-top: 1px solid var(--border);
  }
  .split { grid-template-columns: 1fr; }
  .hud-lock { font-size: 10px; max-width: min(78%, 220px); }
  #btn-expand, .toolbar button, .chip { min-height: 44px; }
}

@media (orientation: landscape) and (max-height: 520px) {
  body.is-schematic #canvas-wrap {
    height: 68dvh;
    min-height: 180px;
  }
}
body.fs-3d .land-hud { display: none !important; }
