:root {
  --background: #050a12;
  --foreground: #e8edf5;
  --white: #ffffff;
  --cyan-400: #00d2ef;
  --cyan-500: #00b7d7;
  --cyan-700: #007492;
  --cyan-800: #005f78;
  --cyan-900: #104e64;
  --cyan-950: #053345;
  --blue-500: #3080ff;
  --blue-600: #155dfc;
  --slate-300: #cad5e2;
  --slate-400: #90a1b9;
  --slate-500: #62748e;
  --slate-700: #314158;
  --slate-800: #1d293d;
  --slate-900: #0f172b;
  --danger: #ff4f68;
  --warning: #ffcc66;
  --success: #14f195;
  --panel: rgba(15, 23, 43, 0.72);
  --panel-strong: rgba(10, 22, 40, 0.84);
  --panel-deep: rgba(5, 10, 18, 0.92);
  --line: rgba(0, 210, 239, 0.34);
  --line-strong: rgba(0, 210, 239, 0.62);
  --shadow: rgba(0, 0, 0, 0.44);
  --font-sans: "Geist", "Aptos", "Segoe UI", sans-serif;
  --font-mono: "Geist Mono", "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-height: 100%;
  background: var(--background);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--foreground);
  font-family: var(--font-sans);
  background:
    radial-gradient(circle at 50% 14%, rgba(0, 183, 215, 0.13), transparent 32rem),
    radial-gradient(circle at 85% 8%, rgba(21, 93, 252, 0.14), transparent 30rem),
    linear-gradient(180deg, rgba(5, 10, 18, 0.76), var(--background));
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -2;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(0, 200, 255, 0.095) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 200, 255, 0.095) 1px, transparent 1px);
  background-size: 60px 60px;
  opacity: 0.28;
}

body::after {
  content: "";
  position: fixed;
  top: 8%;
  left: 50%;
  z-index: -1;
  width: min(640px, 88vw);
  height: min(640px, 88vw);
  pointer-events: none;
  background: rgba(0, 183, 215, 0.075);
  border-radius: 999px;
  filter: blur(72px);
  transform: translateX(-50%);
}

.shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 46px;
}

.operator-shell {
  width: min(1260px, calc(100% - 28px));
}

.debug-shell {
  width: min(1440px, calc(100% - 32px));
}

.quest-shell {
  width: min(1360px, calc(100% - 32px));
}

.brand-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 58px;
  margin-bottom: clamp(32px, 6vw, 72px);
  padding: 0 4px 18px;
  color: var(--slate-500);
  border-bottom: 1px solid rgba(16, 78, 100, 0.5);
  font: 700 12px/1.2 var(--font-mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.brand-mark {
  color: var(--cyan-400);
  font-size: 18px;
  letter-spacing: 0.28em;
  text-decoration: none;
}

.hero {
  position: relative;
  margin-bottom: 26px;
}

.operator-hero {
  display: grid;
  justify-items: center;
  gap: 20px;
  max-width: 980px;
  margin: 0 auto 32px;
  text-align: center;
}

.debug-hero,
.quest-hero {
  max-width: 980px;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  margin: 0 0 14px;
  color: var(--cyan-400);
  font: 700 12px/1.2 var(--font-mono);
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.operator-hero .eyebrow {
  padding: 7px 14px;
  background: rgba(16, 78, 100, 0.28);
  border: 1px solid rgba(0, 210, 239, 0.3);
  border-radius: 999px;
}

.operator-hero .eyebrow::before {
  content: "";
  width: 7px;
  height: 7px;
  background: var(--cyan-400);
  border-radius: 50%;
  box-shadow: 0 0 18px var(--cyan-400);
}

h1 {
  max-width: 980px;
  margin: 0;
  color: var(--white);
  font-size: clamp(44px, 8vw, 96px);
  font-weight: 800;
  line-height: 0.94;
  letter-spacing: -0.055em;
}

.operator-hero h1 {
  background: linear-gradient(90deg, var(--white), var(--cyan-400) 52%, var(--blue-500));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.lede {
  max-width: 660px;
  margin: 18px 0 0;
  color: var(--slate-400);
  font-size: clamp(17px, 2vw, 21px);
  line-height: 1.6;
}

.operator-hero .lede {
  margin-top: 0;
}

.stage-card,
.notes,
.page-navigation,
.debug-card,
.quest-current-card,
.quest-list-card,
.quest-signals-card {
  background: var(--panel);
  border: 1px solid rgba(29, 41, 61, 0.95);
  border-radius: 24px;
  box-shadow: 0 24px 80px var(--shadow);
  backdrop-filter: blur(12px);
}

.stage-card {
  position: relative;
  overflow: visible;
}

.stage-card::before,
.page-navigation::before,
.quest-current-card::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: inherit;
  background:
    linear-gradient(135deg, rgba(0, 210, 239, 0.18), transparent 26%),
    linear-gradient(315deg, rgba(21, 93, 252, 0.14), transparent 32%);
  opacity: 0.65;
}

.stage-card > *,
.page-navigation > *,
.quest-current-card > * {
  position: relative;
}

.operator-card {
  border-color: rgba(0, 210, 239, 0.38);
  box-shadow:
    0 28px 90px rgba(0, 0, 0, 0.52),
    0 0 42px rgba(0, 183, 215, 0.12);
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 78px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.operator-card .toolbar {
  background: rgba(5, 10, 18, 0.5);
  border-bottom-color: rgba(0, 210, 239, 0.28);
}

.source-controls {
  display: flex;
  align-items: end;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.source-controls label,
.performance-controls label {
  display: grid;
  gap: 6px;
  color: var(--slate-400);
  font: 700 11px/1.2 var(--font-mono);
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

select,
input[type="file"],
input[type="range"] {
  min-height: 42px;
  max-width: 240px;
  color: var(--foreground);
  background: rgba(15, 23, 43, 0.76);
  border: 1px solid var(--slate-700);
  border-radius: 999px;
  padding: 0 13px;
  font: 700 13px/1.2 var(--font-mono);
}

select:focus,
input[type="file"]:focus,
input[type="range"]:focus,
button:focus,
.utility-link:focus {
  outline: 2px solid var(--cyan-400);
  outline-offset: 3px;
}

select option {
  color: var(--foreground);
  background: var(--slate-900);
}

.source-select,
.performance-select {
  position: relative;
  min-width: 178px;
}

.native-source-mode,
.native-select-control,
.native-file-input {
  position: absolute;
  width: 1px;
  min-height: 1px;
  height: 1px;
  padding: 0;
  opacity: 0;
  pointer-events: none;
}

.source-menu {
  position: relative;
  display: inline-flex;
  width: 100%;
}

.source-menu-button {
  width: 100%;
  min-width: 178px;
  justify-content: space-between;
  gap: 8px;
}

.source-menu-button::after {
  content: "";
  width: 8px;
  height: 8px;
  margin-left: 12px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: translateY(-2px) rotate(45deg);
  opacity: 0.8;
}

.performance-menu-button {
  min-width: 128px;
  color: var(--foreground);
  background: rgba(15, 23, 43, 0.78);
  border-color: var(--slate-700);
  box-shadow: none;
}

.source-menu-options {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 50;
  display: grid;
  width: 100%;
  min-width: 220px;
  gap: 6px;
  padding: 8px;
  background:
    radial-gradient(circle at 100% 0%, rgba(0, 210, 239, 0.18), transparent 10rem),
    rgba(5, 10, 18, 0.97);
  border: 1px solid var(--line-strong);
  border-radius: 18px;
  box-shadow: 0 20px 64px rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(16px);
}

.performance-menu-options {
  left: 0;
  right: auto;
}

.source-menu-options[hidden],
.file-picker[hidden] {
  display: none;
}

.source-option {
  width: 100%;
  justify-content: flex-start;
  color: var(--slate-300);
  background: rgba(15, 23, 43, 0.62);
  border-color: transparent;
  box-shadow: none;
}

.source-option:hover,
.source-option:focus,
.source-option[aria-selected="true"] {
  color: var(--white);
  background: linear-gradient(90deg, var(--cyan-500), var(--blue-600));
  border-color: rgba(0, 210, 239, 0.72);
}

input[type="file"] {
  padding: 10px 12px;
  border-radius: 16px;
}

.file-picker {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
}

.file-picker-name {
  max-width: 180px;
  overflow: hidden;
  color: var(--slate-400);
  font: 700 12px/1.2 var(--font-mono);
  letter-spacing: 0.02em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.performance-controls {
  display: flex;
  align-items: end;
  gap: 14px;
  flex-wrap: wrap;
  overflow: visible;
  padding: 14px 18px;
  background: rgba(5, 10, 18, 0.46);
  border-bottom: 1px solid var(--line);
}

.performance-controls label {
  min-width: 128px;
}

.range-control {
  display: flex;
  align-items: center;
  gap: 10px;
}

.range-control input {
  width: 180px;
  padding: 0;
  accent-color: var(--cyan-400);
}

.range-control span {
  min-width: 58px;
  color: var(--foreground);
}

.toggle-control {
  min-height: 42px;
  display: flex !important;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 8px !important;
  padding: 0 14px;
  color: var(--slate-300) !important;
  background: rgba(15, 23, 43, 0.7);
  border: 1px solid var(--slate-700);
  border-radius: 999px;
}

.toggle-control input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--cyan-400);
}

.pill,
.meta,
button,
.utility-link {
  font: 700 13px/1.2 var(--font-mono);
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 31px;
  padding: 7px 13px;
  color: var(--cyan-400);
  background: rgba(16, 78, 100, 0.34);
  border: 1px solid rgba(0, 210, 239, 0.42);
  border-radius: 999px;
  text-transform: uppercase;
  box-shadow: 0 0 22px rgba(0, 210, 239, 0.12);
}

.pill.error {
  color: var(--white);
  background: rgba(255, 79, 104, 0.28);
  border-color: rgba(255, 79, 104, 0.72);
}

.meta {
  display: inline-block;
  margin-left: 10px;
  color: var(--slate-500);
}

button,
.utility-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 18px;
  color: var(--white);
  text-align: center;
  text-decoration: none;
  background: linear-gradient(90deg, var(--cyan-500), var(--blue-600));
  border: 1px solid rgba(0, 210, 239, 0.62);
  border-radius: 999px;
  box-shadow: 0 12px 34px rgba(0, 183, 215, 0.22);
  cursor: pointer;
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease,
    opacity 160ms ease,
    transform 160ms ease;
}

button:hover:not(:disabled),
.utility-link:hover {
  border-color: var(--cyan-400);
  box-shadow: 0 16px 42px rgba(0, 183, 215, 0.3);
  transform: translateY(-1px);
}

#stop:not(:disabled) {
  background: linear-gradient(90deg, var(--danger), #ff7a4f);
  border-color: rgba(255, 79, 104, 0.7);
  box-shadow: 0 12px 34px rgba(255, 79, 104, 0.2);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
  transform: none;
}

.utility-link {
  min-height: 40px;
  color: var(--slate-300);
  background: rgba(15, 23, 43, 0.62);
  border-color: var(--slate-700);
  box-shadow: none;
}

.page-navigation {
  position: relative;
  margin-top: 24px;
  padding: 18px;
}

.page-navigation .eyebrow {
  margin-bottom: 12px;
}

.page-nav-bottom {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.stage {
  position: relative;
  display: grid;
  place-items: center;
  overflow: hidden;
  min-height: 380px;
  background:
    radial-gradient(circle at 50% 50%, rgba(0, 183, 215, 0.12), transparent 28rem),
    #050a12;
  border-radius: 0;
}

.stage::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(0, 210, 239, 0.09) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 210, 239, 0.09) 1px, transparent 1px);
  background-size: 44px 44px;
  opacity: 0.44;
}

.stage::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  z-index: 3;
  height: 2px;
  pointer-events: none;
  background: linear-gradient(90deg, transparent, var(--cyan-400), transparent);
  opacity: 0;
}

.stage.stage-scan-once::after {
  animation: stage-scan-once 1800ms ease-in-out 1;
}

video {
  display: none;
}

canvas {
  position: relative;
  z-index: 1;
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 72vh;
  margin: 0 auto;
}

.empty {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  padding: 28px;
  color: rgba(232, 237, 245, 0.72);
  font-size: clamp(18px, 3vw, 22px);
  text-align: center;
}

.empty.hidden {
  display: none;
}

.readout {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-top: 1px solid var(--line);
}

.operator-readout {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.readout div {
  padding: 18px;
  border-right: 1px solid var(--line);
}

.readout div:last-child {
  border-right: 0;
}

.readout strong,
.readout span {
  display: block;
}

.readout strong {
  color: var(--cyan-400);
  font-size: clamp(28px, 5vw, 52px);
  line-height: 0.95;
  text-shadow: 0 0 20px rgba(0, 210, 239, 0.2);
}

.readout span {
  margin-top: 7px;
  color: var(--slate-500);
  font: 700 12px/1.2 var(--font-mono);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.notes {
  margin-top: 24px;
  padding: 18px;
}

.notes p {
  margin: 0 0 12px;
  color: var(--slate-400);
}

.debug-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 18px;
  margin-top: 24px;
}

.debug-card {
  min-width: 0;
  padding: 18px;
  color: var(--foreground);
  background: rgba(15, 23, 43, 0.58);
}

.debug-card-wide {
  grid-column: span 2;
}

.debug-card-full {
  grid-column: 1 / -1;
}

.debug-card h2 {
  margin: 0 0 14px;
  color: var(--cyan-400);
  font: 700 13px/1.2 var(--font-mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.debug-kv {
  display: grid;
  grid-template-columns: minmax(120px, 0.78fr) minmax(0, 1.22fr);
  gap: 8px 12px;
  margin: 0;
  font: 13px/1.35 var(--font-mono);
}

.debug-kv dt {
  color: var(--slate-500);
}

.debug-kv dd {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
}

.debug-table {
  overflow-x: auto;
}

.debug-table table {
  width: 100%;
  border-collapse: collapse;
  font: 12px/1.35 var(--font-mono);
}

.debug-table th,
.debug-table td {
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid rgba(144, 161, 185, 0.18);
}

.debug-table th {
  color: var(--slate-500);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.debug-empty {
  margin: 0;
  color: var(--slate-500);
  font: 13px/1.35 var(--font-mono);
}

.debug-raw {
  max-height: 420px;
  overflow: auto;
}

.stage-capture {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: 14px 18px;
  background: rgba(5, 10, 18, 0.54);
  border-top: 1px solid var(--line);
}

.capture-preview {
  width: 144px;
  max-height: 96px;
  object-fit: contain;
  background: var(--background);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.capture-preview.hidden {
  display: none;
}

.quest-board {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(280px, 0.9fr);
  gap: 18px;
  margin-top: 24px;
}

.quest-current-card,
.quest-list-card,
.quest-signals-card {
  position: relative;
  padding: 20px;
}

.quest-current-card {
  min-height: 290px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.quest-current-card h2 {
  margin: 4px 0 10px;
  color: var(--white);
  font-size: clamp(34px, 6vw, 72px);
  line-height: 0.95;
  letter-spacing: -0.05em;
}

.quest-hint,
.quest-evidence {
  margin: 0;
  color: var(--slate-400);
  font-size: 18px;
  line-height: 1.35;
}

.quest-evidence {
  margin-top: 12px;
  font: 700 13px/1.35 var(--font-mono);
}

.quest-progress-shell {
  height: 22px;
  margin-top: 18px;
  overflow: hidden;
  background: rgba(15, 23, 43, 0.82);
  border: 1px solid var(--slate-700);
  border-radius: 999px;
}

.quest-progress {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--cyan-400), var(--blue-500));
  box-shadow: 0 0 22px rgba(0, 210, 239, 0.34);
  transition: width 120ms linear;
}

.quest-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 18px;
}

.quest-list-card {
  grid-row: span 2;
}

.quest-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: quest;
}

.quest-item {
  counter-increment: quest;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 12px;
  color: var(--slate-300);
  background: rgba(15, 23, 43, 0.64);
  border: 1px solid var(--slate-700);
  border-radius: 18px;
  font: 700 14px/1.2 var(--font-mono);
}

.quest-item::before {
  content: counter(quest);
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  color: var(--background);
  background: var(--cyan-400);
  border-radius: 999px;
}

.quest-item small {
  color: var(--slate-500);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.quest-item.active {
  color: var(--white);
  background: linear-gradient(90deg, rgba(0, 183, 215, 0.34), rgba(21, 93, 252, 0.24));
  border-color: var(--line-strong);
}

.quest-item.done {
  color: rgba(232, 237, 245, 0.74);
  background: rgba(20, 241, 149, 0.12);
  border-color: rgba(20, 241, 149, 0.34);
}

.quest-item.done::before {
  content: "OK";
  color: var(--background);
  background: var(--success);
  font-size: 11px;
}

.quest-signals-card .eyebrow {
  color: var(--cyan-400);
}

code,
pre {
  font-family: var(--font-mono);
}

pre {
  min-height: 72px;
  margin: 0;
  padding: 14px;
  color: var(--slate-300);
  white-space: pre-wrap;
  background: rgba(0, 0, 0, 0.34);
  border: 1px solid rgba(29, 41, 61, 0.7);
  border-radius: 16px;
}

@keyframes stage-scan-once {
  0% {
    top: 0;
    opacity: 0;
  }

  12% {
    opacity: 0.68;
  }

  100% {
    top: 100%;
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .stage.stage-scan-once::after {
    animation: none;
  }
}

@media (max-width: 900px) {
  .debug-grid,
  .debug-card-wide,
  .quest-board,
  .quest-list-card {
    grid-template-columns: 1fr;
    grid-column: auto;
  }
}

@media (max-width: 720px) {
  .shell,
  .operator-shell,
  .debug-shell,
  .quest-shell {
    width: min(100% - 24px, 680px);
    padding-top: 18px;
  }

  .brand-bar {
    align-items: flex-start;
    flex-direction: column;
    margin-bottom: 28px;
  }

  h1 {
    font-size: clamp(42px, 15vw, 68px);
  }

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

  .source-controls {
    justify-content: stretch;
  }

  .source-controls,
  .performance-controls,
  .page-nav-bottom,
  .stage-capture,
  .source-controls label,
  .performance-controls label,
  .range-control,
  .utility-link,
  .file-picker,
  .source-menu-button,
  select,
  input[type="file"],
  input[type="range"],
  button {
    width: 100%;
    max-width: none;
  }

  .range-control {
    align-items: stretch;
    flex-direction: column;
  }

  .source-menu-options {
    min-width: 100%;
  }

  .meta {
    display: block;
    margin: 8px 0 0;
  }

  .stage {
    min-height: 320px;
  }

  .readout,
  .operator-readout {
    grid-template-columns: 1fr;
  }

  .readout div {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .readout div:last-child {
    border-bottom: 0;
  }

  .debug-kv {
    grid-template-columns: 1fr;
  }

  .quest-actions {
    width: 100%;
  }
}
