/*
 * The Explorer host's stylesheet. Ships beside explorer.js and is the other half
 * of it -- the module builds the DOM, this gives it a layout.
 *
 * Every colour is a custom property set by applyThemeVars() from the active Theme,
 * so this file names no colour of its own. That is the rule Geode's docs/adr/0038
 * states: a Theme governs the furniture, and the furniture must therefore not have
 * opinions of its own baked into CSS.
 *
 * Scoped under .dtm-explorer throughout, so a host page can put an Explorer inside
 * a larger document without this leaking onto it.
 */

.dtm-explorer {
  /*
   * The slider thumb's width, and therefore the chart's plot inset.
   *
   * A range input puts its thumb CENTRE at left + W/2 + fraction * (width - W),
   * because the thumb has to stay inside the track at both ends. The chart above the
   * slider insets its plot by W/2 so its marker lands on the thumb. That only works
   * if W is KNOWN, which is why the thumb is styled here rather than left native --
   * native widths differ between browsers. Change this and the recipe's
   * `charts.thumbWidth` must change with it.
   */
  --dtm-thumb: 14px;
  --dtm-radius: 10px;

  position: fixed;
  inset: 0;
  overflow: hidden;
  background: var(--dtm-page);
  color: var(--dtm-ink);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
               "Helvetica Neue", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.dtm-explorer *,
.dtm-explorer *::before,
.dtm-explorer *::after { box-sizing: border-box; }

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

.dtm-stage {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
}

.dtm-stage.is-dragging { cursor: grabbing; }

.dtm-globe { position: absolute; inset: 0; }

.dtm-globe canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

/* The vector overlay must not eat pointer events -- the stage below it owns drag,
   zoom and hover picking for every layer at once. */
.dtm-globe .globe-overlay { pointer-events: none; }

.dtm-loading {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.7rem;
  background: var(--dtm-page);
  color: var(--dtm-ink-dim);
  font-size: 0.85rem;
  transition: opacity 0.6s ease;
}

.dtm-loading span {
  width: 0.8rem;
  height: 0.8rem;
  border: 2px solid var(--dtm-rule);
  border-top-color: var(--dtm-cool);
  border-radius: 50%;
  animation: dtm-spin 0.9s linear infinite;
}

.dtm-loading.is-done { opacity: 0; pointer-events: none; }

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

/* ---- header -------------------------------------------------------------- */

.dtm-header {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 2;
  max-width: 26rem;
  padding: 1.5rem 1.8rem;
  pointer-events: none;
}

.dtm-header h1 {
  margin: 0 0 0.4rem;
  font-size: 1.6rem;
  font-weight: 600;
  line-height: 1.2;
}

.dtm-subtitle {
  margin: 0;
  font-size: 0.9rem;
  color: var(--dtm-ink-dim);
}

/* ---- panels -------------------------------------------------------------- */

.dtm-panel {
  position: absolute;
  z-index: 3;
  border: 1px solid var(--dtm-rule);
  border-radius: var(--dtm-radius);
  background: var(--dtm-panel);
  backdrop-filter: blur(8px);
}

.dtm-legend {
  top: 1.4rem;
  right: 1.4rem;
  width: 17.5rem;
  max-height: calc(100vh - 12rem);
  overflow: hidden auto;
}

.dtm-timebar {
  left: 1.8rem;
  right: 1.8rem;
  bottom: 1.3rem;
  max-width: 46rem;
}

.dtm-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.55rem 0.8rem;
}

.dtm-panel-head h2 {
  margin: 0;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--dtm-ink-dim);
}

.dtm-panel-toggle {
  flex: none;
  width: 1.4rem;
  height: 1.4rem;
  padding: 0;
  border: 1px solid var(--dtm-rule);
  border-radius: 5px;
  background: transparent;
  color: var(--dtm-ink-dim);
  font-size: 0.85rem;
  line-height: 1;
  cursor: pointer;
}

.dtm-panel-toggle:hover { color: var(--dtm-ink); }

.dtm-panel-body { padding: 0 0.8rem 0.8rem; }

.dtm-panel.is-collapsed .dtm-panel-body { display: none; }

/* ---- legend -------------------------------------------------------------- */

.dtm-legend-list {
  margin: 0 0 0.6rem;
  padding: 0;
  list-style: none;
  font-size: 0.8rem;
}

.dtm-legend-list li {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.16rem 0;
  cursor: pointer;
  user-select: none;
}

/* A toggled-off row stays legible: it is still the key to a symbol, it just is not
   currently drawn. Hiding it entirely would make the legend change shape as you
   click through it. */
.dtm-legend-list li.is-off { opacity: 0.32; }

.dtm-swatch {
  flex: none;
  width: 14px;
  height: 3px;
  border-radius: 1px;
}

/* The subduction swatch carries its triangle, because the decoration is the whole
   point of the symbol. */
.dtm-swatch-sz { position: relative; overflow: visible; }

.dtm-swatch-sz i {
  position: absolute;
  top: -4px;
  left: 4px;
  width: 0;
  height: 0;
  border-left: 3px solid transparent;
  border-right: 3px solid transparent;
  border-bottom: 4px solid;
}

.dtm-swatch-sym {
  width: 14px;
  height: 14px;
  background: none;
  line-height: 0;
}

.dtm-legend-count { color: var(--dtm-ink-dim); }

.dtm-legend-group { margin-top: 0.5rem; }

/* Ungrouped layers are one row each; consecutive ones read as a single list. */
.dtm-legend-single { margin-top: 0.1rem; }
.dtm-legend-single .dtm-legend-list { margin-bottom: 0; }
.dtm-legend-single:has(+ :not(.dtm-legend-single)) .dtm-legend-list { margin-bottom: 0.6rem; }
.dtm-swatch-sym canvas { display: block; }

.dtm-legend-grouphead {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.2rem;
}

.dtm-legend-grouphead h3 {
  margin: 0;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--dtm-ink-dim);
}

.dtm-legend-all,
.dtm-velocity-toggle {
  border: 1px solid var(--dtm-rule);
  border-radius: 5px;
  background: transparent;
  color: var(--dtm-ink-dim);
  font: inherit;
  font-size: 0.72rem;
  padding: 0.1rem 0.45rem;
  cursor: pointer;
}

/* model-switch.js's reconstruction-model <select> -- first in the legend panel,
   so it reads as "what the whole map is currently drawn on", not one layer's own
   toggle among the others below it. */
.dtm-model-select {
  display: block;
  width: 100%;
  margin: 0 0 0.9rem;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--dtm-rule);
  border-radius: 5px;
  background: var(--dtm-panel);
  color: var(--dtm-ink);
  font: inherit;
  font-size: 0.78rem;
  cursor: pointer;
}

.dtm-model-select:hover { border-color: var(--dtm-ink-dim); }

.dtm-legend-all:hover,
.dtm-velocity-toggle:hover { color: var(--dtm-ink); border-color: var(--dtm-ink-dim); }

.dtm-velocity-toggle.is-off { opacity: 0.4; }

.dtm-velocity-row { margin-bottom: 0.35rem; }

/* The provenance opener: a full-width filled button rather than a small bordered one
   like the toggles above, and placed first in the panel (see explorer.js) rather than
   last. A reader who never scrolls the legend should still see it. */
.dtm-prov-open {
  display: block;
  width: 100%;
  margin: 0 0 0.9rem;
  padding: 0.55rem 0.8rem;
  border: 1px solid var(--dtm-cool);
  border-radius: 6px;
  background: var(--dtm-cool);
  color: var(--dtm-page);
  font: inherit;
  font-weight: 600;
  font-size: 0.8rem;
  text-align: center;
  cursor: pointer;
}

.dtm-prov-open:hover { opacity: 0.85; }

.dtm-prov-download {
  color: var(--dtm-cool);
  font-size: 0.7rem;
  text-decoration: none;
  white-space: nowrap;
}

.dtm-prov-download:hover { text-decoration: underline; }

.dtm-prov-tag {
  font-size: 0.62rem;
  font-weight: 400;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--dtm-ink-dim);
}

.dtm-prov-filehead {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.6rem;
}

.dtm-scale {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--dtm-cool);
  font-size: 0.72rem;
}

.dtm-scale-label { color: var(--dtm-ink-dim); }

.dtm-credit {
  margin: 0.9rem 0 0.6rem;
  padding-top: 0.7rem;
  border-top: 1px solid var(--dtm-rule);
  font-size: 0.68rem;
  line-height: 1.5;
  color: var(--dtm-ink-dim);
}

/* ---- time bar ------------------------------------------------------------ */

/* .ts-* are timeseries-panel.js's own class names, styled here because the panel
   deliberately ships no stylesheet of its own. */
.dtm-chart {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.dtm-chart .ts-canvas {
  display: block;
  width: 100%;
  cursor: crosshair;
  touch-action: none;
}

/* Mode buttons above the chart, not below it: the chart is the thing, and controls
   sitting between the chart and the slider would break the visual join between
   them -- the whole point of the panel is that they read as one time axis. */
.dtm-chart .ts-modes {
  order: -1;
  display: flex;
  gap: 0.25rem;
  justify-content: flex-end;
}

.dtm-chart .ts-modes button {
  padding: 0.05rem 0.4rem;
  border: 1px solid var(--dtm-rule);
  border-radius: 4px;
  background: none;
  color: var(--dtm-ink-dim);
  font: inherit;
  font-size: 0.66rem;
  letter-spacing: 0.04em;
  cursor: pointer;
}

.dtm-chart .ts-modes button:hover {
  color: var(--dtm-ink);
  border-color: var(--dtm-cool);
}

.dtm-chart .ts-modes button.is-on {
  color: var(--dtm-page);
  background: var(--dtm-cool);
  border-color: var(--dtm-cool);
}

.dtm-chart-note {
  margin: 0.2rem 0 0;
  font-size: 0.65rem;
  color: var(--dtm-ink-dim);
}

/* Toggle rows sit below the heatmap, one row per category -- unlike the timeseries
   mode buttons (single-select, above the chart), these are multi-select per row and
   read more naturally as filters underneath what they filter. */
.dtm-chart .dtm-heatmap-toggles {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  margin-top: 0.3rem;
}

.dtm-heatmap-toggle-row {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.dtm-heatmap-toggle-label {
  font-size: 0.62rem;
  color: var(--dtm-ink-dim);
  min-width: 5.5rem;
}

.dtm-heatmap-toggle {
  padding: 0.05rem 0.45rem;
  border: 1px solid var(--dtm-rule);
  border-radius: 4px;
  background: none;
  color: var(--dtm-ink-dim);
  font: inherit;
  font-size: 0.66rem;
  letter-spacing: 0.02em;
  cursor: pointer;
  text-transform: capitalize;
}

.dtm-heatmap-toggle:hover {
  color: var(--dtm-ink);
  border-color: var(--dtm-cool);
}

.dtm-heatmap-toggle.is-on {
  color: var(--dtm-page);
  background: var(--dtm-cool);
  border-color: var(--dtm-cool);
}

.dtm-controls {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  margin-top: 0.4rem;
}

.dtm-play {
  flex: none;
  width: 2rem;
  height: 2rem;
  border: 1px solid var(--dtm-rule);
  border-radius: 6px;
  background: transparent;
  color: var(--dtm-ink);
  font-size: 0.8rem;
  cursor: pointer;
}

.dtm-play:hover { border-color: var(--dtm-ink-dim); }

.dtm-timecode {
  flex: none;
  min-width: 5rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-size: 0.85rem;
  color: var(--dtm-ink-dim);
}

.dtm-scrub {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: var(--dtm-thumb);
  background: transparent;
  cursor: pointer;
}

.dtm-scrub::-webkit-slider-runnable-track {
  height: 3px;
  border-radius: 2px;
  background: var(--dtm-rule);
}

.dtm-scrub::-moz-range-track {
  height: 3px;
  border-radius: 2px;
  background: var(--dtm-rule);
}

.dtm-scrub::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: var(--dtm-thumb);
  height: var(--dtm-thumb);
  margin-top: calc((3px - var(--dtm-thumb)) / 2);
  border: none;
  border-radius: 50%;
  background: var(--dtm-cool);
}

.dtm-scrub::-moz-range-thumb {
  width: var(--dtm-thumb);
  height: var(--dtm-thumb);
  border: none;
  border-radius: 50%;
  background: var(--dtm-cool);
}

/* ---- hover popup --------------------------------------------------------- */

.dtm-popup {
  position: absolute;
  z-index: 4;
  max-width: 19rem;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--dtm-rule);
  border-radius: 8px;
  background: var(--dtm-panel);
  backdrop-filter: blur(8px);
  font-size: 0.78rem;
  line-height: 1.45;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease;
}

.dtm-popup.is-visible { opacity: 1; }
.dtm-popup.is-pinned { pointer-events: auto; border-color: var(--dtm-ink-dim); }

.dtm-pp-eyebrow {
  display: block;
  font-size: 0.64rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--dtm-cool);
}

.dtm-popup h3 {
  margin: 0.1rem 0 0.4rem;
  font-size: 0.92rem;
  font-weight: 600;
}

.dtm-popup dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.1rem 0.6rem;
  margin: 0;
}

.dtm-popup dt { color: var(--dtm-ink-dim); }
.dtm-popup dd { margin: 0; }

.dtm-pp-footer {
  margin: 0.5rem 0 0;
  padding-top: 0.4rem;
  border-top: 1px solid var(--dtm-rule);
  font-size: 0.68rem;
  color: var(--dtm-ink-dim);
}

/* ---- provenance drawer --------------------------------------------------- */

.dtm-prov {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 6;
  width: min(46rem, 92vw);
  padding: 2rem 2.2rem;
  overflow: auto;
  border-left: 1px solid var(--dtm-rule);
  background: var(--dtm-page);
  transform: translateX(100%);
  transition: transform 0.24s ease;
}

.dtm-prov.is-open { transform: none; }

.dtm-prov-close {
  position: absolute;
  top: 1rem;
  right: 1.2rem;
  width: 2rem;
  height: 2rem;
  border: 1px solid var(--dtm-rule);
  border-radius: 6px;
  background: transparent;
  color: var(--dtm-ink);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}

.dtm-prov h3 {
  margin: 1.8rem 0 0.3rem;
  font-size: 0.95rem;
}

.dtm-prov section:first-child h3 { margin-top: 0; }

.dtm-prov h4 {
  margin: 1.1rem 0 0.4rem;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--dtm-ink-dim);
}

.dtm-prov p {
  margin: 0 0 0.7rem;
  font-size: 0.8rem;
  color: var(--dtm-ink-dim);
}

.dtm-prov pre {
  margin: 0;
  padding: 0.9rem 1rem;
  overflow-x: auto;
  border: 1px solid var(--dtm-rule);
  border-radius: 8px;
  font-size: 0.72rem;
  line-height: 1.55;
  tab-size: 4;
}

.dtm-prov code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.dtm-prov-libs {
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.8rem;
}

.dtm-prov-libs li {
  padding: 0.5rem 0;
  border-top: 1px solid var(--dtm-rule);
}

.dtm-prov-libs span { color: var(--dtm-ink-dim); }
.dtm-prov-libs p { margin: 0.25rem 0 0; font-size: 0.72rem; }

.dtm-prov-list {
  margin: 0;
  padding-left: 1.1rem;
  font-size: 0.8rem;
  line-height: 1.6;
}

.dtm-prov-list li { padding: 0.15rem 0; }

.dtm-prov-missing { color: var(--dtm-hot); }

.dtm-prov-figures {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  margin: 0.6rem 0 1rem;
}

.dtm-prov-figures figure { margin: 0; }

.dtm-prov-figures img {
  display: block;
  width: 100%;
  border: 1px solid var(--dtm-rule);
  border-radius: 8px;
}

.dtm-prov-figures figcaption {
  margin-top: 0.35rem;
  font-size: 0.72rem;
  color: var(--dtm-ink-dim);
}

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

@media (max-width: 720px) {
  .dtm-legend {
    top: auto;
    right: 0.8rem;
    bottom: 9.5rem;
    left: 0.8rem;
    width: auto;
    max-height: 40vh;
  }

  .dtm-timebar { left: 0.8rem; right: 0.8rem; bottom: 0.8rem; }

  .dtm-header { max-width: none; padding: 1rem 1.1rem; }
  .dtm-header h1 { font-size: 1.15rem; }
  .dtm-subtitle { display: none; }
}
