:root {
  --bg: #100e16; --bg2: #1a1624; --bg3: #261f33; --border: #46385a;
  --text: #eee8f4; --muted: #a89bb8; --accent: #d946ef; --accent2: #c4b5fd;
  --nature: #2dd4bf; --eng: #c084fc; --warn: #fdd663; --ok: #86efac;
  --hi: #f0abfc; --resonate: #fbbf24; --flexure: #67e8f9;
}
* { 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(--accent2); }
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.nature { background: #12332f; border-color: #1f6b62; color: #b7efe6; }
.banner.nature strong { color: var(--nature); }
.banner.eng { background: #2a1840; border-color: #6b3fa0; color: #e9d5ff; }
.banner.eng strong { color: var(--eng); }
.banner.note { background: #1a1a22; border-color: #3a3a48; color: var(--muted); }

header.doc-header {
  background: var(--bg2); border-bottom: 1px solid var(--border);
  padding: 10px 16px 0; flex-shrink: 0; z-index: 100;
}
.header-top {
  display: flex; align-items: baseline; 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: 11px; margin-top: 2px; }
.home-link { color: var(--accent2); font-size: 12px; text-decoration: none; }
.home-link:hover, .home-link:focus-visible { text-decoration: underline; }
.hub-back {
  display: inline-flex; align-items: center;
  color: var(--accent2); text-decoration: none;
  font-size: 13px; font-weight: 700;
  min-height: 36px; margin: 0; 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; }

.catalog {
  display: grid; grid-template-columns: 1fr 1fr 1fr;
  margin: 10px 0 8px; border: 1px solid var(--border); border-radius: 10px;
  overflow: hidden; background: #140f1c;
}
.catalog a {
  display: flex; flex-direction: column; justify-content: center; align-items: center;
  text-align: center; text-decoration: none; color: var(--text);
  padding: 8px 6px; min-height: 48px; gap: 2px;
  border-right: 1px solid var(--border); background: #221a2e;
  cursor: pointer;
}
.catalog a:last-child { border-right: none; }
.catalog a:hover, .catalog a:focus-visible {
  background: #3a2a52; color: #fff;
}
.catalog a:hover .id, .catalog a:focus-visible .id { text-decoration: underline; }
.catalog a:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.catalog a[aria-current="page"] {
  background: #6b21a8; color: #fff;
  box-shadow: inset 0 -3px 0 #f0abfc;
}
.catalog a[aria-current="page"]:hover { background: #7e22ce; }
.catalog .id { font-size: 13px; font-weight: 700; letter-spacing: 0.01em; color: #fce7f3; }
.catalog a[aria-current="page"] .id { color: #fff; }
.catalog a[aria-current="page"] .sub { color: #e9d5ff; }
.catalog .sub { font-size: 10px; line-height: 1.25; color: #c4b5fd; }
.catalog .status {
  font-size: 10px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
}
.catalog .status.live { color: var(--ok); }
.catalog a[aria-current="page"] .status.live { color: #bbf7d0; }

.why-chip { display: none; }

nav.tabs {
  display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px;
  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;
}
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: 980px; margin: 0 auto; padding: 20px 16px 60px; width: 100%; }
main.is-3d {
  max-width: none; margin: 0; padding: 0;
  display: flex; flex-direction: column;
  overflow: hidden;
  flex: 1 1 auto;
  min-height: 0;
}

.panel { display: none !important; }
.panel.active { display: block !important; }
#panel-schematic.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 12px; color: #fff; }
h3 { font-size: 0.85rem; margin: 22px 0 8px; color: var(--accent);
  text-transform: uppercase; letter-spacing: 0.04em; }
p, li { margin-bottom: 8px; }
ul, ol { padding-left: 1.35em; margin-bottom: 12px; }
.muted { color: var(--muted); }
.ok { color: var(--ok); }

.card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 10px; padding: 16px 18px; margin-bottom: 16px;
}
.nt-row {
  display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; align-items: start;
  background: var(--bg2); border: 1px solid var(--border); border-radius: 10px;
  padding: 14px 16px; margin-bottom: 12px;
}
.nt-row .k { font-size: 10px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; margin-bottom: 4px; }
.nt-row .from .k { color: var(--nature); }
.nt-row .idea .k { color: var(--warn); }
.nt-row .to .k { color: var(--eng); }
.nt-row strong { display: block; color: #fff; margin-bottom: 4px; font-size: 14px; }
.nt-row p { margin: 0; font-size: 13px; color: var(--muted); }

.step { margin-bottom: 12px; 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: #56486a; }
.step h4 { font-size: 14px; color: #fff; margin-bottom: 4px; }
.gate { font-size: 12px; color: var(--ok); }

.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 {
  background: #3c3348; color: var(--text); border: 1px solid #6b5a80;
  border-radius: 6px; padding: 6px 12px; font-size: 12px; font-weight: 600;
  cursor: pointer; min-height: 36px;
}
.toolbar button:hover { background: #4d425e; }
.toolbar button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.toolbar button.active {
  background: var(--accent); color: #1a0a22; border-color: var(--accent);
}
.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; }

.view3d-wrap {
  flex: 1 1 auto; display: flex; position: relative; min-height: 220px;
  background:
    radial-gradient(ellipse at 40% 35%, rgba(168, 85, 247, 0.16), transparent 55%),
    #140f1c;
}
#canvas-wrap {
  flex: 1 1 auto; position: relative; min-width: 0; min-height: 220px; height: auto;
}
#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; max-height: calc(100% - 24px);
}
#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: #140f1c; color: var(--muted); font-size: 14px;
}
#three-loading.hidden { display: none; }

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

#sidebar-3d {
  width: 320px; max-width: 42vw; flex-shrink: 0;
  background: var(--bg2); border-left: 1px solid var(--border);
  overflow: auto; padding: 14px 16px 28px;
}
#sidebar-3d h2 { font-size: 0.95rem; }
#sidebar-3d h3 {
  font-size: 0.72rem; margin: 16px 0 6px; color: var(--accent);
  text-transform: uppercase; letter-spacing: 0.05em;
}
#sidebar-3d .stat {
  display: flex; justify-content: space-between; gap: 8px;
  padding: 4px 0; border-bottom: 1px solid #2e2538; font-size: 12px;
}
#sidebar-3d .stat span:last-child {
  color: var(--accent2); font-variant-numeric: tabular-nums; font-weight: 600;
  text-align: right;
}
.part-card {
  background: var(--bg3); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; margin-top: 6px; cursor: pointer; font-size: 12px; text-align: left; width: 100%;
  color: inherit; font-family: inherit;
}
.part-card:hover, .part-card.selected { border-color: var(--accent); }
.part-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.part-card strong { color: #fff; display: block; }
.part-card .muted { display: block; margin-top: 2px; font-size: 11px; }
#sel-detail {
  margin-top: 12px; padding: 10px 12px; border-radius: 8px;
  background: #2a1840; border: 1px solid #6b3fa0; display: none;
}
#sel-detail.visible { display: block; }
#sel-detail h4 { color: #fff; font-size: 13px; margin-bottom: 4px; }
#sel-detail p { font-size: 12px; color: var(--muted); }

@media (max-width: 720px) {
  .nt-row { grid-template-columns: 1fr; }
}

@media (max-width: 820px) {
  .banner.nature, .banner.eng { display: none; }
  .why-chip {
    display: block; background: #2a1840; border-color: #6b3fa0; color: #e9d5ff;
    font-size: 11px; padding: 5px 10px;
  }
  .banner.note { font-size: 11px; padding: 5px 10px; }
  header.doc-header { padding: 6px 10px 0; }
  header.doc-header h1 { font-size: 1rem; }
  header.doc-header .meta { font-size: 10px; }
  .catalog { margin: 8px 0 6px; }
  .catalog .id { font-size: 11px; }
  .catalog a { padding: 6px 4px; gap: 0; min-height: 44px; }
  nav.tabs button { padding: 8px 10px; font-size: 12px; min-height: 44px; }
  .toolbar { padding: 6px 8px; gap: 6px; }
  .toolbar button { padding: 6px 9px; }
  .view3d-wrap { flex-direction: column; min-height: 48dvh; }
  #canvas-wrap {
    flex: 0 0 auto; width: 100%;
    height: 50vh; height: 50dvh; min-height: 48vh; min-height: 48dvh;
  }
  #sidebar-3d {
    width: 100%; max-width: none; max-height: 32vh; max-height: 32dvh;
    border-left: none; border-top: 1px solid var(--border);
    padding: 10px 12px 20px;
  }
  .hint { display: none; }
  .hud-lock { top: 8px; left: 8px; font-size: 10px; padding: 5px 8px; max-width: min(78%, 240px); }
}

#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 #sidebar-3d { display: none !important; }
body.fs-3d main.is-3d,
body.fs-3d #panel-schematic.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(16,14,22,0.92), rgba(16,14,22,0.15));
  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;
}
@media (max-width: 820px) {
  #btn-expand { min-height: 44px; }
}

/* Short landscape: hide chrome so the schematic can take over. */
.land-hud { display: none; }
@media (orientation: landscape) and (max-height: 520px) {
  body.is-schematic { overflow: hidden; height: 100dvh; max-height: 100dvh; padding: 0; }
  body.is-schematic .banners,
  body.is-schematic header.doc-header,
  body.is-schematic .toolbar,
  body.is-schematic #sidebar-3d { display: none !important; }
  body.is-schematic main.is-3d,
  body.is-schematic #panel-schematic.panel.active,
  body.is-schematic .view3d-wrap,
  body.is-schematic #canvas-wrap {
    position: fixed; inset: 0;
    width: 100%; height: 100dvh; max-height: none; min-height: 0;
    z-index: 50; border: none;
  }
  body.is-schematic .land-hud {
    display: flex; align-items: center;
    position: fixed; top: 0; left: 0; z-index: 70;
    padding: calc(6px + env(safe-area-inset-top)) 10px 6px;
  }
  body.is-schematic .land-hud .hub-back {
    margin: 0; color: #fff; min-height: 36px;
    text-shadow: 0 1px 4px #000;
  }
}
body.fs-3d .land-hud { display: none !important; }
