/* Fabrica — layout: a full-bleed 3D stage framed by two instrument panels (layers left, structure right)
   under a slim toolbar; on phones the panels become bottom sheets. Neutrals lean slightly teal toward the accent. */
:root {
  --paper: #eaeef0;          /* app ground */
  --panel: #fbfcfc;          /* panel surface */
  --panel-2: #f1f4f5;        /* nested surface, hover */
  --ink: #15212a;            /* primary text */
  --ink-2: #4a5964;          /* secondary text */
  --ink-3: #7a8892;          /* captions */
  --rule: #d8e0e3;           /* hairlines */
  --accent: #0b7c88;         /* UI accent: surgical teal */
  --accent-ink: #ffffff;
  --accent-soft: #d3ecee;
  --stage-hi: #f8fafa;       /* 3D backdrop, centre */
  --stage-lo: #cdd6db;       /* 3D backdrop, edge */
  --hl: #12b4cc;             /* selection glow in 3D (read by the renderer) */
  --origin: #cf4336;         /* muscle origin */
  --insertion: #3c6fd4;      /* muscle insertion */
  --good: #2f8f4e;
  --bad: #c2412f;
  --shadow: 0 1px 2px rgb(16 32 40 / 6%), 0 8px 28px rgb(16 32 40 / 10%);

  --font-display: "Cormorant Garamond", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --font-ui: "IBM Plex Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;

  --fs-cap: 0.75rem;   /* 12 */
  --fs-sm: 0.8125rem;  /* 13 */
  --fs-md: 0.875rem;   /* 14 */
  --fs-lg: 1rem;       /* 16 */
  --fs-xl: 1.375rem;   /* 22 */
  --fs-title: 1.95rem; /* ~31, display serif */

  --top-h: 56px;
  --left-w: 300px;
  --right-w: 372px;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0d1215; --panel: #141b20; --panel-2: #1b242a; --ink: #e3eaee; --ink-2: #a3b1b9; --ink-3: #72828c;
    --rule: #263238; --accent: #3cc4d3; --accent-ink: #052126; --accent-soft: #113a40;
    --stage-hi: #25313a; --stage-lo: #090d10; --hl: #43d8ee; --origin: #f06a5c; --insertion: #6f9cf2;
    --good: #5cc27e; --bad: #f07a66; --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 10px 30px rgb(0 0 0 / 35%);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #0d1215; --panel: #141b20; --panel-2: #1b242a; --ink: #e3eaee; --ink-2: #a3b1b9; --ink-3: #72828c;
  --rule: #263238; --accent: #3cc4d3; --accent-ink: #052126; --accent-soft: #113a40;
  --stage-hi: #25313a; --stage-lo: #090d10; --hl: #43d8ee; --origin: #f06a5c; --insertion: #6f9cf2;
  --good: #5cc27e; --bad: #f07a66; --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 10px 30px rgb(0 0 0 / 35%);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; overflow: hidden;
  background: var(--paper); color: var(--ink);
  font: 400 var(--fs-md)/1.45 var(--font-ui);
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h2, h3 { margin: 0; text-wrap: balance; }
.ico { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.ico .fill { fill: currentColor; stroke: none; }

/* ------------------------------------------------------------ app grid */
.app {
  height: 100%;
  display: grid;
  grid-template-rows: var(--top-h) minmax(0, 1fr);
  grid-template-columns: var(--left-w) minmax(0, 1fr) var(--right-w);
  grid-template-areas: "top top top" "left stage right";
}
.app[data-left="closed"] { grid-template-columns: 0 minmax(0, 1fr) var(--right-w); }
.app[data-right="closed"] { grid-template-columns: var(--left-w) minmax(0, 1fr) 0; }
.app[data-left="closed"][data-right="closed"] { grid-template-columns: 0 minmax(0, 1fr) 0; }
.app[data-left="closed"] .panel-left, .app[data-right="closed"] .panel-right { visibility: hidden; }

/* ------------------------------------------------------------ top bar */
.topbar {
  grid-area: top;
  display: flex; align-items: center; gap: 16px;
  padding-inline: 16px;
  background: var(--panel); border-bottom: 1px solid var(--rule);
  position: relative; z-index: 30;
  min-width: 0;
}
.brand { display: flex; align-items: baseline; gap: 10px; flex: none; }
.brand-mark { width: 24px; height: 24px; align-self: center; fill: none; stroke: var(--accent); stroke-width: 2.1; stroke-linecap: round; }
.brand-name { font-family: var(--font-display); font-weight: 600; font-size: 1.6rem; letter-spacing: .01em; line-height: 1; }
.brand-sub { font-size: var(--fs-cap); color: var(--ink-3); text-transform: uppercase; letter-spacing: .12em; }

.search { position: relative; flex: 1 1 420px; max-width: 560px; min-width: 0; display: flex; align-items: center; }
.search > .ico { position: absolute; left: 12px; color: var(--ink-3); pointer-events: none; }
.search input {
  width: 100%; height: 38px; padding: 0 40px 0 38px;
  border: 1px solid var(--rule); border-radius: 999px; background: var(--panel-2);
  outline: none; transition: border-color .15s, background .15s;
}
.search input:focus { border-color: var(--accent); background: var(--panel); }
.search input::-webkit-search-cancel-button { display: none; }
.kbd-hint, kbd {
  font: 500 11px var(--font-mono); color: var(--ink-3);
  border: 1px solid var(--rule); border-bottom-width: 2px; border-radius: 5px; padding: 1px 6px; background: var(--panel);
}
.search .kbd-hint { position: absolute; right: 12px; pointer-events: none; }
.search input:focus ~ .kbd-hint { display: none; }
.search-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0;
  max-height: min(62vh, 520px); overflow-y: auto;
  background: var(--panel); border: 1px solid var(--rule); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 6px; z-index: 40;
}
.result {
  display: grid; grid-template-columns: 10px minmax(0, 1fr) auto; align-items: center; gap: 10px;
  width: 100%; text-align: left; padding: 7px 10px; border: 0; border-radius: 7px; background: none;
}
.result[aria-selected="true"], .result:hover { background: var(--panel-2); }
.result .dot { width: 10px; height: 10px; border-radius: 50%; }
.result .r-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result .r-name small { color: var(--ink-3); margin-left: 6px; }
.result .r-meta { font-size: var(--fs-cap); color: var(--ink-3); white-space: nowrap; }
.result mark { background: none; color: var(--accent); font-weight: 600; }
.results-empty { padding: 14px 10px; color: var(--ink-3); }

.top-actions { display: flex; align-items: center; gap: 6px; margin-left: auto; flex: none; }
.seg { display: inline-flex; padding: 3px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--rule); margin-right: 6px; }
.seg button { border: 0; background: none; padding: 5px 12px; border-radius: 999px; font-size: var(--fs-sm); color: var(--ink-2); }
.seg button[aria-checked="true"] { background: var(--panel); color: var(--ink); box-shadow: 0 1px 2px rgb(0 0 0 / 12%); font-weight: 500; }
.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px;
  border: 1px solid transparent; border-radius: 9px; background: none; color: var(--ink-2);
}
.icon-btn:hover:not(:disabled) { background: var(--panel-2); color: var(--ink); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.icon-btn.small { width: 28px; height: 28px; }
.pill-btn {
  display: inline-flex; align-items: center; gap: 7px; height: 34px; padding: 0 14px 0 11px;
  border: 1px solid var(--rule); border-radius: 999px; background: var(--panel); color: var(--ink); font-weight: 500;
}
.pill-btn:hover { border-color: var(--accent); color: var(--accent); }
.pill-btn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.text-btn { border: 0; background: none; color: var(--accent); font-size: var(--fs-sm); font-weight: 500; padding: 4px 6px; border-radius: 6px; }
.text-btn:hover { background: var(--accent-soft); }

/* ------------------------------------------------------------ panels */
.panel {
  min-width: 0; min-height: 0; overflow: hidden;
  display: flex; flex-direction: column;
  background: var(--panel); position: relative; z-index: 10;
}
.panel-left { grid-area: left; border-right: 1px solid var(--rule); }
.panel-right { grid-area: right; border-left: 1px solid var(--rule); }
.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 12px 12px 10px 16px; border-bottom: 1px solid var(--rule); flex: none;
}
.panel-head h2 { font-size: var(--fs-cap); font-weight: 600; text-transform: uppercase; letter-spacing: .12em; color: var(--ink-3); }
.panel-head-actions { display: flex; align-items: center; gap: 4px; }
.panel-body { overflow-y: auto; overscroll-behavior: contain; flex: 1; min-height: 0; padding: 8px 0 24px; scrollbar-width: thin; }

/* layers */
.layer-list { list-style: none; margin: 0; padding: 0 8px; }
.layer { border-radius: 9px; }
.layer + .layer { margin-top: 1px; }
.layer-row {
  display: grid; grid-template-columns: 30px 12px minmax(0, 1fr) auto 26px; align-items: center; gap: 8px;
  padding: 4px 4px 4px 2px; border-radius: 9px;
}
.layer-row:hover { background: var(--panel-2); }
.layer.open > .layer-row { background: var(--panel-2); }
.eye {
  display: inline-grid; place-items: center; width: 30px; height: 30px; border: 0; border-radius: 7px; background: none; color: var(--ink-3);
}
.eye:hover { color: var(--ink); background: var(--panel); }
.eye[aria-pressed="true"] { color: var(--accent); }
.swatch { width: 12px; height: 12px; border-radius: 4px; box-shadow: inset 0 0 0 1px rgb(0 0 0 / 15%); }
.layer-name { border: 0; background: none; text-align: left; padding: 6px 0; font-weight: 500; min-width: 0; line-height: 1.25; overflow-wrap: anywhere; }
.layer-off .layer-name { color: var(--ink-2); font-weight: 400; }
.layer-count { font: 400 var(--fs-cap) var(--font-mono); color: var(--ink-3); font-variant-numeric: tabular-nums; }
.layer-count.loading { color: var(--accent); }
.chev { display: inline-grid; place-items: center; width: 26px; height: 26px; border: 0; background: none; border-radius: 6px; color: var(--ink-3); }
.chev:hover { background: var(--panel); color: var(--ink); }
.chev .ico { transition: transform .15s; }
.layer.open .chev .ico { transform: rotate(90deg); }
.layer-detail { padding: 4px 4px 10px 40px; }
.opacity-row { display: grid; grid-template-columns: auto 1fr 3.2em; align-items: center; gap: 10px; font-size: var(--fs-cap); color: var(--ink-3); padding: 2px 6px 8px 0; }
.opacity-row output { font-family: var(--font-mono); text-align: right; font-variant-numeric: tabular-nums; }
input[type="range"] { accent-color: var(--accent); width: 100%; min-width: 0; height: 18px; }

/* structure tree */
.tree { list-style: none; margin: 0; padding: 0; font-size: var(--fs-sm); }
.tree .tree { padding-left: 14px; border-left: 1px solid var(--rule); margin-left: 8px; }
.tnode-row { display: grid; grid-template-columns: 18px 24px minmax(0, 1fr); align-items: center; gap: 2px; border-radius: 6px; }
.tnode-row:hover { background: var(--panel-2); }
.tnode-row.selected { background: var(--accent-soft); }
.tnode-row .tchev { width: 18px; height: 22px; border: 0; padding: 0; background: none; color: var(--ink-3); display: grid; place-items: center; }
.tnode-row .tchev .ico { width: 13px; height: 13px; transition: transform .15s; }
.tnode.open > .tnode-row .tchev .ico { transform: rotate(90deg); }
.tnode-row .teye { width: 24px; height: 24px; border: 0; padding: 0; background: none; color: var(--ink-3); display: grid; place-items: center; border-radius: 5px; }
.tnode-row .teye .ico { width: 15px; height: 15px; }
.tnode-row .teye[aria-pressed="true"] { color: var(--ink-2); }
.tnode-row .teye[aria-pressed="false"] { color: var(--ink-3); opacity: .55; }
.tnode-row .tlabel { border: 0; background: none; text-align: left; padding: 3px 4px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border-radius: 5px; }
.tnode-row .tlabel .tcount { color: var(--ink-3); font-size: var(--fs-cap); margin-left: 5px; font-variant-numeric: tabular-nums; }
.tnode.is-hidden > .tnode-row .tlabel { color: var(--ink-3); }
.tree-more { border: 0; background: none; color: var(--accent); font-size: var(--fs-cap); padding: 4px 8px; }

.tool-section { margin: 14px 8px 0; padding: 14px 8px 0; border-top: 1px solid var(--rule); display: grid; gap: 8px; }
.tool-section h3 { font-size: var(--fs-cap); font-weight: 600; text-transform: uppercase; letter-spacing: .12em; color: var(--ink-3); }
.hint { margin: 0; font-size: var(--fs-cap); color: var(--ink-3); }
.clip-rows { display: grid; gap: 6px; }
.clip-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 10px; }
.clip-row label.switch { min-width: 7.2em; }
.clip-row input[type="range"]:disabled { opacity: .35; }
.flip { border: 1px solid var(--rule); background: var(--panel); border-radius: 6px; font-size: var(--fs-cap); padding: 2px 7px; color: var(--ink-2); }
.flip:disabled { opacity: .35; }
.side-toggles { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-toggle { position: relative; }
.chip-toggle input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.chip-toggle span { display: inline-block; padding: 4px 12px; border-radius: 999px; border: 1px solid var(--rule); color: var(--ink-3); font-size: var(--fs-sm); }
.chip-toggle input:checked + span { background: var(--accent-soft); border-color: transparent; color: var(--ink); }
.chip-toggle input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch { display: flex; align-items: center; gap: 9px; font-size: var(--fs-sm); color: var(--ink-2); cursor: pointer; }
.switch input { accent-color: var(--accent); width: 15px; height: 15px; margin: 0; flex: none; }

/* ------------------------------------------------------------ stage */
.stage {
  grid-area: stage; position: relative; min-width: 0; min-height: 0; overflow: hidden;
  background: radial-gradient(ellipse 75% 70% at 50% 42%, var(--stage-hi), var(--stage-lo));
  touch-action: none;
  container: stage / size;
}
#gl { position: absolute; inset: 0; width: 100%; height: 100%; display: block; outline: none; }
.stage.mode-hide #gl { cursor: crosshair; }
.stage.mode-fade #gl { cursor: cell; }
.overlay, .overlay-lines { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.overlay-lines { width: 100%; height: 100%; }
.overlay-lines line { stroke: var(--ink); stroke-width: 1; opacity: .7; }
.overlay-lines circle { fill: var(--panel); stroke: var(--ink); stroke-width: 1.4; }

.tag {
  position: absolute; left: 0; top: 0; pointer-events: auto; cursor: pointer;
  padding: 4px 9px 5px; border-radius: 7px; background: var(--panel); color: var(--ink);
  font-size: var(--fs-sm); font-weight: 500; line-height: 1.25; white-space: nowrap; box-shadow: var(--shadow);
  border: 1px solid var(--rule); max-width: 260px; overflow: hidden; text-overflow: ellipsis;
}
.tag.primary { border-color: var(--accent); }
.tag .tag-sub { display: block; font: italic 500 var(--fs-sm) var(--font-display); color: var(--ink-2); }
.tag .x { margin-left: 8px; color: var(--ink-3); }
.lm-tag {
  position: absolute; left: 0; top: 0; pointer-events: auto; cursor: pointer;
  font-size: 11.5px; line-height: 1.2; color: var(--ink); white-space: nowrap;
  padding: 2px 6px; border-radius: 5px; background: var(--panel); background: color-mix(in srgb, var(--panel) 82%, transparent);
  border: 1px solid var(--rule); transition: opacity .15s;
}
.lm-tag.hidden-behind { opacity: 0; pointer-events: none; }
.lm-tag:hover, .lm-tag.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.tooltip {
  position: absolute; left: 0; top: 0; pointer-events: none; z-index: 5;
  display: flex; align-items: center; gap: 7px;
  padding: 5px 9px; border-radius: 7px; background: var(--ink); color: var(--panel);
  font-size: var(--fs-sm); white-space: nowrap; max-width: 340px; overflow: hidden; text-overflow: ellipsis;
}
.tooltip .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }

.orient { position: absolute; left: 12px; bottom: 12px; width: 84px; height: 84px; }
#gizmo { width: 84px; height: 84px; cursor: pointer; }
.view-dock {
  position: absolute; left: 50%; top: 12px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 2px; padding: 3px;
  background: var(--panel); background: color-mix(in srgb, var(--panel) 88%, transparent);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  border: 1px solid var(--rule); border-radius: 10px; box-shadow: var(--shadow);
}
.view-dock button { border: 0; background: none; padding: 5px 9px; border-radius: 7px; font-size: var(--fs-cap); font-weight: 500; color: var(--ink-2); letter-spacing: .02em; display: inline-grid; place-items: center; white-space: nowrap; }
.view-dock button:hover { background: var(--panel-2); color: var(--ink); }
.view-dock .ico { width: 16px; height: 16px; }
.dock-sep { width: 1px; height: 18px; background: var(--rule); margin: 0 3px; }

.selbar {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 2px; padding: 4px 4px 4px 14px; max-width: calc(100% - 24px);
  background: var(--panel); border: 1px solid var(--rule); border-radius: 12px; box-shadow: var(--shadow);
}
.selbar-name { font-weight: 600; font-size: var(--fs-sm); margin-right: 8px; min-width: 0; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.selbar button { display: inline-flex; align-items: center; gap: 6px; border: 0; background: none; padding: 6px 10px; border-radius: 8px; font-size: var(--fs-sm); color: var(--ink-2); white-space: nowrap; }
.selbar button:hover { background: var(--panel-2); color: var(--ink); }
.selbar button .ico { width: 16px; height: 16px; }

.panel-reopen {
  position: absolute; top: 12px; display: none; place-items: center; width: 36px; height: 36px;
  border: 1px solid var(--rule); border-radius: 9px; background: var(--panel); color: var(--ink-2); box-shadow: var(--shadow); z-index: 4;
}
.panel-reopen.left { left: 12px; }
.panel-reopen.right { right: 12px; }
.app[data-left="closed"] .panel-reopen.left, .app[data-right="closed"] .panel-reopen.right { display: grid; }

.load-bar { position: absolute; left: 0; right: 0; top: 0; height: 2px; background: transparent; }
.load-bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.toast {
  position: absolute; left: 50%; bottom: 72px; transform: translateX(-50%);
  background: var(--ink); color: var(--panel); padding: 8px 14px; border-radius: 9px; font-size: var(--fs-sm); box-shadow: var(--shadow);
  max-width: calc(100% - 32px);
}

/* ------------------------------------------------------------ info panel */
.info { padding: 6px 20px 0; display: grid; gap: 18px; }
.info-empty { padding: 18px 20px; display: grid; gap: 18px; color: var(--ink-2); }
.info-empty h3 { font: 600 var(--fs-xl)/1.2 var(--font-display); color: var(--ink); font-size: 1.6rem; }
.info-empty p { margin: 0; }
.howto { display: grid; gap: 9px; margin: 0; padding: 0; list-style: none; }
.howto li { display: grid; grid-template-columns: 92px 1fr; gap: 10px; font-size: var(--fs-sm); }
.howto b { font-weight: 500; color: var(--ink); }
.suggest { display: flex; flex-wrap: wrap; gap: 6px; }
.offline-card { display: grid; gap: 8px; padding: 14px 16px; border: 1px solid var(--rule); border-radius: var(--radius); background: var(--panel-2); }
.offline-card h3 { font: 600 1.2rem/1.2 var(--font-display); color: var(--ink); }
.offline-card p { font-size: var(--fs-sm); }
.off-bar { width: 100%; }
.suggest button { border: 1px solid var(--rule); background: var(--panel); border-radius: 999px; padding: 4px 11px; font-size: var(--fs-sm); color: var(--ink-2); }
.suggest button:hover { border-color: var(--accent); color: var(--accent); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px 3px; border-radius: 999px; background: var(--panel-2); font-size: var(--fs-cap); color: var(--ink-2); border: 0; }
button.chip:hover { color: var(--ink); background: var(--accent-soft); }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; }
.title-block { display: grid; gap: 4px; }
.s-title { font: 600 var(--fs-title)/1.08 var(--font-display); letter-spacing: .005em; text-wrap: balance; overflow-wrap: anywhere; }
.s-latin { font: italic 500 1.2rem/1.25 var(--font-display); color: var(--ink-2); overflow-wrap: anywhere; }
.s-alt { font-size: var(--fs-sm); color: var(--ink-3); }
.actions { display: flex; flex-wrap: wrap; gap: 6px; }
.act {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 11px; border-radius: 8px;
  border: 1px solid var(--rule); background: var(--panel); font-size: var(--fs-sm); color: var(--ink-2);
}
.act:hover { border-color: var(--accent); color: var(--accent); }
.act .ico { width: 15px; height: 15px; }
.act.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.act.primary:hover { filter: brightness(1.08); color: var(--accent-ink); }

.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 4px; font-size: var(--fs-cap); color: var(--ink-3); }
.crumbs button { border: 0; background: none; padding: 1px 3px; border-radius: 4px; color: var(--ink-2); font-size: var(--fs-cap); }
.crumbs button:hover { color: var(--accent); background: var(--accent-soft); }
.crumbs .sep { opacity: .6; }

.block { display: grid; gap: 8px; }
.block > h3 { font-size: var(--fs-cap); font-weight: 600; text-transform: uppercase; letter-spacing: .12em; color: var(--ink-3); }
.facts { display: grid; grid-template-columns: minmax(84px, max-content) minmax(0, 1fr); margin: 0; border-top: 1px solid var(--rule); }
.facts dt, .facts dd { margin: 0; padding: 7px 0; border-bottom: 1px solid var(--rule); font-size: var(--fs-sm); }
.facts dt { color: var(--ink-3); padding-right: 14px; }
.facts dd { color: var(--ink); min-width: 0; overflow-wrap: anywhere; }
.facts dd .lnk, .lnk { border: 0; background: none; padding: 0; color: var(--accent); text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--accent) 35%, transparent); text-underline-offset: 2px; font-size: inherit; text-align: left; }
.facts dd .lnk:hover, .lnk:hover { text-decoration-color: var(--accent); }
.att-list { display: grid; gap: 4px; margin: 0; padding: 0; list-style: none; font-size: var(--fs-sm); }
.att-list li { display: grid; grid-template-columns: 10px minmax(0, 1fr); gap: 9px; align-items: baseline; }
.att-list .mk { width: 10px; height: 10px; border-radius: 3px; transform: translateY(1px); }
.mk.o { background: var(--origin); }
.mk.e { background: var(--insertion); }
.att-legend { display: flex; gap: 14px; font-size: var(--fs-cap); color: var(--ink-3); }
.att-legend span { display: inline-flex; align-items: center; gap: 6px; }
.lm-list { display: flex; flex-wrap: wrap; gap: 5px; }
.lm-list button { border: 1px solid var(--rule); background: var(--panel); border-radius: 6px; padding: 2px 8px; font-size: var(--fs-cap); color: var(--ink-2); }
.lm-list button:hover, .lm-list button.active { border-color: var(--accent); color: var(--accent); }

.prose { font-size: var(--fs-md); line-height: 1.6; color: var(--ink); max-width: 65ch; }
.prose p { margin: 0 0 .75em; }
.prose details { border-top: 1px solid var(--rule); }
.prose details:last-child { border-bottom: 1px solid var(--rule); }
.prose summary { cursor: pointer; padding: 9px 0; font-weight: 600; font-size: var(--fs-sm); list-style: none; display: flex; justify-content: space-between; align-items: center; color: var(--ink); }
.prose summary::-webkit-details-marker { display: none; }
.prose summary::after { content: "+"; font: 400 1.1rem var(--font-mono); color: var(--ink-3); }
.prose details[open] > summary::after { content: "–"; }
.prose details > div { padding-bottom: 6px; }
.prose h4 { font-size: var(--fs-sm); margin: .6em 0 .3em; color: var(--ink-2); }
.source { font-size: var(--fs-cap); color: var(--ink-3); }
.source a { color: var(--ink-2); }
.trans { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 14px; font-size: var(--fs-sm); margin: 0; }
.trans dt { color: var(--ink-3); font-family: var(--font-mono); font-size: var(--fs-cap); text-transform: uppercase; padding-top: 2px; }
.trans dd { margin: 0; overflow-wrap: anywhere; }
.trans dd.la { font: italic 500 1.02rem var(--font-display); }
.ids { display: flex; flex-wrap: wrap; gap: 6px; }
.ids span { font: 400 var(--fs-cap) var(--font-mono); background: var(--panel-2); border-radius: 5px; padding: 2px 7px; color: var(--ink-2); }
.links { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: var(--fs-sm); }
.links a { color: var(--accent); text-decoration: none; }
.links a:hover { text-decoration: underline; }
.lm-detail { border: 1px solid var(--accent); border-radius: var(--radius); padding: 12px 14px; display: grid; gap: 6px; background: var(--panel); }
.lm-detail h4 { margin: 0; font: 600 1.2rem/1.2 var(--font-display); }
.lm-detail .s-latin { font-size: 1rem; }
.lm-detail .prose { font-size: var(--fs-sm); }
.muted { color: var(--ink-3); }
.kid-list { display: flex; flex-wrap: wrap; gap: 5px; }
.kid-list button { border: 1px solid var(--rule); background: var(--panel); border-radius: 6px; padding: 2px 8px; font-size: var(--fs-cap); color: var(--ink-2); }
.kid-list button:hover { border-color: var(--accent); color: var(--accent); }

/* quiz */
.quiz { padding: 8px 20px; display: grid; gap: 16px; }
.quiz-score { display: flex; gap: 18px; font-variant-numeric: tabular-nums; }
.quiz-score div { display: grid; }
.quiz-score b { font: 600 1.7rem/1 var(--font-display); }
.quiz-score span { font-size: var(--fs-cap); color: var(--ink-3); text-transform: uppercase; letter-spacing: .1em; }
.quiz-q { font: 600 1.45rem/1.2 var(--font-display); text-wrap: balance; }
.quiz-options { display: grid; gap: 7px; }
.quiz-options button { text-align: left; border: 1px solid var(--rule); background: var(--panel); border-radius: 9px; padding: 10px 12px; font-size: var(--fs-md); }
.quiz-options button:hover:not(:disabled) { border-color: var(--accent); }
.quiz-options button.right { border-color: var(--good); border-width: 2px; background: color-mix(in srgb, var(--good) 14%, var(--panel)); }
.quiz-options button.wrong { border-color: var(--bad); border-width: 2px; background: color-mix(in srgb, var(--bad) 12%, var(--panel)); }
.quiz-feedback { font-size: var(--fs-md); min-height: 1.4em; }
.quiz-feedback.right { color: var(--good); }
.quiz-feedback.wrong { color: var(--bad); }
.quiz-modes { display: flex; gap: 6px; }

/* modal */
.modal { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 16px; background: rgb(8 14 18 / 45%); }
.modal-card { width: min(640px, 100%); max-height: min(86vh, 760px); display: flex; flex-direction: column; background: var(--panel); border-radius: 14px; box-shadow: var(--shadow); border: 1px solid var(--rule); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 14px 10px 20px; border-bottom: 1px solid var(--rule); }
.modal-head h2 { font: 600 1.5rem var(--font-display); }
.modal-body { padding: 16px 20px 22px; overflow-y: auto; display: grid; gap: 14px; font-size: var(--fs-md); }
.modal-body h3 { font-size: var(--fs-cap); font-weight: 600; text-transform: uppercase; letter-spacing: .12em; color: var(--ink-3); margin-top: 6px; }
.modal-body p { margin: 0; color: var(--ink-2); }
.modal-body a { color: var(--accent); }
.keys { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; font-size: var(--fs-sm); margin: 0; }
.keys dt { white-space: nowrap; }
.keys dd { margin: 0; color: var(--ink-2); }
.field { display: grid; gap: 6px; }
.field label { font-size: var(--fs-sm); font-weight: 500; }
.field select { height: 36px; border: 1px solid var(--rule); border-radius: 8px; background: var(--panel-2); padding: 0 10px; }
.shot-img { width: 100%; border-radius: 9px; border: 1px solid var(--rule); background: var(--stage-lo); }

/* boot */
.boot { position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; background: var(--paper); transition: opacity .35s; }
.boot.done { opacity: 0; pointer-events: none; }
.boot-card { display: grid; gap: 10px; justify-items: center; text-align: center; padding: 16px; }
.boot-card .brand-name { font-size: 2.8rem; }
.boot-card p { margin: 0; color: var(--ink-3); font-size: var(--fs-sm); }
.boot-bar { width: 220px; height: 3px; background: var(--rule); border-radius: 3px; overflow: hidden; }
.boot-bar span { display: block; height: 100%; width: 5%; background: var(--accent); transition: width .2s; }

.mobile-tabs { display: none; }

/* ------------------------------------------------------------ narrow screens */
@media (max-width: 1100px) {
  :root { --left-w: 270px; --right-w: 330px; }
  .brand-sub { display: none; }
  .seg button { padding: 5px 9px; }
}
@media (max-width: 860px) {
  :root { --top-h: 52px; }
  .app, .app[data-left], .app[data-right] {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: var(--top-h) minmax(0, 1fr) calc(54px + env(safe-area-inset-bottom, 0px));
    grid-template-areas: "top" "stage" "tabs";
  }
  .topbar { gap: 10px; }
  .brand-name { font-size: 1.35rem; }
  .brand-mark { display: none; }
  .seg, #btn-shot, #btn-redo, .kbd-hint { display: none; }
  .pill-btn span { display: none; }
  .pill-btn { padding: 0 9px; }
  .top-actions { gap: 2px; }
  .panel, .app[data-left="closed"] .panel-left, .app[data-right="closed"] .panel-right {
    visibility: visible;
    position: fixed; left: 0; right: 0; bottom: calc(54px + env(safe-area-inset-bottom, 0px));
    height: min(62%, 560px); border: 0; border-top: 1px solid var(--rule); border-radius: 16px 16px 0 0;
    box-shadow: var(--shadow); transform: translateY(110%); transition: transform .25s ease; z-index: 25;
  }
  .app[data-sheet="layers"] .panel-left, .app[data-sheet="info"] .panel-right { transform: translateY(0); }
  .collapse-btn, .panel-reopen, .app[data-left="closed"] .panel-reopen.left, .app[data-right="closed"] .panel-reopen.right { display: none; }
  .mobile-tabs {
    grid-area: tabs; display: grid; grid-template-columns: repeat(3, 1fr);
    background: var(--panel); border-top: 1px solid var(--rule); padding-bottom: env(safe-area-inset-bottom, 0px); z-index: 30;
  }
  .mobile-tabs button { display: grid; justify-items: center; align-content: center; gap: 2px; border: 0; background: none; color: var(--ink-3); font-size: 11px; }
  .mobile-tabs button[aria-current="true"] { color: var(--accent); }
  .view-dock { top: 8px; max-width: calc(100% - 16px); overflow-x: auto; }
  .view-dock button { padding: 5px 7px; }
  .selbar { bottom: 8px; padding-left: 10px; }
  .selbar button span { display: none; }
  .selbar-name { max-width: 40vw; }
  .orient { bottom: auto; top: 52px; left: 8px; width: 64px; height: 64px; }
  #gizmo { width: 64px; height: 64px; }
  .toast { bottom: 64px; }
}
/* stage-width adjustments: kept last so they win over the base rules above */
@container stage (max-width: 760px) {
  .selbar { left: auto; right: 12px; transform: none; max-width: calc(100% - 112px); }
  .selbar button span { display: none; }
  .selbar button { padding: 7px 8px; }
}
@container stage (max-width: 470px) {
  .view-dock button { padding: 5px 6px; }
  .selbar-name { max-width: 30cqw; }
}
/* browsers without container queries (Safari before 16) get the compact selection bar everywhere */
@supports not (container-type: size) {
  .selbar button span { display: none; }
  .selbar button { padding: 7px 8px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
