/* ===== Hyperfolder — app.css =====
   レイアウト: 製図台の見立て。左にライブラリ、中央に立体と型紙、右に設定。
   色と書体は res-miyamoto.com 本体（墨・生成り・金）を継承。 */

*, *::before, *::after { box-sizing: border-box; }

:root {
  --ink: #0f0f0e;          /* 地 */
  --panel: #161614;        /* パネル */
  --panel-2: #1e1d1a;      /* 入力・ボタン地 */
  --line: #2d2b27;         /* 罫 */
  --text: #e8e4de;         /* 生成り */
  --muted: #8f8b82;
  --gold: #c4a265;
  --gold-soft: rgba(196, 162, 101, 0.14);
  --table: #191815;        /* 型紙の作業台 */
  --paper-shadow: rgba(0, 0, 0, 0.45);
  --warn: #e0876d;

  --display: 'Cormorant Garamond', 'Noto Serif JP', Georgia, serif;
  --serif-ja: 'Noto Serif JP', 'Hiragino Mincho ProN', 'Yu Mincho', serif;
  --sans: 'Noto Sans JP', 'Hiragino Sans', 'Yu Gothic', system-ui, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;

  --topbar-h: 52px;
  --lib-w: 272px;
  --insp-w: 300px;
  color-scheme: dark;
}

html, body { height: 100%; margin: 0; }
body {
  background: var(--ink);
  color: var(--text);
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 1.5px solid var(--gold); outline-offset: 2px; }

/* ---------- 全体グリッド ---------- */
.app {
  height: 100%;
  display: grid;
  grid-template-columns: var(--lib-w) minmax(0, 1fr) var(--insp-w);
  grid-template-rows: var(--topbar-h) minmax(0, 1fr);
  grid-template-areas:
    "top top top"
    "lib stage insp";
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}

.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: var(--ink);
}
.brand-wrap { display: flex; align-items: center; gap: 10px; min-width: 0; }
.ver-chip {
  font-family: var(--mono); font-size: 11px; color: var(--muted); text-decoration: none; white-space: nowrap;
  border: 1px solid var(--line); border-radius: 999px; padding: 1px 8px; transition: color .2s, border-color .2s;
}
.ver-chip:hover, .ver-chip:focus-visible { color: var(--gold); border-color: rgba(196, 162, 101, 0.6); }
.help-keys dd a { color: var(--gold); }
.brand { display: flex; align-items: baseline; gap: 12px; color: var(--text); text-decoration: none; min-width: 0; }
.brand-name { font-family: var(--display); font-size: 21px; letter-spacing: 0.06em; white-space: nowrap; }
.brand-sub { font-family: var(--display); font-style: italic; color: var(--gold); font-size: 15px; letter-spacing: 0.06em; white-space: nowrap; }

.top-actions { display: flex; align-items: center; gap: 10px; }
.demo-btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px 4px 10px; border-radius: 999px; cursor: pointer;
  border: 1px solid rgba(196, 162, 101, 0.55); background: transparent; color: var(--gold); font-size: 12px; letter-spacing: 0.12em;
  transition: background-color .2s, color .2s;
}
.demo-btn svg { width: 11px; height: 11px; fill: currentColor; }
.demo-btn:hover { background: var(--gold); color: #1a1710; }
.lang-btn {
  border: 1px solid var(--line); background: transparent; color: var(--muted); border-radius: 999px; cursor: pointer;
  padding: 3px 10px; font-size: 11.5px; letter-spacing: 0.08em; white-space: nowrap; transition: color .2s, border-color .2s;
}
.lang-btn .l-short { display: none; }
@media (max-width: 480px) { .lang-btn .l-full { display: none; } .lang-btn .l-short { display: inline; } }
/* 幅の狭いスマホ: デモは記号だけにして、版番号が名前に重ならないようにする */
@media (max-width: 400px) {
  .demo-btn > span { display: none; }
  .demo-btn { padding: 5px 8px !important; }
  .brand-name { font-size: 17px !important; }
}
.lang-btn:hover, .lang-btn:focus-visible { color: var(--gold); border-color: rgba(196, 162, 101, 0.6); }
/* 英語表示: 見出しの英語の添え字は本文と重なるので隠し、日本語の添え字は立体の書体にしない */
html[lang="en"] .block-title .en { display: none; }
html[lang="en"] .poly-en, html[lang="en"] .lib-item .en, html[lang="en"] .lib-cat > summary .en,
html[lang="en"] .demo-en { font-family: var(--sans); font-style: normal; letter-spacing: 0.04em; }
html[lang="en"] .demo-intro-ja { display: none; }
html[lang="en"] .title-block h1 { letter-spacing: 0.03em; }
html[lang="en"] .row:has(select + select) { grid-template-columns: 76px minmax(0, 1fr) 100px; }
html[lang="en"] details > summary.block-title::after { content: 'Open'; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; padding: 2px; background: var(--panel); }
.seg button {
  border: 0; background: transparent; padding: 4px 14px; border-radius: 999px; cursor: pointer;
  color: var(--muted); letter-spacing: 0.08em; font-size: 12px;
}
.seg button[aria-selected="true"] { background: var(--gold-soft); color: var(--gold); }
.seg-sm button { padding: 3px 11px; font-size: 11.5px; letter-spacing: 0.04em; }
.net-summary { flex: 1 1 220px; min-width: 0; }

/* ---------- パネル ---------- */
.panel { background: var(--panel); min-height: 0; display: flex; flex-direction: column; }
.library { grid-area: lib; border-right: 1px solid var(--line); }
.inspector { grid-area: insp; border-left: 1px solid var(--line); }
.panel-scroll { overflow-y: auto; flex: 1; min-height: 0; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }

.block { padding: 14px 16px; border-bottom: 1px solid var(--line); }
.block-title {
  margin: 0 0 10px; font-family: var(--serif-ja); font-weight: 500; font-size: 13px; letter-spacing: 0.12em;
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 8px; cursor: default; list-style: none; white-space: nowrap;
}
details > summary.block-title { cursor: pointer; }
details > summary.block-title::-webkit-details-marker { display: none; }
details > summary.block-title::before {
  content: ''; width: 5px; height: 5px; margin: 0 4px 2px 1px; align-self: center; flex: none;
  border-right: 1.5px solid var(--muted); border-bottom: 1.5px solid var(--muted);
  transform: rotate(-45deg); transition: transform .2s ease, border-color .15s;
}
details[open] > summary.block-title::before { transform: rotate(45deg); border-color: var(--gold); }
details > summary.block-title:hover::before { border-color: var(--text); }
details > summary.block-title::after { content: '開く'; margin-left: auto; color: var(--muted); font-family: var(--sans); font-size: 10.5px; letter-spacing: 0.04em; }
details[open] > summary.block-title::after { content: none; }
.block-title .en { font-family: var(--display); font-style: italic; color: var(--muted); letter-spacing: 0.04em; font-weight: 400; font-size: 13px; }

.row { display: grid; grid-template-columns: 76px minmax(0, 1fr) auto; align-items: center; gap: 8px; margin: 8px 0; }
.row > label { color: var(--muted); font-size: 12px; }
.row output, .row .unit { font-family: var(--mono); font-size: 11px; color: var(--muted); min-width: 36px; text-align: right; font-variant-numeric: tabular-nums; }
.row select + select { grid-column: 3; }
.row:has(select + select) { grid-template-columns: 76px minmax(0, 1fr) 64px; }

input[type="range"] { width: 100%; accent-color: var(--gold); }
select, input[type="number"], input[type="text"], input[type="search"] {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; min-width: 0; width: 100%;
}
input[type="number"] { font-family: var(--mono); }

.toggles { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px; margin: 6px 0 10px; }
.check { display: flex; align-items: center; gap: 6px; color: var(--text); font-size: 12px; cursor: pointer; }
.check input { accent-color: var(--gold); margin: 0; }
.block > .check { margin-top: 10px; color: var(--muted); }
.hint { color: var(--muted); font-size: 11px; margin: 4px 0 0; line-height: 1.55; }
.hint.warn { color: var(--warn); }

.btn {
  border: 1px solid var(--line); background: var(--panel-2); border-radius: 6px; padding: 6px 12px;
  cursor: pointer; letter-spacing: 0.06em; font-size: 12px; transition: border-color .15s, color .15s;
}
.btn:hover { border-color: var(--gold); color: var(--gold); }
.btn-gold { background: var(--gold); border-color: var(--gold); color: #1a1710; font-weight: 500; }
.btn-gold:hover { background: #d3b47a; color: #1a1710; }
.export-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.export-grid .btn-gold { grid-column: 1 / -1; padding: 8px; }

/* ---------- ライブラリ ---------- */
.notation { display: flex; gap: 6px; align-items: stretch; }
.notation .btn { white-space: nowrap; flex: none; }
.notation input { font-family: var(--mono); font-size: 15px; letter-spacing: 0.04em; flex: 1; padding: 4px 10px; }
.notation-msg { min-height: 1.4em; margin: 4px 0 2px; font-size: 11px; color: var(--muted); }
.notation-msg.err { color: var(--warn); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0; }
.chip {
  font-family: var(--mono); font-size: 12px; min-width: 26px; padding: 2px 6px; border-radius: 4px; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
}
.chip:hover { border-color: var(--gold); color: var(--gold); }
.seeds .chip { color: var(--gold); }

.search { margin-bottom: 8px; }
.lib-cat { margin: 0 -16px; border-top: 1px solid transparent; }
.lib-cat + .lib-cat { border-top-color: rgba(45, 43, 39, 0.6); }
.lib-cat > summary {
  list-style: none; cursor: pointer; padding: 8px 16px 8px 12px;
  display: grid; grid-template-columns: 16px minmax(0, 1fr) auto; column-gap: 6px; align-items: baseline;
  font-family: var(--serif-ja); letter-spacing: 0.1em; font-size: 12.5px;
  transition: background-color .15s;
}
.lib-cat > summary::-webkit-details-marker { display: none; }
.lib-cat > summary:hover { background: var(--panel-2); }
.lib-cat[open] > summary { background: rgba(196, 162, 101, 0.06); }
.lib-cat > summary .ttl { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 8px; min-width: 0; }
.lib-cat > summary .en { font-family: var(--display); font-style: italic; color: var(--muted); font-size: 12.5px; letter-spacing: 0.02em; }
.lib-cat > summary .n {
  font-family: var(--mono); color: var(--muted); font-size: 10.5px; letter-spacing: 0;
  border: 1px solid var(--line); border-radius: 999px; padding: 0 6px; line-height: 1.6;
}
.lib-cat[open] > summary .n { color: var(--gold); border-color: rgba(196, 162, 101, 0.4); }
/* 行頭マーカー: 閉じると右向き、開くと下向き */
.mk { align-self: center; width: 16px; height: 16px; display: grid; place-items: center; }
.mk::before {
  content: ''; width: 5px; height: 5px; border-right: 1.5px solid var(--muted); border-bottom: 1.5px solid var(--muted);
  transform: rotate(-45deg); transition: transform .2s ease, border-color .15s;
}
.lib-cat > summary:hover .mk::before { border-color: var(--text); transform: rotate(-45deg) translate(1px, 1px); }
.lib-cat[open] > summary .mk::before { transform: rotate(45deg); border-color: var(--gold); }
/* 閉じているときだけ中身を予告する */
.lib-cat > summary .peek {
  grid-column: 2 / -1; font-family: var(--sans); letter-spacing: 0.02em; font-size: 11px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: .8; margin-top: 1px;
}
.lib-cat > summary .peek .cur { color: var(--gold); }
.lib-cat > summary .peek .cur::before { content: '●'; font-size: 7px; vertical-align: 2px; margin-right: 5px; }
.lib-cat[open] > summary .peek { display: none; }
.lib-cat[open] > .lib-items { animation: reveal .22s ease-out; }
@keyframes reveal { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.lib-items { list-style: none; margin: 0; padding: 0 0 6px; }
.lib-item {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0 8px; padding: 5px 16px 5px 26px; cursor: pointer;
  border-left: 2px solid transparent; width: 100%; text-align: left; background: none; border-top: 0; border-right: 0; border-bottom: 0;
}
.lib-item:hover { background: var(--panel-2); }
.lib-item[aria-current="true"] { border-left-color: var(--gold); background: var(--gold-soft); }
.lib-item .ja { font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-item .en { grid-column: 1; font-family: var(--display); font-style: italic; color: var(--muted); font-size: 12.5px; line-height: 1.2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-item .nt { grid-row: 1 / span 2; grid-column: 2; align-self: center; font-family: var(--mono); color: var(--gold); font-size: 11px; opacity: .8; }

/* ---------- ステージ ---------- */
.stage { grid-area: stage; min-height: 0; min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.stage[data-view="3d"] { grid-template-columns: minmax(0, 1fr); }
.stage[data-view="3d"] .pane-net { display: none; }
.stage[data-view="net"] { grid-template-columns: minmax(0, 1fr); }
.stage[data-view="net"] .pane-3d { display: none; }

.pane { position: relative; min-height: 0; min-width: 0; overflow: hidden; }
.pane-3d { background: radial-gradient(120% 90% at 50% 38%, #24221e 0%, #141412 55%, #0c0c0b 100%); }
.gl { position: absolute; inset: 0; }
.gl canvas { display: block; cursor: grab; }
.gl canvas:active { cursor: grabbing; }

.title-block { position: absolute; left: 20px; top: 16px; pointer-events: none; max-width: calc(100% - 140px); }
.title-block h1 { margin: 0; font-family: var(--serif-ja); font-weight: 500; font-size: clamp(18px, 2.2vw, 26px); letter-spacing: 0.12em; text-wrap: balance; }
.poly-en { margin: 0; font-family: var(--display); font-style: italic; font-size: clamp(15px, 1.6vw, 19px); color: var(--gold); letter-spacing: 0.03em; }
.poly-meta { margin: 6px 0 0; display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; color: var(--muted); font-family: var(--mono); font-size: 11px; font-variant-numeric: tabular-nums; }
.chip-mono { border: 1px solid var(--line); border-radius: 4px; padding: 0 6px; color: var(--text); background: rgba(0,0,0,.25); }
.chip-mono:empty { display: none; }

.tools-3d { position: absolute; right: 14px; top: 14px; display: flex; gap: 6px; }
.icon-btn {
  width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--line); background: rgba(22, 22, 20, 0.7);
  display: inline-grid; place-items: center; cursor: pointer; color: var(--text); padding: 0; backdrop-filter: blur(6px);
}
.icon-btn:hover { border-color: var(--gold); color: var(--gold); }
.icon-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn[aria-pressed="true"] { color: var(--gold); border-color: rgba(196,162,101,.5); }
.icon-btn.sm { width: 28px; height: 28px; font-family: var(--mono); font-size: 14px; }
.icon-btn.play svg { fill: currentColor; stroke: none; }

.hover-info {
  position: absolute; left: 20px; bottom: 64px; background: rgba(15, 15, 14, 0.82); border: 1px solid var(--line);
  border-radius: 6px; padding: 6px 10px; font-size: 11.5px; pointer-events: none; max-width: calc(100% - 40px);
  font-variant-numeric: tabular-nums;
}
.hover-info b { font-weight: 500; color: var(--gold); }

.foldbar {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); width: min(460px, calc(100% - 32px));
  display: grid; grid-template-columns: auto auto minmax(0, 1fr) 44px; align-items: center; gap: 10px;
  background: rgba(15, 15, 14, 0.78); border: 1px solid var(--line); border-radius: 999px; padding: 5px 16px 5px 5px;
  backdrop-filter: blur(6px);
}
.fold-label { color: var(--muted); font-size: 12px; letter-spacing: 0.1em; }
.foldbar output { font-family: var(--mono); font-size: 11px; color: var(--gold); text-align: right; font-variant-numeric: tabular-nums; }

/* 型紙 */
.pane-net { background: var(--table); border-left: 1px solid var(--line); display: flex; flex-direction: column; }
.stage[data-view="net"] .pane-net { border-left: 0; }
.net-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.net-summary { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.net-summary b { color: var(--text); font-weight: 500; }
.net-summary .warn { color: var(--warn); }
.net-actions { display: flex; gap: 6px; align-items: center; }
.net-scroll { flex: 1; overflow: auto; min-height: 0; padding: 20px; }
.net-pages { display: flex; flex-direction: column; align-items: center; gap: 22px; margin: 0 auto; }
.net-sheet { position: relative; width: 100%; }
.net-sheet .sheet-head { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; color: var(--muted); font-family: var(--mono); font-size: 10.5px; margin-bottom: 4px; }
.net-sheet .sheet-head button { background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; padding: 0; }
.net-sheet .sheet-head button:hover { color: var(--gold); }
.net-sheet svg { display: block; width: 100%; height: auto; box-shadow: 0 8px 28px var(--paper-shadow), 0 0 0 1px rgba(0,0,0,.3); border-radius: 1px; }
.net-sheet line, .net-sheet text { pointer-events: none; }
.lib-cat.dim4 > summary { color: var(--gold); }
.net-sheet polygon[data-f] { cursor: pointer; transition: fill-opacity .1s; }
.net-sheet polygon[data-f].hl { fill: #f3d995 !important; }

.busy {
  position: absolute; right: 14px; bottom: 14px; background: rgba(15,15,14,.85); border: 1px solid var(--line);
  border-radius: 999px; padding: 4px 12px; font-size: 11px; color: var(--gold);
}

/* ---------- デモ・モード ---------- */
.demo-idle { margin-top: 10px; color: var(--muted); }
body.demo .app { grid-template-columns: minmax(0, 1fr); grid-template-areas: "top" "stage"; }
body.demo .library, body.demo .inspector, body.demo .title-block, body.demo .tools-3d, body.demo .hover-info { display: none !important; }
body.demo .stage { height: auto; }
body.demo .gl canvas { cursor: default; }
.demo-overlay { position: absolute; inset: 0; pointer-events: none; z-index: 3; }
.demo-intro, .demo-caption { position: absolute; opacity: 0; transition: opacity .9s ease, transform .9s ease; }
.demo-intro {
  inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 10px;
  background: radial-gradient(70% 60% at 50% 50%, rgba(12, 12, 11, 0.86) 0%, rgba(12, 12, 11, 0.55) 70%, rgba(12, 12, 11, 0) 100%);
  transform: scale(0.98); padding: 0 24px;
}
.demo-overlay.show-intro .demo-intro { opacity: 1; transform: none; }
.demo-intro-name { margin: 0; font-family: var(--display); font-weight: 400; font-size: clamp(40px, 7vw, 84px); letter-spacing: 0.08em; color: var(--text); }
.demo-intro-sub { margin: 0; font-family: var(--display); font-style: italic; font-size: clamp(18px, 2.6vw, 28px); color: var(--gold); letter-spacing: 0.05em; }
.demo-intro-ja { margin: 6px 0 0; font-family: var(--serif-ja); font-size: clamp(12px, 1.5vw, 15px); letter-spacing: 0.3em; color: var(--muted); }
.demo-intro-desc { margin: 14px 0 0; font-family: var(--serif-ja); font-size: clamp(13px, 1.6vw, 16px); line-height: 1.9; color: var(--text); }
.demo-overlay .nb { display: inline-block; }
.demo-caption { left: max(28px, env(safe-area-inset-left, 0px)); bottom: 84px; max-width: min(520px, calc(100% - 56px)); transform: translateY(8px); }
.demo-overlay.show-scene .demo-caption { opacity: 1; transform: none; }
.demo-count { margin: 0 0 6px; font-family: var(--mono); font-size: 11px; color: var(--gold); letter-spacing: 0.1em; }
.demo-ja { margin: 0; font-family: var(--serif-ja); font-weight: 500; font-size: clamp(22px, 3vw, 34px); letter-spacing: 0.12em; color: var(--text); text-shadow: 0 2px 16px rgba(0,0,0,.6); }
.demo-en { margin: 2px 0 10px; font-family: var(--display); font-style: italic; font-size: clamp(16px, 2vw, 22px); color: var(--gold); }
.demo-note { margin: 0; font-size: 13px; line-height: 1.8; color: var(--text); opacity: .85; text-shadow: 0 1px 10px rgba(0,0,0,.7); }
.demo-progress { position: absolute; left: 0; right: 0; top: 0; height: 2px; background: rgba(196, 162, 101, 0.15); }
.demo-progress span { display: block; height: 100%; width: 0; background: var(--gold); transition: width .8s ease; }
.demo-exit { position: absolute; right: 18px; top: 14px; margin: 0; font-size: 11px; color: var(--muted); letter-spacing: 0.08em; }
@media (max-width: 920px) {
  body.demo .stage { height: calc(100dvh - 60px); min-height: 420px; }
  .demo-caption { bottom: 76px; }
  .demo-exit { right: 12px; }
}

/* 使い方 */
.help ol { margin: 0 0 10px; padding-left: 1.3em; color: var(--muted); font-size: 12px; line-height: 1.7; }
.help ol li::marker { color: var(--gold); font-family: var(--mono); font-size: 11px; }
.help-keys dd { font-family: var(--sans); font-size: 11.5px; color: var(--text); }

/* 情報パネル */
.info-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; margin-bottom: 12px; }
.info-grid.five { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.info-grid div { background: var(--panel-2); border-radius: 6px; padding: 6px 4px; text-align: center; }
.info-grid b { display: block; font-family: var(--mono); font-weight: 500; font-size: 15px; font-variant-numeric: tabular-nums; }
.info-grid span { color: var(--muted); font-size: 10.5px; }
.info-h { font-size: 11px; color: var(--muted); letter-spacing: 0.1em; margin: 12px 0 4px; }
.legend { list-style: none; margin: 0; padding: 0; }
.legend li { display: grid; grid-template-columns: 14px minmax(0, 1fr) auto; gap: 8px; align-items: center; padding: 3px 0; font-size: 12px; cursor: default; }
.legend .sw { width: 14px; height: 14px; border-radius: 3px; box-shadow: inset 0 0 0 1px rgba(255,255,255,.15); }
.legend .ct { font-family: var(--mono); font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.kv { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 10px; font-size: 12px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-family: var(--mono); font-size: 11.5px; text-align: right; font-variant-numeric: tabular-nums; }
.tags { display: flex; flex-wrap: wrap; gap: 4px; }
.tags span { font-family: var(--mono); font-size: 11px; border: 1px solid var(--line); border-radius: 4px; padding: 0 6px; }

/* ---------- 狭い画面 ---------- */
@media (max-width: 1180px) {
  :root { --lib-w: 236px; --insp-w: 268px; }
}
@media (max-width: 920px) {
  body { overflow: auto; }
  .app {
    height: auto;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto auto auto;
    grid-template-areas: "top" "stage" "insp" "lib";
  }
  .topbar { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; padding: 8px max(16px, env(safe-area-inset-left, 0px)); flex-wrap: wrap; height: auto; }
  .brand-sub { display: none; }
  .stage, .stage[data-view="split"] { height: 68vh; min-height: 380px; grid-template-columns: minmax(0, 1fr); }
  .stage[data-view="split"] .pane-net { display: none; }
  .library, .inspector { border: 0; border-top: 1px solid var(--line); }
  .panel-scroll { overflow: visible; }
  .block { padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
  #view-split { display: none; }
  .lib-cat > summary { min-height: 48px; padding-top: 10px; padding-bottom: 10px; align-content: center; }
  .lib-item { padding-top: 8px; padding-bottom: 8px; }
  details > summary.block-title { min-height: 40px; align-items: center; }
}
@media (hover: none) {
  .lib-cat > summary:hover { background: none; }
  .lib-cat[open] > summary { background: rgba(196, 162, 101, 0.06); }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---------- スマホ: 立体の下に、タブつきの操作パネル ---------- */
#msheet, .stepper, .fold-chips { display: none; }
@media (max-width: 920px) {
  html, body { height: 100%; }
  body { overflow: hidden; }
  .app {
    --sheet-h: 42dvh;
    height: 100%;
    height: 100dvh;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) var(--sheet-h);
    grid-template-areas: "top" "stage" "sheet";
  }
  body.msheet-tall .app { --sheet-h: 66dvh; }
  .topbar { position: static; flex-wrap: nowrap; padding: 6px max(12px, env(safe-area-inset-right, 0px)) 6px max(12px, env(safe-area-inset-left, 0px)); gap: 8px; }
  .brand-name { font-size: 18px; }
  .top-actions { gap: 6px; }
  .demo-btn { padding: 4px 9px 4px 8px; }
  .lang-btn { padding: 3px 8px; }
  .brand-wrap { gap: 6px; }
  .ver-chip { padding: 1px 6px; font-size: 10.5px; }
  .seg button { padding: 4px 10px; }
  .stage, .stage[data-view="split"] { height: auto; min-height: 0; }
  .library, .inspector { display: none; }
  .title-block { left: 14px; top: 10px; max-width: calc(100% - 120px); }
  .title-block h1 { font-size: 17px; }
  .poly-en { font-size: 14px; }
  .tools-3d { right: 10px; top: 10px; }
  .hover-info { left: 12px; bottom: 58px; }

  #msheet {
    grid-area: sheet; display: flex; flex-direction: column; min-height: 0;
    background: var(--panel); border-top: 1px solid var(--line);
  }
  .mtabs {
    display: flex; flex: none; border-bottom: 1px solid var(--line);
    padding: 0 max(4px, env(safe-area-inset-right, 0px)) 0 max(4px, env(safe-area-inset-left, 0px));
  }
  .mtabs button {
    flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 2px;
    padding: 7px 2px 5px; background: none; border: 0; border-bottom: 2px solid transparent;
    color: var(--muted); font-size: 10.5px; letter-spacing: 0.08em; cursor: pointer;
  }
  .mtabs button svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
  .mtabs button[aria-selected="true"] { color: var(--gold); border-bottom-color: var(--gold); }
  .mtabs button[hidden] { display: none; }
  .mtabs .msheet-size { flex: 0 0 40px; justify-content: center; }
  .mtabs .msheet-size svg { transition: transform .2s ease; }
  body.msheet-tall .mtabs .msheet-size svg { transform: rotate(180deg); }
  .msheet-body { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding-bottom: env(safe-area-inset-bottom, 0px); }
  #msheet .m-off { display: none !important; }
  #msheet details > summary.block-title { display: none; }
  #msheet .block { border-bottom: 1px solid var(--line); }

  /* スライダーをステッパーに */
  .row { grid-template-columns: 92px minmax(0, 1fr) auto; }
  .row input[type="range"], .row input[type="range"] + .stepper + output, .row output { display: none; }
  .stepper {
    display: inline-grid; grid-template-columns: 44px minmax(56px, 1fr) 44px; align-items: center;
    grid-column: 2 / -1; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--panel-2);
  }
  .stepper button {
    height: 36px; border: 0; background: none; color: var(--text); font-size: 18px; line-height: 1; cursor: pointer;
    touch-action: manipulation; -webkit-user-select: none; user-select: none;
  }
  .stepper button:active { background: var(--gold-soft); color: var(--gold); }
  .st-val { text-align: center; font-family: var(--mono); font-size: 12px; color: var(--gold); font-variant-numeric: tabular-nums; border-left: 1px solid var(--line); border-right: 1px solid var(--line); line-height: 36px; }

  /* 展開スライダーを「閉・半・開」に */
  .foldbar { display: flex; width: auto; gap: 8px; padding: 4px 10px 4px 4px; bottom: 10px; }
  .foldbar input[type="range"] { display: none; }
  .fold-label { white-space: nowrap; }
  .fold-chips { display: inline-flex; gap: 4px; }
  .fold-chips button {
    min-width: 38px; height: 30px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel-2);
    color: var(--text); font-size: 12px; cursor: pointer; touch-action: manipulation;
  }
  .fold-chips button[aria-pressed="true"] { border-color: var(--gold); color: var(--gold); background: var(--gold-soft); }
  .foldbar output { order: 5; min-width: 34px; }

  /* デモ中はパネルを隠して立体だけにする */
  body.demo #msheet { display: none; }
  body.demo .app { grid-template-rows: auto minmax(0, 1fr); grid-template-areas: "top" "stage"; }
  body.demo .stage { height: auto; min-height: 0; }
}

/* ---------- 印刷 ---------- */
#print-root { display: none; }
@media print {
  html, body { height: auto; overflow: visible; background: #fff; }
  .app { display: none !important; }
  #print-root { display: block; }
  #print-root .print-page { break-after: page; page-break-after: always; margin: 0; padding: 0; }
  #print-root .print-page:last-child { break-after: auto; page-break-after: auto; }
  #print-root svg { display: block; }
}
