/* =========================================================
   S-AES CIPHER LAB — DESIGN TOKENS (same family as AES-128 lab)
   ========================================================= */

:root {
  --bg: #0f1b50;
  --surface: #172461;
  --surface-alt: #1e2d75;
  --surface-raised: #2a3a8a;
  --border: #2a3a8a;
  --border-soft: #1e2d75;
  --text-hi: #ededed;
  --text-lo: #a1a1aa;
  --text-faint: #71717a;
  --gold: #818cf8;
  /* Accent 1: Indigo */
  --gold-dim: rgba(129, 140, 248, 0.15);
  --teal: #34d399;
  /* Accent 2: Emerald */
  --teal-dim: rgba(52, 211, 153, 0.15);
  --coral: #fb7185;
  /* Accent 3: Rose */
  --coral-dim: rgba(251, 113, 133, 0.15);
  --radius-s: 6px;
  --radius-m: 10px;
  --radius-l: 16px;
  --shadow-panel: 0 10px 40px -10px rgba(0, 0, 0, 0.08), 0 0 0 1px rgba(0, 0, 0, 0.04);
}

* {
  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-color: var(--bg);
  background-image:
    radial-gradient(ellipse at top left, rgba(52, 211, 153, 0.08), transparent 45%),
    radial-gradient(ellipse at bottom right, rgba(129, 140, 248, 0.08), transparent 45%);
  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");
}

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 {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

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

.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(15, 27, 80, 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;
  color: var(--gold);
}

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

.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: 64px 28px 48px;
  border-bottom: 1px solid var(--border-soft);
}

.hero-inner {
  max-width: 1180px;
  margin: 0 auto;
  text-align: center;
}

.hero-eyebrow {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--gold);
  margin: 0 0 14px;
}

.hero-title {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 600;
  font-size: clamp(24px, 3.6vw, 38px);
  line-height: 1.2;
  margin: 0 auto 44px;
  max-width: 680px;
  color: var(--text-hi);
}

.pipeline {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0;
}

.pipe-stage {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  transition: border-color 0.2s ease;
}

.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);
}

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

@media (max-width: 720px) {
  .pipeline {
    gap: 8px 0;
  }

  .pipe-wire {
    display: none;
  }
}

/* =========================== 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: 15px;
  letter-spacing: 0.12em;
  color: var(--text-hi);
  transition: border-color 0.15s ease, background 0.15s ease;
}

.field input::placeholder {
  color: var(--text-faint);
  letter-spacing: 0.05em;
}

.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: #000000;
}

.btn-primary:hover {
  filter: brightness(1.08);
}

.btn-secondary {
  background: var(--surface-alt);
  border-color: var(--border);
  color: var(--text-hi);
}

.btn-secondary:hover {
  background: var(--border-soft);
  border-color: var(--text-lo);
}

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

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

.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);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.output-row label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-lo);
  margin-bottom: 2px;
  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: 16px;
  letter-spacing: 0.12em;
  color: var(--teal);
  word-break: break-all;
}

.output-box-hex {
  border-color: var(--gold-dim);
}

.output-hex-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--gold);
  font-weight: 700;
}

.output-box-hex code {
  color: var(--gold);
}

.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);
}

/* =========================== REFERENCE TABLES =========================== */

.ref-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 18px;
}

.ref-card {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-l);
  padding: 18px;
  overflow-x: auto;
}

.ref-card::-webkit-scrollbar {
  height: 6px;
}

.ref-card::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 999px;
}

.ref-card h3 {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 13.5px;
  margin: 0 0 14px;
  color: var(--text-hi);
}

.ref-table {
  border-collapse: collapse;
  width: 100%;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
}

.ref-table td {
  text-align: center;
  padding: 6px 4px;
  border: 1px solid var(--border-soft);
  color: var(--text-lo);
}

.ref-table tr:first-child td {
  color: var(--text-faint);
  font-size: 10.5px;
}

.ref-table tr:last-child td {
  color: var(--gold);
  font-weight: 600;
}

.small-matrix {
  display: inline-flex;
  flex-direction: column;
  gap: 4px;
  font-size: 20px;
  color: var(--teal);
  background: var(--surface-alt);
  padding: 12px 20px;
  border-radius: var(--radius-m);
  border: 1px solid var(--border);
}

.ref-note {
  font-size: 11.5px;
  color: var(--text-faint);
  margin: 12px 0 0;
}

.rcon-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 13px;
  color: var(--text-hi);
}

.rcon-hex {
  color: var(--gold);
}

/* =========================== 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);
  background: none;
  border: 1px solid transparent;
  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-nav::-webkit-scrollbar {
  width: 6px;
}

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

/* =========================== 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;
}

/* --- nibble tile: 2x2 state matrix --- */
.state-table {
  border-collapse: separate;
  border-spacing: 6px;
}

.state-table td {
  perspective: 400px;
}

.nibble-tile {
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  font-family: 'JetBrains Mono', monospace;
  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;
  flex-direction: column;
  gap: 1px;
}

.nibble-tile .nib-hex {
  font-size: 15px;
  font-weight: 700;
}

.nibble-tile .nib-bin {
  font-size: 9px;
  color: var(--text-faint);
  letter-spacing: 0.05em;
}

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

.nibble-tile.changed .nib-hex {
  color: var(--gold);
}

.nibble-tile.changed .nib-bin {
  color: var(--gold);
  opacity: 0.7;
}

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

  50% {
    transform: rotateY(90deg);
  }

  100% {
    transform: rotateY(0deg);
  }
}

.nibble-tile.key-tile {
  border-color: var(--teal-dim);
}

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

.nibble-tile.key-tile.changed .nib-hex {
  color: var(--teal);
}

.gf-detail {
  margin-top: 12px;
  padding: 12px 14px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  color: var(--text-lo);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.gf-detail-title {
  color: var(--text-faint);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 4px;
}

/* =========================== 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;
}

.word-steps {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 20px;
}

.word-step {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12.5px;
  padding: 10px 14px;
  background: var(--surface-alt);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-m);
}

.word-step .w-name {
  color: var(--gold);
  font-weight: 700;
  min-width: 34px;
}

.word-step .w-val {
  color: var(--text-hi);
}

.word-step .w-eq {
  color: var(--text-faint);
}

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

.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;
}

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

.stub-note {
  border: 1px dashed var(--coral-dim);
  background: var(--coral-dim);
  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;
}