/* Walleye: shared style for every Walleye page and for embedded viewers.
 *
 * Calm and flat on purpose: texture behind a stereo pair fights fusion.
 * Tokens on :root, light and dark (prefers-color-scheme, overridden by [data-theme] on <html>,
 * which walleye.js sets from localStorage 'walleye-theme'). Text contrast is at least 4.5:1.
 * The --wy-scene-* tokens are the colour names a scene may use (ink, accent, up, low, surface, muted,
 * plain, faint) and are read by walleye.js when it draws.
 */

/* ---------- tokens ---------- */

:root {
  color-scheme: light;
  --wy-bg: #f6f5f1;
  --wy-bg-raised: #fdfcf9;
  --wy-ink: #1d2125;
  --wy-muted: #545b63;
  --wy-line: #d3cfc4;
  --wy-line-strong: #8a8f96;
  --wy-accent: #1c5d8a;
  --wy-accent-ink: #ffffff;
  --wy-accent-soft: #e3edf4;
  --wy-focus: #1c5d8a;
  --wy-mark: #fff4c8;
  --wy-stage-bg: #fbfaf7;

  --wy-scene-ink: #26292d;
  --wy-scene-accent: #1c5d8a;
  --wy-scene-up: #9a3b17;
  --wy-scene-low: #1f5a96;
  --wy-scene-surface: #d9cfba;
  --wy-scene-muted: #6f767e;
  --wy-scene-plain: #6b5a2e;
  --wy-scene-faint: #b7b2a6;
  --wy-scene-axis-x: #b3412a;
  --wy-scene-axis-y: #2f7d4a;
  --wy-scene-axis-z: #2a5fa8;

  --wy-badge-seed: #2f6b3f;
  --wy-badge-historical: #7a4b12;
  --wy-badge-new: #6a3f8f;

  --wy-serif: ui-serif, "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --wy-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --wy-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --wy-radius: 0.5rem;
  --wy-max: 64rem;
  --wy-gutter: 1rem;
  --wy-aspect: 2 / 1;
  --wy-control-h: 2.25rem;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --wy-bg: #14171a;
    --wy-bg-raised: #1b1f23;
    --wy-ink: #e7e9ec;
    --wy-muted: #a3abb4;
    --wy-line: #333a41;
    --wy-line-strong: #6f7882;
    --wy-accent: #86bce6;
    --wy-accent-ink: #0d1b26;
    --wy-accent-soft: #1f2e3a;
    --wy-focus: #9fcbef;
    --wy-mark: #3a3420;
    --wy-stage-bg: #181b1f;

    --wy-scene-ink: #e4e6e9;
    --wy-scene-accent: #86bce6;
    --wy-scene-up: #f0936a;
    --wy-scene-low: #82b4f0;
    --wy-scene-surface: #a59d8c;
    --wy-scene-muted: #8d959e;
    --wy-scene-plain: #cdb57c;
    --wy-scene-faint: #4a5158;
    --wy-scene-axis-x: #f0806a;
    --wy-scene-axis-y: #72c48c;
    --wy-scene-axis-z: #7fa9f0;

    --wy-badge-seed: #8fd19e;
    --wy-badge-historical: #e5b46e;
    --wy-badge-new: #c9a7ea;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --wy-bg: #14171a;
  --wy-bg-raised: #1b1f23;
  --wy-ink: #e7e9ec;
  --wy-muted: #a3abb4;
  --wy-line: #333a41;
  --wy-line-strong: #6f7882;
  --wy-accent: #86bce6;
  --wy-accent-ink: #0d1b26;
  --wy-accent-soft: #1f2e3a;
  --wy-focus: #9fcbef;
  --wy-mark: #3a3420;
  --wy-stage-bg: #181b1f;

  --wy-scene-ink: #e4e6e9;
  --wy-scene-accent: #86bce6;
  --wy-scene-up: #f0936a;
  --wy-scene-low: #82b4f0;
  --wy-scene-surface: #a59d8c;
  --wy-scene-muted: #8d959e;
  --wy-scene-plain: #cdb57c;
  --wy-scene-faint: #4a5158;
  --wy-scene-axis-x: #f0806a;
  --wy-scene-axis-y: #72c48c;
  --wy-scene-axis-z: #7fa9f0;

  --wy-badge-seed: #8fd19e;
  --wy-badge-historical: #e5b46e;
  --wy-badge-new: #c9a7ea;
}

@media (prefers-contrast: more) {
  :root {
    --wy-muted: var(--wy-ink);
    --wy-line: var(--wy-line-strong);
    --wy-scene-faint: var(--wy-scene-muted);
  }
}

/* ---------- page ---------- */

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
@media (prefers-reduced-motion: no-preference) { html { scroll-behavior: smooth; } }

.wy-page {
  margin: 0;
  background: var(--wy-bg);
  color: var(--wy-ink);
  font-family: var(--wy-serif);
  font-size: 1.0625rem;
  line-height: 1.6;
  overflow-wrap: break-word;
}
.wy-page *, .wy-page *::before, .wy-page *::after { box-sizing: border-box; }
.wy-page h1, .wy-page h2, .wy-page h3 { font-family: var(--wy-sans); line-height: 1.25; font-weight: 600; }
.wy-page h1 { font-size: 1.85rem; margin: 0.5rem 0 0.75rem; }
.wy-page h2 { font-size: 1.35rem; margin: 2rem 0 0.75rem; }
.wy-page h3 { font-size: 1.1rem; margin: 1.5rem 0 0.5rem; }
.wy-page a { color: var(--wy-accent); text-underline-offset: 0.15em; }
.wy-page a:hover { text-decoration-thickness: 2px; }
.wy-page code, .wy-page pre, .wy-page kbd { font-family: var(--wy-mono); font-size: 0.9em; }
.wy-page pre { overflow-x: auto; padding: 0.75rem 1rem; background: var(--wy-bg-raised); border: 1px solid var(--wy-line); border-radius: var(--wy-radius); }
.wy-page kbd { padding: 0.05em 0.35em; border: 1px solid var(--wy-line-strong); border-radius: 0.25rem; background: var(--wy-bg-raised); }
.wy-page img, .wy-page svg, .wy-page video { max-width: 100%; height: auto; }
.wy-page table { border-collapse: collapse; display: block; max-width: 100%; overflow-x: auto; }
.wy-page th, .wy-page td { text-align: left; padding: 0.35rem 0.75rem 0.35rem 0; border-bottom: 1px solid var(--wy-line); vertical-align: top; }

/* the hidden attribute always wins over display rules below */
[hidden] { display: none !important; }

/* deep links land in the middle of the screen, not under the top edge */
[id] { scroll-margin-block: 5rem; }

/* focus: one visible ring everywhere */
:focus-visible { outline: 3px solid var(--wy-focus); outline-offset: 2px; }
:focus:not(:focus-visible) { outline: none; }
[tabindex="-1"]:focus { outline: none; }

/* ---------- skip link, header, nav ---------- */

.wy-skip {
  position: absolute; left: 0.5rem; top: -10rem; z-index: 10;
  padding: 0.5rem 1rem; background: var(--wy-accent); color: var(--wy-accent-ink) !important;
  font-family: var(--wy-sans); border-radius: var(--wy-radius); text-decoration: none;
}
.wy-skip:focus { top: 0.5rem; }

.wy-header {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1.25rem;
  max-width: var(--wy-max); margin: 0 auto; padding: 0.75rem var(--wy-gutter);
  border-bottom: 1px solid var(--wy-line);
  font-family: var(--wy-sans);
}
.wy-brand { font-weight: 700; font-size: 1.15rem; color: var(--wy-ink) !important; text-decoration: none; letter-spacing: 0.01em; }
.wy-brand:hover { text-decoration: underline; }
.wy-nav, .wy-header nav { display: flex; flex-wrap: wrap; gap: 0.25rem 0.9rem; font-size: 0.95rem; }
.wy-nav a, .wy-header nav a { color: var(--wy-ink); text-decoration: none; padding: 0.2rem 0; border-bottom: 2px solid transparent; }
.wy-nav a:hover, .wy-header nav a:hover { border-bottom-color: var(--wy-line-strong); }
.wy-nav a[aria-current="page"], .wy-header nav a[aria-current="page"] { border-bottom-color: var(--wy-accent); font-weight: 600; }
.wy-theme-toggle { margin-left: auto; }

/* ---------- main, lede, footer ---------- */

.wy-main { display: block; max-width: var(--wy-max); margin: 0 auto; padding: 1rem var(--wy-gutter) 3rem; }
.wy-main:focus { outline: none; }
.wy-lede { font-size: 1.2rem; line-height: 1.55; color: var(--wy-ink); max-width: 42rem; margin: 0 0 1.5rem; }
.wy-main > p, .wy-main section > p { max-width: 42rem; }
.wy-crumb { font-family: var(--wy-sans); font-size: 0.95rem; margin: 0.25rem 0 0; }
.wy-footer {
  max-width: var(--wy-max); margin: 0 auto; padding: 1.25rem var(--wy-gutter) 2rem;
  border-top: 1px solid var(--wy-line); color: var(--wy-muted); font-family: var(--wy-sans); font-size: 0.9rem;
}
.wy-footer a { color: var(--wy-accent); }

/* ---------- buttons ---------- */

.wy-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.35rem;
  min-height: var(--wy-control-h); min-width: var(--wy-control-h); padding: 0.3rem 0.8rem;
  font: 500 0.9rem/1.2 var(--wy-sans);
  color: var(--wy-ink); background: var(--wy-bg-raised);
  border: 1px solid var(--wy-line-strong); border-radius: 0.4rem;
  text-decoration: none; cursor: pointer; white-space: nowrap;
}
a.wy-btn { color: var(--wy-ink); }
.wy-btn:hover { border-color: var(--wy-ink); }
.wy-btn[aria-pressed="true"] { background: var(--wy-accent); color: var(--wy-accent-ink); border-color: var(--wy-accent); }
.wy-btn--primary { background: var(--wy-accent); color: var(--wy-accent-ink) !important; border-color: var(--wy-accent); }
.wy-btn:disabled, .wy-btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }
@media (pointer: coarse) { :root { --wy-control-h: 2.75rem; } }

/* ---------- viewer: stage, toolbar, coach ---------- */

.wy-viewer { display: block; margin: 1rem 0; font-family: var(--wy-sans); }

/* the stage keeps one box in every mode; its size is reserved before any script runs */
.wy-stage {
  position: relative; display: block; width: 100%;
  aspect-ratio: var(--wy-aspect);
  background: var(--wy-stage-bg);
  border: 1px solid var(--wy-line); border-radius: var(--wy-radius);
  overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none;
  contain: layout paint;
}
@supports not (aspect-ratio: 1 / 1) { .wy-stage { height: 0; padding-bottom: 50%; } }
.wy-stage:focus-visible { outline: 3px solid var(--wy-focus); outline-offset: 2px; }
.wy-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; }
.wy-canvas:active { cursor: grabbing; }

/* [data-walleye] before mount: reserve the stage and one toolbar row so nothing below moves */
[data-walleye]:not(.wy-viewer), .wy-reserve:not(.wy-viewer) { display: block; margin: 1rem 0; }
[data-walleye]:not(.wy-viewer):not(:has(.wy-stage))::before, .wy-reserve:not(.wy-viewer):not(:has(.wy-stage))::before {
  content: ""; display: block; aspect-ratio: var(--wy-aspect);
  background: var(--wy-stage-bg); border: 1px solid var(--wy-line); border-radius: var(--wy-radius);
}
[data-walleye]:not(.wy-viewer)::after, .wy-reserve:not(.wy-viewer)::after { content: ""; display: block; height: calc(var(--wy-control-h) + 1.75rem); }

.wy-eye-btn { position: absolute; left: 50%; bottom: 0.6rem; transform: translateX(-50%); z-index: 1; }

.wy-toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem;
  margin: 0.6rem 0 0; min-height: var(--wy-control-h);
  font-family: var(--wy-sans);
}
.wy-group { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.wy-group[hidden] { display: none; }

.wy-coach { margin: 0.5rem 0 0; min-height: 1.5em; color: var(--wy-muted); font-size: 0.95rem; line-height: 1.45; font-family: var(--wy-sans); }
.wy-status { margin: 0.2rem 0 0; color: var(--wy-muted); font-size: 0.85rem; font-family: var(--wy-sans); font-variant-numeric: tabular-nums; }
.wy-caption { margin: 0.6rem 0 0; font-family: var(--wy-serif); font-size: 1rem; max-width: 42rem; }
.wy-credit { margin: 0.3rem 0 0; color: var(--wy-muted); font-size: 0.85rem; max-width: 42rem; }
.wy-caption[hidden], .wy-credit[hidden] { display: none; }

.wy-keys {
  margin: 0.75rem 0 0; padding: 0.75rem 1rem; max-width: 34rem;
  background: var(--wy-bg-raised); border: 1px solid var(--wy-line); border-radius: var(--wy-radius);
  font-size: 0.9rem;
}
.wy-keys[hidden] { display: none; }
.wy-keys-title { margin: 0 0 0.5rem; font-weight: 600; }
.wy-keys dl { display: grid; grid-template-columns: minmax(7rem, max-content) 1fr; gap: 0.2rem 1rem; margin: 0 0 0.75rem; }
.wy-keys dt { font-family: var(--wy-mono); font-size: 0.85rem; }
.wy-keys dd { margin: 0; color: var(--wy-muted); }

.wy-sr {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
}

/* ---------- gallery: grid, cards, badges ---------- */

.wy-grid {
  display: grid; gap: 1rem;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 16rem), 1fr));
  margin: 1rem 0; padding: 0; list-style: none;
}
.wy-card {
  position: relative; display: flex; flex-direction: column; gap: 0.5rem;
  padding: 1rem; background: var(--wy-bg-raised);
  border: 1px solid var(--wy-line); border-radius: var(--wy-radius);
  scroll-margin-block: 30vh;
}
.wy-card > :first-child { margin-top: 0; }
.wy-card > :last-child { margin-bottom: 0; }
.wy-card h2, .wy-card h3 { margin: 0; font-size: 1.05rem; }
.wy-card:focus-visible, .wy-card:focus { outline: 3px solid var(--wy-focus); outline-offset: 2px; }
.wy-card:focus-within { border-color: var(--wy-line-strong); }
.wy-card:target, .wy-card.is-returned { border-color: var(--wy-accent); box-shadow: 0 0 0 2px var(--wy-accent); }

.wy-badge {
  display: inline-block; padding: 0.05rem 0.5rem;
  font: 600 0.75rem/1.5 var(--wy-sans); letter-spacing: 0.02em;
  color: var(--wy-muted); border: 1px solid currentColor; border-radius: 999px;
}
.wy-badge--seed { color: var(--wy-badge-seed); }
.wy-badge--historical { color: var(--wy-badge-historical); }
.wy-badge--new { color: var(--wy-badge-new); }
.wy-badge--educational, .wy-badge--mathematics, .wy-badge--science { color: var(--wy-accent); }
.wy-badge--intro, .wy-badge--intermediate, .wy-badge--advanced { color: var(--wy-muted); border-style: dashed; }

/* ---------- prose blocks: note, steps, figure ---------- */

.wy-note {
  margin: 1.25rem 0; padding: 0.75rem 1rem; max-width: 42rem;
  background: var(--wy-bg-raised); border: 1px solid var(--wy-line); border-left: 4px solid var(--wy-accent);
  border-radius: 0 var(--wy-radius) var(--wy-radius) 0; font-size: 0.98rem;
}
.wy-note > :first-child { margin-top: 0; }
.wy-note > :last-child { margin-bottom: 0; }

.wy-steps { list-style: none; counter-reset: wy-step; margin: 1rem 0; padding: 0; max-width: 42rem; }
.wy-steps > li { counter-increment: wy-step; position: relative; padding: 0 0 0.9rem 2.75rem; min-height: 2rem; }
.wy-steps > li::before {
  content: counter(wy-step); position: absolute; left: 0; top: 0;
  width: 1.9rem; height: 1.9rem; display: grid; place-items: center;
  font: 600 0.95rem/1 var(--wy-sans); color: var(--wy-accent-ink); background: var(--wy-accent); border-radius: 50%;
}

.wy-figure { margin: 1.5rem 0; }
.wy-figure > figcaption { margin-top: 0.5rem; color: var(--wy-muted); font-size: 0.95rem; max-width: 42rem; }

/* ---------- forms (setup tool) ---------- */

.wy-field { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.75rem; margin: 0.75rem 0; font-family: var(--wy-sans); font-size: 0.95rem; }
.wy-field input[type="number"] { width: 6rem; }
.wy-page input, .wy-page select { font: inherit; color: var(--wy-ink); background: var(--wy-bg-raised); border: 1px solid var(--wy-line-strong); border-radius: 0.3rem; padding: 0.3rem 0.45rem; min-height: var(--wy-control-h); }
.wy-page input[type="range"] { padding: 0; border: 0; background: transparent; accent-color: var(--wy-accent); min-width: 10rem; flex: 1 1 12rem; }
.wy-page input[type="checkbox"], .wy-page input[type="radio"] { min-height: 0; width: 1.15rem; height: 1.15rem; accent-color: var(--wy-accent); }
.wy-check { display: flex; align-items: flex-start; gap: 0.6rem; margin: 1rem 0; padding: 0.6rem 0.8rem; border: 1px dashed var(--wy-line-strong); border-radius: var(--wy-radius); font-family: var(--wy-sans); font-size: 0.95rem; max-width: 42rem; }
.wy-check input { margin-top: 0.2rem; flex: none; }
.wy-choices { display: grid; gap: 0.5rem; margin: 0.75rem 0; padding: 0; border: 0; max-width: 42rem; }
.wy-choices legend { font-family: var(--wy-sans); font-weight: 600; margin-bottom: 0.25rem; }
.wy-choice { display: flex; gap: 0.6rem; align-items: flex-start; padding: 0.6rem 0.8rem; border: 1px solid var(--wy-line); border-radius: var(--wy-radius); background: var(--wy-bg-raised); cursor: pointer; }
.wy-choice:has(input:checked) { border-color: var(--wy-accent); box-shadow: inset 0 0 0 1px var(--wy-accent); }
.wy-choice input { margin-top: 0.25rem; flex: none; }
.wy-choice small { display: block; color: var(--wy-muted); font-size: 0.9rem; }
.wy-output { font-family: var(--wy-sans); font-variant-numeric: tabular-nums; }

/* ---------- motion and contrast ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; scroll-behavior: auto !important; }
}
@media (prefers-contrast: more) {
  .wy-btn, .wy-card, .wy-stage, .wy-note, .wy-keys { border-width: 2px; }
  .wy-page a { text-decoration-thickness: 2px; }
}
@media (forced-colors: active) {
  .wy-btn[aria-pressed="true"] { outline: 2px solid CanvasText; }
  .wy-stage { border: 1px solid CanvasText; }
}

/* ---------- narrow screens: 360px wide with no sideways scroll ---------- */

@media (max-width: 30rem) {
  .wy-page { font-size: 1rem; }
  .wy-page h1 { font-size: 1.5rem; }
  .wy-lede { font-size: 1.08rem; }
  .wy-toolbar { gap: 0.4rem 0.6rem; }
  .wy-btn { padding: 0.3rem 0.6rem; }
  .wy-keys dl { grid-template-columns: 1fr; }
  .wy-keys dd { margin-bottom: 0.3rem; }
}
