/* ============================================================
   DEPARTMENT OF LINGUISTIC SECURITY — stylesheet
   ============================================================ */

:root {
  --paper: #F5F0E8;
  --ink: #1A1A1A;
  --dark: #0D0D0D;
  --stamp: #CC0000;
  --word-primary: #FFFFFF;
  --word-secondary: #CCCCCC;
  --word-muted: #888888;

  --serif-mono: 'Courier Prime', 'Courier New', monospace;
  --typewriter: 'Special Elite', 'Courier Prime', monospace;
}

* { box-sizing: border-box; }

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

body {
  font-family: var(--serif-mono);
  background-color: var(--paper);
  color: var(--ink);
  /* Locked until the document is declassified */
  overflow: hidden;
  transition: background-color 1.1s ease;
}

/* After transition: dark, scrollable */
body.revealed {
  background-color: var(--dark);
  color: var(--word-secondary);
  overflow-x: hidden;
  overflow-y: auto;
}

/* ============================================================
   STATE 1 — DOCUMENT
   ============================================================ */

#document {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 6vh 16px;
  overflow-y: auto;
  background-color: var(--paper);
  /* Subtle aged-paper grain */
  background-image:
    radial-gradient(circle at 20% 15%, rgba(0,0,0,0.035) 0%, transparent 45%),
    radial-gradient(circle at 80% 70%, rgba(0,0,0,0.045) 0%, transparent 50%),
    repeating-linear-gradient(0deg, rgba(0,0,0,0.012) 0px, rgba(0,0,0,0.012) 1px, transparent 1px, transparent 3px);
  transition: opacity 0.9s ease, transform 0.9s ease, filter 0.5s ease;
}

.doc-sheet {
  width: 100%;
  max-width: 720px;
  background: rgba(255, 255, 255, 0.35);
  padding: 48px clamp(20px, 6vw, 64px) 56px;
  box-shadow: 0 1px 0 rgba(0,0,0,0.08);
  border: 1px solid rgba(0,0,0,0.08);
}

.doc-header { text-align: center; }

.doc-agency {
  font-family: var(--typewriter);
  font-size: clamp(18px, 4.5vw, 30px);
  letter-spacing: 0.12em;
  margin: 0 0 6px;
}

.doc-class {
  font-family: var(--typewriter);
  font-size: 13px;
  letter-spacing: 0.28em;
  margin: 0 0 18px;
  color: #555;
}

.doc-rule {
  border: none;
  border-top: 2px solid var(--ink);
  margin: 18px 0;
}

.doc-re {
  font-family: var(--serif-mono);
  font-weight: 700;
  font-size: clamp(12px, 2.6vw, 15px);
  letter-spacing: 0.04em;
  margin: 0 0 36px;
}

.doc-body { margin-bottom: 40px; }

.doc-line {
  margin: 0 0 18px;
  line-height: 1;
}

/* Black redaction bars over "classified" text */
.redaction {
  display: inline-block;
  height: 1.1em;
  vertical-align: middle;
  margin-right: 8px;
  background: var(--ink);
  /* Slight imperfection */
  box-shadow: 0 0 0 1px var(--ink);
}

.doc-prompt {
  text-align: center;
  font-family: var(--typewriter);
  font-size: 13px;
  letter-spacing: 0.24em;
  color: #777;
  margin: 0;
  animation: prompt-pulse 2.4s ease-in-out infinite;
}

@keyframes prompt-pulse {
  0%, 100% { opacity: 0.35; }
  50%      { opacity: 0.85; }
}

/* --- Transition out: glitchy peel + dissolve --- */
body.revealed #document {
  opacity: 0;
  transform: scale(1.02);
  pointer-events: none;
  animation: doc-glitch 0.55s steps(2, end) 1;
}

@keyframes doc-glitch {
  0%   { filter: none; clip-path: inset(0 0 0 0); transform: translate(0,0); }
  20%  { filter: invert(0.06); clip-path: inset(8% 0 32% 0); transform: translate(-6px, 2px); }
  40%  { clip-path: inset(48% 0 12% 0); transform: translate(5px, -3px); }
  60%  { filter: invert(0.04); clip-path: inset(20% 0 56% 0); transform: translate(-3px, 4px); }
  80%  { clip-path: inset(70% 0 4% 0); transform: translate(4px, -1px); }
  100% { filter: none; clip-path: inset(0 0 0 0); transform: translate(0,0); }
}

/* Redaction bars peel away on reveal */
body.revealed .redaction {
  animation: redaction-peel 0.5s ease forwards;
}

@keyframes redaction-peel {
  0%   { transform: scaleX(1) skewX(0); opacity: 1; }
  40%  { transform: scaleX(1.04) skewX(-8deg); opacity: 1; }
  100% { transform: scaleX(0) skewX(-22deg); opacity: 0; }
}

/* ============================================================
   STATE 2 — SWIRL (fixed background layer)
   ============================================================ */

#swirl {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
  opacity: 0;
  background-color: var(--dark);
  transition: opacity 1.4s ease 0.3s;
}

body.revealed #swirl { opacity: 1; }

.swirl-word {
  position: absolute;
  font-family: var(--typewriter);
  white-space: nowrap;
  user-select: none;
  will-change: transform, opacity;
  transform: translate(-50%, -50%);
  animation-name: drift, fade-cycle;
  animation-timing-function: ease-in-out, ease-in-out;
  animation-iteration-count: infinite, infinite;
  animation-direction: alternate, alternate;
}

.swirl-word.w-primary   { color: var(--word-primary); }
.swirl-word.w-secondary { color: var(--word-secondary); }
.swirl-word.w-muted     { color: var(--word-muted); }

@keyframes drift {
  0%   { transform: translate(-50%, -50%) rotate(var(--rot, 0deg)) translate(0, 0); }
  50%  { transform: translate(-50%, -50%) rotate(calc(var(--rot, 0deg) + 4deg)) translate(var(--dx, 12px), var(--dy, -10px)); }
  100% { transform: translate(-50%, -50%) rotate(calc(var(--rot, 0deg) - 3deg)) translate(calc(var(--dx, 12px) * -1), var(--dy, -10px)); }
}

@keyframes fade-cycle {
  0%   { opacity: 0.15; }
  50%  { opacity: var(--peak, 0.85); }
  100% { opacity: 0.25; }
}

/* ============================================================
   STATE 2 — CONTENT (scrolls over the swirl)
   ============================================================ */

#content {
  position: relative;
  z-index: 10;
  display: none;
}

body.revealed #content { display: block; }

section {
  max-width: 860px;
  margin: 0 auto;
  padding: 64px clamp(20px, 6vw, 48px);
}

/* --- Hero --- */
#hero {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
}

.site-title {
  font-family: var(--typewriter);
  font-size: clamp(28px, 7vw, 58px);
  line-height: 1.1;
  letter-spacing: 0.06em;
  color: var(--word-primary);
  margin: 0 0 18px;
  text-shadow: 0 2px 18px rgba(0,0,0,0.8);
}

.site-subtitle {
  font-family: var(--serif-mono);
  font-size: 13px;
  letter-spacing: 0.26em;
  color: var(--word-muted);
  margin: 0 0 64px;
}

.scroll-cue {
  font-family: var(--serif-mono);
  font-size: 12px;
  letter-spacing: 0.22em;
  color: var(--word-muted);
  animation: prompt-pulse 2.4s ease-in-out infinite;
}

/* --- Shared section headings --- */
.section-title {
  font-family: var(--typewriter);
  font-size: clamp(16px, 3.4vw, 24px);
  letter-spacing: 0.05em;
  color: var(--word-primary);
  border-bottom: 1px solid rgba(255,255,255,0.18);
  padding-bottom: 14px;
  margin: 0 0 28px;
}

.section-instruction {
  font-family: var(--serif-mono);
  font-size: 14px;
  color: var(--word-secondary);
  margin: 0 0 24px;
  line-height: 1.6;
}

/* --- Glossary --- */
.query {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.query-label {
  font-family: var(--typewriter);
  font-size: 13px;
  letter-spacing: 0.14em;
  color: var(--word-muted);
}

#glossary-search {
  flex: 1;
  min-width: 180px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.22);
  color: var(--word-primary);
  font-family: var(--serif-mono);
  font-size: 14px;
  padding: 10px 12px;
  outline: none;
}

#glossary-search:focus {
  border-color: rgba(255,255,255,0.55);
  background: rgba(255,255,255,0.08);
}

#glossary-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--serif-mono);
  font-size: 14px;
}

#glossary-table th {
  text-align: left;
  font-family: var(--typewriter);
  font-weight: 400;
  font-size: 13px;
  letter-spacing: 0.1em;
  color: var(--word-muted);
  border-bottom: 1px solid rgba(255,255,255,0.28);
  padding: 10px 16px 10px 0;
}

#glossary-table td {
  padding: 12px 16px 12px 0;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  vertical-align: top;
}

#glossary-table td:first-child { color: var(--word-secondary); }
#glossary-table td:last-child  { color: var(--word-primary); }

.glossary-empty {
  font-family: var(--serif-mono);
  font-size: 14px;
  color: var(--word-muted);
  letter-spacing: 0.08em;
  padding-top: 18px;
}

/* --- Sandbox --- */
.sandbox-field {
  position: relative;
}

#sandbox-input {
  width: 100%;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.22);
  color: var(--word-primary);
  font-family: var(--serif-mono);
  font-size: 15px;
  line-height: 1.6;
  padding: 16px;
  resize: vertical;
  outline: none;
}

#sandbox-input:focus {
  border-color: rgba(255,255,255,0.5);
  background: rgba(255,255,255,0.07);
}

/* Rejection stamp */
.stamp {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 5;
  pointer-events: none;
  font-family: var(--typewriter);
  font-size: clamp(15px, 3.4vw, 26px);
  letter-spacing: 0.04em;
  text-align: center;
  color: var(--stamp);
  border: 4px solid var(--stamp);
  padding: 14px 22px;
  max-width: 90%;
  background: rgba(13, 13, 13, 0.35);
  /* Crooked + hidden by default */
  opacity: 0;
  transform: translate(-50%, -50%) rotate(-8deg) scale(2.4);
}

.stamp.show {
  animation: stamp-slam 0.28s cubic-bezier(0.18, 0.89, 0.32, 1.28) forwards;
}

@keyframes stamp-slam {
  0%   { opacity: 0;    transform: translate(-50%, -50%) rotate(-8deg) scale(2.4); }
  60%  { opacity: 1;    transform: translate(-50%, -50%) rotate(-8deg) scale(0.92); }
  80%  {                transform: translate(-50%, -50%) rotate(-8deg) scale(1.04); }
  100% { opacity: 1;    transform: translate(-50%, -50%) rotate(-8deg) scale(1); }
}

/* Fade-out applied via class after the hold */
.stamp.fade {
  opacity: 0;
  transition: opacity 0.6s ease;
}

@media (prefers-reduced-motion: reduce) {
  .swirl-word,
  .doc-prompt,
  .scroll-cue { animation: none !important; }
  body, #swirl, #document { transition-duration: 0.2s; }
}
