:root {
  --bg: #12110c; --bg2: #1b1810; --bg3: #2a2416; --border: #4a3f28;
  --text: #f4efe4; --muted: #b5a88c; --accent: #f5b942; --accent2: #fde68a;
  --warn: #fdd663; --ok: #86efac;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { min-height: 100%; }
html:has(body.is-viewer), body.is-viewer {
  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;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
body.is-viewer {
  display: flex; flex-direction: column;
  min-height: 100vh; min-height: 100dvh;
  overflow: hidden;
}
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; }
.back-bar {
  flex-shrink: 0;
  padding: 5px 16px;
  font-size: 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.back-bar a {
  color: var(--accent2);
  text-decoration: none;
  font-weight: 600;
}
.back-bar a:hover, .back-bar a:focus-visible { text-decoration: underline; }
.back-bar .sep { color: var(--muted); margin: 0 0.45em; }
.back-bar .sub { color: var(--muted); font-weight: 500; }
.banner {
  padding: 7px 16px; font-size: 12px; text-align: center; border-bottom: 1px solid;
}
.banner strong { color: #fff; }
.banner.draft { background: #3a2e10; border-color: #8a6a20; color: #fde68a; }
.banner.draft strong { color: var(--accent); }
.banner.note { background: #1a1812; border-color: #3a3428; color: var(--muted); }

header.doc-header {
  background: var(--bg2); border-bottom: 1px solid var(--border);
  padding: 12px 20px; flex-shrink: 0; z-index: 100;
}
header.doc-header h1 { font-size: 1.2rem; 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; }
.back-bar .hub-back { min-height: 32px; }
.crumb { color: var(--muted); font-size: 12px; }
.crumb a { color: var(--accent2); text-decoration: none; }
.crumb a:hover, .crumb a:focus-visible { text-decoration: underline; }

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); }
.warn { color: var(--warn); }

.card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 10px; padding: 16px 18px; margin-bottom: 16px;
}
.landing-wrap { max-width: 52rem; margin: 0 auto; padding: 20px 16px 60px; }
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(15.5rem, 1fr));
  gap: 0.9rem;
  margin: 1rem 0 1.5rem;
}
a.tile {
  display: flex; flex-direction: column; min-height: 100%;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 12px; padding: 1rem 1.05rem 1.1rem;
  text-decoration: none; color: inherit;
  box-shadow: inset 0 3px 0 var(--accent);
}
a.tile:hover, a.tile:focus-visible {
  border-color: var(--accent); background: var(--bg3);
  outline: 2px solid var(--accent); outline-offset: 2px;
}
a.tile .kicker {
  font-size: 0.7rem; font-weight: 700; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--accent); margin-bottom: 0.35rem;
}
a.tile h2 { font-size: 1.05rem; margin: 0 0 0.4rem; }
a.tile p { margin: 0 0 0.85rem; color: var(--muted); font-size: 0.92rem; flex: 1; }
a.tile .tile-preview {
  display: block; width: calc(100% + 2.1rem); margin: -1rem -1.05rem 0.8rem;
  aspect-ratio: 3 / 2; object-fit: cover; border-radius: 12px 12px 0 0;
  border-bottom: 1px solid var(--border); background: #16130c;
}
a.tile .path { display: none; }
a.tile .path {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.78rem; color: var(--accent);
}

table.data {
  width: 100%; border-collapse: collapse; font-size: 13px;
  margin: 8px 0 16px; background: var(--bg2); border-radius: 8px; overflow: hidden;
}
table.data th, table.data td {
  padding: 7px 10px; text-align: left; border-bottom: 1px solid var(--border);
}
table.data th {
  background: var(--bg3); color: var(--accent); font-weight: 600;
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em;
}
table.data tr:last-child td { border-bottom: none; }
table.data td.num { font-variant-numeric: tabular-nums; }

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

.open-list { list-style: none; padding: 0; }
.open-list li {
  display: flex; gap: 10px; align-items: baseline;
  padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 14px;
}
.open-list .tag {
  flex-shrink: 0; font-size: 10px; font-weight: 800; letter-spacing: 0.06em;
  text-transform: uppercase; color: #1a1408; background: var(--accent);
  border-radius: 4px; padding: 2px 6px;
}

.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: #3c3424; color: var(--text); border: 1px solid #6b5a38;
  border-radius: 6px; padding: 6px 12px; font-size: 12px; font-weight: 600;
  cursor: pointer; min-height: 36px;
}
.toolbar button:hover { background: #4a4030; }
.toolbar button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.toolbar button.active {
  background: var(--accent); color: #1a1408; 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;
}
.toolbar .catalog { flex-basis: 100%; }
.hint { font-size: 11px; color: var(--muted); flex-basis: 100%; }
#three-retry { margin-top: 8px; }

.catalog {
  display: flex; flex-wrap: wrap; gap: 0; border: 1px solid var(--border);
  border-radius: 8px; overflow: hidden;
}
.catalog a {
  border-right: 1px solid var(--border); min-width: 5.5rem;
  display: flex; flex-direction: column; align-items: flex-start;
  gap: 1px; padding: 5px 12px; min-height: 40px;
  background: #3c3424; color: var(--text); text-decoration: none;
  font-size: 12px; font-weight: 600;
}
.catalog a:last-child { border-right: none; }
.catalog a:hover { background: #4a4030; }
.catalog a:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.catalog .cat-k {
  font-size: 9px; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--muted); font-weight: 700;
}
.catalog a[aria-current="page"] {
  background: var(--accent); color: #1a1408;
}
.catalog a[aria-current="page"] .cat-k { color: #5a3d08; }

.view3d-wrap {
  flex: 1; display: flex; position: relative; min-height: 0;
  background:
    radial-gradient(ellipse at 40% 35%, rgba(245, 185, 66, 0.12), transparent 55%),
    #16130c;
}
#canvas-wrap {
  flex: 1; position: relative; min-width: 0; min-height: 0; height: 100%;
}
#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: #16130c; color: var(--muted); font-size: 14px;
}
#three-loading.hidden { display: none; }

#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 #2e2818; 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: #3a2e10; border: 1px solid #8a6a20; 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: 820px) {
  header.doc-header { padding: 8px 12px; }
  header.doc-header h1 { font-size: 1.05rem; }
  .banner { font-size: 11px; padding: 6px 10px; }
  .view3d-wrap { flex-direction: column; }
  #canvas-wrap {
    flex: 0 0 auto; width: 100%;
    height: 58vh; height: 58dvh; min-height: 50vh; min-height: 50dvh;
  }
  #sidebar-3d {
    width: 100%; max-width: none; max-height: 38vh;
    border-left: none; border-top: 1px solid var(--border);
  }
  .hint { display: none; }
  .catalog a { min-width: 4.6rem; }
}

#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 .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,17,12,0.92), rgba(18,17,12,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; }
}

.land-hud { display: none; }
@media (orientation: landscape) and (max-height: 520px) {
  body.is-viewer { overflow: hidden; height: 100dvh; max-height: 100dvh; padding: 0; }
  body.is-viewer .banners,
  body.is-viewer header.doc-header,
  body.is-viewer .toolbar,
  body.is-viewer #sidebar-3d { display: none !important; }
  body.is-viewer .view3d-wrap,
  body.is-viewer #canvas-wrap {
    position: fixed; inset: 0;
    width: 100%; height: 100dvh; max-height: none; min-height: 0;
    z-index: 50; border: none;
  }
  body.is-viewer .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-viewer .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; }
