/* Permanent visual rule: Prototype 5 uses no box shadows, text shadows, or
   drop-shadow filters. Depth comes from borders, fills, and contrast. */
:root {
  color-scheme: dark;
  --ink: #101c38;
  --ink-deep: #070a18;
  --lilac: #b69de3;
  --paper: #f7f2e7;
  --gold: #e3b64f;
  --cyan: #9fe0e8;
  --quiet: rgba(247, 242, 231, 0.62);
  --line: rgba(247, 242, 231, 0.22);
  --glass: rgba(8, 13, 31, 0.72);
  --ui: Arial, "Helvetica Neue", sans-serif;
  --mono: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--ink-deep);
}

body {
  font-family: var(--ui);
  color: var(--paper);
  overscroll-behavior: none;
}

button,
input { font: inherit; }

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

.study {
  position: fixed;
  inset: 0;
  isolation: isolate;
  overflow: hidden;
  background: #0d132a;
}

/* A fixed canvas is a replaced element: explicit dimensions are required. */
canvas#scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

canvas#scene[hidden] { display: none; }

/* Production evidence keeps Prototype 5's media-only invitation cursor. */
#pill {
  position: fixed;
  z-index: 18;
  left: 0;
  top: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px 9px 12px;
  border: 1px solid rgba(16, 28, 56, 0.12);
  border-radius: 999px;
  background: rgba(247, 242, 231, 0.96);
  pointer-events: none;
  transform: translate(-50%, -50%) scale(0);
  transform-origin: 50% 50%;
  transition: transform 180ms cubic-bezier(.2,.75,.24,1);
}

#pill.on { transform: translate(-50%, -50%) scale(1); }
#pill.off { transition-duration: 120ms; }
#pill svg { width: 10px; height: 14px; flex: 0 0 auto; }
#pill span {
  color: var(--ink);
  font: 700 10px/1 var(--mono);
  letter-spacing: 0.12em;
  white-space: nowrap;
}

@media (hover: none), (pointer: coarse) { #pill { display: none; } }

[data-pill] { pointer-events: auto; }

.fallback {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: grid;
  place-items: center;
  padding: 30px;
  background:
    linear-gradient(180deg, #635b9b 0%, #b69de3 42%, #f0c2a0 71%, #173151 72%, #101c38 100%);
}

.fallback[hidden] { display: none; }

.fallback > div {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
.fallback p { margin: 0; }
.fallback-kicker {
  margin-bottom: 14px !important;
  font: 700 12px/1 var(--mono) !important;
  letter-spacing: 0.18em;
  color: var(--gold);
}

.study-head {
  position: absolute;
  z-index: 4;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  padding: clamp(18px, 3vw, 38px) clamp(18px, 4vw, 58px);
  pointer-events: none;
}

.study-head p { margin: 0; }

.study-kicker,
.gate-readout,
.timeline-copy,
.probe,
.zenith-mark {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  text-transform: uppercase;
}

.study-kicker {
  margin-bottom: 8px !important;
  font-size: 10px;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: 0.18em;
  color: var(--gold);
}

.study-state {
  display: flex;
  gap: 8px;
  font-size: clamp(17px, 2vw, 25px);
  font-weight: 750;
  line-height: 1.05;
  letter-spacing: -0.02em;
}

.study-state #stateIndex {
  color: var(--cyan);
  font-family: var(--mono);
  font-size: 0.72em;
  line-height: 1.55;
  letter-spacing: 0.06em;
}

.gate-readout {
  display: grid;
  justify-items: end;
  gap: 7px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.16em;
  color: var(--quiet);
}

.gate-readout span:first-child { color: var(--paper); }

.diagnostic-controls {
  position: absolute;
  z-index: 5;
  left: 50%;
  bottom: clamp(14px, 2.6vw, 32px);
  width: min(780px, calc(100% - 36px));
  transform: translateX(-50%);
  padding: 14px 16px 13px;
  border: 1px solid rgba(247, 242, 231, 0.18);
  border-radius: 14px;
  background: var(--glass);
  backdrop-filter: blur(14px) saturate(0.9);
}

.diagnostic-controls[hidden] { display: none; }

.timeline-copy {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 9px;
  font-size: 9px;
  line-height: 1;
  letter-spacing: 0.14em;
  color: var(--quiet);
}

.timeline-copy span:first-child { color: var(--gold); }

.scrubber {
  position: relative;
  display: block;
  height: 24px;
}

.scrubber::before,
.scrubber::after {
  content: "";
  position: absolute;
  top: 11px;
  height: 1px;
  pointer-events: none;
}

.scrubber::before {
  left: 0;
  width: calc(var(--p, 0) * 100%);
  background: var(--gold);
}

.scrubber::after {
  right: 0;
  width: calc((1 - var(--p, 0)) * 100%);
  background: rgba(247, 242, 231, 0.24);
}

.scrubber input {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 24px;
  margin: 0;
  cursor: ew-resize;
  opacity: 0;
}

.scrubber .fix {
  position: absolute;
  z-index: 1;
  top: 6px;
  left: calc(var(--p, 0) * 100%);
  width: 11px;
  height: 11px;
  transform: translateX(-50%) rotate(45deg);
  border: 1px solid var(--gold);
  background: #0c142a;
}

.control-row {
  display: flex;
  gap: 7px;
  margin-top: 8px;
}

.control-row button {
  min-height: 32px;
  border: 1px solid rgba(247, 242, 231, 0.2);
  border-radius: 999px;
  padding: 7px 13px;
  cursor: pointer;
  background: rgba(7, 10, 24, 0.6);
  color: var(--paper);
  font: 700 9px/1 var(--mono);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.control-row button:hover { border-color: rgba(247, 242, 231, 0.48); }

.control-row button:disabled {
  cursor: default;
  opacity: 0.42;
}

.scrubber input:disabled { cursor: default; }

.control-row button[aria-pressed="true"] {
  border-color: rgba(227, 182, 79, 0.72);
  background: rgba(227, 182, 79, 0.13);
  color: var(--gold);
}

.probe {
  position: absolute;
  z-index: 6;
  top: clamp(92px, 14vh, 132px);
  right: clamp(18px, 4vw, 58px);
  width: min(380px, calc(100% - 36px));
  max-height: calc(100vh - 270px);
  overflow: auto;
  padding: 13px 14px;
  border-left: 1px solid rgba(159, 224, 232, 0.62);
  background: rgba(7, 10, 24, 0.68);
  backdrop-filter: blur(12px);
  color: rgba(247, 242, 231, 0.76);
}

.probe[hidden] { display: none; }

.probe-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  font-size: 9px;
  line-height: 1;
  letter-spacing: 0.14em;
  color: var(--cyan);
}

.probe pre {
  margin: 0;
  white-space: pre-wrap;
  font: 500 9px/1.48 var(--mono);
}

.safe-layer {
  position: absolute;
  z-index: 3;
  inset: 0;
  display: none;
  pointer-events: none;
}

.safe-layer.on { display: block; }

.safe-rect {
  position: absolute;
  border: 1px dashed rgba(159, 224, 232, 0.78);
  background: rgba(159, 224, 232, 0.035);
}

.safe-secondary { display: none; }

.safe-layer.two .safe-secondary { display: block; }

#safeLabel {
  position: absolute;
  padding: 5px 7px;
  border: 1px solid rgba(159, 224, 232, 0.5);
  background: rgba(7, 10, 24, 0.84);
  color: var(--cyan);
  font: 700 8px/1 var(--mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.zenith-mark {
  position: absolute;
  z-index: 2;
  top: 50%;
  left: 50%;
  display: grid;
  justify-items: center;
  gap: 7px;
  opacity: 0;
  transform: translate(-50%, -50%);
  pointer-events: none;
  transition: opacity 140ms linear;
  font-size: 8px;
  letter-spacing: 0.16em;
  color: rgba(159, 224, 232, 0.7);
}

.zenith-mark.on { opacity: 1; }

html[data-diagnostics="off"] .zenith-mark { display: none !important; }

.zenith-mark i {
  width: 7px;
  height: 7px;
  border: 1px solid rgba(159, 224, 232, 0.8);
  border-radius: 50%;
}

.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;
}

@media (max-width: 680px) {
  .study-head { padding: 18px; }
  .study-kicker { max-width: 220px; }
  .study-state { font-size: 17px; }
  .gate-readout { font-size: 8px; }
  .gate-readout span:first-child { max-width: 128px; text-align: right; }
  .diagnostic-controls { width: calc(100% - 24px); bottom: 12px; padding: 12px; }
  .timeline-copy { font-size: 8px; }
  #timelineHint { display: none; }
  .control-row { display: grid; grid-template-columns: repeat(4, 1fr); }
  .control-row button { padding-inline: 6px; font-size: 8px; letter-spacing: 0.06em; }
  .probe {
    top: 84px;
    right: 12px;
    width: calc(100% - 24px);
    max-height: calc(100vh - 250px);
    background: rgba(7, 10, 24, 0.82);
  }
}

@media (prefers-reduced-motion: reduce) {
  .zenith-mark,
  #pill { transition: none; }
}

.clean-capture .controls,
.clean-capture .diagnostic-controls,
.clean-capture .zenith-mark,
.clean-capture #pill { display: none !important; }

@media print {
  .controls,
  .diagnostic-controls,
  .probe,
  .safe-layer,
  .zenith-mark { display: none !important; }
}
