@font-face {
  font-family: Figtree;
  src: url("fonts/figtree-latin.woff2") format("woff2");
  font-style: normal;
  font-weight: 300 900;
  font-display: swap;
}
:root {
  --paper: #fbfcf8;
  --ink: #152d29;
  --muted: #52645f;
  --line: #d7e0d8;
  --accent: #087e63;
  --accent-dark: #075440;
  --stage: #f0f5ee;
  --gutter: clamp(16px, 3.4vw, 60px);
  color-scheme: light;
  font-family: Figtree, system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
body { margin: 0; height: 100svh; display: flex; flex-direction: column; }
button, a, input { -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
a { color: inherit; text-underline-offset: 4px; text-decoration-thickness: 1px; }
button:focus-visible, a:focus-visible, input:focus-visible { outline: 3px solid var(--accent); outline-offset: 4px; }
button:disabled { opacity: .4; cursor: default; }
button svg, .reading-jump svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
::selection { color: white; background: #087e63; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }

header {
  flex-shrink: 0;
  min-height: 100px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 15px var(--gutter);
  gap: 20px;
}
.wordmark { justify-self: start; font-size: 36px; line-height: 1.15; letter-spacing: -1.7px; font-weight: 800; text-decoration: none; }
.wordmark span { color: var(--accent); }
h1 { font-size: clamp(18px, 1.8vw, 26px); letter-spacing: -.6px; font-weight: 500; line-height: 1.25; margin: 0; }
#motion { justify-self: end; font-size: 14px; min-height: 44px; padding: 10px 0 10px 12px; text-align: right; color: var(--muted); }
#motion:hover { color: var(--accent); }

#grid {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
  flex: 1;
  min-height: 420px;
  margin: 0 var(--gutter);
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
}
.object {
  display: flex;
  flex-direction: column;
  position: relative;
  min-width: 0;
  min-height: 0;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 8px 14px 17px;
  align-items: center;
  justify-content: flex-end;
  transition: background-color .16s ease;
  isolation: isolate;
}
.object:first-child { grid-column: span 2; }
.object:focus-visible { background: #eaf2e9; outline-offset: -4px; }
.object:active { background: #e5eee4; }
.object canvas { display: block; width: 100%; flex: 1; min-height: 0; pointer-events: none; }
.object-name { max-width: 100%; font-size: clamp(13px, 1.05vw, 16px); font-weight: 650; letter-spacing: -.2px; line-height: 1.2; text-wrap: balance; }
.object small { position: absolute; top: 10px; right: 13px; opacity: 0; transition: opacity .16s; color: var(--accent); font-size: 22px; line-height: 1; font-weight: 400; }
.object:focus-visible small { opacity: 1; }
@media (hover: hover) and (pointer: fine) {
  .object:hover { background: #edf3e9; }
  .object:hover small { opacity: 1; }
}
footer { flex-shrink: 0; min-height: 60px; display: flex; justify-content: flex-end; align-items: center; padding: 5px var(--gutter); gap: 16px; font-size: 14px; color: var(--muted); }
footer button { font-size: inherit; min-height: 44px; padding: 8px 0 8px 12px; }
footer button:hover { color: var(--ink); text-decoration: underline; }

dialog {
  padding: 0;
  border: 1px solid #d2dcd1;
  border-radius: 16px;
  color: var(--ink);
  background: var(--paper);
  width: min(1440px, calc(100% - 56px));
  max-width: none;
  height: var(--detail-height, min(940px, calc(100dvh - 48px)));
  max-height: none;
  overflow: hidden;
  box-shadow: 0 22px 90px #152d2929;
}
dialog[open] { animation: arrive .18s ease-out both; }
dialog::backdrop { background: #152d2980; }
@keyframes arrive { from { opacity: 0; } to { opacity: 1; } }
.detail-top { height: 68px; padding: 0 25px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.detail-top button { min-height: 44px; padding: 10px; display: inline-flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; border-radius: 6px; white-space: nowrap; }
#back { padding-left: 0; }
#back:hover { color: var(--accent); }
.neighbors { display: flex; align-items: center; gap: 6px; }
.neighbors button { width: 44px; justify-content: center; }
.neighbors #reset, .neighbors #detail-motion { width: auto; min-width: 60px; font-size: 13px; }
.neighbors button:hover { background: #edf2e9; }
.detail-layout { display: grid; grid-template-columns: minmax(0, 1.08fr) minmax(0, 1fr); align-items: start; height: calc(100% - 68px); overflow: auto; overscroll-behavior: contain; scrollbar-gutter: stable; overflow-anchor: none; }
.instrument {
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  border-right: 1px solid var(--line);
  padding: clamp(24px, 3vh, 40px) 32px 24px;
  position: relative;
  overflow: visible;
  overscroll-behavior: auto;
  background: var(--stage);
  scrollbar-width: thin;
}
.instrument-heading { text-align: center; width: 100%; flex-shrink: 0; }
h2 { margin: 0; font-size: clamp(28px, 3vw, 44px); line-height: 1.06; letter-spacing: -.045em; font-weight: 750; text-wrap: balance; }
#pair { margin: 10px 0 0; color: var(--muted); font-size: 15px; line-height: 1.3; }
#stage { display: block; width: 100%; flex: 0 0 auto; height: clamp(230px, 35svh, 360px); min-height: 210px; max-height: 400px; touch-action: pan-y; }
#detail[data-object="balance"] #stage, #detail[data-object="compass"] #stage, #detail[data-object="pendulum"] #stage { cursor: grab; }
#stage:active { cursor: grabbing; }
#custom-stage { width: 100%; min-width: 0; flex-shrink: 0; }
.object-name { text-transform: lowercase; overflow-wrap: anywhere; }
#drag-handle { position: absolute; width: 52px; height: 52px; transform: translate(-50%,-50%); border-radius: 50%; touch-action: none; z-index: 2; cursor: grab; }
#instruction { max-width: 34ch; font-size: 15px; line-height: 1.4; margin: 8px 0 17px; text-align: center; color: var(--ink); flex-shrink: 0; }
#controls { width: min(400px, 100%); display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; flex-shrink: 0; }
#controls .action { border: 1px solid var(--accent-dark); min-height: 46px; padding: 10px 19px; background: var(--accent); color: #fff; border-radius: 7px; font-size: 15px; line-height: 1.3; font-weight: 650; box-shadow: 0 2px 0 var(--accent-dark); transition: transform .12s ease, box-shadow .12s ease, background .12s; }
#controls .action:hover { background: #086c56; }
#controls .action:active { transform: translateY(2px); box-shadow: 0 0 0 var(--accent-dark); }
#detail[data-object="fork"] #controls .action[aria-pressed] { border-color: #a4b6ac; background: transparent; color: var(--ink); box-shadow: none; font-weight: 550; }
#detail[data-object="fork"] #controls .action[aria-pressed="true"] { background: #e0ebe2; border-color: var(--accent); }
.slider-row { width: 100%; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 12px; font-size: 15px; line-height: 1.4; }
.slider-row > span { font-weight: 600; }
.slider-row > output { font-weight: 650; color: var(--accent-dark); font-variant-numeric: tabular-nums; text-align: right; }
.slider-row input { grid-column: 1/-1; width: 100%; margin: 0; min-height: 44px; padding: 0; background: transparent; accent-color: var(--accent); cursor: ew-resize; -webkit-appearance: none; appearance: none; }
.slider-row input::-webkit-slider-runnable-track { height: 5px; border-radius: 4px; background: linear-gradient(to right, var(--accent) 0 var(--range-fill, 50%), #bfcfc2 var(--range-fill, 50%) 100%); }
.slider-row input::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 22px; height: 22px; margin-top: -8.5px; border-radius: 50%; background: var(--paper); border: 5px solid var(--accent); box-shadow: 0 2px 3px #152d2920; }
.slider-row input::-moz-range-track { height: 5px; border-radius: 4px; background: #bfcfc2; }
.slider-row input::-moz-range-progress { height: 5px; border-radius: 4px; background: var(--accent); }
.slider-row input::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: var(--paper); border: 5px solid var(--accent); box-shadow: 0 2px 3px #152d2920; }
#result { font-size: 16px; font-weight: 600; min-height: 46px; max-width: 38ch; margin: 20px 0 0; text-align: center; line-height: 1.45; flex-shrink: 0; text-wrap: pretty; }
.model-note { font-size: 13px; color: var(--muted); max-width: 38ch; line-height: 1.5; text-align: center; margin: 11px 0 0; flex-shrink: 0; }
.model-note a { min-height: 44px; display: inline-flex; align-items: center; }
.paused-hint { display: block; margin-top: 6px; font-size: 13px; color: var(--muted); }
.reading-jump { display: none; }
.reading { padding: 38px clamp(26px, 3.6vw, 58px) 38px; overflow: visible; }
#lead { font-size: clamp(24px, 2.2vw, 32px); font-weight: 650; line-height: 1.22; letter-spacing: -.035em; margin: 0 0 26px; max-width: 29ch; text-wrap: pretty; }
.reading p { font-size: 16px; line-height: 1.7; margin: 0 0 22px; }
.reading h3 { font-size: 17px; line-height: 1.4; margin: 28px 0 10px; font-weight: 700; }
.reading .surprise { font-weight: 600; }
.reading details { border-top: 1px solid var(--line); }
.reading summary { cursor: pointer; font-size: 15px; font-weight: 600; line-height: 1.4; padding: 17px 0; min-height: 52px; list-style-position: inside; }
.reading summary:hover { color: var(--accent); }
.reading details p { font-size: 15px; line-height: 1.65; }
.reading details a { display: block; font-size: 14px; line-height: 1.5; padding: 12px 0; min-height: 44px; overflow-wrap: anywhere; }
.reading details a:hover { color: var(--accent); }
.reading figure { margin: 28px 0; }
.reading figure img { width: 100%; height: auto; max-height: 340px; object-fit: contain; display: block; background: #e7ede4; }
.reading figcaption { font-size: 13px; line-height: 1.6; color: var(--muted); margin-top: 11px; }
.reading figcaption a { display: inline; }
.photo-missing { font-size: 14px; padding: 18px; background: #e7ede4; }
#related { margin-top: 28px; border-top: 1px solid var(--line); padding-top: 18px; }
#related p { font-size: 14px; color: var(--muted); margin-bottom: 6px; }
#related button { display: inline-flex; align-items: center; text-decoration: underline; text-underline-offset: 5px; font-size: 14px; font-weight: 600; padding: 10px 0; margin-right: 20px; min-height: 44px; }
#related button:hover { color: var(--accent); }
#about-dialog { width: min(570px, calc(100% - 32px)); height: auto; max-height: calc(100dvh - 32px); overflow: auto; padding: 54px 42px 38px; }
#about-dialog h2 { font-size: clamp(42px, 6vw, 60px); font-weight: 750; margin-bottom: 28px; letter-spacing: -.05em; text-wrap: initial; }
#about-dialog p { font-size: 17px; line-height: 1.6; }
#about-dialog a { font-size: 16px; font-weight: 600; display: inline-flex; align-items: center; min-height: 44px; margin-top: 12px; }
.about-close { position: absolute; right: 14px; top: 12px; width: 44px; height: 44px; display: grid; place-items: center; }
.about-close:hover { color: var(--accent); }
.nojs { margin: 30px; max-width: 50ch; }
body:has(.nojs) { height: auto; min-height: 100svh; }
body:has(.nojs) #grid, body:has(.nojs) #motion, body:has(.nojs) footer { display: none; }
.sources-page { height: auto; display: block; }
.sources-page main { width: min(100%, 760px); margin: 0 auto; padding: 24px max(24px, 4vw) 48px; }
.source-back { display: inline-flex; align-items: center; min-height: 44px; margin-bottom: 28px; font-size: 15px; font-weight: 600; }
.sources-page h1 { font-size: clamp(34px, 6vw, 52px); line-height: 1.1; font-weight: 750; letter-spacing: -.04em; margin: 0 0 22px; }
.sources-page h2 { font-size: 30px; text-wrap: initial; }
.sources-page p { font-size: 17px; line-height: 1.65; }
.sources-page section { margin: 38px 0; border-top: 1px solid var(--line); padding-top: 30px; }
.sources-page .source-lead { font-size: 20px; font-weight: 600; line-height: 1.4; }
.sources-page summary { font-weight: 600; cursor: pointer; padding: 12px 0; min-height: 44px; }
.sources-page ul { padding-left: 20px; }
.sources-page li a { display: inline-flex; align-items: center; min-height: 44px; padding: 8px 0; line-height: 1.5; overflow-wrap: anywhere; }

@media (min-width: 1900px) {
  #grid { width: calc(100% - 120px); max-width: 1900px; margin-inline: auto; }
  header, footer { width: 100%; max-width: 2020px; margin-inline: auto; }
}
@media (max-width: 1000px) and (orientation: portrait) {
  #grid { grid-template-columns: repeat(3, minmax(0, 1fr)); grid-template-rows: repeat(9, minmax(66px, 1fr)); min-height: 594px; }
  .object { padding: 4px 9px 11px; }
  .object-name { font-size: 14px; }
}
@media (max-width: 800px) {
  header { min-height: 92px; grid-template-columns: 1fr auto; gap: 1px 16px; padding-block: 9px 13px; }
  .wordmark { font-size: 32px; }
  h1 { grid-column: 1/-1; grid-row: 2; font-size: 17px; letter-spacing: -.35px; }
  #motion { grid-column: 2; grid-row: 1; font-size: 13px; }
  footer { min-height: 50px; font-size: 13px; padding-block: 3px; }
  dialog { width: 100%; height: var(--detail-height, 100dvh); border: 0; border-radius: 0; margin: 0; }
  .detail-top { height: 60px; padding: 0 18px; background: var(--paper); }
  .detail-top button { font-size: 13px; padding: 8px; }
  #back { padding-left: 0; }
  .neighbors { gap: 4px; }
  .neighbors #reset, .neighbors #detail-motion { width: 44px; min-width: 44px; padding-inline: 0; font-size: 12px; }
  .detail-layout { height: calc(100% - 60px); display: block; overflow: auto; overscroll-behavior: contain; }
  .instrument { min-height: 0; height: auto; border: 0; border-bottom: 1px solid var(--line); padding: 25px max(24px, 6vw) 17px; overflow: visible; }
  h2 { font-size: clamp(30px, 5vw, 40px); }
  #pair { font-size: 14px; margin-top: 8px; }
  #stage { flex: 0 0 auto; height: clamp(200px, 31svh, 280px); min-height: 200px; max-height: none; }
  #instruction { font-size: 15px; margin: 4px 0 15px; }
  #result { margin-top: 16px; }
  .reading-jump { display: inline-flex; justify-content: center; align-items: center; gap: 8px; min-height: 44px; margin-top: 12px; font-size: 15px; font-weight: 650; flex-shrink: 0; }
  .reading-jump svg { width: 18px; height: 18px; }
  .model-note { margin-top: 0; }
  .reading { overflow: visible; padding: 30px max(24px, 6vw) 40px; }
  #lead { font-size: 28px; }
  .reading p { font-size: 16px; }
  #about-dialog { margin: auto; padding: 50px 28px 30px; border-radius: 14px; }
}
@media (max-width: 600px) and (orientation: portrait) {
  .object-name { font-size: 12px; line-height: 1.15; min-height: 14px; display: flex; align-items: center; justify-content: center; }
  .object { padding: 3px 6px 7px; }
  .object small { display: none; }
}
@media (max-width: 350px) {
  :root { --gutter: 12px; }
  .detail-top { padding: 0 12px; }
  .neighbors { gap: 2px; }
  .object-name { font-size: 11.5px; letter-spacing: -.15px; }
}
@media (max-height: 640px) {
  header { min-height: 72px; padding-block: 6px; }
  footer { min-height: 44px; padding-block: 0; }
  #grid { min-height: 360px; }
  .object { padding-top: 2px; padding-bottom: 7px; }
  .instrument { padding-top: 20px; }
  #stage { min-height: 170px; }
}
@media (max-height: 500px) and (orientation: landscape) {
  header { min-height: 60px; grid-template-columns: 1fr auto 1fr; padding-block: 5px; }
  h1 { grid-column: 2; grid-row: 1; font-size: 16px; }
  #motion { grid-column: 3; }
  .wordmark { font-size: 28px; }
  #grid { min-height: 230px; grid-template-columns: repeat(9, minmax(0, 1fr)); grid-template-rows: repeat(3, minmax(0, 1fr)); }
  .object-name { font-size: 11px; }
  .object { padding: 0 5px 5px; }
  .object small { display: none; }
  .detail-layout { display: grid; grid-template-columns: 1fr 1fr; }
  .instrument, .reading { padding: 20px; }
  #stage { height: 190px; }
  .reading-jump { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}
