/* ═══════════════════════════════════════════════════════════
   QALNIX — The Experimental Grid
   HTML + CSS only | Brutalist System Interface
   ═══════════════════════════════════════════════════════════ */

:root {
  --black: #0b0b0b;
  --graphite: #1a1a1a;
  --steel: #a3a3a3;
  --soft-white: #e5e5e5;
  --electric: rgba(34, 197, 94, 0.1);
  --index-width: 3.5rem;
  --content-pad: clamp(1.25rem, 4vw, 3rem);
  --font-display: "IBM Plex Mono", monospace;
  --font-heading: "Space Mono", monospace;
  --font-body: "Inter", system-ui, sans-serif;
}

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

html {
  scroll-behavior: auto;
  font-size: 16px;
}

body {
  font-family: var(--font-body);
  background: var(--black);
  color: var(--steel);
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ─── System Index (left rail) ─── */
.system-index {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: var(--index-width);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  background: var(--graphite);
  border-right: 1px solid #2a2a2a;
  z-index: 100;
  pointer-events: none;
}

.index-letter {
  font-family: var(--font-display);
  font-size: 0.65rem;
  font-weight: 500;
  letter-spacing: 0.2em;
  color: var(--soft-white);
  writing-mode: vertical-rl;
  text-orientation: mixed;
  transform: rotate(180deg);
  opacity: 0.85;
  line-height: 1;
  padding: 0.35rem 0;
}

.index-letter:nth-child(odd) {
  color: var(--steel);
}

/* ─── Top-right status ─── */
.system-status {
  position: fixed;
  top: 0.75rem;
  right: var(--content-pad);
  font-family: var(--font-display);
  font-size: 0.6rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--steel);
  z-index: 100;
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  max-width: calc(100% - var(--index-width) - 2rem);
  justify-content: flex-end;
}

.status-sep {
  opacity: 0.4;
}

.status-flicker {
  animation: flicker 4s infinite;
}

@keyframes flicker {
  0%, 92%, 100% { opacity: 1; }
  93% { opacity: 0.4; }
  94% { opacity: 1; }
  96% { opacity: 0.6; }
  97% { opacity: 1; }
}

/* ─── Main content offset ─── */
.interface {
  margin-left: var(--index-width);
  padding: 0 var(--content-pad);
}

.section {
  padding: clamp(3rem, 8vh, 6rem) 0;
  border-bottom: 1px solid #1f1f1f;
  position: relative;
}

.section-header {
  margin-bottom: 2rem;
  display: grid;
  gap: 0.35rem;
}

.section-id {
  font-family: var(--font-display);
  font-size: 0.65rem;
  letter-spacing: 0.2em;
  color: var(--steel);
  opacity: 0.7;
}

.section-title {
  font-family: var(--font-heading);
  font-size: clamp(0.85rem, 2vw, 1rem);
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--soft-white);
}

/* ═══ BOOT ═══ */
.section-boot {
  min-height: 85vh;
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom-color: #252525;
}

.boot-inner {
  text-align: center;
  width: 100%;
  max-width: 36rem;
  animation: bootFade 1.2s ease-out forwards;
  opacity: 0;
}

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

.boot-label {
  font-family: var(--font-display);
  font-size: 0.65rem;
  letter-spacing: 0.25em;
  color: var(--steel);
  margin-bottom: 1.5rem;
}

.boot-title {
  font-family: var(--font-heading);
  font-size: clamp(1.1rem, 3.5vw, 1.75rem);
  font-weight: 400;
  color: var(--soft-white);
  letter-spacing: 0.02em;
  margin-bottom: 2.5rem;
}

.boot-loader {
  display: flex;
  justify-content: center;
  gap: 4px;
  margin-bottom: 2rem;
  padding: 0 1rem;
}

.loader-segment {
  flex: 1;
  max-width: 2.5rem;
  height: 3px;
  background: #2a2a2a;
  position: relative;
  overflow: hidden;
}

.loader-segment::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--soft-white);
  transform: scaleX(0);
  transform-origin: left;
  animation: lineReveal 2.4s steps(8) forwards;
}

.loader-segment:nth-child(1)::after { animation-delay: 0.1s; }
.loader-segment:nth-child(2)::after { animation-delay: 0.35s; }
.loader-segment:nth-child(3)::after { animation-delay: 0.6s; }
.loader-segment:nth-child(4)::after { animation-delay: 0.85s; }
.loader-segment:nth-child(5)::after { animation-delay: 1.1s; }
.loader-segment:nth-child(6)::after { animation-delay: 1.35s; }
.loader-segment:nth-child(7)::after { animation-delay: 1.6s; }
.loader-segment:nth-child(8)::after { animation-delay: 1.85s; }

@keyframes lineReveal {
  to { transform: scaleX(1); }
}

.boot-meta {
  font-family: var(--font-display);
  font-size: 0.6rem;
  letter-spacing: 0.15em;
  color: var(--steel);
  opacity: 0.6;
}

/* ═══ MODULES ═══ */
.terminal-list {
  list-style: none;
  font-family: var(--font-display);
  font-size: clamp(0.75rem, 2vw, 0.9rem);
  border: 1px solid #252525;
  background: var(--graphite);
}

.terminal-list li {
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid #252525;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem;
  color: var(--soft-white);
  animation: lineRevealRow 0.6s ease-out backwards;
}

.terminal-list li:nth-child(1) { animation-delay: 0.05s; }
.terminal-list li:nth-child(2) { animation-delay: 0.12s; }
.terminal-list li:nth-child(3) { animation-delay: 0.19s; }
.terminal-list li:nth-child(4) { animation-delay: 0.26s; }
.terminal-list li:nth-child(5) { animation-delay: 0.33s; }

@keyframes lineRevealRow {
  from {
    opacity: 0;
    border-left-color: transparent;
  }
  to {
    opacity: 1;
  }
}

.terminal-list li:last-child {
  border-bottom: none;
}

.term-prompt {
  color: var(--steel);
  flex-shrink: 0;
}

.term-state {
  margin-left: auto;
  font-size: 0.65rem;
  letter-spacing: 0.1em;
  color: var(--steel);
}

.terminal-list li:first-child .term-state,
.terminal-list li:nth-child(2) .term-state,
.terminal-list li:nth-child(3) .term-state,
.terminal-list li:nth-child(5) .term-state {
  color: var(--soft-white);
  text-shadow: 0 0 20px var(--electric);
}

/* ═══ DATA GRID ═══ */
.data-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1px;
  background: #2a2a2a;
  border: 1px solid #2a2a2a;
}

.data-cell {
  background: var(--black);
  padding: clamp(1.25rem, 4vw, 2rem);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-height: 6rem;
}

.data-key {
  font-family: var(--font-display);
  font-size: 0.65rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--steel);
}

.data-val {
  font-family: var(--font-heading);
  font-size: clamp(1.25rem, 4vw, 1.75rem);
  color: var(--soft-white);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

/* ═══ EXPERIMENTS ═══ */
.experiment-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.experiment-entry {
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  align-items: center;
  gap: 0.75rem 1rem;
  padding: 1rem 0;
  border-top: 1px solid #1f1f1f;
  font-family: var(--font-display);
  font-size: clamp(0.7rem, 2vw, 0.85rem);
}

.experiment-entry:last-child {
  border-bottom: 1px solid #1f1f1f;
}

.exp-id {
  color: var(--soft-white);
  letter-spacing: 0.1em;
}

.exp-arrow {
  color: var(--steel);
  opacity: 0.5;
}

.exp-name {
  color: var(--soft-white);
}

.exp-status {
  font-size: 0.6rem;
  letter-spacing: 0.15em;
  color: var(--steel);
  text-align: right;
}

/* ═══ SIGNAL ═══ */
.section-signal {
  padding-bottom: clamp(4rem, 10vh, 7rem);
}

.signal-canvas {
  position: relative;
  height: clamp(12rem, 35vw, 20rem);
  margin-bottom: 3rem;
  border: 1px solid #252525;
  background: var(--graphite);
  overflow: hidden;
}

.signal-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(#2a2a2a 1px, transparent 1px),
    linear-gradient(90deg, #2a2a2a 1px, transparent 1px);
  background-size: 24px 24px;
  opacity: 0.6;
}

.signal-blocks {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 1px;
  padding: 1px;
}

.signal-blocks span {
  background: var(--black);
  opacity: 0.3;
}

.signal-blocks span:nth-child(3),
.signal-blocks span:nth-child(5),
.signal-blocks span:nth-child(7),
.signal-blocks span:nth-child(10) {
  background: #222;
  opacity: 0.8;
}

.signal-blocks span:nth-child(6) {
  background: var(--soft-white);
  opacity: 0.04;
}

.signal-noise {
  position: absolute;
  inset: 0;
  background-image: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(229, 229, 229, 0.02) 2px,
    rgba(229, 229, 229, 0.02) 3px
  );
  animation: noiseShift 8s linear infinite;
  pointer-events: none;
}

@keyframes noiseShift {
  0% { transform: translateY(0); }
  100% { transform: translateY(24px); }
}

.signal-statement {
  font-family: var(--font-heading);
  font-size: clamp(1rem, 3vw, 1.5rem);
  font-weight: 400;
  color: var(--soft-white);
  text-align: center;
  letter-spacing: 0.02em;
  max-width: 28ch;
  margin: 0 auto;
  line-height: 1.4;
}

/* ═══ ARCHIVE ═══ */
.archive-list {
  list-style: none;
  font-family: var(--font-display);
  font-size: clamp(0.75rem, 2vw, 0.88rem);
}

.archive-list li {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.75rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid #1a1a1a;
  color: var(--soft-white);
}

.archive-list time {
  color: var(--steel);
  font-variant-numeric: tabular-nums;
  min-width: 5ch;
}

.archive-arrow {
  color: var(--steel);
  opacity: 0.4;
}

/* ═══ CONTROL PANEL ═══ */
.control-grid {
  border: 1px solid #252525;
  background: var(--graphite);
}

.control-row {
  display: grid;
  grid-template-columns: minmax(8rem, 1fr) 2fr;
  gap: 1rem;
  align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid #252525;
}

.control-row:last-child {
  border-bottom: none;
}

.control-label {
  font-family: var(--font-display);
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--steel);
}

.control-ui {
  display: flex;
  align-items: center;
  gap: 1rem;
  justify-content: flex-end;
}

.control-track {
  flex: 1;
  max-width: 12rem;
  height: 4px;
  background: #0b0b0b;
  border: 1px solid #333;
  position: relative;
}

.control-fill {
  display: block;
  height: 100%;
  width: var(--fill);
  background: var(--soft-white);
  animation: lineReveal 0.8s ease-out backwards;
}

.control-readout {
  font-family: var(--font-heading);
  font-size: 0.75rem;
  color: var(--soft-white);
  min-width: 3.5ch;
  text-align: right;
}

.control-toggle {
  gap: 0;
  border: 1px solid #333;
}

.toggle-opt {
  font-family: var(--font-display);
  font-size: 0.6rem;
  letter-spacing: 0.1em;
  padding: 0.4rem 0.75rem;
  color: var(--steel);
  border-right: 1px solid #333;
}

.toggle-opt:last-child {
  border-right: none;
}

.toggle-active {
  background: var(--black);
  color: var(--soft-white);
}

.control-blocks {
  display: flex;
  gap: 3px;
}

.control-blocks i {
  display: block;
  width: 10px;
  height: 14px;
  background: #333;
  font-style: normal;
}

.control-blocks .block-on {
  background: var(--soft-white);
}

.debug-indicator {
  width: 6px;
  height: 6px;
  background: var(--electric);
  box-shadow: 0 0 8px rgba(34, 197, 94, 0.15);
  border: 1px solid rgba(34, 197, 94, 0.25);
}

/* ═══ FINAL STATE ═══ */
.section-final {
  min-height: 70vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: var(--black);
  border-bottom: none;
  margin: 0 calc(-1 * var(--content-pad));
  padding-left: var(--content-pad);
  padding-right: var(--content-pad);
  position: relative;
}

.section-final::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center, #111 0%, var(--black) 70%);
  pointer-events: none;
}

.final-title,
.final-sub {
  position: relative;
  z-index: 1;
}

.final-title {
  font-family: var(--font-heading);
  font-size: clamp(1.5rem, 5vw, 2.5rem);
  font-weight: 400;
  letter-spacing: 0.2em;
  color: var(--soft-white);
  margin-bottom: 1.25rem;
}

.final-sub {
  font-family: var(--font-body);
  font-size: 0.8rem;
  color: var(--steel);
  max-width: 32ch;
  letter-spacing: 0.02em;
}

/* ═══ CONTACT ═══ */
.contact-terminal {
  font-family: var(--font-display);
  font-size: clamp(0.75rem, 2vw, 0.88rem);
  border-left: 2px solid #333;
  padding-left: 1.25rem;
}

.contact-terminal p {
  margin-bottom: 0.75rem;
  color: var(--soft-white);
}

.contact-terminal p:last-child {
  margin-bottom: 0;
}

.contact-key {
  color: var(--steel);
  margin-right: 0.5rem;
}

.contact-terminal a {
  color: var(--soft-white);
  text-decoration: none;
  border-bottom: 1px solid #444;
}

.contact-terminal a:hover {
  border-bottom-color: var(--soft-white);
}

/* ═══ FOOTER ═══ */
.system-footer {
  margin-left: var(--index-width);
  padding: 2rem var(--content-pad) 3rem;
  border-top: 1px solid #1a1a1a;
}

.system-footer p {
  font-family: var(--font-display);
  font-size: 0.55rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--steel);
  opacity: 0.5;
}

/* ═══ RESPONSIVE ═══ */
@media (max-width: 640px) {
  :root {
    --index-width: 2.25rem;
  }

  .index-letter {
    font-size: 0.5rem;
    padding: 0.2rem 0;
  }

  .system-status {
    font-size: 0.5rem;
    top: 0.5rem;
    right: 0.75rem;
    line-height: 1.4;
  }

  .experiment-entry {
    grid-template-columns: auto 1fr;
    grid-template-rows: auto auto;
  }

  .exp-arrow {
    display: none;
  }

  .exp-name {
    grid-column: 1 / -1;
    padding-left: 0;
  }

  .exp-status {
    grid-column: 2;
    grid-row: 1;
  }

  .control-row {
    grid-template-columns: 1fr;
    gap: 0.5rem;
  }

  .control-ui {
    justify-content: flex-start;
  }

  .data-grid {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 900px) {
  .data-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

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

  .boot-inner {
    opacity: 1;
  }
}
