:root {
  color-scheme: light dark;
  --ink: light-dark(#1a1a1a, #f5f3ec);
  --muted: light-dark(#7c786d, #918c80);
  --quiet: light-dark(#918b7d, #777269);
  --line: light-dark(#ddd8cc, #3a3a3a);
  --panel: light-dark(rgba(255, 253, 248, .9), rgba(30, 30, 35, .9));
  --panel-solid: light-dark(#fffdf8, #1e1e23);
  --bg: light-dark(#f6f3ec, #16161a);
  --cyan: light-dark(#1552a1, #7aa6e0);
  --cyan-soft: light-dark(rgba(21, 82, 161, .1), rgba(122, 166, 224, .12));
  --gold: light-dark(#9a6300, #e0a860);
  --control: light-dark(rgba(255, 253, 248, .86), rgba(30, 30, 35, .86));
  --control-soft: light-dark(rgba(26, 26, 26, .035), rgba(255, 255, 255, .035));
  --control-hover: light-dark(rgba(21, 82, 161, .07), rgba(255, 255, 255, .06));
  --control-active: light-dark(#e8edf4, #292e38);
  --control-disabled: light-dark(#aaa497, #625e57);
  --veil: light-dark(rgba(246, 243, 236, .66), rgba(22, 22, 26, .66));
  --stage: light-dark(radial-gradient(circle at 50% 43%, #fffdf8 0, #f1ede4 42%, #e5dfd3 100%), radial-gradient(circle at 50% 43%, #282c36 0, #1d2027 42%, #16161a 100%));
  --stage-grid: light-dark(rgba(70, 68, 61, .1), rgba(200, 196, 185, .08));
  --shadow: light-dark(rgba(60, 45, 15, .14), rgba(0, 0, 0, .28));
  --radius: 14px;
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { width: 100%; min-height: 100%; margin: 0; background: var(--bg); }
body {
  min-height: 100vh;
  min-height: 100svh;
  overflow: hidden;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input { font: inherit; }
button { color: inherit; }
a { color: var(--cyan); text-underline-offset: .2em; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.topbar {
  height: 72px;
  display: grid;
  grid-template-columns: 260px 1fr 260px;
  align-items: center;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  position: relative;
  z-index: 10;
}
.back { color: var(--cyan); font-family: Georgia, "Times New Roman", serif; font-size: .9rem; }
.back:visited { color: var(--cyan); }
.title-block { text-align: center; }
.title-block h1 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: 1.45rem; font-weight: 500; letter-spacing: .015em; }
.title-block p { margin: 4px 0 0; color: var(--muted); font-size: .75rem; letter-spacing: .12em; text-transform: uppercase; }
.top-actions { justify-self: end; display: flex; align-items: center; gap: 9px; }
.icon-button {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--control-soft);
  cursor: pointer;
}
.icon-button:hover, .icon-button:focus-visible { border-color: var(--cyan); background: var(--cyan-soft); }
.icon-button svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.theme-toggle { width: 34px; height: 34px; display: grid; place-items: center; padding: 0; color: var(--ink); background: none; border: 1px solid var(--line); border-radius: 50%; cursor: pointer; }
.theme-toggle:hover { border-color: var(--cyan); }
.theme-toggle:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }
.theme-toggle svg { width: 17px; height: 17px; }
:root[data-theme="dark"] .theme-toggle .moon { display: none; }
:root[data-theme="light"] .theme-toggle .sun { display: none; }
.workspace { height: calc(100svh - 72px); display: grid; grid-template-columns: minmax(240px, 300px) minmax(0, 1fr) minmax(260px, 320px); grid-template-rows: minmax(0, 1fr); }
.catalogue, .details { min-width: 0; min-height: 0; background: var(--panel); backdrop-filter: blur(18px); }
.catalogue { display: flex; flex-direction: column; border-right: 1px solid var(--line); }
.catalogue-head { padding: 16px 14px 12px; border-bottom: 1px solid var(--line); }
.tabs { display: grid; grid-template-columns: 1fr 1fr; padding: 4px; border-radius: 11px; background: var(--control-soft); }
.tab, .filter, .family-card, .model-button { border: 0; cursor: pointer; }
.tab { padding: 9px 7px; border-radius: 8px; color: var(--muted); background: transparent; font-weight: 650; font-size: .86rem; }
.tab.active { color: var(--ink); background: var(--control-active); box-shadow: 0 1px 6px var(--shadow); }
.search-wrap { height: 40px; display: flex; align-items: center; gap: 8px; margin-top: 12px; padding: 0 11px; border: 1px solid var(--line); border-radius: 9px; color: var(--quiet); background: var(--control-soft); }
.search-wrap:focus-within { border-color: var(--cyan); }
.search-wrap svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.search-wrap input { min-width: 0; width: 100%; border: 0; outline: 0; color: var(--ink); background: transparent; font-size: .84rem; }
.search-wrap input::placeholder { color: var(--quiet); }
.filters { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.filter { padding: 6px 9px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); background: transparent; font-size: .72rem; }
.filter span { color: var(--quiet); }
.filter.active { color: var(--cyan); border-color: var(--cyan); background: var(--cyan-soft); }
.model-list, .family-list { min-height: 0; overflow-y: auto; padding: 7px; }
.model-button { width: 100%; display: grid; grid-template-columns: 1fr auto; gap: 3px 10px; padding: 10px 11px; border-radius: 9px; text-align: left; background: transparent; }
.model-button:hover { background: var(--control-hover); }
.model-button.active { background: var(--cyan-soft); box-shadow: inset 3px 0 var(--cyan); }
.model-button strong { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85rem; font-weight: 650; }
.model-button .type { color: var(--gold); font-family: Georgia, serif; font-size: .82rem; }
.model-button small { grid-column: 1 / -1; color: var(--quiet); font-size: .7rem; }
.empty { padding: 32px 18px; color: var(--muted); text-align: center; line-height: 1.5; }
.family-list { padding: 14px; }
.family-card { width: 100%; display: flex; flex-direction: column; gap: 5px; padding: 16px; margin-bottom: 10px; border: 1px solid var(--line); border-radius: 12px; text-align: left; background: var(--control-soft); }
.family-card:hover, .family-card.active { border-color: var(--cyan); background: var(--cyan-soft); }
.family-card strong { font-family: Georgia, serif; font-size: 1.12rem; font-weight: 500; }
.family-card > span:last-child { color: var(--muted); font-size: .8rem; line-height: 1.4; }
.eyebrow { color: var(--cyan); font-size: .68rem; font-weight: 750; letter-spacing: .13em; text-transform: uppercase; }
.stage { position: relative; min-width: 0; min-height: 0; overflow: hidden; background: var(--stage); container-type: size; }
.stage::before { content: ""; position: absolute; inset: 0; opacity: .7; background-image: linear-gradient(var(--stage-grid) 1px, transparent 1px), linear-gradient(90deg, var(--stage-grid) 1px, transparent 1px); background-size: 44px 44px; mask-image: radial-gradient(circle, black, transparent 72%); }
#viewer { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; outline: none; }
#viewer:active { cursor: grabbing; }
#viewer:focus-visible { box-shadow: inset 0 0 0 2px var(--cyan); }
.loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); background: var(--veil); }
.loading[hidden] { display: none; }
.gesture-hint { position: absolute; left: 50%; bottom: 258px; transform: translateX(-50%); padding: 7px 12px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); background: var(--control); font-size: .72rem; white-space: nowrap; pointer-events: none; transition: opacity .5s; }
.gesture-hint.used { opacity: 0; }
.view-controls { position: absolute; top: 16px; left: 16px; display: flex; flex-direction: column; gap: 7px; }
.view-controls .icon-button { background: var(--control); font-size: 1.25rem; }
.display-controls { position: absolute; top: 16px; right: 16px; left: 72px; display: flex; justify-content: center; gap: 12px; overflow-x: auto; scrollbar-width: none; }
.display-controls::-webkit-scrollbar { display: none; }
.control-group { flex: none; display: flex; align-items: center; gap: 3px; padding: 4px; border: 1px solid var(--line); border-radius: 11px; background: var(--control); box-shadow: 0 4px 16px -12px var(--shadow); }
.view-options { display: grid; grid-template-columns: auto repeat(8, max-content); min-width: 0; }
.view-options .panel-label { display: flex; align-items: center; }
.panel-label { flex: none; padding: 0 7px 0 5px; color: var(--cyan); font-size: .61rem; font-weight: 750; letter-spacing: .12em; text-transform: uppercase; white-space: nowrap; }
.option-button { min-height: 32px; padding: 0 9px; border: 0; border-radius: 7px; color: var(--quiet); background: transparent; cursor: pointer; font-size: .72rem; white-space: nowrap; }
.option-button:hover, .option-button:focus-visible { color: var(--ink); background: var(--control-hover); }
.option-button.active { color: var(--ink); background: var(--control-active); box-shadow: inset 0 0 0 1px var(--cyan-soft); }
.option-button:disabled { color: var(--control-disabled); background: transparent; box-shadow: none; cursor: not-allowed; opacity: .5; }
.face-controls { position: absolute; left: 16px; bottom: 16px; display: flex; align-items: center; gap: 7px; padding: 6px; border: 1px solid var(--line); border-radius: 11px; background: var(--control); box-shadow: 0 4px 16px -12px var(--shadow); }
.face-controls button { height: 32px; padding: 0 10px; border: 1px solid var(--line); border-radius: 7px; color: var(--muted); background: var(--control-soft); cursor: pointer; font-size: .74rem; }
.face-controls button:hover { color: var(--ink); border-color: var(--cyan); }
.face-controls #selection-toggle[aria-pressed="true"] { color: var(--ink); border-color: var(--cyan); background: var(--control-active); }
.face-controls button:disabled, .face-controls input:disabled { cursor: not-allowed; opacity: .32; }
.face-controls label.disabled { opacity: .32; }
.face-controls label { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: .72rem; }
.face-controls output { min-width: 42px; color: var(--ink); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.face-controls input { width: clamp(60px, 7vw, 100px); accent-color: var(--cyan); }
.render-controls { position: absolute; right: 16px; bottom: 16px; display: grid; justify-items: end; gap: 6px; }
.render-controls .control-group { max-width: 100%; }
.details { overflow-y: auto; padding: 28px 24px; border-left: 1px solid var(--line); }
.detail-heading { padding-bottom: 22px; border-bottom: 1px solid var(--line); }
.detail-heading h2 { margin: 7px 0 5px; font-family: Georgia, "Times New Roman", serif; font-size: clamp(2rem, 3vw, 3rem); font-weight: 400; line-height: 1; }
.detail-heading p { margin: 0; color: var(--muted); font-size: .9rem; }
.facts { margin: 0; padding: 16px 0; border-bottom: 1px solid var(--line); }
.facts div { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; padding: 7px 0; }
.facts dt { color: var(--muted); font-size: .78rem; }
.facts dd { margin: 0; color: var(--ink); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .84rem; text-align: right; }
.family-parameters { padding: 18px 0 5px; border-bottom: 1px solid var(--line); }
.family-parameters label { display: grid; grid-template-columns: 1fr auto; gap: 7px; margin-bottom: 17px; color: var(--muted); font-size: .78rem; }
.family-parameters output { color: var(--ink); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.family-parameters input { grid-column: 1 / -1; width: 100%; accent-color: var(--cyan); }
.family-parameters select { grid-column: 1 / -1; width: 100%; padding: 8px; border: 1px solid var(--line); border-radius: 7px; color: var(--ink); background: var(--panel-solid); }
.appearance { padding: 18px 0 5px; border-bottom: 1px solid var(--line); }
.appearance > label:not(.projection-toggle) { display: grid; grid-template-columns: 1fr auto; gap: 7px; margin-bottom: 14px; color: var(--muted); font-size: .78rem; }
.appearance output { color: var(--ink); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.appearance input[type="range"] { grid-column: 1 / -1; display: block; min-width: 100%; width: 100%; accent-color: var(--cyan); }
.projection-toggle { display: flex; align-items: center; gap: 8px; margin: 4px 0 14px; color: var(--muted); font-size: .78rem; cursor: pointer; }
.projection-toggle input { accent-color: var(--cyan); }
.about { padding: 18px 0; }
.paper-name { padding-top: 0; }
.about h3 { margin: 0 0 8px; font-family: Georgia, serif; font-size: 1rem; font-weight: 500; }
.about p { margin: 0; color: var(--muted); font-family: Georgia, serif; font-size: .88rem; line-height: 1.58; }
.sources { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; padding-top: 18px; border-top: 1px solid var(--line); font-size: .76rem; }
@media (max-width: 980px) {
  .topbar { grid-template-columns: 1fr auto 1fr; }
  .back { font-size: 0; text-decoration: none; }
  .back::before { content: "←"; font-size: 1.2rem; }
  .workspace { grid-template-columns: 230px minmax(0, 1fr); }
  .details { position: absolute; right: 0; top: 72px; z-index: 8; width: min(320px, 42vw); height: calc(100svh - 72px); background: var(--panel); pointer-events: none; }
  .details .sources, .details .about { display: none; }
}
@media (max-width: 680px) {
  .topbar { height: 58px; padding: 0 10px; }
  .title-block h1 { font-size: 1.1rem; }
  .title-block p { display: none; }
  .workspace { height: calc(100svh - 58px); display: block; }
  .catalogue { position: absolute; left: 0; right: 0; bottom: 0; z-index: 9; height: 154px; border: 0; border-top: 1px solid var(--line); }
  .catalogue-head { padding: 8px 9px 6px; }
  .tabs { float: left; width: 208px; }
  .tab { padding: 7px 5px; }
  .search-wrap { margin: 0 0 0 216px; height: 36px; }
  .filters { display: none; }
  .model-list, .family-list { display: flex; gap: 7px; overflow-x: auto; overflow-y: hidden; padding: 7px 9px 10px; }
  .model-button { min-width: 125px; width: 125px; padding: 8px 10px; }
  .family-card { min-width: 210px; margin: 0; padding: 10px 13px; }
  .stage { position: absolute; inset: 58px 0 154px; }
  .details { top: 112px; right: 8px; width: auto; height: auto; padding: 0; border: 0; background: transparent; pointer-events: none; }
  .detail-heading { padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; text-align: right; background: var(--control); }
  .detail-heading h2 { margin: 3px 0 0; font-size: 1.5rem; }
  .detail-heading { width: 148px; max-width: 148px; overflow: hidden; }
  .detail-heading h2 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .detail-heading p, .facts, .family-parameters, .appearance, .about, .sources { display: none !important; }
  .view-controls { top: 10px; left: 10px; }
  .view-controls .icon-button { width: 36px; height: 36px; }
  .display-controls { top: 10px; right: 8px; bottom: auto; left: 54px; justify-content: flex-start; gap: 10px; }
  .option-button { min-height: 36px; padding: 0 10px; }
  .face-controls { left: 8px; bottom: 8px; }
  .render-controls { right: 8px; bottom: 58px; max-width: calc(100% - 16px); gap: 4px; }
  .render-controls .control-group { max-width: 100%; overflow-x: auto; }
  .render-controls .option-button { min-height: 36px; }
  .face-controls label { display: none; }
  .gesture-hint { display: none; }
}
@media (max-height: 430px) and (pointer: coarse) {
  .topbar { height: 44px; }
  .workspace { position: relative; display: block; height: calc(100svh - 44px); }
  .stage { position: absolute; inset: 0 164px 0 0; }
  .catalogue { position: absolute; top: 0; right: 0; bottom: 0; left: auto; width: 164px; height: auto; border-top: 0; border-left: 1px solid var(--line); }
  .catalogue-head { padding: 7px; }
  .tabs { float: none; width: auto; grid-template-columns: 1fr; }
  .tab { padding: 5px; font-size: .7rem; }
  .search-wrap { height: 30px; margin: 6px 0 0; padding: 0 7px; }
  .model-list, .family-list { display: block; overflow-x: hidden; overflow-y: auto; padding: 5px; }
  .model-button { min-width: 0; width: 100%; padding: 6px 8px; }
  .model-button small { display: none; }
  .family-card { min-width: 0; padding: 9px; }
  .details { display: none; }
  .display-controls { top: 7px; right: 7px; left: 50px; }
  .option-button { min-height: 30px; padding: 0 8px; }
  .face-controls { bottom: 7px; }
  .render-controls { right: 7px; bottom: 47px; gap: 3px; }
  .render-controls .option-button { min-height: 30px; padding: 0 7px; }
  .face-controls label { display: none; }
  .gesture-hint { display: none; }
}
@media (prefers-reduced-motion: reduce) { .gesture-hint { transition: none; } }
