/* The page's own chrome. Everything inside the canvas is coloured by the Rust
   palette instead, so the two themes here only have to agree with it at the edges:
   --canvas is overwritten from the scene's own background colour on every load. */

:root {
  --canvas: #11141a;
  --bg: #0c0e13;
  --surface: #161a22;
  --surface-2: #1d222c;
  --border: #262c38;
  --text: #e6eaf0;
  --muted: #98a2b3;
  --accent: #4dd0e1;
  --accent-strong: #22b8cf;
  --danger: #ff8f6b;
  --radius: 10px;
  --panel-width: 310px;
  color-scheme: dark;
}

body[data-theme='light'] {
  --canvas: #f7f8fa;
  --bg: #eef1f5;
  --surface: #ffffff;
  --surface-2: #f2f4f8;
  --border: #d8dee8;
  --text: #1b1f27;
  --muted: #5c6675;
  --accent: #0b8499;
  --accent-strong: #076d80;
  --danger: #b23a10;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

/* Several elements here are toggled with the `hidden` attribute *and* carry a
   `display` of their own, which would otherwise win over the user-agent rule. */
[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue',
    'Hiragino Sans', 'Noto Sans JP', sans-serif;
  overflow: hidden;
}

code,
pre {
  font-family: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;
  font-size: 0.92em;
}

/* --- top bar ------------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand .mark {
  width: 30px;
  height: 30px;
  flex: none;
  color: var(--text);
}

.brand h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.brand p {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.links {
  display: flex;
  gap: 14px;
  flex: none;
}

.links a {
  color: var(--muted);
  text-decoration: none;
  font-size: 13px;
  border-bottom: 1px solid transparent;
}

.links a:hover {
  color: var(--text);
  border-bottom-color: var(--accent);
}

/* --- layout -------------------------------------------------------------- */

.layout {
  flex: 1;
  display: flex;
  min-height: 0;
}

.panel {
  width: var(--panel-width);
  flex: none;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.block {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.block h2 {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
}

.stage {
  position: relative;
  flex: 1;
  min-width: 0;
  background: var(--canvas);
}

/* The viewer mounts its own shadow root in here and sizes itself from this box;
   the page contributes nothing but the box. */
.viewer {
  position: absolute;
  inset: 0;
}

/* --- controls ------------------------------------------------------------ */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
}

.button:hover {
  border-color: var(--accent);
}

.button.primary {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  color: #06222a;
  font-weight: 600;
}

body[data-theme='light'] .button.primary {
  color: #ffffff;
}

.button.primary:hover {
  filter: brightness(1.08);
}

.file-actions {
  display: grid;
  gap: 8px;
}

.hint {
  margin: 10px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.hint code {
  background: var(--surface-2);
  padding: 1px 4px;
  border-radius: 4px;
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
  font-size: 13px;
}

.row select {
  flex: 1;
  max-width: 62%;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 12px;
}

.row.checkbox {
  justify-content: flex-start;
}

.row.checkbox input {
  accent-color: var(--accent-strong);
}

.row input[type='range'] {
  flex: 1;
  max-width: 62%;
  accent-color: var(--accent-strong);
}

/* The relief a map actually has, beside the toggle that would show it. */
.row .count {
  font-size: 11px;
  color: var(--muted);
}

/* A map whose nodes carry no elevation has nothing to draw in 3D. */
.row.checkbox:has(input:disabled) {
  opacity: 0.45;
}

#three-d-controls {
  margin: 0 0 8px 22px;
}

#export-button {
  margin-top: 4px;
}

.toggles {
  display: grid;
  gap: 2px;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 4px 6px;
  border-radius: 7px;
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}

.toggle:hover {
  background: var(--surface-2);
}

.toggle input {
  accent-color: var(--accent-strong);
}

.toggle .count {
  margin-left: auto;
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.toggle.empty {
  opacity: 0.45;
}

/* --- facts and legend ---------------------------------------------------- */

.facts {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 12px;
  margin: 12px 0 0;
  font-size: 12.5px;
}

.facts dt {
  color: var(--muted);
}

.facts dd {
  margin: 0;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.legend {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 5px;
  font-size: 12.5px;
}

.legend li {
  display: flex;
  align-items: center;
  gap: 9px;
}

.legend .swatch {
  width: 22px;
  height: 12px;
  flex: none;
  border-radius: 3px;
  background: var(--surface-2);
}

.problem h2 {
  color: var(--danger);
}

.problem .count {
  color: var(--muted);
  letter-spacing: 0;
}

#errors {
  margin: 0;
  max-height: 190px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 11.5px;
  color: var(--muted);
}

/* --- stage furniture ----------------------------------------------------- */

.dropzone {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
  color: var(--muted);
  pointer-events: none;
  transition: background 0.15s;
}

.dropzone[hidden] {
  display: none;
}

.dropzone svg {
  width: 76px;
  height: 76px;
  margin-bottom: 12px;
  color: var(--border);
}

.dropzone .big {
  margin: 0 0 6px;
  font-size: 17px;
  color: var(--text);
}

.dropzone .small {
  margin: 0;
  font-size: 13px;
  max-width: 30rem;
}

/* Deliberately beats the `[hidden]` rule above: once a map is loaded the hint is
   hidden, but it has to come back while something is being dragged over the page. */
body.dragging .dropzone {
  display: grid !important;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  outline: 2px dashed var(--accent);
  outline-offset: -14px;
}

body.dragging .dropzone svg {
  color: var(--accent);
}

/* The one overlay the page still owns. Pan, zoom, the scale bar and the tooltip
   moved into the viewer's shadow root when it became embeddable; this did not,
   because "fetching the example map" is the demo's business, not the viewer's. */

.overlay-status {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  font-size: 13px;
  z-index: 6;
}

.overlay-status.error {
  border-color: var(--danger);
  color: var(--danger);
  max-width: min(90%, 34rem);
  text-align: left;
}

.overlay-status.error .spinner {
  display: none;
}

.spinner {
  width: 14px;
  height: 14px;
  flex: none;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation-duration: 3s;
  }
}

/* --- narrow screens ------------------------------------------------------ */

@media (max-width: 760px) {
  .layout {
    flex-direction: column-reverse;
  }

  .panel {
    width: 100%;
    max-height: 46vh;
    border-right: none;
    border-top: 1px solid var(--border);
  }

  .brand p,
  .links {
    display: none;
  }
}
