:root {
  --engine-dark-water: #041514;
  --engine-signal-teal: #74e7d8;
  --engine-soft-aqua: #a8d8cd;
  --engine-bone-light: #f2ead8;
}

.engine-header {
  position: relative;
  isolation: isolate;
  padding: clamp(4.5rem, 11vw, 8rem) 0 clamp(3rem, 8vw, 5.5rem);
  overflow: hidden;
  border-bottom: 1px solid var(--soft-line);
}

.engine-header::before {
  position: absolute;
  z-index: -1;
  content: "";
  inset: 0;
  background:
    radial-gradient(circle at 82% 48%, transparent 0 8rem, rgba(116, 231, 216, 0.22) 8.1rem 8.22rem, transparent 8.32rem),
    radial-gradient(circle at 82% 48%, transparent 0 12rem, rgba(231, 184, 92, 0.09) 12.05rem 12.18rem, transparent 12.28rem),
    linear-gradient(120deg, rgba(7, 31, 28, 0.98) 0 62%, rgba(4, 21, 20, 0.72) 62% 100%);
}

.engine-header__layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 2rem;
  align-items: center;
}

.engine-orientation {
  max-width: 48rem;
  margin: 1.3rem 0 0;
  color: rgba(244, 232, 197, 0.8);
  font-size: clamp(1.08rem, 2vw, 1.4rem);
}

.engine-dial {
  display: grid;
  width: clamp(8rem, 20vw, 13rem);
  aspect-ratio: 1;
  place-items: center;
  color: var(--gold);
  background: rgba(7, 19, 15, 0.72);
  border: 1px dashed var(--teal);
  border-radius: 50%;
  box-shadow:
    inset 0 0 0 0.8rem rgba(13, 33, 26, 0.85),
    inset 0 0 0 0.9rem rgba(231, 184, 92, 0.25),
    var(--shadow);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(3.2rem, 9vw, 6rem);
}

.engine-main {
  padding-block: clamp(3rem, 7vw, 6rem);
}

.orientation-panel {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: clamp(1.2rem, 4vw, 2.3rem);
  align-items: start;
  padding: clamp(1.4rem, 5vw, 3rem);
  color: var(--ink);
  background:
    linear-gradient(170deg, rgba(244, 232, 197, 0.98), rgba(231, 184, 92, 0.86)),
    var(--bone);
  border: 0.35rem double rgba(16, 32, 25, 0.52);
  box-shadow: var(--shadow);
  transform: rotate(-0.2deg);
}

.orientation-panel h2,
.orientation-panel .station-label {
  color: var(--ink);
}

.orientation-panel__mark {
  display: grid;
  width: 4.2rem;
  aspect-ratio: 1;
  place-items: center;
  border: 0.2rem solid var(--ink);
  border-radius: 50%;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 2rem;
  font-weight: 800;
}

.privacy-readout {
  margin: 1.4rem 0 0;
  padding: 0.9rem 1rem;
  background: rgba(16, 32, 25, 0.09);
  border-left: 0.28rem solid var(--copper);
}

.fallback-panel,
.error-panel {
  margin-top: 2rem;
  padding: clamp(1.4rem, 4vw, 2.3rem);
  background: rgba(13, 33, 26, 0.82);
  border: 1px solid var(--copper);
}

.engine-controls {
  display: none;
}

.js .engine-controls {
  display: grid;
  gap: 1.3rem;
  margin-block: clamp(4rem, 9vw, 7rem);
}

.instrument-heading {
  max-width: 58rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--line);
}

.instrument-heading > p:last-child {
  color: rgba(244, 232, 197, 0.7);
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.85rem;
}

.mode-control {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 10rem;
  grid-template-rows: auto 1fr;
  gap: 1.2rem;
  align-content: space-between;
  padding: 1.25rem;
  color: var(--bone);
  background:
    radial-gradient(circle at 88% 18%, rgba(101, 166, 158, 0.16), transparent 5rem),
    linear-gradient(155deg, rgba(13, 33, 26, 0.98), rgba(7, 19, 15, 0.92));
  border: 1px solid var(--soft-line);
  border-radius: 0.4rem 1.5rem 0.4rem 0.8rem;
  cursor: pointer;
  font-weight: 800;
  text-align: left;
}

.mode-control:hover {
  border-color: var(--gold);
  transform: translateY(-0.15rem);
}

.mode-control__mark {
  display: grid;
  width: 2.7rem;
  aspect-ratio: 1;
  place-items: center;
  color: var(--teal);
  border: 1px solid currentColor;
  border-radius: 50%;
  font-size: 0.76rem;
  letter-spacing: 0.08em;
}

.snag-console,
.theme-node-console {
  display: grid;
  grid-template-columns: minmax(12rem, 1fr) auto;
  gap: 1.2rem;
  align-items: end;
  padding: 1.25rem;
  background:
    radial-gradient(circle at 90% 12%, rgba(116, 231, 216, .11), transparent 9rem),
    rgba(7, 31, 28, 0.82);
  border: 1px dashed var(--copper);
}

.snag-console label,
.theme-node-console label,
.machine-prompt-panel label {
  display: block;
  margin-bottom: 0.45rem;
  color: var(--gold);
  font-weight: 800;
}

.snag-console select,
.theme-node-console select {
  width: min(100%, 25rem);
  min-height: 3rem;
  padding: 0.55rem 2.4rem 0.55rem 0.8rem;
  color: var(--ink);
  background: var(--bone);
  border: 0.2rem double var(--copper);
  border-radius: 0.25rem;
}

.result-console {
  min-width: 0;
}

.result-console [hidden] {
  display: none !important;
}

.pre-js-invitation {
  margin: 0;
  padding: 1.2rem;
  color: rgba(244, 232, 197, 0.72);
  background: rgba(13, 33, 26, 0.5);
  border-left: 0.25rem solid var(--moss);
}

.route-header {
  max-width: 65rem;
  margin-bottom: 2rem;
}

.route-kind,
.thinker-name,
.direction-register {
  margin: 0 0 0.45rem;
  color: var(--teal);
  font-size: 0.78rem;
  font-weight: 850;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.route-invitation {
  color: rgba(244, 232, 197, 0.76);
  font-size: clamp(1.04rem, 2vw, 1.25rem);
}

.passage-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 19rem), 1fr));
  gap: 1rem;
  align-items: start;
}

.passage-card {
  min-width: 0;
  padding: clamp(1.25rem, 4vw, 2rem);
  background:
    linear-gradient(158deg, rgba(13, 33, 26, 0.98), rgba(7, 19, 15, 0.96));
  border: 1px solid var(--soft-line);
  border-radius: 0.35rem 1.6rem 0.35rem 0.8rem;
  box-shadow: var(--shadow);
}

.passage-title {
  margin-bottom: 1.3rem;
}

.source-part + .source-part {
  margin-top: 1.8rem;
  padding-top: 1.5rem;
  border-top: 1px dashed rgba(231, 184, 92, 0.35);
}

.source-excerpt {
  margin: 0 0 1.2rem;
  padding: 1.2rem 1.2rem 1.2rem 1.4rem;
  overflow-wrap: anywhere;
  color: var(--ink);
  background: var(--bone);
  border-left: 0.35rem solid var(--copper);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.02rem, 2vw, 1.22rem);
  line-height: 1.72;
  white-space: pre-line;
}

.source-title,
.source-citation,
.reading-route {
  margin: 0.55rem 0 0;
  color: rgba(244, 232, 197, 0.72);
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

.source-context {
  margin-top: 1.5rem;
  padding: 1rem;
  background: rgba(101, 166, 158, 0.1);
  border: 1px solid rgba(101, 166, 158, 0.28);
}

.source-context strong {
  color: var(--teal);
}

.direction-panel {
  margin-top: 1.2rem;
  padding: 1rem;
  background: rgba(184, 108, 66, 0.1);
  border: 1px solid rgba(184, 108, 66, 0.42);
}

.direction-heading {
  margin-bottom: 0.6rem;
}

.direction-body,
.direction-question {
  overflow-wrap: anywhere;
}

.direction-question {
  color: var(--gold);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.05rem;
}

.unresolved-question {
  margin-block: 1.5rem 0;
  padding: clamp(1.2rem, 4vw, 2rem);
  color: var(--ink);
  background:
    linear-gradient(170deg, rgba(244, 232, 197, 0.98), rgba(231, 184, 92, 0.84)),
    var(--bone);
  border: 0.3rem double rgba(16, 32, 25, 0.48);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.15rem, 2.5vw, 1.7rem);
  line-height: 1.45;
}

.route-actions {
  display: grid;
  justify-items: start;
  gap: 1rem;
  margin-top: 1.5rem;
}

.machine-prompt-panel {
  width: 100%;
  padding: clamp(1.25rem, 4vw, 2.2rem);
  background:
    linear-gradient(145deg, rgba(162, 79, 55, 0.2), rgba(7, 19, 15, 0.9));
  border: 1px solid rgba(184, 108, 66, 0.58);
}

.machine-prompt-panel textarea {
  display: block;
  width: 100%;
  min-height: 24rem;
  padding: 1rem;
  resize: vertical;
  color: var(--ink);
  background: var(--bone);
  border: 0.25rem double var(--copper);
  border-radius: 0.25rem;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.prompt-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
  margin-top: 1rem;
}

.unresolved-control {
  padding: 0.5rem 0;
  color: var(--teal);
  background: transparent;
  border: 0;
  border-bottom: 1px solid currentColor;
  cursor: pointer;
  font-weight: 800;
}

.error-panel {
  border-color: var(--rust);
}

.engine-live-status {
  min-height: 1.65em;
  margin: 1.2rem 0 0;
  color: var(--teal);
  font-weight: 800;
}

.mode-control:focus-visible,
.snag-console select:focus-visible,
.theme-node-console select:focus-visible,
.machine-prompt-panel textarea:focus-visible,
.unresolved-control:focus-visible {
  outline: 0.2rem solid var(--gold);
  outline-offset: 0.24rem;
}

@media (max-width: 48rem) {
  .engine-header__layout,
  .mode-grid,
  .snag-console,
  .theme-node-console {
    grid-template-columns: minmax(0, 1fr);
  }

  .engine-dial {
    display: none;
  }

  .mode-control {
    min-height: 7rem;
  }

  .passage-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 320px) {
  .engine-main {
    padding-block: 2rem;
  }

  .orientation-panel {
    grid-template-columns: minmax(0, 1fr);
    padding: 1rem;
    transform: none;
  }

  .orientation-panel__mark {
    width: 3.3rem;
  }

  .mode-control,
  .snag-console,
  .theme-node-console,
  .passage-card,
  .machine-prompt-panel {
    padding: 0.9rem;
  }

  .prompt-actions {
    align-items: stretch;
    flex-direction: column;
  }
}

@media (prefers-reduced-motion: reduce) {
  .mode-control {
    transform: none !important;
    transition: none !important;
  }
}
