:root {
  --ink: #12202a;
  --muted: #68736f;
  --paper: #e8e7df;
  --panel: rgba(246, 246, 241, 0.9);
  --line: rgba(18, 32, 42, 0.17);
  --water: #4f9fc7;
  --snow: #f8faf8;
  --sun: #e7a83c;
  --shadow: 0 24px 70px rgba(28, 38, 36, 0.16);
}

* {
  box-sizing: border-box;
}

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

body {
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: "Inconsolata", monospace;
}

button,
input {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 0.8rem;
  left: 0.8rem;
  padding: 0.65rem 0.85rem;
  background: #fff;
  color: var(--ink);
  transform: translateY(-180%);
  transition: transform 160ms ease;
}

.skip-link:focus {
  transform: translateY(0);
}

.lab-header {
  position: fixed;
  z-index: 20;
  top: 0;
  right: 0;
  left: 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  min-height: 5.3rem;
  padding: max(1rem, env(safe-area-inset-top)) clamp(1rem, 3.4vw, 3.5rem) 0.9rem;
  pointer-events: none;
}

.lab-header::after {
  position: absolute;
  right: clamp(1rem, 3.4vw, 3.5rem);
  bottom: 0;
  left: clamp(1rem, 3.4vw, 3.5rem);
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--line) 18%, var(--line) 82%, transparent);
  content: "";
}

.lab-brand,
.lab-info-button {
  pointer-events: auto;
}

.lab-brand {
  justify-self: start;
  color: var(--ink);
  font-family: "Inconsolata", monospace;
  font-size: 1.7rem;
  font-weight: 400;
  letter-spacing: 0;
  text-decoration: none;
}

.lab-identity {
  display: flex;
  align-items: baseline;
  gap: 0.65rem;
  justify-self: center;
  white-space: nowrap;
}

.lab-identity span {
  color: var(--muted);
  font-size: 0.67rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.lab-identity strong {
  font-family: "Raleway", sans-serif;
  font-size: 1rem;
  letter-spacing: -0.02em;
}

.lab-info-button {
  justify-self: end;
  padding: 0.35rem 0;
  border: 0;
  border-bottom: 1px solid currentColor;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  font-size: 0.76rem;
}

.lab-main,
.lab-stage,
.lab-canvas-shell {
  width: 100%;
  height: 100dvh;
  min-height: 34rem;
}

.lab-canvas-shell {
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(circle at 56% 37%, rgba(255, 255, 255, 0.7), transparent 34%),
    var(--paper);
}

#terrain-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}

body[data-tool="orbit"] #terrain-canvas {
  cursor: grab;
}

body[data-tool="orbit"] #terrain-canvas:active {
  cursor: grabbing;
}

#terrain-canvas.is-rotating {
  cursor: grabbing;
}

.lab-loading {
  position: absolute;
  z-index: 8;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  background: var(--paper);
  transition: opacity 500ms ease, visibility 500ms ease;
}

.lab-loading.is-hidden {
  visibility: hidden;
  opacity: 0;
}

.lab-loading span {
  width: 3.5rem;
  height: 3.5rem;
  border: 1px solid rgba(18, 32, 42, 0.17);
  border-top-color: var(--ink);
  border-radius: 50%;
  animation: terrain-spin 1.1s linear infinite;
}

.lab-loading p {
  margin: 0;
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

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

.lab-metrics {
  position: absolute;
  z-index: 5;
  top: 6.4rem;
  right: clamp(1rem, 3.4vw, 3.5rem);
  display: flex;
  gap: 1.3rem;
  padding: 0.65rem 0.85rem;
  border: 1px solid rgba(255, 255, 255, 0.55);
  background: rgba(243, 243, 237, 0.58);
  box-shadow: 0 8px 28px rgba(52, 63, 59, 0.06);
  backdrop-filter: blur(10px);
  pointer-events: none;
}

.lab-metrics > div {
  display: grid;
  grid-template-columns: 0.45rem auto;
  align-items: center;
  column-gap: 0.38rem;
}

.lab-metrics strong {
  font-size: 0.75rem;
  font-weight: 700;
}

.lab-metrics small {
  grid-column: 2;
  color: var(--muted);
  font-size: 0.61rem;
}

.metric-dot {
  grid-row: 1 / 3;
  width: 0.42rem;
  height: 0.42rem;
  border-radius: 50%;
}

.metric-dot--water { background: var(--water); }
.metric-dot--snow { border: 1px solid #aab3af; background: var(--snow); }
.metric-dot--sun { background: var(--sun); }

.lab-route-context {
  position: absolute;
  z-index: 5;
  top: 6.4rem;
  left: clamp(1rem, 3.4vw, 3.5rem);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.28rem;
  padding: 0.7rem 0.85rem;
  border: 1px solid rgba(255, 255, 255, 0.55);
  background: rgba(243, 243, 237, 0.62);
  box-shadow: 0 8px 28px rgba(52, 63, 59, 0.06);
  backdrop-filter: blur(10px);
}

.lab-route-context[hidden] {
  display: none;
}

.lab-route-context a {
  color: var(--ink);
  font-size: 0.7rem;
  font-weight: 700;
  text-decoration: none;
}

.lab-route-context a:hover {
  text-decoration: underline;
}

.lab-route-context span {
  color: var(--muted);
  font-size: 0.6rem;
}

.lab-canvas-hint {
  position: absolute;
  z-index: 4;
  right: 0;
  bottom: 8.9rem;
  left: 0;
  margin: 0;
  color: rgba(18, 32, 42, 0.61);
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  text-align: center;
  pointer-events: none;
  transition: opacity 200ms ease;
}

.lab-attribution {
  position: absolute;
  z-index: 4;
  right: clamp(1rem, 3.4vw, 3.5rem);
  bottom: 8.9rem;
  margin: 0;
  color: rgba(18, 32, 42, 0.46);
  font-size: 0.56rem;
  pointer-events: none;
}

.lab-attribution[hidden] {
  display: none;
}

.lab-status {
  position: absolute;
  z-index: 6;
  bottom: 1rem;
  left: 1rem;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.weather-panel {
  position: fixed;
  z-index: 12;
  right: 50%;
  bottom: max(1.2rem, env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  gap: 1rem;
  width: min(60rem, calc(100% - 2rem));
  padding: 0.68rem;
  border: 1px solid rgba(255, 255, 255, 0.7);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px) saturate(120%);
  transform: translateX(50%);
}

.weather-tools {
  display: grid;
  grid-template-columns: repeat(4, minmax(4.4rem, 1fr));
  gap: 0.35rem;
  flex: 1 1 auto;
}

.weather-tool {
  position: relative;
  display: grid;
  grid-template-columns: 1rem auto;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 3.35rem;
  padding: 0.55rem 0.75rem;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  font-size: 0.78rem;
  transition: background 160ms ease, border-color 160ms ease, color 160ms ease;
}

.weather-tool:hover {
  background: rgba(18, 32, 42, 0.045);
}

.weather-tool.is-active {
  border-color: rgba(18, 32, 42, 0.14);
  background: #fff;
  box-shadow: 0 4px 14px rgba(30, 44, 42, 0.08);
}

.weather-tool[data-tool="rain"].is-active { color: #317fa6; }
.weather-tool[data-tool="sun"].is-active { color: #a96e0d; }

.weather-tool kbd {
  position: absolute;
  top: 0.2rem;
  right: 0.32rem;
  border: 0;
  background: transparent;
  color: rgba(18, 32, 42, 0.36);
  font-size: 0.56rem;
  font-weight: 400;
}

.weather-symbol {
  position: relative;
  display: block;
  width: 0.92rem;
  height: 0.92rem;
}

.weather-symbol--rain::before,
.weather-symbol--rain::after {
  position: absolute;
  width: 0.28rem;
  height: 0.72rem;
  border-radius: 60% 40% 70% 30%;
  background: var(--water);
  content: "";
  transform: rotate(34deg);
}

.weather-symbol--rain::before { top: 0; left: 0.08rem; }
.weather-symbol--rain::after { right: 0.02rem; bottom: 0; height: 0.54rem; opacity: 0.62; }

.weather-symbol--snow::before,
.weather-symbol--snow::after {
  position: absolute;
  top: 50%;
  left: 0;
  width: 100%;
  height: 1px;
  background: #61706d;
  content: "";
}

.weather-symbol--snow::after { transform: rotate(60deg); }
.weather-symbol--snow { transform: rotate(-30deg); }

.weather-symbol--sun {
  border: 1px solid #b87913;
  border-radius: 50%;
  box-shadow: 0 0 0 3px rgba(231, 168, 60, 0.2);
  background: var(--sun);
}

.weather-symbol--orbit {
  border: 1px solid #596663;
  border-radius: 50%;
}

.weather-symbol--orbit::after {
  position: absolute;
  top: 0.24rem;
  right: -0.21rem;
  width: 0.32rem;
  height: 0.32rem;
  border-top: 1px solid #596663;
  border-right: 1px solid #596663;
  content: "";
  transform: rotate(35deg);
}

.weather-tuning {
  display: grid;
  gap: 0.45rem;
  width: 11rem;
  padding: 0 0.8rem;
  border-left: 1px solid var(--line);
}

.weather-tuning label {
  display: grid;
  grid-template-columns: 3.8rem 1fr;
  align-items: center;
  gap: 0.5rem;
  color: var(--muted);
  font-size: 0.65rem;
}

.weather-tuning input {
  width: 100%;
  height: 1rem;
  margin: 0;
  accent-color: var(--ink);
  cursor: pointer;
}

.weather-actions {
  display: grid;
  gap: 0.3rem;
  width: 6.8rem;
}

.weather-actions button {
  padding: 0.35rem 0.45rem;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.65rem;
  text-align: left;
}

.weather-actions button:hover {
  color: var(--ink);
}

.lab-intro {
  position: fixed;
  z-index: 40;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(225, 225, 216, 0.38);
  backdrop-filter: blur(12px);
  transition: opacity 420ms ease, visibility 420ms ease;
}

.lab-intro.is-hidden {
  visibility: hidden;
  opacity: 0;
}

.lab-intro-card {
  width: min(35rem, 100%);
  padding: clamp(2rem, 5vw, 4.2rem);
  border: 1px solid rgba(255, 255, 255, 0.7);
  background: rgba(246, 246, 241, 0.92);
  box-shadow: var(--shadow);
}

.lab-eyebrow {
  margin: 0 0 1.1rem;
  color: var(--muted);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.17em;
  text-transform: uppercase;
}

.lab-intro h2,
.lab-info h2 {
  margin: 0;
  font-family: "Raleway", sans-serif;
  font-size: clamp(2.4rem, 6vw, 4.8rem);
  font-weight: 520;
  letter-spacing: -0.06em;
  line-height: 0.96;
}

.lab-intro-card > p:not(.lab-eyebrow) {
  max-width: 28rem;
  margin: 1.5rem 0 1.8rem;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.65;
}

.lab-intro-card button,
.lab-info button {
  padding: 0.85rem 1.1rem;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: #fff;
  cursor: pointer;
  font-size: 0.74rem;
  letter-spacing: 0.03em;
}

.lab-intro-card small {
  display: block;
  margin-top: 1rem;
  color: #89918e;
  font-size: 0.62rem;
}

.lab-info {
  position: fixed;
  z-index: 50;
  inset: 0 0 0 auto;
  width: min(37rem, 100%);
  padding: clamp(5.8rem, 10vh, 8rem) clamp(1.5rem, 6vw, 4.5rem) 2rem;
  overflow-y: auto;
  border-left: 1px solid rgba(255, 255, 255, 0.7);
  background: rgba(246, 246, 241, 0.96);
  box-shadow: -24px 0 70px rgba(28, 38, 36, 0.16);
  backdrop-filter: blur(20px);
}

.lab-info[hidden] {
  display: none;
}

.lab-info h2 {
  font-size: clamp(2.2rem, 5vw, 4rem);
}

.lab-info p:not(.lab-eyebrow) {
  margin: 1.4rem 0 0;
  color: var(--muted);
  line-height: 1.65;
}

.lab-info dl {
  margin: 2rem 0;
  border-top: 1px solid var(--line);
}

.lab-info dl div {
  display: grid;
  grid-template-columns: 5rem 1fr;
  gap: 1rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--line);
}

.lab-info dt {
  font-weight: 700;
}

.lab-info dd {
  margin: 0;
  color: var(--muted);
}

.lab-fallback {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 2rem;
  background: var(--paper);
  text-align: center;
}

@media (max-width: 900px) {
  .lab-header {
    grid-template-columns: 1fr auto;
  }

  .lab-identity {
    display: none;
  }

  .weather-panel {
    flex-wrap: wrap;
    gap: 0.55rem;
  }

  .weather-tools {
    width: 100%;
    flex-basis: 100%;
  }

  .weather-tuning {
    width: auto;
    flex: 1 1 auto;
    grid-template-columns: repeat(2, minmax(8rem, 1fr));
    gap: 0.8rem;
    padding-left: 0.35rem;
    border-left: 0;
  }

  .weather-actions {
    display: flex;
    justify-content: flex-end;
    width: auto;
  }

  .lab-canvas-hint {
    bottom: 10.4rem;
  }

  .lab-attribution {
    bottom: 10.4rem;
  }
}

@media (max-width: 600px) {
  .lab-header {
    min-height: 4.5rem;
    padding-bottom: 0.65rem;
  }

  .lab-brand {
    font-size: 1.15rem;
  }

  .lab-info-button {
    font-size: 0.68rem;
  }

  .lab-metrics {
    top: 5.25rem;
    right: 50%;
    gap: 0.85rem;
    width: max-content;
    transform: translateX(50%);
  }

  .lab-route-context {
    top: 8.7rem;
    left: 50%;
    align-items: center;
    width: max-content;
    max-width: calc(100% - 2rem);
    padding: 0.48rem 0.7rem;
    transform: translateX(-50%);
  }

  .lab-route-context span {
    display: none;
  }

  .weather-panel {
    bottom: max(0.55rem, env(safe-area-inset-bottom));
    width: calc(100% - 1rem);
    padding: 0.48rem;
  }

  .weather-tools {
    gap: 0.15rem;
  }

  .weather-tool {
    grid-template-columns: 0.9rem auto;
    gap: 0.35rem;
    min-height: 3rem;
    padding: 0.42rem 0.25rem;
    font-size: 0.7rem;
  }

  .weather-tool kbd {
    display: none;
  }

  .weather-tuning {
    grid-template-columns: 1fr 1fr;
    width: 100%;
    padding: 0.1rem 0.35rem 0;
  }

  .weather-tuning label {
    grid-template-columns: 3.2rem 1fr;
    font-size: 0.61rem;
  }

  .weather-actions {
    width: 100%;
    justify-content: space-between;
    padding: 0 0.15rem;
  }

  .weather-actions button {
    font-size: 0.61rem;
  }

  .lab-canvas-hint {
    bottom: 10.8rem;
    font-size: 0.62rem;
  }

  .lab-attribution {
    right: 50%;
    bottom: 11.7rem;
    width: max-content;
    max-width: calc(100% - 2rem);
    font-size: 0.5rem;
    text-align: center;
    transform: translateX(50%);
  }

  .lab-intro-card {
    padding: 2rem 1.5rem;
  }

  .lab-intro h2 {
    font-size: clamp(2.6rem, 14vw, 4rem);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
