:root {
  color-scheme: dark;
  --bg: #070c16;
  --ocean: #0d1b2e;
  --ink: #e8f0f8;
  --muted: rgba(232, 240, 248, 0.62);
  --accent: #8fd4f0;
  --panel: rgba(9, 16, 28, 0.86);
  --line: rgba(143, 212, 240, 0.22);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 ui-sans-serif, system-ui, -apple-system, sans-serif;
}

canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}
canvas.over-plate { cursor: move; }
canvas.dragging { cursor: grabbing; }

.panel {
  position: absolute;
  left: 1rem;
  top: 1rem;
  z-index: 2;
  width: min(22rem, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
  padding: 0.9rem 1.1rem;
  border-radius: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  backdrop-filter: blur(8px);
}

h1 { margin: 0 0 0.3rem; font-size: 1.05rem; font-weight: 600; }
.chapter-pick select {
  width: 100%;
  margin: 0.2rem 0 0.5rem;
  font: inherit;
  font-size: 0.85rem;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.3rem 0.4rem;
}
.intro { margin: 0 0 0.5rem; font-size: 0.85rem; }
.questions { margin: 0 0 0.7rem; padding-left: 1.2rem; font-size: 0.8rem; color: var(--muted); }
.questions li { margin-bottom: 0.2rem; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0);
}
.hint, .note, .source { margin: 0 0 0.7rem; font-size: 0.8rem; color: var(--muted); }
.source { margin: 0.6rem 0 0; font-size: 0.72rem; }
kbd {
  font: inherit;
  padding: 0 0.3rem;
  border: 1px solid var(--line);
  border-radius: 3px;
}

.plates {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
  margin-bottom: 0.4rem;
}
.plates th {
  text-align: right;
  font-weight: 500;
  color: var(--muted);
  padding: 0 0.3rem 0.25rem;
}
.plates th:nth-child(2) { text-align: left; }
.plates td { padding: 0.15rem 0.3rem; text-align: right; }
.plates td:nth-child(2) { text-align: left; white-space: nowrap; }
.plates tr.active td { color: var(--accent); }
.plates tr.moved td:nth-child(n+3) { color: var(--ink); }
.plates td:nth-child(n+3) { color: var(--muted); }
.swatch {
  display: inline-block;
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 2px;
  vertical-align: -0.1rem;
}

.row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.9rem;
  margin-top: 0.55rem;
}
.toggle { display: flex; align-items: center; gap: 0.35rem; font-size: 0.82rem; }
button {
  font: inherit;
  font-size: 0.82rem;
  color: var(--ink);
  background: rgba(143, 212, 240, 0.12);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.3rem 0.75rem;
  cursor: pointer;
}
button:hover:not(:disabled) { background: rgba(143, 212, 240, 0.22); }
button:disabled { opacity: 0.4; cursor: default; }
input[type=checkbox] { accent-color: var(--accent); }

.timebar {
  position: absolute;
  z-index: 2;
  left: 50%;
  bottom: 1rem;
  transform: translateX(-50%);
  width: min(40rem, calc(100vw - 2rem));
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.55rem 0.9rem;
  border-radius: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  backdrop-filter: blur(8px);
}
@media (min-width: 901px) {
  /* Centre under the globe, not the window: the panel takes the left of the screen. */
  .timebar { left: calc(50% + 12rem); }
}
.timebar input[type=range] { flex: 1; accent-color: var(--accent); }
.play { min-width: 5.5rem; }
.shown-age {
  min-width: 4.5rem;
  text-align: right;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

.tag {
  font-size: 0.68rem;
  padding: 0 0.3rem;
  border: 1px solid var(--line);
  border-radius: 3px;
  color: var(--muted);
}
.toggle select {
  font: inherit;
  font-size: 0.82rem;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 0.15rem 0.3rem;
}
.misfit {
  position: absolute;
  z-index: 2;
  right: 1rem;
  top: 1rem;
  width: 15rem;
  padding: 0.6rem 0.9rem;
  border-radius: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  backdrop-filter: blur(8px);
}
.misfit[hidden] { display: none; }
.misfit h2 { margin: 0 0 0.3rem; font-size: 0.85rem; font-weight: 600; }
.misfit h2 span { color: var(--accent); font-variant-numeric: tabular-nums; }
.misfit td:first-child, .misfit th:first-child { text-align: left; }
.misfit td { color: var(--ink) !important; }

/* The hidden attribute wins over any display rule above (.row is a flex box). */
[hidden] { display: none !important; }

/* "Moves with" menus in the plate table (rotation-tree chapters). */
.plates select.parent {
  font: inherit; font-size: 0.75rem; max-width: 7.5rem; padding: 0.05rem 0.2rem;
  background: #16263d; color: inherit; border: 1px solid rgba(143, 212, 240, 0.3); border-radius: 4px;
}
.tree .panel { width: min(26rem, calc(100vw - 2rem)); }
.tree .plates td { padding: 0.15rem 0.2rem; }
#link-row { align-items: baseline; flex-wrap: wrap; }
#link-note { margin: 0; flex: 1 1 12rem; }
canvas.linking, canvas.linking.over-plate { cursor: crosshair; }

/* Chapters that build on earlier ones: what was carried over, and file fallbacks. */
.carry .note { margin-bottom: 0.4rem; }
.file-button {
  font-size: 0.78rem; padding: 0.3rem 0.6rem; border-radius: 6px; cursor: pointer;
  border: 1px solid rgba(143, 212, 240, 0.35); background: rgba(143, 212, 240, 0.08);
}
.file-button input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.file-button:focus-within { outline: 2px solid #6fe3ff; }

/* Collapsible misfit box. */
.misfit-toggle {
  all: unset; cursor: pointer; display: flex; align-items: baseline; gap: 0.35rem; width: 100%;
  font: inherit; font-size: 0.85rem; font-weight: 600;
}
.misfit-toggle:focus-visible { outline: 2px solid #6fe3ff; outline-offset: 2px; border-radius: 3px; }
.misfit-toggle .chev { display: inline-block; transition: transform 0.15s; color: var(--muted); }
.misfit.collapsed .chev { transform: rotate(-90deg); }
.misfit.collapsed #misfit-body { display: none; }
.misfit.collapsed h2 { margin: 0; }

/* Spreading rates, lower right, clear of the time bar. */
.rates { top: auto; bottom: 5rem; width: 19rem; }
.rates.collapsed #rates-body { display: none; }
.rates.collapsed .chev { transform: rotate(-90deg); }
.rates-legend { list-style: none; margin: 0.2rem 0 0.3rem; padding: 0; display: flex; gap: 0.7rem; font-size: 0.75rem; color: var(--muted); }
.rates-legend li { display: flex; align-items: center; gap: 0.3rem; }
.rates-legend i { width: 0.8rem; height: 2px; border-radius: 1px; }
#rates-plot { display: block; width: 100%; height: 150px; overflow: visible; cursor: crosshair; }
#rates-plot text { fill: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; }
#rates-plot .grid { stroke: rgba(143, 212, 240, 0.12); }
#rates-plot .axis { stroke: rgba(143, 212, 240, 0.35); }
.rates-readout { margin: 0.2rem 0 0; min-height: 1.1em; font-variant-numeric: tabular-nums; }

/* Globe / Map switch. */
.segmented { display: inline-flex; border: 1px solid rgba(143, 212, 240, 0.35); border-radius: 6px; overflow: hidden; }
.segmented button { border: 0; border-radius: 0; padding: 0.3rem 0.8rem; background: transparent; }
.segmented button[aria-pressed="true"] { background: rgba(143, 212, 240, 0.25); color: var(--ink); }

/* The legend in the panel: every symbol and colour scale this chapter uses. */
.legend { font-size: 0.75rem; color: var(--muted); margin: 0.2rem 0 0.6rem; }
.key-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.25rem; }
.key-list li { display: flex; align-items: center; gap: 0.45rem; flex-wrap: wrap; }
.key-list li[hidden] { display: none; }
.key-list .key-note { font-style: italic; }
.legend .ramp {
  display: block; width: 100%; height: 0.6rem; border-radius: 2px;
  background: linear-gradient(90deg, #fcfdbf, #fecf92, #fe9f6d, #f7705c, #de4968, #b73779, #8c2981);
}
.legend .ramp-ticks { display: flex; justify-content: space-between; width: 100%; font-variant-numeric: tabular-nums; }
.legend .key-label { width: 100%; }
.legend .ring { flex: none; width: 0.7rem; height: 0.7rem; border-radius: 50%; border: 2px solid #ff5a5a; box-sizing: border-box; }
.legend .sq { flex: none; width: 0.6rem; height: 0.6rem; background: #de4968; outline: 1px solid #0d1b2e; }
.legend .dot { flex: none; width: 0.7rem; height: 0.7rem; border-radius: 50%; background: #de4968; box-shadow: 0 0 0 1.5px rgba(240, 246, 252, 0.9); }
.legend .cells { flex: none; width: 0.8rem; height: 0.6rem; background: repeating-linear-gradient(90deg, #fe9f6d 0 3px, transparent 3px 4px); }
.legend .star { flex: none; color: #ffd34d; font-size: 0.95rem; line-height: 1; }
.legend .link { flex: none; width: 1.1rem; height: 2px; background: #e8663c; }
.legend .ghost { flex: none; width: 0.8rem; height: 0.6rem; border: 1px solid rgba(232, 240, 248, 0.6); box-sizing: border-box; }
.timebar .segmented button { padding: 0.3rem 0.6rem; font-size: 0.8rem; }

.questions-box { margin: 0 0 0.6rem; font-size: 0.8rem; color: var(--muted); }
.questions-box summary { cursor: pointer; color: var(--ink); }
.questions-box .questions { margin: 0.35rem 0 0; }
.sources summary { cursor: pointer; margin-top: 0.45rem; font-size: 0.72rem; }
.sources .source { margin-top: 0.25rem; }
.tree .plates td { padding-top: 0.05rem; padding-bottom: 0.05rem; }
.tree .plates select.parent { padding: 0 0.2rem; }
.legend .fz { flex: none; width: 1.1rem; height: 2px; background: rgba(236, 242, 250, 0.9); }
.legend .iso { flex: none; width: 1.1rem; height: 3px; background: linear-gradient(90deg, #fe9f6d, #b73779); }
.legend .poles { flex: none; width: 1.2rem; height: 0.55rem; background: radial-gradient(circle at 20% 50%, #fecf92 0 0.2rem, transparent 0.22rem), radial-gradient(circle at 80% 50%, #b73779 0 0.2rem, transparent 0.22rem), linear-gradient(transparent 45%, rgba(255,255,255,0.8) 45% 58%, transparent 58%); }
.legend .dot.small { width: 0.55rem; height: 0.55rem; }

/* Isochron picker (South Atlantic). */
.stage-row .stages { display: flex; flex-wrap: wrap; gap: 0.3rem; margin: 0 0 0.4rem; }
.stage-row button { padding: 0.2rem 0.45rem; font-size: 0.78rem; line-height: 1.15; display: inline-flex; flex-direction: column; align-items: center; }
.stage-row button small { font-size: 0.62rem; color: var(--muted); }
.stage-row button[aria-pressed="true"] { background: rgba(143, 212, 240, 0.28); border-color: var(--accent); }
.stage-row button.fitted::after { content: "\2713"; font-size: 0.6rem; color: #7fe0a0; }
.stage-row button.now { margin-left: auto; }
.stage-row .note { margin: 0 0 0.6rem; }
