/* ═══════════════════════════════════════════════════════════
   CHEM-LAB ANALYSIS SYSTEM — Splash CTF Theme (refined)
   Visual-only restyle. All selectors of the original kept.
   ═══════════════════════════════════════════════════════════ */

:root {
  --bg: #0b0910;
  --bg-2: #120d14;
  --green: #ffc44a;      /* sodium yellow (primary text/accent) */
  --green-dim: #e0a030;
  --blue: #ff547a;       /* phenolphthalein carmine */
  --blue-dim: #d43b5c;
  --cyan: #ffe496;
  --yellow: #fff1a8;
  --text: #f3e6d0;
  --muted: #8f8590;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 84, 122, 0.32);
  --shadow: rgba(255, 196, 64, 0.14);
  --panel-bg: rgba(20, 15, 22, 0.78);
  --terminal-glow: rgba(255, 84, 122, 0.06);
  --radius: 14px;
  --radius-sm: 8px;
  --mono: ui-monospace, "Cascadia Code", "JetBrains Mono", "SF Mono", Menlo, Consolas,
          "Sarasa Mono SC", "Noto Sans Mono CJK SC", "Liberation Mono", "Courier New", monospace;
}

* { box-sizing: border-box; }

::selection { background: rgba(255, 84, 122, 0.35); color: #fff; }

::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: rgba(255, 196, 64, 0.22); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255, 196, 64, 0.42); }

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

body {
  background:
    radial-gradient(60rem 40rem at 10% -10%, rgba(255, 84, 122, 0.18), transparent 60%),
    radial-gradient(50rem 36rem at 110% 110%, rgba(255, 196, 64, 0.10), transparent 60%),
    linear-gradient(160deg, #08070b 0%, var(--bg) 50%, var(--bg-2) 100%);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--mono);
  font-size: 15px;
  letter-spacing: 0.01em;
  padding: clamp(2.5rem, 7vh, 5rem) 1.2rem 6rem;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  animation: pageFlickerIn 0.5s ease-out;
}

/* subtle grid + scanlines */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  background:
    repeating-linear-gradient(to bottom, rgba(255,255,255,0.018) 0, rgba(255,255,255,0.018) 1px, transparent 1px, transparent 4px);
  mix-blend-mode: screen;
  animation: scanlineShift 8s linear infinite;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -1;
  background-image:
    linear-gradient(rgba(255,255,255,0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.025) 1px, transparent 1px);
  background-size: 48px 48px;
  -webkit-mask-image: radial-gradient(ellipse at center, #000 30%, transparent 80%);
          mask-image: radial-gradient(ellipse at center, #000 30%, transparent 80%);
}

/* ── Floating Particles ────────────────────────────────── */
.particles { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 0; }
.particles::before,
.particles::after {
  content: "";
  position: absolute;
  width: 4px; height: 4px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 10px var(--green);
  opacity: 0.35;
  animation: particleDrift1 12s ease-in-out infinite;
}
.particles::after {
  width: 3px; height: 3px;
  background: var(--blue);
  box-shadow: 0 0 10px var(--blue);
  opacity: 0.25;
  animation: particleDrift2 16s ease-in-out infinite;
}

/* ── Boot Sequence Overlay ─────────────────────────────── */
.boot-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: radial-gradient(ellipse at center, #120c10 0%, #050406 70%);
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 2rem clamp(1rem, 6vw, 4rem);
  font-size: clamp(0.72rem, 1.6vw, 0.9rem);
  color: var(--muted);
  transition: opacity 0.8s ease;
  overflow-x: auto;
}
.boot-overlay.fade-out { opacity: 0; pointer-events: none; }
.boot-line {
  opacity: 0;
  transform: translateX(-8px);
  animation: bootLineIn 0.3s ease forwards;
  margin: 0.2rem 0;
  white-space: nowrap;
}
.boot-line .ok {
  color: var(--green);
  font-weight: 700;
  text-shadow: 0 0 8px rgba(255, 196, 64, 0.5);
}
.boot-line .fail { color: #ff4d6a; }

/* ── Terminal Panel ────────────────────────────────────── */
.terminal {
  width: min(880px, 100%);
  margin: 0 auto;
  border: 1px solid var(--line);
  border-top-color: rgba(255, 255, 255, 0.14);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, var(--terminal-glow), transparent 30%),
    var(--panel-bg);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
          backdrop-filter: blur(14px) saturate(1.2);
  box-shadow:
    0 30px 80px -20px rgba(0, 0, 0, 0.7),
    0 0 0 1px rgba(255, 84, 122, 0.05),
    0 0 60px -10px var(--shadow);
  padding: clamp(1.4rem, 4vw, 2.6rem);
  padding-top: clamp(1rem, 3vw, 1.4rem);
  position: relative;
  animation: terminalBoot 0.7s cubic-bezier(0.22, 1, 0.36, 1) forwards;
  z-index: 1;
}

/* top accent line */
.terminal::after {
  content: "";
  position: absolute;
  left: 1.5rem; right: 1.5rem; top: -1px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--blue), var(--green), transparent);
  opacity: 0.8;
  pointer-events: none;
}

.terminal.success-glow {
  border-color: rgba(255, 196, 64, 0.28);
  animation: terminalBoot 0.7s cubic-bezier(0.22, 1, 0.36, 1) forwards,
             successPulse 3s ease-in-out infinite;
}

/* ── Status Bar ────────────────────────────────────────── */
.status-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0 7rem 1rem 0;
  margin: 0 0 1.6rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}
.status-item {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.22rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.025);
  font-variant-numeric: tabular-nums;
}
.blink-dot {
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 8px var(--green);
  animation: blinkDot 1.8s ease-in-out infinite;
}
.blink-dot.blue { background: var(--blue); box-shadow: 0 0 8px var(--blue); }

/* ── Stage Badge ───────────────────────────────────────── */
.stage-badge {
  position: absolute;
  top: clamp(1rem, 3vw, 1.4rem);
  right: clamp(1.4rem, 4vw, 2.6rem);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  padding: 0.28rem 0.75rem;
  border: 1px solid rgba(255, 84, 122, 0.45);
  border-radius: 999px;
  color: var(--blue);
  background: rgba(255, 84, 122, 0.1);
  text-transform: uppercase;
  z-index: 2;
}
.stage-badge.complete {
  border-color: rgba(255, 196, 64, 0.55);
  color: var(--green);
  background: rgba(255, 196, 64, 0.1);
  animation: badgePulse 2s ease-in-out infinite;
}

/* ── Headings ──────────────────────────────────────────── */
h1 {
  font-size: clamp(1.6rem, 4.4vw, 2.5rem);
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: 0.02em;
  margin: 0 0 0.9rem;
  min-height: 1.2em;
  color: var(--blue);
  background: linear-gradient(92deg, #ff6d8e 0%, #ff547a 40%, #ffc44a 100%);
  -webkit-background-clip: text;
          background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 18px rgba(255, 84, 122, 0.3));
  animation: textPulse 4s ease-in-out infinite;
}
h2 {
  color: var(--green);
  font-size: clamp(1.05rem, 2.4vw, 1.3rem);
  font-weight: 700;
  letter-spacing: 0.08em;
  margin: 1.4rem 0 0.7rem;
}

.cursor {
  display: inline-block;
  color: var(--green);
  -webkit-text-fill-color: var(--green);
  animation: cursorBlink 0.8s step-end infinite;
}

/* ── Section Headers ───────────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  color: var(--blue);
  text-transform: uppercase;
  margin: 2rem 0 0.75rem;
  padding: 0;
}
.section-header::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, rgba(255, 84, 122, 0.35), transparent);
}

/* ── Chemical Formula ──────────────────────────────────── */
.formula {
  display: inline-block;
  font-size: clamp(1rem, 2.4vw, 1.25rem);
  color: var(--cyan);
  letter-spacing: 0.05em;
  padding: 0.5rem 1rem;
  margin: 0.2rem 0 0.6rem;
  border: 1px solid rgba(255, 228, 150, 0.18);
  border-radius: var(--radius-sm);
  background: rgba(255, 228, 150, 0.04);
  text-shadow: 0 0 14px rgba(255, 228, 150, 0.35);
}
.formula sub { font-size: 0.72em; }

/* ── Lead & Paragraph ──────────────────────────────────── */
.lead, p {
  margin: 0.4rem 0 0.8rem;
  font-size: clamp(0.92rem, 2vw, 1.02rem);
  color: var(--text);
}
.lead { color: #d9c9b6; font-style: italic; }

/* ── Poem (pre block) ──────────────────────────────────── */
.poem {
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--mono);
  line-height: 1.85;
  font-size: clamp(0.86rem, 1.9vw, 0.98rem);
  color: var(--green);
  margin: 0.4rem 0 0;
  padding: 1rem 1.2rem 1rem 1.3rem;
  border: 1px solid var(--line);
  border-left: 3px solid rgba(255, 196, 64, 0.35);
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.22);
  animation: borderGlow 4s ease-in-out infinite;
}

.comment-block { margin: 0.4rem 0; }
.comment-block .poem {
  color: #a79ea6;
  border-left-color: rgba(143, 133, 144, 0.45);
  background: rgba(255, 255, 255, 0.02);
  font-size: clamp(0.8rem, 1.7vw, 0.9rem);
  animation: none;
}

/* ── Spectrum Panel ────────────────────────────────────── */
.spectrum-panel {
  margin: 1.2rem 0 0.4rem;
  padding: 0.9rem 1rem 0.7rem;
  border: 1px solid rgba(255, 84, 122, 0.2);
  border-radius: var(--radius-sm);
  background:
    linear-gradient(180deg, rgba(255, 84, 122, 0.04), rgba(0, 0, 0, 0.35));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}
.spectrum-panel .panel-label {
  font-size: 0.66rem;
  letter-spacing: 0.14em;
  color: var(--muted);
  text-transform: uppercase;
  margin-bottom: 0.5rem;
}
#spectrum-canvas { width: 100%; height: 190px; display: block; }
#precipitate-canvas,
#bead-canvas { width: 100%; height: 150px; display: block; border-radius: 6px; }

/* ── Download Button ───────────────────────────────────── */
.download {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 2rem;
  color: #1a1208;
  text-decoration: none;
  font-weight: 700;
  border: 0;
  border-radius: 999px;
  padding: 0.85rem 1.5rem;
  background: linear-gradient(92deg, #ffd166, var(--green) 50%, #ff9e5a);
  box-shadow: 0 10px 30px -8px rgba(255, 196, 64, 0.55);
  font-size: 0.82rem;
  letter-spacing: 0.1em;
  position: relative;
  overflow: hidden;
  transition: transform 0.2s ease, box-shadow 0.3s ease;
}
.download::before {
  content: "";
  position: absolute;
  top: 0; left: -100%;
  width: 100%; height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.45), transparent);
  transition: left 0.6s ease;
}
.download:hover,
.download:focus {
  color: #1a1208;
  transform: translateY(-2px);
  box-shadow: 0 16px 40px -8px rgba(255, 196, 64, 0.75);
  outline: none;
}
.download:focus-visible { outline: 2px solid var(--cyan); outline-offset: 3px; }
.download:hover::before { left: 100%; }

/* ── Flag Box ──────────────────────────────────────────── */
.flag-box {
  margin: 1rem 0;
  padding: 1.2rem 1.4rem;
  border: 1px solid rgba(255, 196, 64, 0.4);
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, rgba(255, 196, 64, 0.08), rgba(255, 84, 122, 0.05));
  animation: flagGlow 2.5s ease-in-out infinite;
}
.flag-box .poem {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--green);
  font-size: clamp(1rem, 2.4vw, 1.25rem);
  font-weight: 700;
  text-align: center;
  text-shadow: 0 0 12px rgba(255, 196, 64, 0.4);
  animation: none;
}

/* ── Morse Code (deliberately faint) ───────────────────── */
.morse {
  width: min(880px, 100%);
  margin: 2.5rem auto 0;
  color: rgba(26, 26, 26, 0.6);
  font-size: 10px;
  text-align: center;
  user-select: text;
  transition: color 0.8s ease;
  position: relative;
  z-index: 1;
}
.morse:hover { color: rgba(110, 124, 133, 0.4); }

/* ── Glitch Text (404) ─────────────────────────────────── */
.glitch-text {
  font-size: clamp(4.5rem, 14vw, 8.5rem);
  font-weight: 900;
  line-height: 1;
  color: var(--blue);
  position: relative;
  display: inline-block;
  margin-top: 0.4rem;
  text-shadow: 0 0 40px rgba(255, 84, 122, 0.45);
  animation: textPulse 3s ease-in-out infinite;
}
.glitch-text::before,
.glitch-text::after {
  content: attr(data-text);
  position: absolute;
  top: 0; left: 0;
  opacity: 0.8;
}
.glitch-text::before { color: #ff0040; animation: glitch1 3s infinite; clip-path: inset(0 0 65% 0); }
.glitch-text::after  { color: #ffc44a; animation: glitch2 3s infinite; clip-path: inset(65% 0 0 0); }

.error-detail {
  color: var(--muted);
  font-size: 0.8rem;
  margin: 0.25rem 0;
  letter-spacing: 0.06em;
}

.return-link {
  display: inline-block;
  margin-top: 1.6rem;
  color: var(--green);
  text-decoration: none;
  border: 1px solid rgba(255, 196, 64, 0.35);
  border-radius: 999px;
  padding: 0.65rem 1.3rem;
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  transition: all 0.25s ease;
}
.return-link:hover,
.return-link:focus {
  background: rgba(255, 196, 64, 0.12);
  box-shadow: 0 0 20px rgba(255, 196, 64, 0.2);
  outline: none;
}

.ascii-art {
  color: rgba(255, 84, 122, 0.22);
  font-size: clamp(0.45rem, 1.4vw, 0.65rem);
  line-height: 1.1;
  margin: 0.6rem 0 1rem;
  overflow-x: auto;
  user-select: none;
}

#celebration-canvas { position: fixed; inset: 0; pointer-events: none; z-index: 0; }

sub { font-size: 0.75em; }

/* ── Footer ────────────────────────────────────────────── */
footer {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  padding: 0.8rem 1rem;
  border-top: 1px solid var(--line);
  background: rgba(8, 7, 11, 0.82);
  -webkit-backdrop-filter: blur(10px);
          backdrop-filter: blur(10px);
  color: var(--muted);
  text-align: center;
  font-size: 0.68rem;
  letter-spacing: 0.18em;
  z-index: 10;
  animation: footerSlide 0.8s ease forwards;
}

/* ═══════════════════════════════════════════════════════════
   KEYFRAMES
   ═══════════════════════════════════════════════════════════ */
@keyframes pageFlickerIn { 0% { opacity: 0; } 20% { opacity: 0.7; } 30% { opacity: 0.4; } 50%, 100% { opacity: 1; } }
@keyframes scanlineShift { 0% { transform: translateY(0); } 100% { transform: translateY(4px); } }
@keyframes terminalBoot {
  0%   { opacity: 0; transform: translateY(14px) scale(0.985); filter: brightness(1.6); }
  100% { opacity: 1; transform: none; filter: none; }
}
@keyframes textPulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.88; } }
@keyframes cursorBlink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }
@keyframes blinkDot { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }
@keyframes borderGlow {
  0%, 100% { border-left-color: rgba(255, 196, 64, 0.3); }
  50%      { border-left-color: rgba(255, 196, 64, 0.7); }
}
@keyframes successPulse {
  0%, 100% { box-shadow: 0 30px 80px -20px rgba(0,0,0,0.7), 0 0 60px -6px rgba(255, 196, 64, 0.22); }
  50%      { box-shadow: 0 30px 80px -20px rgba(0,0,0,0.7), 0 0 90px -4px rgba(255, 196, 64, 0.38); }
}
@keyframes flagGlow {
  0%, 100% { border-color: rgba(255, 196, 64, 0.35); box-shadow: 0 0 20px rgba(255, 196, 64, 0.1); }
  50%      { border-color: rgba(255, 196, 64, 0.7);  box-shadow: 0 0 36px rgba(255, 196, 64, 0.25); }
}
@keyframes badgePulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.65; } }
@keyframes footerSlide { from { transform: translateY(100%); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes bootLineIn { from { opacity: 0; transform: translateX(-8px); } to { opacity: 1; transform: none; } }
@keyframes particleDrift1 { 0% { top: 100%; left: 15%; opacity: 0; } 10%, 90% { opacity: 0.35; } 100% { top: -5%; left: 25%; opacity: 0; } }
@keyframes particleDrift2 { 0% { top: 100%; left: 70%; opacity: 0; } 10%, 90% { opacity: 0.25; } 100% { top: -5%; left: 60%; opacity: 0; } }
@keyframes glitch1 { 0%, 90%, 100% { transform: none; } 92% { transform: translate(-3px, 1px); } 94% { transform: translate(3px, -1px); } 96% { transform: translate(-2px, 2px); } }
@keyframes glitch2 { 0%, 88%, 100% { transform: none; } 90% { transform: translate(3px, -1px); } 93% { transform: translate(-3px, 2px); } 96% { transform: translate(2px, -2px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
  .boot-line { opacity: 1; transform: none; }
}

/* ═══════════════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 620px) {
  body { padding: 1.4rem 0.7rem 4.8rem; font-size: 14px; }
  .terminal { padding: 1.1rem; border-radius: 12px; }
  .status-bar { padding-right: 0; font-size: 0.6rem; gap: 0.35rem; }
  .stage-badge { position: static; display: inline-block; margin-bottom: 0.8rem; }
  .glitch-text { font-size: clamp(3.2rem, 18vw, 5rem); }
  #spectrum-canvas { height: 140px; }
  .poem { padding: 0.8rem 0.9rem; }
}
