: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; }
.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] { display: none; }
