/* ============================================================
   Interactive topographic runoff simulation — embedded widget
   Used on: how-to-read-a-topographic-map-site-design.html
   Colors/fonts pull from resources/blog.css tokens (loaded first).
   ============================================================ */

.topo-sim {
  position: relative;
  margin: 32px 0;
  border: 1px solid var(--card-border);
  border-radius: 12px;
  background: var(--bg-white);
  overflow: hidden;
  display: grid;
  grid-template-columns: 1fr;
}

/* Breakout: on wide desktop viewports the widget reads more comfortably
   a bit wider than the 760px article column (992px total here, vs 712px
   of text). Gated at min-width:1040px so there's always at least a 24px
   gutter left on each side at the threshold width, growing from there —
   never causes horizontal overflow. Math: at window width W, the
   article's own side margin is (W-760)/2; pulling the widget out by
   140px leaves (W-760)/2 + 24 - 140 px of gutter, which is exactly 0
   at W=992 — so 1040px gives a comfortable safety margin above that. */
@media (min-width: 1040px) {
  .topo-sim {
    margin-left: -140px;
    margin-right: -140px;
  }
}

.topo-sim__viewport {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #e9e5da;
  /* Let a one-finger vertical swipe scroll the page normally; only a
     two-finger gesture (configured in JS as DOLLY_ROTATE) is claimed for
     orbiting/zooming. Plain touch-action:none would trap every swipe for
     orbit, making it impossible to scroll past the widget with one finger. */
  touch-action: pan-y;
}
.topo-sim__viewport canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.topo-sim__loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font: 500 13px "Space Mono", monospace;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  background: #e9e5da;
  text-align: center;
  padding: 0 24px;
}
.topo-sim__loading[hidden] {
  display: none;
}

.topo-sim__hint {
  position: absolute;
  left: 10px;
  bottom: 10px;
  max-width: calc(100% - 20px);
  font: 400 11px/1.4 "Space Mono", monospace;
  color: rgba(26, 26, 14, 0.65);
  background: rgba(255, 255, 255, 0.78);
  padding: 4px 8px;
  border-radius: 6px;
  pointer-events: none;
}
/* Devices with a coarse pointer (touch) get the two-finger instructions
   — a plain mouse/trackpad still drags with one. */
.topo-sim__hint--touch {
  display: none;
}
@media (pointer: coarse) {
  .topo-sim__hint--mouse {
    display: none;
  }
  .topo-sim__hint--touch {
    display: inline;
  }
}

.topo-sim__minimap {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 96px;
  padding: 7px;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--card-border);
  border-radius: 8px;
}
.topo-sim__minimap-hd {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font: 600 8.5px/1 "Space Mono", monospace;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 5px;
}
.topo-sim__minimap-hd b {
  color: var(--text-dark);
  font-weight: 600;
}
.topo-sim__minimap canvas {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 4px;
  cursor: zoom-in;
}

.topo-sim__controls {
  padding: 20px;
  border-top: 1px solid var(--card-border);
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.topo-sim__group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.topo-sim__row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}
.topo-sim__label {
  font: 600 10.5px/1 "Space Mono", monospace;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.topo-sim__val {
  font: 600 12px "Space Mono", monospace;
  color: var(--text-dark);
  font-variant-numeric: tabular-nums;
}

.topo-sim input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 24px;
  background: transparent;
  margin: 0;
  cursor: pointer;
}
.topo-sim input[type="range"]::-webkit-slider-runnable-track {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
}
.topo-sim input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  margin-top: -6.5px;
  border-radius: 50%;
  background: var(--gold-btn);
  border: 2px solid var(--bg-white);
  box-shadow: 0 0 0 1px var(--gold-btn);
}
.topo-sim input[type="range"]::-moz-range-track {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
}
.topo-sim input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--gold-btn);
  border: 2px solid var(--bg-white);
  box-shadow: 0 0 0 1px var(--gold-btn);
}
.topo-sim input[type="range"]:focus-visible {
  outline: 2px solid var(--green-mid);
  outline-offset: 3px;
}

.topo-sim__btnrow {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.topo-sim__btn {
  flex: 1 1 auto;
  min-width: 118px;
  font: 600 13px "Space Grotesk", sans-serif;
  color: var(--text-dark);
  background: var(--bg-main);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  padding: 9px 14px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.topo-sim__btn:hover {
  border-color: var(--green-mid);
}
.topo-sim__btn:active {
  background: var(--green-light);
}
.topo-sim__btn.is-primary {
  background: var(--gold-btn);
  color: #fff;
  border-color: var(--gold-btn);
}
.topo-sim__btn.is-primary:hover {
  background: var(--gold-btn-hover);
  border-color: var(--gold-btn-hover);
}

.topo-sim__checks {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}
.topo-sim__chk {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-mid);
  cursor: pointer;
}
.topo-sim__chk input {
  appearance: none;
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  margin: 0;
  flex: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-white);
  cursor: pointer;
}
.topo-sim__chk input:checked {
  background: var(--green-mid);
  border-color: var(--green-mid);
}
.topo-sim__chk input:focus-visible {
  outline: 2px solid var(--green-mid);
  outline-offset: 2px;
}

.topo-sim__readout {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 12px;
  font-size: 13px;
}
.topo-sim__readout dt {
  color: var(--text-muted);
}
.topo-sim__readout dd {
  margin: 0;
  font: 600 13px "Space Mono", monospace;
  color: var(--text-dark);
  text-align: right;
}

.topo-sim__legend {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--text-mid);
}
.topo-sim__legend div {
  display: flex;
  align-items: center;
  gap: 8px;
}
.topo-sim__sw {
  width: 18px;
  height: 3px;
  flex: none;
  border-radius: 2px;
}

.topo-sim__hr {
  height: 1px;
  background: var(--card-border);
  border: 0;
  margin: 0;
}

.topo-sim__caption {
  grid-column: 1 / -1;
  padding: 14px 20px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-muted);
  border-top: 1px solid var(--card-border);
}

@media (min-width: 760px) {
  .topo-sim {
    display: flex;
    flex-wrap: wrap;
  }
  .topo-sim__viewport {
    flex: 1 1 0%;
    min-width: 0;
    min-height: 460px;
    aspect-ratio: auto;
    height: auto;
  }
  .topo-sim__controls {
    flex: 0 0 260px;
    width: 260px;
    border-top: none;
    border-left: 1px solid var(--card-border);
  }
  .topo-sim__caption {
    flex: 1 1 100%;
  }
}

/* ── Touch / small-screen refinements ── */

/* A squarer viewport gives more vertical drag room for orbiting on a
   phone, and the minimap shrinks so it doesn't crowd a small canvas. */
@media (max-width: 480px) {
  .topo-sim__viewport {
    aspect-ratio: 1 / 1;
  }
  .topo-sim__minimap {
    width: 74px;
    padding: 5px;
  }
  .topo-sim__minimap-hd {
    font-size: 7.5px;
    margin-bottom: 3px;
  }
  .topo-sim__hint {
    font-size: 10px;
    padding: 3px 6px;
  }
}

/* Bigger hit targets on touch devices — the mouse-tuned sizes above read
   fine with a cursor but are tight for a fingertip. */
@media (pointer: coarse) {
  .topo-sim__btn {
    padding: 13px 14px;
    font-size: 14px;
  }
  .topo-sim__chk {
    font-size: 14px;
  }
  .topo-sim__chk input {
    width: 20px;
    height: 20px;
  }
  .topo-sim input[type="range"] {
    height: 32px;
  }
  .topo-sim input[type="range"]::-webkit-slider-thumb {
    width: 22px;
    height: 22px;
    margin-top: -9.5px;
  }
  .topo-sim input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
  }
}
