.earth-study {
  --earth-accent: #8a4c18;
  --earth-lattice: #965823;
  --earth-shell: #236679;
  --earth-core: #3a578e;
  --earth-event: #9c3d48;
  --earth-plate-bg: #edf2f7;
  --earth-plate-glow: #f9fbfe;
  --earth-surface: #f2f5f9;
  --earth-grid: #38536a16;
  --earth-canvas-core-light: #b6d1ed;
  --earth-canvas-core-dark: #4a6793;
  --earth-canvas-metal-light: #c3cdd8;
  --earth-canvas-metal-dark: #5d7087;
  --earth-canvas-mark: #f0f5ff;
  min-height: 100vh;
  height: auto;
  overflow: visible;
  background-image: none;
  line-height: 1.55;
}

:root[data-theme="dark"] .earth-study {
  --earth-accent: #f4bc81;
  --earth-lattice: #eab67d;
  --earth-shell: #83c9d4;
  --earth-core: #a4bef1;
  --earth-event: #f1a294;
  --earth-plate-bg: #0c1420;
  --earth-plate-glow: #1a2a3c;
  --earth-surface: #182332;
  --earth-grid: #94beda16;
  --earth-canvas-core-light: #537fac;
  --earth-canvas-core-dark: #16263e;
  --earth-canvas-metal-light: #688397;
  --earth-canvas-metal-dark: #233446;
  --earth-canvas-mark: #e5eeff;
}

.earth-study [hidden] { display: none !important; }
.earth-study a { color: inherit; }
.earth-study :focus-visible { outline: 2px solid var(--in); outline-offset: 3px; }
.earth-wrap { width: min(1340px, calc(100% - 72px)); margin-inline: auto; }
.earth-skip { position: absolute; top: 8px; left: 8px; z-index: 3; padding: 8px 12px; background: var(--paper); transform: translateY(-160%); }
.earth-skip:focus { transform: none; }

.earth-header {
  display: grid;
  grid-template-columns: minmax(max-content, 1fr) auto minmax(38px, 1fr);
  gap: 20px;
  align-items: center;
  min-height: 70px;
  border-bottom: 1px solid var(--rule);
}
#earth-theme { justify-self: end; }
.earth-nav { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.earth-nav a, .earth-segment button {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid transparent;
  color: var(--ink-2);
  font: 500 0.875rem/1.3 var(--sans);
  text-decoration: none;
}
.earth-nav a:hover, .earth-segment button:hover { color: var(--ink); background: var(--hover-ink); }
.earth-nav a[aria-current="page"] { color: var(--earth-accent); border-color: var(--rule); background: var(--earth-surface); }

.earth-intro {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 20px 36px;
  padding: clamp(26px, 4vw, 56px) 0 clamp(24px, 3.5vw, 40px);
}
.earth-overline {
  margin: 0 0 9px;
  color: var(--earth-accent);
  font: 500 0.8125rem/1.4 var(--mono);
  letter-spacing: 0.045em;
  text-transform: uppercase;
}
.earth-intro h1 {
  margin: 0 0 12px;
  font-size: clamp(2.85rem, 6.4vw, 6.3rem);
  line-height: 0.96;
  text-wrap: initial;
}
.earth-intro h1 em { color: var(--earth-accent); }
.earth-lede { max-width: 67ch; margin: 0; color: var(--ink-2); font-size: clamp(1rem, 1.45vw, 1.15rem); }
.earth-source-button {
  display: grid;
  gap: 3px;
  align-content: center;
  min-height: 61px;
  padding: 8px 15px;
  border: 1px solid var(--rule);
  text-decoration: none;
  white-space: nowrap;
}
.earth-source-button:hover { border-color: var(--earth-accent); background: var(--hover-ink); }
.earth-source-button strong { font-size: 0.9375rem; font-weight: 600; }
.earth-source-button span { color: var(--ink-2); font: 400 0.8125rem/1.4 var(--mono); }

.earth-workspace { display: grid; grid-template-columns: minmax(0, 1.8fr) minmax(285px, 1fr); gap: 16px; }
.earth-plate, .earth-roles { margin: 0; min-width: 0; border: 1px solid var(--rule); background: var(--earth-surface); }
.earth-plate-head, .earth-panel-head { padding: 16px 19px; }
.earth-plate-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; }
.earth-study h2, .earth-study h3 { margin: 0; font-family: var(--serif); font-weight: 400; line-height: 1.03; }
.earth-study h2 { font-size: clamp(1.9rem, 3.1vw, 3.2rem); }
.earth-study h3 { font-size: clamp(1.5rem, 2.45vw, 2.1rem); }
.earth-plate-head h2, .earth-panel-head h2 { font-size: clamp(1.75rem, 2.5vw, 2.5rem); }
.earth-segment { display: inline-flex; gap: 2px; padding: 2px; border: 1px solid var(--rule); background: var(--paper); }
.earth-segment button { min-height: 33px; border: 0; padding-block: 4px; background: transparent; cursor: pointer; }
.earth-segment button[aria-pressed="true"] { color: var(--paper); background: var(--ink); }

.earth-stage {
  position: relative;
  height: clamp(375px, 38vw, 510px);
  overflow: hidden;
  border-block: 1px solid var(--rule-soft);
  background:
    linear-gradient(var(--earth-grid) 1px, transparent 1px) center / 24px 24px,
    linear-gradient(90deg, var(--earth-grid) 1px, transparent 1px) center / 24px 24px,
    radial-gradient(ellipse at center, var(--earth-plate-glow), var(--earth-plate-bg) 77%);
}
.earth-stage canvas { display: block; width: 100%; height: 100%; cursor: grab; touch-action: pan-y; }
.earth-stage canvas:active { cursor: grabbing; }
.earth-stage canvas:focus-visible { outline-offset: -3px; }
.earth-canvas-fallback { max-width: 42ch; margin: 0; position: absolute; left: 50%; top: 50%; width: calc(100% - 40px); transform: translate(-50%, -50%); }
.earth-stage-hint {
  position: absolute;
  inset-inline: 14px;
  bottom: 11px;
  margin: 0;
  color: var(--ink-2);
  font: 400 0.8125rem/1.2 var(--mono);
  text-align: right;
  pointer-events: none;
}
.earth-plate-controls {
  display: grid;
  grid-template-columns: auto minmax(64px, 1fr) minmax(6ch, auto) auto;
  gap: 12px;
  align-items: center;
  padding: 11px 16px;
  border-bottom: 1px solid var(--rule-soft);
  font-size: 0.875rem;
}
.earth-plate-controls input { width: 100%; min-width: 0; margin: 0; accent-color: var(--earth-shell); }
.earth-plate-controls output { color: var(--ink-2); font: 400 0.8125rem/1.2 var(--mono); text-align: end; }
.earth-plate-controls button {
  min-height: 37px;
  padding: 3px 9px;
  border: 1px solid var(--rule);
  color: var(--ink);
  background: transparent;
  cursor: pointer;
}
.earth-plate-controls button:hover { background: var(--hover-ink); }
.earth-plate-playback { padding: 11px 16px 13px; border-bottom: 1px solid var(--rule-soft); }
.earth-plate-playback > p { margin: 0 0 7px; }
.earth-plate-playback > p:first-child { font-weight: 600; }
.earth-plate-playback > p:last-child { margin: 9px 0 0; }
.earth-plate-playback .earth-cycle-transport .tbtn { width: 38px; height: 38px; }
.earth-plate-playback .earth-cycle-transport .tbtn.play { width: 44px; height: 44px; }
.earth-caption { padding: 13px 16px 15px; color: var(--ink-2); }
.earth-caption p { margin: 0 0 5px; font-size: 0.9375rem; }
.earth-caption p:last-child { margin-bottom: 0; }
.earth-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 0 0 8px; padding: 0; list-style: none; }
.earth-legend li { display: inline-flex; align-items: center; gap: 6px; color: var(--ink); font-size: 0.875rem; }
.earth-legend li::before { content: ""; flex: none; width: 12px; height: 3px; background: var(--key); }
.earth-key--lattice { --key: var(--earth-lattice); }
.earth-key--shell { --key: var(--earth-shell); }
.earth-key--core { --key: var(--earth-core); }
.earth-study .earth-note { color: var(--ink-2); font-size: 0.875rem; }

.earth-roles { display: flex; flex-direction: column; }
.earth-panel-head p { margin: 9px 0 0; color: var(--ink-2); }
.earth-role-choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 5px; margin: 0 18px 17px; }
.earth-role-choices button {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 46px;
  padding: 7px 8px;
  border: 1px solid var(--rule);
  background: var(--paper);
  color: var(--ink-2);
  font-size: 0.875rem;
  line-height: 1.15;
  text-align: left;
  cursor: pointer;
}
.earth-role-choices button:hover { background: var(--hover-ink); }
.earth-role-choices button[aria-pressed="true"] { color: var(--ink); border-color: var(--role-key); box-shadow: inset 0 -2px var(--role-key); }
.earth-role-choices b { color: var(--role-key); font: 600 0.875rem/1 var(--mono); }
.earth-role-choices [data-role="CC"] { --role-key: var(--earth-core); }
.earth-role-choices [data-role="AA"] { --role-key: var(--earth-lattice); }
.earth-role-choices [data-role="CA"] { --role-key: var(--earth-shell); }
.earth-role-choices [data-role="AC"] { --role-key: var(--earth-event); }
.earth-role-notes article { padding: 17px 19px; border-top: 1px solid var(--rule-soft); }
.earth-role-notes dl, .earth-boundary dl { margin: 17px 0 0; }
.earth-role-notes dt, .earth-boundary dt { margin: 13px 0 3px; font-weight: 600; }
.earth-role-notes dd, .earth-boundary dd { margin: 0; color: var(--ink-2); }
.earth-role-cross { margin: 0 19px; padding: 14px 0; border-top: 1px solid var(--rule-soft); }
.earth-role-cross figcaption { font-size: 0.9375rem; font-weight: 600; }
.earth-role-cross .e1p-graph { max-width: 290px; }
.earth-role-cross .e1p-legend { justify-content: center; margin: 0; font-size: 0.8125rem; }
.earth-player-link { margin: auto 19px 0; padding-block: 14px; border-top: 1px solid var(--rule-soft); }
.earth-disclosure { border-top: 1px solid var(--rule-soft); padding: 10px 0; }
.earth-disclosure summary { min-height: 26px; font-size: 0.9375rem; font-weight: 500; cursor: pointer; }
.earth-disclosure summary::marker { color: var(--earth-accent); }
.earth-disclosure p { margin: 6px 0 0; color: var(--ink-2); }

.earth-section { margin-top: clamp(40px, 6.5vw, 88px); }
.earth-section-heading { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 7px 18px; margin-bottom: 17px; }
.earth-section-heading p { max-width: 44ch; margin: 0; color: var(--ink-2); }
.earth-cycle { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); border: 1px solid var(--rule); background: var(--earth-surface); }
.earth-cycle-diagram {
  display: grid;
  grid-template-rows: auto minmax(180px, 1fr) auto;
  min-width: 0;
  border-right: 1px solid var(--rule);
  background:
    linear-gradient(var(--earth-grid) 1px, transparent 1px) center / 24px 24px,
    linear-gradient(90deg, var(--earth-grid) 1px, transparent 1px) center / 24px 24px,
    radial-gradient(ellipse at center, var(--earth-plate-glow), var(--earth-plate-bg) 77%);
}
.earth-cycle-diagram canvas { display: block; width: 100%; height: 100%; min-height: 0; }
.earth-cycle-ends {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 16px 0;
  color: var(--ink-2);
  font: 400 0.8125rem/1.2 var(--mono);
}
.earth-cycle-diagram .earth-note { margin: 0; padding: 0 16px 13px; }
.earth-cycle-panel { padding: clamp(13px, 1.8vw, 23px); min-width: 0; }
.earth-cycle-sequence { margin: 0 0 16px; }
.earth-cycle-sequence:not(.is-interactive) { padding-left: 1.4rem; }
.earth-cycle-sequence.is-interactive {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 5px;
  padding: 0;
  list-style: none;
}
.earth-cycle-sequence button {
  width: 100%;
  min-height: 43px;
  padding: 6px 9px;
  border: 1px solid var(--rule);
  background: var(--paper);
  color: var(--ink-2);
  font-size: 0.875rem;
  line-height: 1.2;
  text-align: left;
  cursor: pointer;
}
.earth-cycle-sequence button:hover { background: var(--hover-ink); }
.earth-cycle-sequence button[aria-pressed="true"] { border-color: var(--earth-shell); box-shadow: inset 0 -2px var(--earth-shell); color: var(--ink); }
.earth-cycle-now { min-height: 112px; }
.earth-cycle-now p, .earth-cycle-sequence p { margin: 7px 0 12px; color: var(--ink-2); }
.earth-cycle-scrub, .earth-cycle-rate {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 8px;
  align-items: baseline;
  color: var(--ink-2);
  font-size: 0.875rem;
}
.earth-cycle-scrub output, .earth-cycle-rate output { justify-self: end; font: 400 0.8125rem/1.2 var(--mono); }
.earth-cycle-scrub input, .earth-cycle-rate input { grid-column: 1 / -1; width: 100%; min-height: 22px; margin: 0; accent-color: var(--earth-shell); }
.earth-cycle-transport { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 13px; margin-top: 9px; }
.earth-cycle-transport .transport { margin: 0; gap: 5px; }
.earth-cycle-speed { display: grid; gap: 3px; color: var(--ink-2); font-size: 0.875rem; }
.earth-cycle-speed .seg button { min-height: 36px; font-size: 0.875rem; }
.earth-cycle-rate { flex: 1; min-width: min(100%, 126px); }
.earth-cycle-reference { margin: 14px 0 0; }
.earth-cycle:has(.earth-cycle-diagram[hidden]) { grid-template-columns: minmax(0, 1fr); }
.earth-evidence {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.earth-evidence li { padding: 17px 18px; border: 1px solid var(--rule-soft); border-top: 2px solid var(--rule); background: var(--earth-surface); }
.earth-evidence li > p:not(.earth-overline) { margin: 11px 0 0; color: var(--ink-2); }
.earth-study .earth-links { display: flex; flex-wrap: wrap; gap: 5px 13px; font-size: 0.875rem; }
.earth-links a, .earth-footer a { text-decoration-color: var(--earth-shell); text-underline-offset: 3px; }
.earth-links a:hover, .earth-footer a:hover { color: var(--earth-accent); }
.earth-boundary { margin-top: 14px; }
.earth-boundary dl { max-width: 80ch; }

.earth-test-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.earth-test-plan, .earth-frequency { min-width: 0; padding: clamp(16px, 2.25vw, 28px); border: 1px solid var(--rule-soft); background: var(--earth-surface); }
.earth-test-grid p:not(.earth-overline) { margin: 10px 0 0; color: var(--ink-2); }
.earth-tests { margin-top: 20px; }
.earth-fields { display: grid; gap: 10px; margin: 17px 0; }
.earth-fields label { display: grid; gap: 4px; font-size: 0.875rem; font-weight: 500; }
.earth-fields select, .earth-fields input {
  min-height: 42px;
  min-width: 0;
  padding: 6px 9px;
  border: 1px solid var(--rule);
  border-radius: 0;
  color: var(--ink);
  background: var(--paper);
  font: 400 0.9375rem/1.15 var(--sans);
}
.earth-fields select {
  width: 100%;
  padding-right: 28px;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 48%, var(--ink-2) 49%), linear-gradient(135deg, var(--ink-2) 49%, transparent 50%);
  background-size: 5px 5px;
  background-repeat: no-repeat;
  background-position: right 14px center, right 9px center;
}
.earth-fields input { width: min(100%, 10rem); }
.earth-frequency-bars { display: grid; gap: 6px; font-size: 0.875rem; }
.earth-frequency-bars > div:not(.earth-bar) { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0 10px; }
.earth-frequency-bars strong { font: 500 0.8125rem/1.6 var(--mono); color: var(--ink-2); }
.earth-bar { height: 6px; background: var(--rule-soft); }
.earth-bar i { display: block; height: 100%; background: var(--earth-shell); }
#gap-bar { background: var(--earth-lattice); }
.earth-frequency-result { display: block; margin-top: 13px; font-weight: 600; }
.earth-frequency-result[data-resolved="false"] { color: var(--earth-accent); }
.earth-frequency-result[data-resolved="true"] { color: var(--earth-shell); }

.earth-footer { margin-top: 40px; padding: 19px 0 26px; border-top: 1px solid var(--rule); color: var(--ink-2); font-size: 0.875rem; }
.earth-footer p { margin: 0 0 5px; }

@media (max-width: 1040px) {
  .earth-wrap { width: calc(100% - 44px); }
  .earth-workspace { grid-template-columns: minmax(0, 1.4fr) minmax(285px, 1fr); }
}

@media (max-width: 760px) {
  .earth-wrap { width: calc(100% - 32px); }
  .earth-header { grid-template-columns: 1fr auto; gap: 9px; padding-block: 10px; }
  .earth-nav { grid-row: 2; grid-column: 1 / -1; justify-content: start; gap: 3px; }
  .earth-nav a { padding-inline: 8px; }
  .earth-intro, .earth-workspace, .earth-cycle, .earth-evidence, .earth-test-grid { grid-template-columns: minmax(0, 1fr); }
  .earth-source-button { justify-self: start; }
  .earth-stage { height: clamp(350px, 69vw, 450px); }
  .earth-cycle-diagram { border-right: 0; border-bottom: 1px solid var(--rule); }
  .earth-cycle-diagram canvas { height: clamp(190px, 34vw, 260px); }
}

@media (max-width: 430px) {
  .earth-plate-head { padding-inline: 12px; }
  .earth-plate-controls { grid-template-columns: minmax(0, 1fr) auto; gap: 7px 12px; }
  .earth-plate-controls label { grid-column: 1; }
  .earth-plate-controls input { grid-column: 1; grid-row: 2; }
  .earth-plate-controls output { grid-column: 2; grid-row: 1; }
  .earth-plate-controls button { grid-column: 2; grid-row: 2; }
  .earth-role-choices button { min-height: 44px; }
}
