/* =========================================================
   AES-128 CIPHER LAB — DESIGN TOKENS
   Palette:
     --bg          #0D1117  ink graphite background
     --surface     #141B22  panel surface
     --surface-alt #1B242D  raised surface / table cell
     --border      #29323C  hairline borders
     --text-hi     #E7EBEE  primary text
     --text-lo     #8B96A3  secondary text
     --gold        #E3A21A  round-key / signal accent
     --teal        #2FC9B3  encrypt-flow accent
     --coral       #E2604F  decrypt / diff accent
   Type:
     Display : 'Space Grotesk'  (headings, brand)
     Body    : 'Inter'          (UI copy)
     Data    : 'JetBrains Mono' (hex bytes, state matrices)
   ========================================================= */

:root {
  --bg: #0D1117;
  --surface: #141B22;
  --surface-alt: #1B242D;
  --surface-raised: #202A34;
  --border: #29323C;
  --border-soft: #1F2830;
  --text-hi: #E7EBEE;
  --text-lo: #8B96A3;
  --text-faint: #576270;
  --gold: #E3A21A;
  --gold-dim: rgba(227, 162, 26, 0.14);
  --teal: #2FC9B3;
  --teal-dim: rgba(47, 201, 179, 0.14);
  --coral: #E2604F;
  --coral-dim: rgba(226, 96, 79, 0.14);
  --radius-s: 6px;
  --radius-m: 10px;
  --radius-l: 16px;
  --shadow-panel: 0 20px 60px -30px rgba(0,0,0,0.6);
}

* { box-sizing: border-box; }

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

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text-hi);
  font-family: 'Inter', system-ui, sans-serif;
  line-height: 1.5;
  position: relative;
  min-height: 100vh;
}

.noise-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

a { color: inherit; }
code, .mono { font-family: 'JetBrains Mono', monospace; }

::selection { background: var(--gold-dim); color: var(--gold); }

button {
  font-family: inherit;
  cursor: pointer;
}

input:focus-visible,
button:focus-visible,
label:has(input:focus-visible) .toggle-track {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

/* =========================== HEADER =========================== */

.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(13, 17, 23, 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-soft);
}

.header-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 16px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }

.brand-mark {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  font-size: 20px;
  letter-spacing: 0.02em;
}
.brand-mark-sub { color: var(--gold); font-weight: 600; }

.brand-tag {
  font-size: 12.5px;
  color: var(--text-lo);
  letter-spacing: 0.01em;
}

.brand-meta { display: flex; gap: 8px; }

.meta-pill {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--text-lo);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  letter-spacing: 0.03em;
}

/* =========================== HERO =========================== */

.hero {
  position: relative;
  z-index: 1;
  padding: 80px 28px 64px;
  border-bottom: 1px solid var(--border-soft);
  overflow: hidden;
  min-height: 420px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* --- Animated background glow orbs --- */
.hero-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.glow-orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(100px);
  opacity: 0.18;
}

.glow-orb--teal {
  width: 420px;
  height: 420px;
  background: radial-gradient(circle, #2FC9B3 0%, transparent 70%);
  top: -80px;
  left: -60px;
  animation: orbDrift1 14s ease-in-out infinite alternate;
}

.glow-orb--gold {
  width: 350px;
  height: 350px;
  background: radial-gradient(circle, #E3A21A 0%, transparent 70%);
  top: 50%;
  right: -40px;
  transform: translateY(-50%);
  animation: orbDrift2 18s ease-in-out infinite alternate;
}

.glow-orb--coral {
  width: 300px;
  height: 300px;
  background: radial-gradient(circle, #E2604F 0%, transparent 70%);
  bottom: -60px;
  left: 40%;
  animation: orbDrift3 16s ease-in-out infinite alternate;
}

@keyframes orbDrift1 {
  0%   { transform: translate(0, 0) scale(1); opacity: 0.15; }
  50%  { transform: translate(60px, 40px) scale(1.15); opacity: 0.22; }
  100% { transform: translate(30px, 80px) scale(0.95); opacity: 0.12; }
}

@keyframes orbDrift2 {
  0%   { transform: translateY(-50%) translate(0, 0) scale(1); opacity: 0.12; }
  50%  { transform: translateY(-50%) translate(-50px, 30px) scale(1.1); opacity: 0.20; }
  100% { transform: translateY(-50%) translate(-20px, -40px) scale(0.9); opacity: 0.14; }
}

@keyframes orbDrift3 {
  0%   { transform: translate(0, 0) scale(1); opacity: 0.10; }
  50%  { transform: translate(-40px, -30px) scale(1.2); opacity: 0.18; }
  100% { transform: translate(50px, -10px) scale(0.85); opacity: 0.13; }
}

/* --- Subtle grid overlay for depth --- */
.grid-overlay {
  position: absolute;
  inset: 0;
  opacity: 0.035;
  background-image:
    linear-gradient(rgba(231, 235, 238, 0.3) 1px, transparent 1px),
    linear-gradient(90deg, rgba(231, 235, 238, 0.3) 1px, transparent 1px);
  background-size: 60px 60px;
  mask-image: radial-gradient(ellipse 70% 70% at 50% 50%, black 30%, transparent 80%);
  -webkit-mask-image: radial-gradient(ellipse 70% 70% at 50% 50%, black 30%, transparent 80%);
}

/* --- Floating hex particles --- */
.hex-particles {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

.hex-particle {
  position: absolute;
  left: var(--x);
  top: var(--y);
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-faint);
  opacity: 0;
  animation: hexFloat 8s ease-in-out infinite;
  animation-delay: var(--delay);
}

@keyframes hexFloat {
  0%   { opacity: 0; transform: translateY(0) scale(0.8); }
  15%  { opacity: 0.35; }
  50%  { opacity: 0.15; transform: translateY(-20px) scale(1); }
  85%  { opacity: 0.3; }
  100% { opacity: 0; transform: translateY(-40px) scale(0.8); }
}

/* --- Hero content --- */
.hero-inner {
  max-width: 1180px;
  margin: 0 auto;
  position: relative;
  z-index: 1;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.hero-eyebrow {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--gold);
  margin: 0 0 18px;
  opacity: 0;
  animation: fadeSlideUp 0.8s ease-out 0.1s forwards;
}

.hero-title {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 600;
  font-size: clamp(26px, 4vw, 44px);
  line-height: 1.22;
  margin: 0 0 48px;
  max-width: 680px;
  color: var(--text-hi);
  opacity: 0;
  animation: fadeSlideUp 0.9s ease-out 0.25s forwards;
}

.hero-title-accent {
  background: linear-gradient(135deg, var(--gold) 0%, var(--teal) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* --- Staggered fade-in animation --- */
@keyframes fadeSlideUp {
  from {
    opacity: 0;
    transform: translateY(24px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* --- Signature element: the four-gate pipeline --- */
.pipeline {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0;
  opacity: 0;
  animation: fadeSlideUp 0.9s ease-out 0.5s forwards;
}

.pipe-stage {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(20, 27, 34, 0.75);
  backdrop-filter: blur(8px);
  transition: border-color 0.3s ease, transform 0.2s ease, box-shadow 0.3s ease;
}

.pipe-stage:hover {
  border-color: var(--text-lo);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px -8px rgba(0, 0, 0, 0.4);
}

.pipe-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-faint);
  animation: pulseDot 3.2s ease-in-out infinite;
}
.pipe-stage[data-stage="sub"] .pipe-dot { animation-delay: 0s; background: var(--teal); }
.pipe-stage[data-stage="shift"] .pipe-dot { animation-delay: 0.8s; background: var(--gold); }
.pipe-stage[data-stage="mix"] .pipe-dot { animation-delay: 1.6s; background: var(--coral); }
.pipe-stage[data-stage="add"] .pipe-dot { animation-delay: 2.4s; background: var(--teal); }

@keyframes pulseDot {
  0%, 100% { box-shadow: 0 0 0 0 currentColor; opacity: 0.6; }
  50% { box-shadow: 0 0 0 5px transparent; opacity: 1; transform: scale(1.3); }
}

.pipe-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12.5px;
  color: var(--text-lo);
  transition: color 0.2s ease;
}

.pipe-stage:hover .pipe-label { color: var(--text-hi); }

.pipe-wire {
  width: 36px;
  height: 1px;
  background: repeating-linear-gradient(90deg, var(--border) 0 6px, transparent 6px 10px);
}

@media (max-width: 720px) {
  .hero { padding: 56px 20px 48px; min-height: auto; }
  .pipeline { gap: 8px 0; }
  .pipe-wire { display: none; }
  .glow-orb { filter: blur(80px); }
  .glow-orb--teal { width: 250px; height: 250px; }
  .glow-orb--gold { width: 200px; height: 200px; }
  .glow-orb--coral { width: 180px; height: 180px; }
}

/* =========================== PANEL SHELL =========================== */

.panel {
  position: relative;
  z-index: 1;
  border-bottom: 1px solid var(--border-soft);
}

.panel-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 40px 28px;
}

.panel-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.02em;
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 22px;
  color: var(--text-hi);
}

.panel-num {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  color: var(--gold);
  border: 1px solid var(--gold-dim);
  background: var(--gold-dim);
  border-radius: var(--radius-s);
  padding: 2px 7px;
}

/* =========================== FORM =========================== */

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 22px;
}

@media (max-width: 760px) {
  .form-grid { grid-template-columns: 1fr; }
}

.field { display: flex; flex-direction: column; gap: 8px; }

.field label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-lo);
  letter-spacing: 0.01em;
}

.field input {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  padding: 13px 14px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 14px;
  color: var(--text-hi);
  transition: border-color 0.15s ease, background 0.15s ease;
}

.field input::placeholder { color: var(--text-faint); }

.field input:focus {
  border-color: var(--gold);
  background: var(--surface-alt);
}

.field input.invalid { border-color: var(--coral); }

.field-hint {
  font-size: 11.5px;
  color: var(--text-faint);
}
.field-hint.error { color: var(--coral); }

.form-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
}

.mode-switch {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
}

.mode-btn {
  border: none;
  background: transparent;
  color: var(--text-lo);
  font-size: 13px;
  font-weight: 600;
  padding: 8px 18px;
  border-radius: 999px;
  transition: background 0.2s ease, color 0.2s ease;
}

.mode-btn.active {
  background: var(--gold);
  color: #1A1305;
}

.action-buttons {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.btn {
  border: 1px solid transparent;
  border-radius: var(--radius-m);
  padding: 11px 20px;
  font-size: 13.5px;
  font-weight: 600;
  transition: transform 0.12s ease, filter 0.15s ease, background 0.15s ease;
}
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--gold);
  color: #1A1305;
}
.btn-primary:hover { filter: brightness(1.08); }

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-hi);
}
.btn-ghost:hover { border-color: var(--text-lo); }

.btn-secondary {
  background: var(--teal-dim);
  border-color: var(--teal);
  color: var(--teal);
}
.btn-secondary:hover { filter: brightness(1.15); background: rgba(47, 201, 179, 0.22); }

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  cursor: pointer;
  user-select: none;
}
.toggle input { position: absolute; opacity: 0; pointer-events: none; }

.toggle-track {
  width: 34px;
  height: 20px;
  border-radius: 999px;
  background: var(--border);
  position: relative;
  transition: background 0.2s ease;
  flex-shrink: 0;
}
.toggle-thumb {
  position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--text-hi);
  transition: transform 0.2s ease;
}
.toggle input:checked + .toggle-track { background: var(--teal); }
.toggle input:checked + .toggle-track .toggle-thumb { transform: translateX(14px); }

.toggle-label { font-size: 12.5px; color: var(--text-lo); }

.error-msg {
  color: var(--coral);
  font-size: 13px;
  margin: 16px 0 0;
  min-height: 0;
}
.error-msg:empty { display: none; }

.output-row {
  margin-top: 26px;
  padding-top: 24px;
  border-top: 1px dashed var(--border);
}
.output-row label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-lo);
  margin-bottom: 8px;
  letter-spacing: 0.02em;
}

.output-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--teal-dim);
  border-radius: var(--radius-m);
  padding: 14px 16px;
}
.output-box code {
  font-size: 15px;
  letter-spacing: 0.06em;
  color: var(--teal);
  word-break: break-all;
}
.copy-btn {
  flex-shrink: 0;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  color: var(--text-hi);
  border-radius: var(--radius-s);
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 600;
}
.copy-btn:hover { border-color: var(--teal); }
.copy-btn.copied { color: var(--teal); border-color: var(--teal); }

/* =========================== WORKSPACE LAYOUT =========================== */

.workspace {
  position: relative;
  z-index: 1;
  max-width: 1180px;
  margin: 0 auto;
  padding: 40px 28px 80px;
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 32px;
  align-items: start;
}

@media (max-width: 880px) {
  .workspace { grid-template-columns: 1fr; }
  .round-nav { position: static !important; order: 2; }
}

.round-nav {
  position: sticky;
  top: 84px;
  max-height: calc(100vh - 110px);
  overflow-y: auto;
  border-right: 1px solid var(--border-soft);
  padding-right: 16px;
}

.round-nav-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-faint);
  margin-bottom: 12px;
  font-weight: 600;
}

.round-nav-list { display: flex; flex-direction: column; gap: 2px; }

.round-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 8px;
  border-radius: var(--radius-s);
  font-size: 12.5px;
  color: var(--text-lo);
  text-decoration: none;
  border: 1px solid transparent;
  background: none;
  width: 100%;
  text-align: left;
  transition: background 0.15s ease, color 0.15s ease;
}
.round-nav-item:hover { background: var(--surface); color: var(--text-hi); }
.round-nav-item.active {
  background: var(--gold-dim);
  color: var(--gold);
  border-color: var(--gold-dim);
  font-weight: 600;
}
.round-nav-item .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-faint); flex-shrink: 0;
}
.round-nav-item.active .dot { background: var(--gold); }

/* =========================== ROUND / STAGE CARDS =========================== */

.rounds-main { min-width: 0; }

.round-card {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-l);
  margin-bottom: 18px;
  overflow: hidden;
  scroll-margin-top: 90px;
  box-shadow: var(--shadow-panel);
}

.round-card summary {
  list-style: none;
  cursor: pointer;
  padding: 18px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.round-card summary::-webkit-details-marker { display: none; }

.round-card-heading {
  display: flex;
  align-items: center;
  gap: 12px;
}

.round-badge {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--gold);
  background: var(--gold-dim);
  border-radius: var(--radius-s);
  padding: 3px 9px;
}
.round-badge.decrypt { color: var(--coral); background: var(--coral-dim); }
.round-badge.key { color: var(--teal); background: var(--teal-dim); }

.round-title {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 600;
  font-size: 15px;
}
.round-sub { font-size: 12px; color: var(--text-faint); }

.chevron {
  width: 18px; height: 18px;
  flex-shrink: 0;
  transition: transform 0.2s ease;
  color: var(--text-lo);
}
.round-card[open] .chevron { transform: rotate(180deg); }

.round-body {
  padding: 0 22px 24px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.stage-block {
  border-top: 1px solid var(--border-soft);
  padding-top: 18px;
}

.stage-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.stage-name {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--text-hi);
}
.stage-desc { font-size: 12px; color: var(--text-faint); }

.matrix-pair {
  display: flex;
  align-items: center;
  gap: 22px;
  flex-wrap: wrap;
}

.matrix-block { display: flex; flex-direction: column; gap: 8px; }
.matrix-caption {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
}

.matrix-arrow {
  color: var(--text-faint);
  font-size: 18px;
}

/* --- signature: byte tile state matrix --- */
.state-table {
  border-collapse: separate;
  border-spacing: 5px;
}
.state-table td {
  perspective: 400px;
}

.byte-tile {
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 7px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  font-family: 'JetBrains Mono', monospace;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-hi);
  transform-style: preserve-3d;
  transition: transform 0.5s cubic-bezier(.4,.2,.2,1), background 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

.byte-tile.changed {
  border-color: var(--gold);
  background: var(--gold-dim);
  color: var(--gold);
  animation: flipTile 0.55s ease;
}

@keyframes flipTile {
  0% { transform: rotateY(0deg); }
  50% { transform: rotateY(90deg); }
  100% { transform: rotateY(0deg); }
}

.byte-tile.key-tile { border-color: var(--teal-dim); }
.byte-tile.key-tile.changed { border-color: var(--teal); background: var(--teal-dim); color: var(--teal); }

/* =========================== KEY EXPANSION SECTION =========================== */

.keyexp-card {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-l);
  padding: 22px;
  margin-bottom: 28px;
  box-shadow: var(--shadow-panel);
}

.keyexp-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 6px;
}

.keyexp-title {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 600;
  font-size: 16px;
}

.keyexp-desc {
  font-size: 12.5px;
  color: var(--text-faint);
  margin: 0 0 18px;
  max-width: 640px;
}

.roundkey-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}

.roundkey-item {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  padding: 12px;
}
.roundkey-item-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--teal);
  margin-bottom: 8px;
}

/* =========================== EMPTY / STUB NOTE =========================== */

.stub-note {
  border: 1px dashed var(--coral-dim);
  background: rgba(226, 96, 79, 0.06);
  border-radius: var(--radius-m);
  padding: 14px 16px;
  font-size: 12.5px;
  color: var(--text-lo);
  line-height: 1.6;
}
.stub-note strong { color: var(--coral); }
.stub-note code { color: var(--text-hi); }

/* =========================== FOOTER =========================== */

.site-footer {
  border-top: 1px solid var(--border-soft);
  padding: 28px;
  text-align: center;
}
.site-footer p {
  font-size: 12px;
  color: var(--text-faint);
  margin: 0;
}

/* =========================== SCROLLBAR =========================== */

.round-nav::-webkit-scrollbar { width: 6px; }
.round-nav::-webkit-scrollbar-thumb { background: var(--border); border-radius: 999px; }
