/* Ouroboros viewer design system — instrument / plasma-lab direction */
@import url("https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,500;0,9..40,700;1,9..40,500&family=JetBrains+Mono:wght@400;600&family=Syne:wght@700;800&display=swap");

:root {
  --ink: #e8eef2;
  --ink-dim: #8a9aa6;
  --ink-mute: #5c6b76;
  --bg-deep: #070b0e;
  --bg-0: #0c1217;
  --bg-1: #121a21;
  --bg-panel: rgba(18, 28, 36, 0.82);
  --line: rgba(120, 160, 180, 0.22);
  --line-strong: rgba(180, 210, 220, 0.35);
  --phosphor: #3ef0c8;
  --phosphor-dim: #1a8f78;
  --amber: #f0a35e;
  --rose: #e06b6b;
  --field: rgba(8, 14, 18, 0.55);
  --radius: 2px;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --font-brand: "Syne", system-ui, sans-serif;
  --font-ui: "DM Sans", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;
}

*,
*::before,
*::after { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  color: var(--ink);
  font-family: var(--font-ui);
  font-optical-sizing: auto;
  background:
    radial-gradient(ellipse 90% 55% at 8% -10%, rgba(62, 240, 200, 0.14), transparent 55%),
    radial-gradient(ellipse 70% 50% at 100% 110%, rgba(240, 163, 94, 0.10), transparent 50%),
    radial-gradient(circle at 50% 40%, #152029 0%, var(--bg-deep) 70%);
  background-attachment: fixed;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.35;
  background-image:
    linear-gradient(rgba(232, 238, 242, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(232, 238, 242, 0.03) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse 80% 70% at 50% 40%, #000 20%, transparent 75%);
  z-index: 0;
  animation: gridDrift 40s linear infinite;
}

@keyframes gridDrift {
  from { background-position: 0 0, 0 0; }
  to { background-position: 48px 24px, 24px 48px; }
}

@keyframes riseIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes brandPulse {
  0%, 100% { letter-spacing: -0.03em; text-shadow: 0 0 0 transparent; }
  50% { letter-spacing: -0.01em; text-shadow: 0 0 28px rgba(62, 240, 200, 0.18); }
}

@keyframes stageGlow {
  0%, 100% { box-shadow: inset 0 0 0 1px var(--line), 0 0 0 0 rgba(62, 240, 200, 0); }
  50% { box-shadow: inset 0 0 0 1px rgba(62, 240, 200, 0.35), 0 0 40px rgba(62, 240, 200, 0.08); }
}

@keyframes scrubPulse {
  from { opacity: 0.55; }
  to { opacity: 1; }
}

.app {
  position: relative;
  z-index: 1;
  max-width: 1280px;
  margin: 0 auto;
  padding: 1.25rem 1.25rem 2.5rem;
  animation: riseIn 0.55s var(--ease) both;
}

/* —— chrome —— */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem 1.5rem;
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--line);
}

.brand-block { min-width: min(100%, 280px); }

.brand {
  font-family: var(--font-brand);
  font-weight: 800;
  font-size: clamp(2rem, 5vw, 3rem);
  line-height: 0.95;
  margin: 0;
  letter-spacing: -0.03em;
  color: var(--ink);
  animation: brandPulse 6s var(--ease) infinite;
}

.brand span {
  color: var(--phosphor);
}

.tagline {
  margin: 0.45rem 0 0;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

.tagline a {
  color: var(--phosphor);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s var(--ease), color 0.2s;
}
.tagline a:hover { border-bottom-color: var(--phosphor); color: #fff; }

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}

.nav a {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-decoration: none;
  color: var(--ink-dim);
  padding: 0.55rem 0.85rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}

.nav a:hover {
  color: var(--ink);
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.03);
}

.nav a.active {
  color: var(--bg-deep);
  background: var(--phosphor);
  border-color: var(--phosphor);
  font-weight: 600;
}

/* —— layout —— */
.workspace {
  display: grid;
  gap: 1rem;
}

@media (min-width: 960px) {
  .workspace {
    grid-template-columns: 280px minmax(0, 1fr);
    align-items: start;
  }
}

.rail {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  animation: riseIn 0.65s var(--ease) 0.05s both;
}

.panel {
  background: var(--bg-panel);
  backdrop-filter: blur(14px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
}

.panel h2 {
  margin: 0 0 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-mute);
}

.field { margin-bottom: 0.75rem; }
.field:last-child { margin-bottom: 0; }

label {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-mute);
  margin-bottom: 0.35rem;
}

select,
input[type="text"] {
  width: 100%;
  font: inherit;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--ink);
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.55rem 0.65rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

select:focus,
input[type="text"]:focus,
input[type="range"]:focus {
  border-color: var(--phosphor-dim);
  box-shadow: 0 0 0 3px rgba(62, 240, 200, 0.12);
}

.btn-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-top: 0.85rem;
}

button {
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 0.85rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: transparent;
  color: var(--ink);
  padding: 0.65rem 0.85rem;
  cursor: pointer;
  transition: transform 0.15s var(--ease), background 0.2s, border-color 0.2s, color 0.2s;
}

button:hover {
  transform: translateY(-1px);
  border-color: var(--phosphor);
  color: var(--phosphor);
}

button:active { transform: translateY(0); }

button.primary {
  background: var(--phosphor);
  border-color: var(--phosphor);
  color: var(--bg-deep);
}

button.primary:hover {
  background: #6ff7d8;
  color: var(--bg-deep);
  border-color: #6ff7d8;
}

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

.scrub {
  margin-top: 0.35rem;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: linear-gradient(90deg, var(--phosphor-dim), var(--amber));
  border: none;
  border-radius: 99px;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--ink);
  border: 2px solid var(--phosphor);
  box-shadow: 0 0 12px rgba(62, 240, 200, 0.45);
  cursor: pointer;
}

.scrub-meta {
  display: flex;
  justify-content: space-between;
  margin-top: 0.4rem;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--ink-mute);
}

.scrub-meta strong { color: var(--amber); font-weight: 600; }

/* —— stage —— */
.main {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  min-width: 0;
  animation: riseIn 0.7s var(--ease) 0.1s both;
}

.stage-wrap {
  position: relative;
  background:
    radial-gradient(ellipse 60% 50% at 70% 45%, rgba(62, 240, 200, 0.07), transparent 60%),
    linear-gradient(160deg, #101820, #0a1014 60%, #0e151b);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  animation: stageGlow 5.5s ease-in-out infinite;
}

.stage-wrap canvas {
  display: block;
  width: 100%;
  height: auto;
  vertical-align: middle;
}

.stage-badge {
  position: absolute;
  top: 0.75rem;
  left: 0.75rem;
  z-index: 2;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--bg-deep);
  background: var(--phosphor);
  padding: 0.28rem 0.5rem;
  border-radius: var(--radius);
  pointer-events: none;
}

.stage-empty {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  text-align: center;
  padding: 2rem;
  background: rgba(7, 11, 14, 0.55);
  backdrop-filter: blur(2px);
}

.stage-empty.visible { display: grid; }

.stage-empty h3 {
  font-family: var(--font-brand);
  font-size: 1.4rem;
  margin: 0 0 0.5rem;
}

.stage-empty p {
  margin: 0;
  max-width: 28ch;
  color: var(--ink-dim);
  font-size: 0.92rem;
  line-height: 1.45;
}

/* —— telemetry —— */
.telemetry {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem;
}

@media (min-width: 640px) {
  .telemetry { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

.stat {
  border: 1px solid var(--line);
  background: var(--bg-panel);
  padding: 0.7rem 0.8rem;
  border-radius: var(--radius);
  min-height: 4.2rem;
}

.stat .k {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-mute);
  margin-bottom: 0.25rem;
}

.stat .v {
  font-family: var(--font-mono);
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: -0.02em;
}

.stat .v em {
  font-style: normal;
  color: var(--ink-dim);
  font-size: 0.75rem;
  font-weight: 400;
  margin-left: 0.2rem;
}

.legend {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--ink-mute);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.legend-bar {
  flex: 1;
  height: 6px;
  border-radius: 99px;
  background: linear-gradient(90deg, #1a8f78, #c9d6a8 45%, #f0a35e);
  border: 1px solid var(--line);
}

.hints {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--ink-mute);
  line-height: 1.5;
}

.hints kbd {
  display: inline-block;
  padding: 0.1rem 0.35rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink-dim);
  background: rgba(255, 255, 255, 0.03);
  font-size: 0.65rem;
}

.status {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.pill {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.28rem 0.5rem;
  border-radius: 99px;
  border: 1px solid var(--line);
  color: var(--ink-dim);
}

.pill.ok {
  color: var(--bg-deep);
  background: var(--phosphor);
  border-color: var(--phosphor);
}

.pill.warn {
  color: var(--bg-deep);
  background: var(--amber);
  border-color: var(--amber);
}

.pill.err {
  color: #fff;
  background: var(--rose);
  border-color: var(--rose);
}

.err {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: #ffb4b4;
  min-height: 1.2em;
}

.err:empty { display: none; }

.footer {
  margin-top: 1.5rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-mute);
}

.footer a { color: var(--ink-dim); text-decoration: none; }
.footer a:hover { color: var(--phosphor); }

/* protocol page */
.protocol-list {
  display: grid;
  gap: 0.55rem;
}

.endpoint {
  display: grid;
  gap: 0.2rem;
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--line);
  background: var(--field);
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 0.78rem;
}

.endpoint code {
  color: var(--phosphor);
  font-size: 0.85rem;
}

.endpoint span { color: var(--ink-mute); font-size: 0.7rem; }

pre.json {
  margin: 0;
  padding: 1rem;
  overflow: auto;
  max-height: 360px;
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  line-height: 1.45;
  color: var(--ink-dim);
}

@media (max-width: 640px) {
  .app { padding: 1rem 0.85rem 2rem; }
  .btn-row { grid-template-columns: 1fr; }
}
