:root {
  --bg: #05070d;
  --panel: #0d1220;
  --line: #1f2a40;
  --text: #dfe7f2;
  --muted: #8a97ab;
  --accent: #ffd34d;
  --green: #6ab787;
  --orange: #ffb347;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}

a { color: #8cc4ff; }

#app {
  display: grid;
  grid-template-columns: 1fr 360px;
  height: 100%;
}

#stage { position: relative; min-height: 0; overflow: hidden; }
#three, #three canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
#three canvas { display: block; }
.labels { position: absolute; inset: 0; pointer-events: none; }

.label {
  font-size: 12px;
  color: var(--muted);
  padding: 1px 5px;
  border-radius: 3px;
  background: rgba(5, 7, 13, 0.55);
  white-space: nowrap;
}
.label.light { color: var(--accent); }
.label.plane { color: #b7c3d4; }
.label.tangent { color: #b7c3d4; transform: translateY(-14px); }

#panel {
  background: var(--panel);
  border-left: 1px solid var(--line);
  overflow-y: auto;
  padding: 14px 16px 24px;
}

header h1 { margin: 0; font-size: 20px; letter-spacing: 0.02em; }
.sub { margin: 2px 0 0; color: var(--muted); }

section { padding: 12px 0; border-bottom: 1px solid var(--line); }
section:last-child { border-bottom: 0; }

.presets { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 10px; }

button, select {
  font: inherit;
  color: var(--text);
  background: #18213a;
  border: 1px solid #2a3756;
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
}
button:hover { background: #222d4b; }
button.active { border-color: var(--accent); color: var(--accent); }
button.small { padding: 2px 8px; font-size: 12px; }

.row { display: flex; justify-content: space-between; margin-top: 8px; color: var(--muted); }
.row output { color: var(--text); font-variant-numeric: tabular-nums; }

input[type="range"] { width: 100%; accent-color: var(--accent); margin: 4px 0 0; }

.scale { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); }

#map2d { display: block; width: 100%; aspect-ratio: 1; border-radius: 6px; }

.badge { font-size: 12px; margin: 6px 0 0; color: var(--muted); }
.badge.ok { color: var(--green); }

.projline { display: flex; gap: 8px; align-items: flex-start; }
#projstring {
  flex: 1;
  font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
  background: #070b16;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  word-break: break-all;
}
#projstring.none { color: var(--muted); }
.describe { margin: 8px 0 0; }

.buttons, .toggles, .share { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; align-items: center; }
.toggles label { display: flex; gap: 5px; align-items: center; color: var(--muted); }
.share a { margin-left: auto; }

.about summary { cursor: pointer; font-weight: 600; }
.about p { color: #c4cedb; }
.about table { border-collapse: collapse; width: 100%; font-size: 13px; }
.about th, .about td { text-align: left; padding: 3px 6px; border-bottom: 1px solid var(--line); }
.about th { color: var(--muted); font-weight: 500; }
.about ul.credits { margin: 6px 0 0; padding-left: 18px; color: #c4cedb; font-size: 13px; }
.about ul.credits li { margin: 3px 0; }

/* phones and narrow windows: stack the scene above the panel */
@media (max-width: 820px) {
  #app { grid-template-columns: 1fr; grid-template-rows: 58vh auto; height: auto; }
  #stage { height: 58vh; }
  #panel { border-left: 0; border-top: 1px solid var(--line); overflow: visible; }
}

/* ?embed=1: the scene fills the frame with a compact overlay */
body.embed #app { grid-template-columns: 1fr; height: 100%; }
body.embed #stage { height: 100%; }
body.embed #panel {
  position: absolute;
  left: 8px; bottom: 8px;
  width: min(300px, calc(100% - 16px));
  padding: 8px 10px;
  background: rgba(13, 18, 32, 0.85);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: visible;
}
body.embed #panel > :not(.embed-keep):not(.embed-map) { display: none; }
body.embed #panel section { padding: 0; border: 0; }
body.embed .embed-map {
  position: fixed;
  right: 8px; top: 8px;
  width: min(34vw, 220px);
}
body.embed .embed-map .badge { display: none; }
body.embed #map2d { border: 1px solid var(--line); }
select.wide { width: 100%; margin-top: 4px; }
label.inline { display: flex; gap: 6px; align-items: center; color: var(--muted); }
button:disabled { opacity: 0.5; cursor: default; }
.status { margin: 6px 0 0; font-size: 12px; color: var(--orange); min-height: 0; }
.status:empty { display: none; }
.status .probe-list { list-style: none; margin: 0; padding: 0; color: var(--text); }
.status .probe-list li { margin: 2px 0; }
.hint { margin: 6px 0 0; font-size: 12px; color: var(--muted); }
.credit {
  position: absolute; right: 8px; bottom: 6px; margin: 0;
  max-width: 60%;
  font-size: 11px; color: var(--muted); text-align: right;
  background: rgba(5, 7, 13, 0.6); padding: 2px 6px; border-radius: 4px;
}
.credit:empty { display: none; }
.open-full {
  position: absolute; top: 8px; left: 8px;
  font-size: 12px;
  background: rgba(13, 18, 32, 0.85);
  padding: 3px 8px; border-radius: 4px;
  text-decoration: none;
}

.presets.three { grid-template-columns: repeat(3, 1fr); }
.pages { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 6px; font-size: 13px; }
/* related pages sit together; a wider gap between families */
.pages { column-gap: 26px; }
.pages .group { display: inline-flex; flex-wrap: wrap; gap: 4px 14px; }
.pages a { color: var(--muted); text-decoration: none; padding-bottom: 2px; border-bottom: 2px solid transparent; }
.pages a:hover { color: var(--text); }
.pages a[aria-current="page"] { color: var(--text); border-bottom-color: var(--accent); }
#map2d.wide-map { aspect-ratio: auto; }
input.token {
  flex: 1; min-width: 0;
  font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--text); background: #070b16;
  border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px;
}
input.token.bad { border-color: var(--orange); }
canvas.view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; }
.step-title { margin: 0 0 4px; font-weight: 600; font-size: 16px; }
.steps { margin: 0; padding-left: 22px; color: var(--muted); }
.steps li { cursor: pointer; padding: 1px 0; }
.steps li:hover { color: var(--text); }
.steps li.active { color: var(--accent); }
/* tissot.html: the globe and the map side by side in the stage */
#stage.split { display: grid; grid-template-columns: 1fr 1fr; }
#stage.split > .half { position: relative; min-width: 0; min-height: 0; overflow: hidden; }
#stage.split > .half + .half { border-left: 1px solid var(--line); }
#map { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: crosshair; }
.half-label {
  position: absolute; left: 8px; bottom: 6px; pointer-events: none;
  font-size: 12px; color: var(--muted);
  background: rgba(5, 7, 13, 0.6); padding: 1px 6px; border-radius: 4px;
}
.readout { border-collapse: collapse; width: 100%; font-size: 13px; margin-top: 6px; font-variant-numeric: tabular-nums; }
.readout td { padding: 2px 6px; border-bottom: 1px solid var(--line); }
.readout td:first-child { color: var(--muted); }
.readout td:last-child { text-align: right; }
/* stacked when the stage is taller than it is wide (set from js) */
#stage.split.stacked { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
#stage.split.stacked > .half + .half { border-left: 0; border-top: 1px solid var(--line); }
@media (max-width: 820px) { #stage.split { height: 92vh; } }
body.embed #stage.split .half-label { display: none; }
/* structure.html: levels table, file layout bar and the close look at a pick */
.readout.levels tr[data-k], #pick-levels tr[data-k] { cursor: pointer; }
.readout tr.active td { color: var(--accent); }
.readout.levels td:last-child { text-align: right; }
.layout-bar { display: flex; height: 18px; margin-top: 6px; border: 1px solid var(--line); border-radius: 4px; overflow: hidden; }
.layout-bar > div { min-width: 2px; }
.layout-bar .head { background: var(--orange); }
.layout-bar .gap { background: #101727; }
.layout-bar .lvl { background: #2b5487; border-left: 1px solid #05070d; cursor: pointer; }
.layout-bar .lvl:nth-child(even) { background: #3d6ea8; }
.layout-bar .lvl.active { background: var(--accent); }
canvas.inset { display: block; width: 100%; margin-top: 8px; border-radius: 6px; border: 1px solid var(--line); }
#presets { grid-template-columns: 1fr 1fr; }
#spec-box input.token[type="text"], #zarr-ctl input.token { display: block; width: 100%; margin-top: 4px; }
.readout.levels { font-size: 12px; }
.readout.levels td { white-space: nowrap; padding: 2px 4px; }
#ghost:empty { display: none; }
#ghost { word-break: break-word; }
/* rasterize.html: the two answers side by side */
canvas.cells { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: crosshair; touch-action: none; }
#sources { grid-template-columns: 1fr 1fr 1fr; }
#sources button { font-size: 12px; padding: 4px 6px; }
#bytes td:first-child, #counts td:first-child { white-space: normal; }
#counts td { text-align: right; white-space: nowrap; }
#counts td:first-child { text-align: left; }
#counts tr.head td { color: var(--muted); font-size: 12px; }
#tile-row[hidden] { display: none; }
body.embed #shapes, body.embed #detail, body.embed label[for="detail"] { display: none; }
/* regular.html: pasted lon/lat */
#paste {
  display: block; width: 100%; margin-top: 4px; resize: vertical;
  font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--text); background: #070b16;
  border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px;
}
#answer { word-break: break-word; }
.presets[hidden], .buttons[hidden] { display: none; }
/* Tissot: colour bar and the distortion summary */
.cbar { display: block; width: 100%; height: 34px; margin-top: 10px; }
.readout.summary { font-size: 12px; margin-top: 8px; }
.readout.summary td { padding: 2px 4px; text-align: right; }
.readout.summary td:first-child { text-align: left; }
.readout.summary th { font-weight: normal; color: var(--muted); text-align: right; padding: 2px 4px; }
/* rhumb.html: four maps of the same two lines */
#stage.quad { display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
#stage.quad > .half { position: relative; min-width: 0; min-height: 0; overflow: hidden; }
#stage.quad > .half:nth-child(even) { border-left: 1px solid var(--line); }
#stage.quad > .half:nth-child(n+3) { border-top: 1px solid var(--line); }
@media (max-width: 820px) {
  #app:has(#stage.quad) { grid-template-rows: auto auto; }
  #stage.quad { height: auto; grid-template-columns: 1fr; grid-template-rows: repeat(4, min(80vw, 60vh)); }
  #stage.quad > .half:nth-child(even) { border-left: 0; }
  #stage.quad > .half + .half { border-top: 1px solid var(--line); }
}
body.embed #stage.quad .half-label { display: none; }

/* ellipsoid.html: a readout with a true and a drawn column */
.readout.both td.num { text-align: right; white-space: nowrap; }
.readout.both tr.sub td { color: var(--text); font-weight: 600; padding-top: 8px; text-align: left; }
pre.projdef { font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; background: #070b16; border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; margin: 8px 0 0; white-space: pre-wrap; word-break: break-all; }
/* geoid.html: the globe over its profile */
#stage.split.stacked.geoid, #stage.split.stacked.penguin { grid-template-rows: 3fr 2fr; }
/* texture.html: vertex numbers on the small mesh, and its vertex table */
.vlabel {
  font: bold 12px system-ui, sans-serif; color: var(--accent);
  background: rgba(5, 7, 13, 0.7); padding: 0 4px; border-radius: 3px;
}
.readout table.vtable { width: 100%; border-collapse: collapse; font-size: 12px; }
.readout table.vtable th { color: var(--muted); font-weight: normal; text-align: right; padding: 1px 4px; }
.readout table.vtable td { text-align: right; padding: 1px 4px; border-bottom: 0; color: var(--text); }
.readout table.vtable tr.on td { color: var(--accent); }
/* affine.html: the image beside the map, the point table and the GDAL command */
#stage.split.affine canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.gt-text, pre.gdal { width: 100%; font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--text); background: #070b16; border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; margin: 6px 0 0; }
.gt-text { resize: vertical; }
pre.gdal { white-space: pre-wrap; word-break: break-all; }
pre.gdal:empty { display: none; }
table.gcps { width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 6px; font-variant-numeric: tabular-nums; }
table.gcps th { color: var(--muted); font-weight: normal; text-align: right; padding: 1px 3px; }
table.gcps td { text-align: right; padding: 1px 3px; border-bottom: 1px solid var(--line); }
table.gcps input { width: 72px; font: inherit; color: var(--text); background: #070b16; border: 1px solid var(--line); border-radius: 4px; padding: 1px 3px; text-align: right; }
@media (max-width: 820px) {
  #stage.split.affine { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
  #stage.split.affine > .half + .half { border-left: 0; border-top: 1px solid var(--line); }
}
/* ortho.html: the four images take the whole lower half on a phone */
@media (max-width: 820px) { #map-label { display: none; } }
/* rectilinear.html: the cuts along an axis, and the chunk_grid */
canvas.axis { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: col-resize; touch-action: none; }
.warn { color: var(--orange); }
#url { display: block; width: 100%; margin-top: 4px; }
#note3d:empty, #custom-note:empty { display: none; }

/* Frame: the locator globe and a legend ramp */
.locator { position: absolute; right: 12px; bottom: 12px; width: 168px; height: 168px; pointer-events: none; }
.locator[hidden] { display: none; }
.legend { margin-top: 8px; }
.legend[hidden] { display: none; }
.legend-ramp { height: 12px; border-radius: 3px; border: 1px solid var(--line); }
/* sight.html: the terrain over the eye's view */
#stage.split.stacked.sight { grid-template-rows: 3fr 2fr; }
/* guide.html: a reading page, not a stage and a panel */
body.guide-body { height: auto; }
.guide-top { padding: 14px 16px 10px; border-bottom: 1px solid var(--line); background: var(--panel); }
.guide { max-width: 760px; margin: 0 auto; padding: 8px 16px 48px; font-size: 16px; line-height: 1.6; }
.guide h1 { font-size: 28px; margin: 24px 0 6px; }
.guide h2 { font-size: 20px; margin: 0 0 6px; }
.guide section { padding: 22px 0; }
.guide .lede { color: #c4cedb; font-size: 17px; }
.guide p { margin: 8px 0; }
.guide .toc ol { columns: 2; column-gap: 32px; padding-left: 22px; margin: 12px 0 0; }
.guide ul.try { margin: 10px 0 0; padding-left: 20px; color: #c4cedb; font-size: 15px; }
.guide ul.try li { margin: 4px 0; }
.guide table.fam { border-collapse: collapse; margin: 10px 0; font-size: 14px; }
.guide table.fam th, .guide table.fam td { text-align: left; padding: 3px 14px 3px 0; border-bottom: 1px solid var(--line); }
.guide table.fam th { color: var(--muted); font-weight: 500; }
.guide table.fam td:not(:first-child) { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.guide pre.eq { font: 14px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; background: #070b16; border: 1px solid var(--line); border-radius: 6px; padding: 8px 12px; overflow-x: auto; }
.guide .src { font-size: 13px; color: var(--muted); }
.guide .sources ul { padding-left: 20px; font-size: 14px; color: #c4cedb; }
@media (max-width: 600px) { .guide .toc ol { columns: 1; } }
/* peel.html: the flat pieces, and the gore flattenings compared */
.flat { position: absolute; inset: 0; }
.flat canvas { display: block; width: 100%; height: 100%; }
.readout.peel-cmp th { color: var(--muted); font-weight: 400; text-align: right; padding: 2px 6px; font-size: 12px; }
.readout.peel-cmp td { text-align: right; }
.readout.peel-cmp tr.on td { color: var(--accent); }
#stage.peel .credit { bottom: auto; top: 6px; }

/* cutaway: the block above, the section below */
body.cutaway #three { bottom: 36%; height: auto; }
body.cutaway #section { position: absolute; left: 0; right: 0; bottom: 0; width: 100%; height: 36%; display: block; border-top: 1px solid var(--line); cursor: crosshair; }
body.cutaway canvas.cut-map { display: block; width: 100%; max-width: 300px; aspect-ratio: 1; margin: 8px 0 4px; border-radius: 6px; cursor: crosshair; touch-action: none; }
body.cutaway .map-zoom button { min-width: 2em; }
body.cutaway .map-at { min-height: 1.3em; margin: 2px 0; font-variant-numeric: tabular-nums; }
body.cutaway .credit { bottom: auto; top: 6px; }

/* fourd.html: time series at the picked point */
.series-ctl { display: flex; gap: 6px; align-items: center; margin-top: 8px; }
#series { display: block; width: 100%; max-width: 300px; margin-top: 8px; }
.series-key { font-size: 12px; color: var(--muted); }
.series-key span.sw { display: inline-block; width: 10px; height: 3px; margin-right: 5px; vertical-align: middle; }
