:root {
  color-scheme: light dark;
  --ink: light-dark(#1a1a1a, #f5f3ec);
  --muted: light-dark(#706d65, #aaa59a);
  --quiet: light-dark(#918b7d, #777269);
  --line: light-dark(#ddd8cc, #3a3a3a);
  --panel: light-dark(rgba(255, 253, 248, .92), rgba(30, 30, 35, .92));
  --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, .88), rgba(30, 30, 35, .88));
  --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);
  --stage: light-dark(radial-gradient(circle at 50% 45%, #fffdf8 0, #f1ede4 43%, #e5dfd3 100%), radial-gradient(circle at 50% 45%, #282c36 0, #1d2027 43%, #16161a 100%));
  --stage-grid: light-dark(rgba(70, 68, 61, .095), rgba(200, 196, 185, .075));
  --shadow: light-dark(rgba(60, 45, 15, .14), rgba(0, 0, 0, .28));
  --canvas-edge: #333942;
  --canvas-guide: rgba(55, 63, 76, .22);
  --canvas-trail: rgba(36, 48, 67, .12);
  --canvas-outline: rgba(255, 253, 248, .9);
  --canvas-highlight: #9a6300;
  --radius: 14px;
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] {
  color-scheme: dark;
  --canvas-edge: #b8c2d1;
  --canvas-guide: rgba(210, 218, 230, .16);
  --canvas-trail: rgba(198, 213, 235, .11);
  --canvas-outline: rgba(22, 22, 26, .88);
  --canvas-highlight: #e0a860;
}
* { 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; }
sub { font-size: .62em; }
.topbar {
  position: relative;
  z-index: 20;
  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);
}
.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(230px, 280px) minmax(0, 1fr) minmax(270px, 320px);
  grid-template-rows: minmax(0, 1fr);
}
.control-panel, .details {
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  background: var(--panel);
  backdrop-filter: blur(18px);
}
.control-panel { border-right: 1px solid var(--line); }
.panel-section { padding: 17px 15px; border-bottom: 1px solid var(--line); }
.section-heading { min-height: 20px; display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 11px; }
.section-heading output { color: var(--muted); font-size: .71rem; text-align: right; }
.eyebrow { color: var(--cyan); font-size: .66rem; font-weight: 750; letter-spacing: .13em; text-transform: uppercase; }
.choice-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.choice {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  text-align: left;
  background: var(--control-soft);
  cursor: pointer;
}
.choice:hover, .choice:focus-visible { border-color: var(--cyan); background: var(--control-hover); }
.choice.active { border-color: var(--cyan); background: var(--cyan-soft); box-shadow: inset 0 0 0 1px var(--cyan-soft); }
.choice strong { font-family: Georgia, "Times New Roman", serif; font-size: .84rem; font-weight: 600; }
.choice span { color: var(--quiet); font-size: .65rem; white-space: nowrap; }
.select-row { display: grid; gap: 6px; margin-top: 11px; color: var(--muted); font-size: .69rem; }
.select-row select { width: 100%; min-height: 34px; padding: 0 30px 0 9px; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); background: var(--control-soft); font: inherit; cursor: pointer; }
.select-row select:hover, .select-row select:focus-visible { border-color: var(--cyan); outline: 0; }
.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; padding: 4px; border-radius: 10px; background: var(--control-soft); }
.segment { min-height: 33px; padding: 0 8px; border: 0; border-radius: 7px; color: var(--muted); background: transparent; cursor: pointer; font-size: .74rem; }
.segment:hover, .segment:focus-visible { color: var(--ink); background: var(--control-hover); }
.segment.active { color: var(--ink); background: var(--control-active); box-shadow: 0 1px 6px var(--shadow); }
.range-row { display: grid; grid-template-columns: 1fr auto; gap: 7px; margin-top: 16px; color: var(--muted); font-size: .73rem; }
.range-row output { color: var(--ink); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.range-row input { grid-column: 1 / -1; width: 100%; accent-color: var(--cyan); }
.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: .78;
  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 74%);
}
#viewer { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; outline: none; }
#viewer.grabbing { cursor: grabbing; }
#viewer.root-drag { cursor: move; }
#viewer:focus-visible { box-shadow: inset 0 0 0 2px var(--cyan); }
.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; overflow-x: auto; scrollbar-width: none; pointer-events: none; }
.display-controls::-webkit-scrollbar { display: none; }
.control-group { 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); pointer-events: auto; }
.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); }
.gesture-hint { position: absolute; left: 50%; bottom: 54px; transform: translateX(-50%); padding: 7px 12px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); background: var(--control); font-size: .71rem; white-space: nowrap; pointer-events: none; transition: opacity .5s; }
.gesture-hint.used { opacity: 0; }
.stage-status { position: absolute; right: 16px; bottom: 15px; left: 16px; display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-size: .68rem; letter-spacing: .04em; pointer-events: none; }
.hover-card { position: absolute; z-index: 5; min-width: 112px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); background: var(--control); box-shadow: 0 8px 22px var(--shadow); font-size: .68rem; line-height: 1.4; pointer-events: none; }
.hover-card strong { display: block; color: var(--cyan); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.details { 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: .88rem; }
.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 { flex: none; color: var(--muted); font-size: .75rem; }
.facts dd { margin: 0; color: var(--ink); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .76rem; text-align: right; }
.facts .coordinate-row { display: block; }
.facts .coordinate-row dd { margin-top: 7px; line-height: 1.55; text-align: left; overflow-wrap: anywhere; }
.relation-panel { padding: 18px 0; border-bottom: 1px solid var(--line); }
.relation-panel h3, .about h3 { margin: 0 0 10px; font-family: Georgia, serif; font-size: 1rem; font-weight: 500; }
.relation { display: grid; grid-template-columns: 9px 1fr auto; align-items: center; gap: 8px; padding: 5px 0; color: var(--muted); font-size: .72rem; }
.relation i { width: 7px; height: 7px; border-radius: 50%; background: var(--quiet); }
.relation i.same { background: var(--gold); }
.relation i.near { background: #2e9f91; }
.relation i.orthogonal { background: #88909c; }
.relation i.far { background: #8b6fc5; }
.relation i.opposite { background: #ca5674; }
.relation strong { color: var(--ink); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 500; }
.appearance { padding: 18px 0 4px; border-bottom: 1px solid var(--line); }
.appearance label { display: grid; grid-template-columns: 1fr auto; gap: 7px; margin-bottom: 14px; color: var(--muted); font-size: .75rem; }
.appearance output { color: var(--ink); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.appearance input { grid-column: 1 / -1; width: 100%; accent-color: var(--cyan); }
.about { padding: 18px 0; }
.about p { margin: 0 0 10px; color: var(--muted); font-family: Georgia, serif; font-size: .85rem; line-height: 1.55; }
.sources { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; padding-top: 18px; border-top: 1px solid var(--line); font-size: .74rem; }
.info-page { min-height: 100svh; overflow: auto; }
.info-page main { width: min(760px, calc(100% - 36px)); margin: 0 auto; padding: 54px 0 80px; }
.info-page h1, .info-page h2 { font-family: Georgia, "Times New Roman", serif; font-weight: 500; }
.info-page h1 { font-size: clamp(2.2rem, 6vw, 4rem); }
.info-page h2 { margin-top: 2rem; }
.info-page p, .info-page li { max-width: 68ch; line-height: 1.65; }
.info-page .back { display: inline-block; margin-bottom: 22px; }

@media (max-width: 1080px) {
  .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; top: 72px; right: 0; z-index: 8; width: min(300px, 35vw); height: calc(100svh - 72px); padding: 18px; background: linear-gradient(90deg, transparent, var(--panel) 18%); pointer-events: none; }
  .details .relation-panel, .details .appearance, .details .about, .details .sources { display: none; }
  .detail-heading, .facts { margin-left: 42px; }
}

@media (max-width: 900px) {
  .details { top: 120px; right: 8px; width: auto; height: auto; padding: 0; border: 0; background: transparent; }
  .detail-heading { width: 148px; max-width: 148px; margin: 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; text-align: right; background: var(--control); overflow: hidden; }
  .detail-heading h2 { margin: 3px 0 0; font-size: 1.5rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .detail-heading p, .facts { 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 { position: relative; height: calc(100svh - 58px); display: block; }
  .stage { position: absolute; inset: 0 0 184px; }
  .control-panel { position: absolute; right: 0; bottom: 0; left: 0; z-index: 9; height: 184px; display: flex; overflow-x: auto; overflow-y: hidden; border-top: 1px solid var(--line); border-right: 0; scroll-snap-type: x proximity; }
  .panel-section { flex: 0 0 235px; height: 100%; overflow-y: auto; padding: 12px; border-right: 1px solid var(--line); border-bottom: 0; scroll-snap-align: start; }
  .projection-section, .colour-section { flex-basis: 255px; }
  .section-heading { margin-bottom: 8px; }
  .choice { padding: 7px 9px; }
  .choice strong { font-size: .76rem; }
  .choice span { font-size: .6rem; }
  .range-row { margin-top: 10px; }
  .details { top: 112px; right: 8px; width: auto; height: auto; padding: 0; border: 0; background: transparent; pointer-events: none; }
  .detail-heading { width: 136px; max-width: 136px; margin: 0; padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px; text-align: right; background: var(--control); overflow: hidden; }
  .detail-heading h2 { margin: 3px 0 0; font-size: 1.35rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .detail-heading p { display: none; }
  .facts, .relation-panel, .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; left: 54px; justify-content: flex-start; }
  .control-group { overflow-x: auto; }
  .panel-label { display: none; }
  .option-button { min-height: 36px; padding: 0 10px; }
  .gesture-hint { display: none; }
  .stage-status { right: 8px; bottom: 8px; left: 8px; font-size: .61rem; }
  .hover-card { display: none; }
}

@media (max-height: 430px) and (pointer: coarse) {
  .topbar { height: 44px; }
  .title-block h1 { font-size: 1rem; }
  .title-block p { display: none; }
  .workspace { height: calc(100svh - 44px); }
  .stage { inset: 0 190px 0 0; }
  .control-panel { top: 0; right: 0; bottom: 0; left: auto; width: 190px; height: auto; display: block; overflow-x: hidden; overflow-y: auto; border-top: 0; border-left: 1px solid var(--line); }
  .panel-section, .projection-section, .colour-section { width: 100%; height: auto; min-height: 0; padding: 9px; overflow: visible; border-right: 0; border-bottom: 1px solid var(--line); }
  .panel-section:not(.projection-section) { display: none; }
  .choice { padding: 6px 8px; }
  .choice span { display: none; }
  .details { display: none; }
  .display-controls { top: 7px; right: 7px; left: 50px; }
  .option-button { min-height: 30px; padding: 0 8px; }
  .view-controls { top: 7px; left: 7px; gap: 5px; }
  .view-controls .icon-button { width: 34px; height: 34px; }
  .stage-status { bottom: 6px; }
  .gesture-hint { display: none; }
}

@media (prefers-reduced-motion: reduce) { .gesture-hint { transition: none; } }
