:root {
  color-scheme: dark;
  --ink: #d7e7df;
  --muted: #71877d;
  --dim: #3d554a;
  --line: #1c3329;
  --line-hot: #3f735d;
  --panel: #080d0b;
  --panel-raised: #0c1411;
  --black: #030504;
  --green: #7be6a8;
  --green-bright: #a1f7bd;
  --cyan: #55d9ff;
  --amber: #e1cf78;
  --danger: #ff7b74;
  --mono: "Cascadia Code", "JetBrains Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--black);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 84% 7%, rgb(30 83 62 / 0.22), transparent 31rem),
    radial-gradient(circle at 9% 82%, rgb(21 65 78 / 0.13), transparent 34rem),
    linear-gradient(145deg, #020403, #060b08 55%, #020504);
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.5;
}

body::before {
  position: fixed;
  z-index: 20;
  inset: 0;
  pointer-events: none;
  content: "";
  background: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent 3px,
    rgb(128 255 177 / 0.018) 4px
  );
}

.noise {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.24;
  background-image:
    linear-gradient(90deg, rgb(123 230 168 / 0.025) 1px, transparent 1px),
    linear-gradient(rgb(123 230 168 / 0.018) 1px, transparent 1px);
  background-size: 54px 54px;
  mask-image: linear-gradient(to bottom, black, transparent 75%);
}

button,
input {
  font: inherit;
}

button,
input,
.graph-scroll {
  outline: none;
}

button:focus-visible,
.graph-scroll:focus-visible {
  box-shadow: 0 0 0 2px var(--black), 0 0 0 4px var(--green);
}

.terminal-shell {
  position: relative;
  width: min(1540px, calc(100% - 48px));
  margin: 24px auto;
  background: rgb(4 8 6 / 0.94);
  box-shadow: 0 28px 100px rgb(0 0 0 / 0.48), inset 0 0 80px rgb(75 181 119 / 0.025);
  animation: terminal-in 500ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.input-row,
footer {
  display: flex;
  align-items: center;
}

.mobile-hint {
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.16em;
}

p {
  margin-top: 0;
}

.command-panel {
  padding: 24px 30px 0;
  animation: module-in 450ms 100ms ease-out both;
}

.query-form {
  width: 100%;
}

.input-row {
  position: relative;
  border: 1px solid var(--line-hot);
  background: #030705;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.input-row:focus-within {
  border-color: var(--green);
  box-shadow: 0 0 28px rgb(123 230 168 / 0.08);
}

input {
  min-width: 0;
  flex: 1;
  border: 0;
  padding: 15px 13px;
  color: var(--ink);
  background: transparent;
  caret-color: var(--green);
}

input::selection {
  color: var(--black);
  background: var(--green);
}

input::-webkit-search-cancel-button {
  filter: invert(1);
  opacity: 0.4;
}

button {
  display: flex;
  min-height: 48px;
  align-items: center;
  gap: 18px;
  border: 0;
  border-left: 1px solid var(--line-hot);
  padding: 0 20px;
  color: var(--black);
  background: var(--green);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 150ms ease, padding 150ms ease;
}

button:hover:not(:disabled) {
  padding-inline: 24px 16px;
  background: var(--green-bright);
}

button:disabled {
  color: var(--dim);
  background: #102019;
  cursor: wait;
}

.submit-icon {
  font-size: 18px;
  line-height: 1;
}

.output-panel {
  padding: 18px 30px 22px;
  animation: module-in 450ms 180ms ease-out both;
}

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

.graph-scroll {
  position: relative;
  overflow-x: auto;
  overflow-y: hidden;
  background: #020403;
  scrollbar-color: var(--line-hot) var(--black);
  scrollbar-width: thin;
  overscroll-behavior-inline: contain;
}

.graph-scroll::-webkit-scrollbar {
  height: 9px;
}

.graph-scroll::-webkit-scrollbar-track {
  background: var(--black);
}

.graph-scroll::-webkit-scrollbar-thumb {
  border: 2px solid var(--black);
  background: var(--line-hot);
}

.graph-stage {
  position: relative;
  transition: opacity 180ms ease;
}

.graph-stage.is-loading {
  min-height: min(64vw, 760px);
}

.graph-stage > svg {
  display: block;
  width: 100%;
  min-width: 980px;
  height: auto;
}

.graph-stage.is-loading > svg {
  opacity: 0.28;
  filter: saturate(0.5);
}

.graph-stage.is-error {
  min-height: 320px;
}

.graph-stage.is-error::after {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--danger);
  content: "[ UPSTREAM PROCESS FAILED ]";
  font-size: 12px;
  letter-spacing: 0.12em;
}

.loader {
  position: absolute;
  z-index: 3;
  top: 50%;
  left: 50%;
  display: flex;
  gap: 5px;
  transform: translate(-50%, -50%);
}

.loader span {
  width: 5px;
  height: 28px;
  background: var(--green);
  animation: meter 900ms ease-in-out infinite;
}

.loader span:nth-child(2) { animation-delay: 90ms; }
.loader span:nth-child(3) { animation-delay: 180ms; }
.loader span:nth-child(4) { animation-delay: 270ms; }
.loader span:nth-child(5) { animation-delay: 360ms; }

.graph-stage:not(.is-loading):not(:empty) .loader {
  display: none;
}

.graph-stage [data-tooltip] {
  cursor: crosshair;
  outline: none;
}

.graph-stage [data-tooltip]:focus-visible {
  filter: drop-shadow(0 0 5px var(--green));
}

.mobile-hint {
  display: none;
  margin: 13px 0 0;
  letter-spacing: 0.08em;
}

.tooltip {
  position: fixed;
  z-index: 100;
  max-width: min(320px, calc(100vw - 24px));
  padding: 9px 11px;
  border: 1px solid var(--green);
  color: var(--green-bright);
  background: rgb(3 8 5 / 0.97);
  box-shadow: 6px 6px 0 rgb(15 43 31 / 0.8), 0 0 32px rgb(123 230 168 / 0.14);
  font-size: 11px;
  line-height: 1.45;
  pointer-events: none;
  white-space: pre-line;
}

.tooltip[hidden] {
  display: none;
}

footer {
  min-height: 42px;
  justify-content: space-between;
  gap: 20px;
  border-top: 1px solid var(--line);
  padding: 0 30px;
  color: var(--dim);
  font-size: 9px;
  letter-spacing: 0.1em;
}

.footer-accent {
  color: var(--green);
}

@keyframes terminal-in {
  from { opacity: 0; transform: translateY(10px) scale(0.995); }
  to { opacity: 1; transform: none; }
}

@keyframes module-in {
  from { opacity: 0; transform: translateY(7px); }
  to { opacity: 1; transform: none; }
}

@keyframes meter {
  0%, 100% { transform: scaleY(0.3); opacity: 0.25; }
  50% { transform: scaleY(1); opacity: 1; }
}

@media (max-width: 850px) {
  .terminal-shell {
    width: calc(100% - 24px);
    margin: 12px auto;
  }

  .graph-stage.is-loading {
    min-height: 580px;
  }

  .graph-stage > svg {
    width: 980px;
  }

  .mobile-hint {
    display: block;
  }
}

@media (max-width: 560px) {
  body {
    font-size: 13px;
  }

  .terminal-shell {
    width: 100%;
    margin: 0;
  }

  .command-panel,
  .output-panel {
    padding-inline: 16px;
  }

  .input-row {
    flex-wrap: nowrap;
  }

  .input-row input {
    width: 0;
    flex: 1 1 0;
  }

  .input-row button {
    width: 52px;
    min-width: 52px;
    flex: 0 0 52px;
    justify-content: center;
    border-top: 0;
    border-left: 1px solid var(--line-hot);
    padding: 0;
  }

  footer {
    justify-content: center;
    padding: 12px 16px;
    text-align: center;
  }

  footer span:not(.footer-accent) {
    display: none;
  }
}

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