:root {
  --ink: #f2efe6;
  --ink-dim: #b3ada0;
  --panel-bg: rgba(16, 18, 17, 0.66);
  --panel-border: rgba(242, 239, 230, 0.13);
  --accent: #e0a35a;
  --control-bg: rgba(255, 255, 255, 0.06);
  --control-border: rgba(255, 255, 255, 0.14);
}

* {
  box-sizing: border-box;
}

/* .field sets display:flex, which otherwise wins over the hidden attribute
   and leaves controls on screen that do nothing. */
[hidden] {
  display: none !important;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: #0a0c0a;
  font-family: -apple-system, "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
}

canvas#terrain {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}

canvas#terrain.grabbing {
  cursor: grabbing;
}

.panel {
  position: fixed;
  top: 20px;
  left: 20px;
  width: 264px;
  max-width: calc(100vw - 40px);
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 18px 18px 16px;
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  box-shadow: 0 16px 44px rgba(0, 0, 0, 0.4);
  display: flex;
  flex-direction: column;
  gap: 13px;
  transition: transform 220ms ease, opacity 220ms ease;
}

.panel.hidden {
  transform: translateX(-18px);
  opacity: 0;
  pointer-events: none;
}

/* The page is a full-bleed canvas, so the real heading and description are
   present for screen readers and search engines without being drawn. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.panel header h2 {
  margin: 0 0 5px;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.busy {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0;
  transition: opacity 140ms ease;
}

.busy.on {
  opacity: 1;
  animation: pulse 900ms ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.6); }
}

@media (prefers-reduced-motion: reduce) {
  .busy.on { animation: none; }
  .panel { transition: none; }
}

.panel .tagline {
  margin: 0;
  font-size: 11.5px;
  line-height: 1.55;
  color: var(--ink-dim);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--ink-dim);
  display: flex;
  justify-content: space-between;
}

.mono {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color: var(--accent);
  text-transform: none;
  letter-spacing: 0;
}

.row {
  display: flex;
  gap: 8px;
}

.row input[type="range"] {
  flex: 1;
  min-width: 0;
}

#flood {
  flex: 0 0 auto;
  width: 38px;
  padding: 6px;
  font-size: 12px;
}

#flood[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--accent);
}

input[type="number"],
select {
  flex: 1;
  min-width: 0;
  background: var(--control-bg);
  border: 1px solid var(--control-border);
  color: var(--ink);
  border-radius: 8px;
  padding: 7px 9px;
  font-size: 13px;
  outline: none;
}

input[type="number"] {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

input[type="number"]:focus-visible,
select:focus-visible,
button:focus-visible,
input[type="range"]:focus-visible,
input[type="checkbox"]:focus-visible,
summary:focus-visible,
a:focus-visible,
canvas#terrain:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* The canvas is focusable so arrow-key panning is reachable without a mouse;
   the inset keeps the ring visible against a full-bleed element. */
canvas#terrain:focus-visible {
  outline-offset: -3px;
}

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

.checks {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}

.check {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--ink-dim);
  cursor: pointer;
}

.check input {
  accent-color: var(--accent);
  margin: 0;
}

button {
  background: var(--control-bg);
  border: 1px solid var(--control-border);
  color: var(--ink);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
}

button:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: var(--accent);
}

#randomize {
  flex: 0 0 auto;
  width: 38px;
  font-size: 15px;
  padding: 6px;
}

.actions {
  display: flex;
  gap: 8px;
}

.actions button {
  flex: 1;
}

.group {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 13px;
  border-top: 1px solid var(--panel-border);
}

.note {
  margin: -2px 0 0;
  font-size: 10.5px;
  line-height: 1.45;
  color: var(--ink-dim);
}

.note[hidden] {
  display: none;
}

.status {
  margin: 0;
  min-height: 14px;
  font-size: 11px;
  color: var(--accent);
}

.hint,
.credit {
  margin: 0;
  font-size: 11px;
  color: var(--ink-dim);
}

kbd {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 10px;
  border: 1px solid var(--control-border);
  border-radius: 4px;
  padding: 0 3px;
  color: var(--ink);
}

button:disabled {
  opacity: 0.5;
  cursor: default;
}

button:disabled:hover {
  background: var(--control-bg);
  border-color: var(--control-border);
}

.credit a {
  color: var(--accent);
  text-decoration: none;
}

.credit a:hover {
  text-decoration: underline;
}

details > summary {
  cursor: pointer;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--ink-dim);
  list-style: none;
  padding: 2px 0;
}

details > summary::-webkit-details-marker { display: none; }

/* Drawn with borders rather than a glyph: the ▸ character does not resolve in
   every UI font and fell back to a bullet. */
details > summary::before {
  content: "";
  display: inline-block;
  width: 0;
  height: 0;
  margin-right: 6px;
  vertical-align: middle;
  border-left: 5px solid currentColor;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transition: transform 120ms ease;
}

details[open] > summary::before {
  transform: rotate(90deg);
}

@media (prefers-reduced-motion: reduce) {
  details > summary::before { transition: none; }
}

details > summary:hover { color: var(--ink); }

.readout {
  margin: 8px 0 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11.5px;
}

.readout > div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.readout dt {
  color: var(--ink-dim);
  margin: 0;
}

.readout dd {
  margin: 0;
  text-align: right;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.provenance {
  margin-top: 8px;
  font-size: 11px;
  line-height: 1.5;
  color: var(--ink-dim);
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.provenance .prov-row {
  display: flex;
  gap: 7px;
  align-items: baseline;
}

/* Colour-coded so the measured/derived/invented distinction is scannable,
   with a text tag so it never depends on colour alone. */
.prov-tag {
  flex: 0 0 auto;
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 3px;
  border: 1px solid currentColor;
}

.prov-measured { color: #6fce7a; }
.prov-derived { color: #e0a35a; }
.prov-generated { color: #c58fd8; }

.progress {
  height: 4px;
  border-radius: 2px;
  background: var(--control-bg);
  overflow: hidden;
}

.progress span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 120ms linear;
}

/* Point inspector: a small card pinned near the probed point, plus a dot
   marking the exact world coordinate. Both are re-projected on every render
   so they track the terrain through pans and zooms. */
.inspector {
  position: fixed;
  z-index: 5;
  width: 212px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 10px 12px;
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

.inspector .readout {
  margin: 0;
  padding-right: 14px;
}

#inspectorClose {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 22px;
  height: 22px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--ink-dim);
  font-size: 14px;
  line-height: 1;
}

#inspectorClose:hover {
  background: transparent;
  border: none;
  color: var(--ink);
}

.inspector-dot {
  position: fixed;
  z-index: 4;
  width: 10px;
  height: 10px;
  margin: -5px 0 0 -5px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  background: rgba(224, 163, 90, 0.25);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4);
  pointer-events: none;
}

/* Zoom controls: the only discoverable zoom on a touchscreen without a
   scroll wheel, and a keyboard-reachable one everywhere else. */
.zoomers {
  position: fixed;
  right: 20px;
  bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.zoomers button {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  font-size: 19px;
  line-height: 1;
  padding: 0;
}

.toggle {
  position: fixed;
  top: 20px;
  right: 20px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  color: var(--ink);
  font-size: 18px;
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

@media (max-width: 520px) {
  .panel {
    left: 12px;
    top: 12px;
    right: 12px;
    width: auto;
  }
  .toggle {
    top: 12px;
    right: 12px;
  }
}
