:root {
  color-scheme: dark;
  --text: #f8fbff;
  --muted: rgba(234, 244, 248, 0.74);
  --dim: rgba(234, 244, 248, 0.56);
  --panel: rgba(5, 11, 18, 0.72);
  --panel-strong: rgba(8, 18, 27, 0.88);
  --panel-border: rgba(117, 255, 227, 0.22);
  --shadow: rgba(0, 0, 0, 0.48);
  --bg-top: #071117;
  --bg-mid: #120717;
  --bg-deep: #020306;
  --accent: #20f7c6;
  --accent-2: #ff4fc3;
  --accent-3: #f7ff57;
  --accent-4: #47a8ff;
  --accent-soft: rgba(32, 247, 198, 0.15);
  --warning-soft: rgba(247, 255, 87, 0.12);
}

body[data-mode="posttraining"] {
  --panel: rgba(14, 7, 20, 0.75);
  --panel-strong: rgba(19, 9, 26, 0.9);
  --panel-border: rgba(255, 79, 195, 0.24);
  --bg-top: #120716;
  --bg-mid: #071016;
  --bg-deep: #020306;
  --accent: #ff4fc3;
  --accent-2: #20f7c6;
  --accent-3: #f7ff57;
  --accent-4: #9cff6a;
  --accent-soft: rgba(255, 79, 195, 0.15);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  background:
    linear-gradient(125deg, rgba(32, 247, 198, 0.16), transparent 28%),
    linear-gradient(235deg, rgba(255, 79, 195, 0.16), transparent 30%),
    linear-gradient(180deg, var(--bg-top) 0%, var(--bg-mid) 48%, var(--bg-deep) 100%);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  overflow: hidden;
  transition: background 420ms ease;
}

button,
input {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover,
a:focus-visible {
  color: var(--accent-3);
  text-decoration: underline;
  text-underline-offset: 0.16rem;
}

.page-shell {
  position: relative;
  min-height: 100vh;
  isolation: isolate;
}

.page-shell::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, transparent 0 12%, rgba(255, 255, 255, 0.03) 12.2% 12.35%, transparent 12.6% 100%),
    linear-gradient(180deg, transparent 0 22%, rgba(255, 255, 255, 0.025) 22.2% 22.35%, transparent 22.6% 100%);
  background-size: 38rem 38rem, 32rem 32rem;
  opacity: 0.38;
  pointer-events: none;
  z-index: 0;
}

.fx-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(32, 247, 198, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 79, 195, 0.06) 1px, transparent 1px);
  background-size: 4.2rem 4.2rem;
  mask-image: linear-gradient(180deg, transparent 0%, black 18%, black 85%, transparent 100%);
  opacity: 0.28;
  transform: perspective(46rem) rotateX(62deg) translateY(12rem);
  transform-origin: center bottom;
  pointer-events: none;
  z-index: 0;
}

.grain {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.025), rgba(255, 255, 255, 0.025)),
    linear-gradient(90deg, rgba(255, 255, 255, 0.016) 1px, transparent 1px),
    linear-gradient(rgba(255, 255, 255, 0.012) 1px, transparent 1px);
  background-size: auto, 6px 6px, 6px 6px;
  mix-blend-mode: soft-light;
  opacity: 0.16;
  pointer-events: none;
  z-index: 0;
}

.ambient {
  position: absolute;
  width: 74vw;
  height: 14rem;
  border-radius: 8px;
  filter: blur(24px);
  opacity: 0.5;
  mix-blend-mode: screen;
  pointer-events: none;
  z-index: 0;
}

.ambient-a {
  top: 4rem;
  left: -18vw;
  background: linear-gradient(90deg, transparent, rgba(32, 247, 198, 0.42), transparent);
  transform: rotate(-18deg);
  animation: drift-ambient 24s ease-in-out infinite alternate;
}

.ambient-b {
  right: -16vw;
  top: 18rem;
  background: linear-gradient(90deg, transparent, rgba(255, 79, 195, 0.36), transparent);
  transform: rotate(16deg);
  animation: drift-ambient 31s ease-in-out infinite alternate-reverse;
}

.ambient-c {
  left: 14vw;
  bottom: 2rem;
  background: linear-gradient(90deg, transparent, rgba(247, 255, 87, 0.22), transparent);
  transform: rotate(-7deg);
  animation: drift-ambient 27s ease-in-out infinite alternate;
}

.hud {
  position: relative;
  z-index: 3;
  display: grid;
  gap: 0.65rem;
  width: min(100%, 74rem);
  padding: 0.85rem;
  pointer-events: none;
}

.panel {
  pointer-events: auto;
  position: relative;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.075), rgba(255, 255, 255, 0.018)),
    var(--panel);
  backdrop-filter: blur(24px);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  box-shadow:
    0 28px 80px var(--shadow),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
  padding: 0.85rem;
}

.panel::before {
  content: "";
  position: absolute;
  inset: 0;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  pointer-events: none;
}

.title-panel {
  max-width: 48rem;
}

.title-topline,
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.eyebrow,
.panel-label,
.pill,
.fragment-chip,
.fragment-source,
.fragment-footer,
.fragment-phase,
.signal-card span,
.stream-stats span {
  font-family: "SFMono-Regular", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  letter-spacing: 0;
  text-transform: uppercase;
}

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-size: 0.72rem;
}

h1,
h2,
h3,
p {
  overflow-wrap: anywhere;
}

h1 {
  margin: 0.65rem 0 0;
  max-width: none;
  font-size: 3.2rem;
  line-height: 0.95;
  letter-spacing: 0;
}

.lede {
  margin: 0.55rem 0 0;
  max-width: 43rem;
  color: var(--muted);
  font-size: 0.96rem;
  line-height: 1.46;
}

.mode-switch {
  display: inline-grid;
  grid-template-columns: repeat(2, minmax(8.5rem, 1fr));
  gap: 0.35rem;
  width: min(100%, 22rem);
  margin-top: 0.7rem;
  padding: 0.28rem;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.22);
}

.mode-toggle,
.dataset-toggle,
.text-button,
.dock-button {
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.055);
  color: var(--text);
  border-radius: 6px;
  min-height: 2.34rem;
  padding: 0.5rem 0.72rem;
  cursor: pointer;
  transition:
    transform 160ms ease,
    background 160ms ease,
    border-color 160ms ease,
    color 160ms ease,
    box-shadow 160ms ease;
}

.mode-toggle,
.dataset-toggle {
  width: 100%;
}

.mode-toggle.is-active,
.dataset-toggle.is-active {
  background:
    linear-gradient(135deg, rgba(32, 247, 198, 0.18), rgba(255, 79, 195, 0.14)),
    rgba(255, 255, 255, 0.08);
  border-color: color-mix(in srgb, var(--accent) 55%, white 18%);
  box-shadow: 0 0 22px rgba(32, 247, 198, 0.14);
}

.mode-toggle:hover,
.mode-toggle:focus-visible,
.dataset-toggle:hover,
.dataset-toggle:focus-visible,
.text-button:hover,
.text-button:focus-visible,
.dock-button:hover,
.dock-button:focus-visible {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.11);
  border-color: rgba(255, 255, 255, 0.22);
}

.subtle-button {
  min-height: 2.08rem;
  padding: 0.42rem 0.68rem;
  color: var(--muted);
}

.hero-pills,
.label-cluster {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.hero-pills {
  margin-top: 0.7rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 1.66rem;
  padding: 0.28rem 0.5rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.09);
  color: rgba(248, 251, 255, 0.88);
  font-size: 0.66rem;
}

.hud-grid {
  display: grid;
  gap: 0.65rem;
  grid-template-columns: minmax(18rem, 22rem) minmax(20rem, 25rem);
  max-width: 48rem;
}

.panel-label {
  margin: 0 0 0.56rem;
  color: var(--accent-3);
  font-size: 0.7rem;
}

.panel-label-spaced {
  margin-top: 1rem;
}

.panel h2 {
  margin: 0;
  font-size: 1.24rem;
  line-height: 1.18;
  letter-spacing: 0;
}

.panel-copy {
  margin: 0.45rem 0 0;
  color: var(--muted);
  line-height: 1.55;
}

.dataset-switch {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr));
  gap: 0.45rem;
}

.signal-card {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.7rem;
  margin-top: 0.72rem;
  padding-top: 0.66rem;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.signal-card div,
.stream-stats div {
  min-width: 0;
}

.signal-card span,
.stream-stats span {
  display: block;
  color: var(--dim);
  font-size: 0.63rem;
}

.signal-card strong,
.stream-stats strong {
  display: block;
  margin-top: 0.2rem;
  color: var(--text);
  font-size: 0.86rem;
  line-height: 1.22;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  color: var(--muted);
  margin-bottom: 0.72rem;
}

.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
}

.switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch-track {
  position: relative;
  display: inline-flex;
  width: 3.3rem;
  height: 1.85rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.12);
  transition: background 160ms ease, border-color 160ms ease;
}

.switch-track::after {
  content: "";
  position: absolute;
  top: 0.18rem;
  left: 0.2rem;
  width: 1.22rem;
  height: 1.22rem;
  border-radius: 999px;
  background: #ffffff;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.28);
  transition: transform 180ms ease;
}

.switch input:checked + .switch-track {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 45%, white 16%);
}

.switch input:checked + .switch-track::after {
  transform: translateX(1.38rem);
}

.control-row {
  display: grid;
  gap: 0.35rem;
  margin-bottom: 0.58rem;
}

.control-row label {
  color: var(--muted);
}

.control-row input {
  width: 100%;
  accent-color: var(--accent);
}

.button-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.48rem;
  margin-top: 0.48rem;
}

.label-note {
  margin: 0.85rem 0 0;
  color: rgba(248, 251, 255, 0.66);
  line-height: 1.5;
}

.stream-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.7rem;
  margin-top: 0.72rem;
  padding-top: 0.66rem;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.lamp-stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
  z-index: 1;
}

.stage-halo {
  position: absolute;
  width: min(54vw, 38rem);
  height: 72vh;
  left: 58%;
  top: 16vh;
  border-radius: 8px;
  background:
    linear-gradient(180deg, transparent, rgba(32, 247, 198, 0.14), rgba(255, 79, 195, 0.14), transparent),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.07) 0 1px, transparent 1px 3.4rem);
  filter: blur(10px);
  opacity: 0.62;
  transform: skewX(-9deg);
  pointer-events: none;
}

.stage-rings {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.ring {
  position: absolute;
  left: 54%;
  top: 57%;
  transform: translate(-50%, -50%) rotate(-7deg);
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.11);
  opacity: 0.32;
}

.ring-a {
  width: min(34rem, 54vw);
  height: min(18rem, 30vw);
  animation: ring-float 18s ease-in-out infinite alternate;
}

.ring-b {
  width: min(48rem, 68vw);
  height: min(25rem, 38vw);
  opacity: 0.22;
  animation: ring-float 22s ease-in-out infinite alternate-reverse;
}

.ring-c {
  width: min(62rem, 82vw);
  height: min(31rem, 44vw);
  opacity: 0.14;
  animation: ring-float 28s ease-in-out infinite alternate;
}

.stream {
  position: absolute;
  inset: 0;
}

.scanlines {
  position: absolute;
  inset: 0;
  background-image: linear-gradient(
    rgba(255, 255, 255, 0.035) 0,
    rgba(255, 255, 255, 0.012) 1px,
    transparent 1px,
    transparent 7px
  );
  mask-image: linear-gradient(180deg, transparent 0%, black 12%, black 90%, transparent 100%);
  opacity: 0.18;
  pointer-events: none;
}

.fragment {
  position: absolute;
  width: min(29rem, calc(100vw - 2rem));
  min-width: min(18rem, calc(100vw - 2rem));
  padding: 0.88rem 0.92rem 0.95rem;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.13), rgba(255, 255, 255, 0.035)),
    rgba(3, 9, 15, 0.76);
  box-shadow:
    0 20px 70px rgba(0, 0, 0, 0.48),
    0 0 28px color-mix(in srgb, var(--fragment-tint) 24%, transparent),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(18px);
  animation: float-fragment linear forwards;
  will-change: transform, opacity;
  z-index: 2;
}

.fragment::before {
  content: "";
  position: absolute;
  inset: 0;
  border-left: 3px solid var(--fragment-tint);
  border-radius: inherit;
  background:
    linear-gradient(90deg, color-mix(in srgb, var(--fragment-tint) 28%, transparent), transparent 42%),
    linear-gradient(135deg, rgba(255, 255, 255, 0.07), transparent 42%);
  opacity: 0.76;
  pointer-events: none;
}

.fragment[data-role="assistant"] {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0.035)),
    rgba(13, 7, 20, 0.8);
}

.fragment-topline {
  position: relative;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.6rem;
  margin-bottom: 0.65rem;
  z-index: 1;
}

.label-cluster {
  min-width: 0;
}

.fragment-chip {
  max-width: 100%;
  padding: 0.28rem 0.44rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.085);
  color: rgba(248, 251, 255, 0.85);
  font-size: 0.6rem;
  line-height: 1.2;
}

.fragment-phase {
  flex: 0 0 auto;
  color: var(--fragment-tint);
  font-size: 0.6rem;
  line-height: 1.4;
}

.fragment-text {
  position: relative;
  margin: 0;
  color: rgba(248, 251, 255, 0.97);
  font-size: 1.02rem;
  line-height: 1.55;
  text-wrap: pretty;
  z-index: 1;
}

.fragment-footer {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  gap: 0.52rem;
  margin-top: 0.78rem;
  color: rgba(248, 251, 255, 0.64);
  font-size: 0.6rem;
  line-height: 1.35;
  z-index: 1;
}

.fragment-source {
  position: relative;
  margin: 0.45rem 0 0;
  color: rgba(248, 251, 255, 0.58);
  font-size: 0.6rem;
  line-height: 1.35;
  word-break: break-word;
  z-index: 1;
}

body.labels-hidden .label-cluster,
body.labels-hidden .fragment-footer,
body.labels-hidden .fragment-source,
body.labels-hidden .fragment-phase {
  margin: 0;
  max-height: 0;
  opacity: 0;
  overflow: hidden;
}

.footer-note {
  position: absolute;
  left: auto;
  right: 1rem;
  bottom: 0.9rem;
  width: min(36rem, calc(100vw - 2rem));
  z-index: 3;
  pointer-events: none;
}

.footer-note p {
  margin: 0;
  max-width: none;
  color: rgba(248, 251, 255, 0.7);
  font-size: 0.84rem;
  line-height: 1.5;
  text-align: right;
}

.hud,
.footer-note {
  transition:
    opacity 220ms ease,
    transform 220ms ease,
    visibility 220ms ease;
}

body.ui-hidden .hud,
body.ui-hidden .footer-note {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

body.ui-hidden .hud {
  transform: translateY(-1rem);
}

body.ui-hidden .footer-note {
  transform: translateY(1rem);
}

.stage-dock {
  position: absolute;
  top: 1rem;
  right: 1rem;
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  opacity: 0;
  transform: translate3d(0, -0.75rem, 0);
  pointer-events: none;
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

body.ui-hidden .stage-dock {
  opacity: 1;
  transform: translate3d(0, 0, 0);
  pointer-events: auto;
}

.dock-button {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.03)),
    rgba(7, 14, 24, 0.75);
  backdrop-filter: blur(20px);
  box-shadow:
    0 18px 36px rgba(0, 0, 0, 0.34),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.about-modal {
  width: min(42rem, calc(100vw - 2rem));
  max-height: min(42rem, calc(100vh - 2rem));
  color: var(--text);
  background: transparent;
  border: 0;
  padding: 0;
}

.about-modal::backdrop {
  background: rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(8px);
}

.modal-shell {
  overflow: auto;
  max-height: min(42rem, calc(100vh - 2rem));
  padding: 1rem;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.018)),
    var(--panel-strong);
  box-shadow: 0 26px 90px rgba(0, 0, 0, 0.56);
}

.modal-shell h2 {
  margin: 0.9rem 0 0;
  font-size: 1.7rem;
  line-height: 1.15;
}

.modal-shell h3 {
  margin: 0 0 0.55rem;
  font-size: 0.95rem;
}

.modal-shell p {
  color: var(--muted);
  line-height: 1.58;
}

.about-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.about-grid section {
  display: grid;
  align-content: start;
  gap: 0.48rem;
  min-width: 0;
}

.modal-note {
  margin-bottom: 0;
  padding-top: 0.9rem;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}

body.paused .fragment,
body.paused .ambient,
body.paused .ring {
  animation-play-state: paused;
}

@keyframes float-fragment {
  0% {
    opacity: 0;
    transform: translate3d(0, 113vh, 0) rotate(var(--tilt)) scale(0.97);
  }
  10% {
    opacity: 1;
  }
  84% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate3d(var(--drift-x), -136vh, 0) rotate(var(--tilt)) scale(1.02);
  }
}

@keyframes drift-ambient {
  from {
    translate: -2% -1%;
  }
  to {
    translate: 3% 2%;
  }
}

@keyframes ring-float {
  from {
    translate: 0 0;
    scale: 0.98;
  }
  to {
    translate: 0 -0.8rem;
    scale: 1.03;
  }
}

@media (max-width: 960px) {
  body {
    overflow: auto;
  }

  .hud {
    width: 100%;
  }

  .hud-grid {
    grid-template-columns: 1fr;
    max-width: 28rem;
  }

  h1 {
    font-size: 3rem;
  }

  .lamp-stage {
    position: relative;
    min-height: 58rem;
  }

  .stage-dock {
    top: auto;
    right: 1rem;
    bottom: 1rem;
    left: 1rem;
    justify-content: flex-end;
    flex-wrap: wrap;
  }

  .footer-note {
    position: relative;
    left: auto;
    right: auto;
    width: auto;
    margin-top: -3.5rem;
  }

  .footer-note p {
    text-align: left;
  }
}

@media (max-width: 680px) {
  .hud {
    padding: 0.75rem;
  }

  .panel {
    padding: 0.85rem;
  }

  .title-topline,
  .modal-header {
    align-items: flex-start;
  }

  h1 {
    font-size: 3rem;
    max-width: 10ch;
  }

  .mode-switch,
  .button-row,
  .stream-stats,
  .about-grid {
    grid-template-columns: 1fr;
  }

  .signal-card {
    grid-template-columns: 1fr;
  }

  .fragment {
    width: min(22rem, calc(100vw - 1.4rem));
  }
}

@media (prefers-reduced-motion: reduce) {
  body {
    overflow: auto;
  }

  .ambient,
  .ring {
    animation: none;
  }

  .lamp-stage {
    position: relative;
    min-height: 58vh;
  }

  .stage-halo,
  .stage-rings,
  .scanlines {
    display: none;
  }

  .fragment {
    animation: none;
    position: relative;
    transform: none;
    margin: 0;
  }

  .stream {
    position: relative;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
    gap: 0.7rem;
    padding: 0 0.75rem 2rem;
  }
}
