/* =====================================================================
   S·AES LAB — stylesheet
   Design language: "cipher lab notebook" — deep indigo-black canvas,
   brass/gold as the signal accent, teal as the XOR/binary accent.
   Display type: Space Grotesk · Body: Inter · Data: JetBrains Mono
   ===================================================================== */

:root {
  --bg: #0a0e18;
  --bg-elevated: #10162578;
  --panel: #121a2bcc;
  --panel-solid: #121a2b;
  --border: #263049;
  --border-soft: #1b2438;
  --text: #e9e7de;
  --text-dim: #9aa3bd;
  --text-faint: #5c6684;

  --gold: #d4a24c;
  --gold-soft: #d4a24c22;
  --teal: #5eead4;
  --teal-soft: #5eead422;
  --danger: #e8776b;

  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;

  --font-display: "Space Grotesk", sans-serif;
  --font-body: "Inter", sans-serif;
  --font-mono: "JetBrains Mono", monospace;

  --shadow-soft: 0 10px 40px -12px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  position: relative;
}

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

a { color: var(--teal); }

code, .mono { font-family: var(--font-mono); }

/* ---------------------------------------------------------------------
   Ambient circuit background — subtle, low-motion signature texture
   --------------------------------------------------------------------- */
.circuit-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image:
    linear-gradient(var(--border-soft) 1px, transparent 1px),
    linear-gradient(90deg, var(--border-soft) 1px, transparent 1px);
  background-size: 42px 42px;
  opacity: 0.35;
  mask-image: radial-gradient(ellipse 90% 60% at 50% 0%, black 10%, transparent 75%);
}
.circuit-bg::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(600px 300px at 15% -5%, #d4a24c14, transparent 60%),
    radial-gradient(500px 260px at 90% 10%, #5eead414, transparent 60%);
}

/* ---------------------------------------------------------------------
   Hero
   --------------------------------------------------------------------- */
.hero {
  position: relative;
  z-index: 1;
  padding: 72px 24px 56px;
  text-align: center;
  border-bottom: 1px solid var(--border-soft);
}
.hero__inner { max-width: 760px; margin: 0 auto; }

.hero__badge {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  color: var(--teal);
  background: var(--teal-soft);
  border: 1px solid #5eead43a;
  padding: 6px 14px;
  border-radius: 999px;
  margin-bottom: 22px;
}

.hero__title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(2.6rem, 6vw, 4.2rem);
  letter-spacing: -0.01em;
  margin: 0 0 18px;
}
.hero__title span { color: var(--gold); }

.hero__subtitle {
  color: var(--text-dim);
  font-size: 1.05rem;
  max-width: 620px;
  margin: 0 auto 34px;
}

.hero__meta {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}
.hero__meta-item {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  background: var(--bg-elevated);
}
.hero__meta-item span {
  display: block;
  font-family: var(--font-display);
  font-size: 1.4rem;
  color: var(--gold);
  font-weight: 700;
}

/* ---------------------------------------------------------------------
   Layout shell
   --------------------------------------------------------------------- */
.shell {
  position: relative;
  z-index: 1;
  max-width: 920px;
  margin: 0 auto;
  padding: 40px 20px 80px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
  backdrop-filter: blur(6px);
  box-shadow: var(--shadow-soft);
}

.panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 14px;
  margin-bottom: 22px;
}
.panel__header h2 {
  font-family: var(--font-display);
  margin: 0;
  font-size: 1.3rem;
}

.section-title {
  font-family: var(--font-display);
  font-size: 1.15rem;
  margin: 0 0 6px;
}
.section-desc {
  color: var(--text-dim);
  font-size: 0.92rem;
  margin: 0 0 18px;
}

/* ---------------------------------------------------------------------
   Mode toggle (segmented control)
   --------------------------------------------------------------------- */
.mode-toggle {
  display: inline-flex;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px;
  gap: 4px;
}
.mode-toggle button {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 13px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  padding: 8px 18px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.mode-toggle button.is-active {
  background: var(--gold);
  color: #1a1305;
}

/* ---------------------------------------------------------------------
   Form fields
   --------------------------------------------------------------------- */
.field { margin-bottom: 20px; }
.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 8px;
  letter-spacing: 0.02em;
}
.field__hint {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-faint);
  margin-top: 6px;
}

.bin-input {
  width: 100%;
  font-family: var(--font-mono);
  font-size: 1.15rem;
  letter-spacing: 0.18em;
  background: var(--bg);
  border: 1.5px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.bin-input:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-soft);
}
.bin-input.is-complete { border-color: var(--teal); }

.error-box {
  display: none;
  color: var(--danger);
  background: #e8776b1a;
  border: 1px solid #e8776b44;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13.5px;
  margin-bottom: 16px;
}
.error-box.is-visible { display: block; }

.button-row { display: flex; gap: 10px; flex-wrap: wrap; }

.btn {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 14px;
  border-radius: var(--radius-md);
  padding: 12px 22px;
  border: 1.5px solid transparent;
  cursor: pointer;
  transition: transform 0.15s ease, filter 0.15s ease, background 0.15s;
}
.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); }
.btn--ghost:hover { border-color: var(--teal); color: var(--teal); }
.btn--outline {
  background: var(--bg-elevated);
  border-color: var(--border);
  color: var(--text);
  width: 100%;
}
.btn--outline:hover { border-color: var(--gold); color: var(--gold); }
.btn--small { padding: 8px 16px; font-size: 12.5px; margin-top: 14px; }

/* ---------------------------------------------------------------------
   Result panel
   --------------------------------------------------------------------- */
.panel--result {
  display: none;
  text-align: center;
  border-color: var(--gold);
  background: linear-gradient(180deg, #16130c, var(--panel));
}
.panel--result.is-visible { display: block; animation: pop-in 0.35s ease; }

.result-label {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 10px;
}
.result-values__bin {
  font-family: var(--font-mono);
  font-size: clamp(1.4rem, 4vw, 2.1rem);
  letter-spacing: 0.14em;
  color: var(--text);
  word-break: break-all;
}
.result-values__hex {
  font-family: var(--font-mono);
  color: var(--text-dim);
  margin-top: 6px;
}

@keyframes pop-in {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------------------------------------------------------------------
   Steps toggle + timeline
   --------------------------------------------------------------------- */
.steps-toggle-row { display: flex; }

.steps-wrap {
  display: none;
  flex-direction: column;
  gap: 24px;
}
.steps-wrap.is-open { display: flex; animation: fade-down 0.3s ease; }

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

.word-row { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 22px; }
.word-chip {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 130px;
}
.word-chip__label { font-size: 11px; color: var(--text-faint); font-family: var(--font-mono); }
.word-chip__bin { font-family: var(--font-mono); font-size: 15px; letter-spacing: 0.06em; }
.word-chip__hex { font-family: var(--font-mono); font-size: 11px; color: var(--gold); }

.kx-blocks { display: flex; flex-direction: column; gap: 16px; margin-bottom: 24px; }
.kx-block {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  background: var(--bg-elevated);
}
.kx-formula {
  font-family: var(--font-mono);
  color: var(--teal);
  font-size: 13.5px;
  margin-bottom: 10px;
}
.kx-rows { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.kx-row { display: flex; align-items: center; gap: 10px; font-size: 12.5px; color: var(--text-dim); }
.kx-row__tag {
  font-family: var(--font-mono);
  background: var(--panel-solid);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 2px 8px;
  font-size: 11px;
  color: var(--text-dim);
  min-width: 76px;
  text-align: center;
}
.kx-row code { font-family: var(--font-mono); color: var(--text); letter-spacing: 0.05em; }

.kx-equation { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 10px 0; }
.kx-operand { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.kx-operand__label { font-size: 10.5px; color: var(--text-faint); }
.kx-operand code { font-family: var(--font-mono); font-size: 13px; background: var(--panel-solid); padding: 3px 8px; border-radius: 5px; border: 1px solid var(--border); }
.kx-op { color: var(--gold); font-weight: 700; }

.kx-result {
  display: flex; align-items: center; gap: 8px;
  border-top: 1px dashed var(--border);
  padding-top: 10px; margin-top: 4px;
  font-size: 13.5px;
}
.kx-result code { font-family: var(--font-mono); color: var(--teal); font-weight: 600; letter-spacing: 0.06em; }
.kx-result__hex { color: var(--text-faint); font-family: var(--font-mono); font-size: 12px; }

.subkey-heading { font-family: var(--font-display); font-size: 1rem; margin: 4px 0 12px; color: var(--text-dim); }
.subkey-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }
.subkey-card {
  border: 1px solid var(--gold);
  background: var(--gold-soft);
  border-radius: var(--radius-md);
  padding: 14px 16px;
}
.subkey-card__label { font-family: var(--font-mono); font-size: 11.5px; color: var(--gold); margin-bottom: 6px; }
.subkey-card__bin { font-family: var(--font-mono); font-size: 1.05rem; letter-spacing: 0.06em; }
.subkey-card__hex { font-family: var(--font-mono); font-size: 12px; color: var(--text-dim); margin-top: 4px; }

/* --- Step timeline cards --- */
.steps-timeline { display: flex; flex-direction: column; gap: 14px; }

.phase-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 10px 0 -2px;
  color: var(--gold);
  font-family: var(--font-mono);
  font-size: 12.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.phase-divider::before, .phase-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border));
}
.phase-divider::before { background: linear-gradient(90deg, var(--gold), var(--border)); flex: 0 0 24px; }

.step-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.step-card__header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--bg-elevated);
}
.step-card__index {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-faint);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 7px;
}
.step-card__icon { font-size: 18px; }
.step-card__phase { font-size: 11px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.08em; }
.step-card__title { font-family: var(--font-display); font-size: 1.02rem; }
.step-card__body { padding: 20px; }

.step-note { color: var(--text-dim); font-size: 13px; margin: 12px 0 0; }

/* --- State matrix / nibble tiles (signature element) --- */
.before-after { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.before-after__arrow { font-size: 1.4rem; color: var(--gold); }

.state-matrix-wrap { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.state-matrix-caption { font-size: 11px; color: var(--text-faint); font-family: var(--font-mono); text-transform: uppercase; letter-spacing: 0.06em; }

.state-matrix {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  perspective: 600px;
}

.nibble-tile {
  width: 76px;
  height: 76px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: var(--panel-solid);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  position: relative;
  transition: transform 0.45s cubic-bezier(0.2, 0.8, 0.2, 1), border-color 0.3s, background 0.3s;
  transform-style: preserve-3d;
}
.nibble-tile__label {
  position: absolute;
  top: 4px;
  left: 6px;
  font-size: 8.5px;
  color: var(--text-faint);
  font-family: var(--font-mono);
}
.nibble-tile__bin {
  font-family: var(--font-mono);
  font-size: 13.5px;
  letter-spacing: 0.08em;
  color: var(--text);
}
.nibble-tile__hex {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
}
.nibble-tile--changed {
  border-color: var(--teal);
  background: var(--teal-soft);
  animation: flip-tile 0.5s ease;
}
.nibble-tile--changed .nibble-tile__bin { color: var(--teal); }

@keyframes flip-tile {
  from { transform: rotateY(90deg); opacity: 0.2; }
  to { transform: rotateY(0deg); opacity: 1; }
}

/* --- AddRoundKey detail row --- */
.ark-detail { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }

/* --- MixColumns GF detail --- */
.mix-detail { margin-top: 16px; }
.mix-detail__matrix {
  font-family: var(--font-mono);
  color: var(--gold);
  font-size: 12.5px;
  margin-bottom: 12px;
}
.mix-column-block {
  border: 1px solid var(--border-soft);
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 10px;
}
.mix-column-block__title { font-size: 12px; color: var(--text-dim); margin-bottom: 8px; font-family: var(--font-mono); }
.gf-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 12.5px; margin-bottom: 6px; }
.gf-row__out { font-family: var(--font-mono); color: var(--text-dim); min-width: 26px; }
.gf-term code {
  font-family: var(--font-mono);
  background: var(--panel-solid);
  border: 1px solid var(--border);
  padding: 2px 7px;
  border-radius: 5px;
  font-size: 12px;
}
.gf-row__result {
  font-family: var(--font-mono);
  color: var(--teal);
  background: var(--teal-soft);
  padding: 2px 8px;
  border-radius: 5px;
  font-weight: 600;
}

/* --- GF(2^4) multiplication step-by-step detail (per term) --- */
.gf-term-block { margin-bottom: 14px; }
.gf-mul-detail-group { display: flex; flex-direction: column; gap: 6px; margin: 6px 0 4px 26px; }
.gf-mul-detail {
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel-solid);
  padding: 8px 12px;
}
.gf-mul-detail summary {
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--gold);
  list-style: none;
  user-select: none;
}
.gf-mul-detail summary::-webkit-details-marker { display: none; }
.gf-mul-detail summary::before {
  content: "▸ ";
  display: inline-block;
  transition: transform 0.15s ease;
}
.gf-mul-detail[open] summary::before { transform: rotate(90deg); }
.gf-mul-table__scroll { overflow-x: auto; margin-top: 8px; }
.gf-mul-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 11px;
  font-family: var(--font-mono);
}
.gf-mul-table th, .gf-mul-table td {
  padding: 5px 8px;
  text-align: left;
  white-space: nowrap;
  border-bottom: 1px solid var(--border-soft);
}
.gf-mul-table th { color: var(--text-faint); font-weight: 500; }
.gf-mul-table__mono { color: var(--text-dim); }
.gf-mul-detail__result {
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-dim);
}
.gf-mul-detail__result code {
  font-family: var(--font-mono);
  background: var(--teal-soft);
  color: var(--teal);
  padding: 2px 7px;
  border-radius: 5px;
}

/* ---------------------------------------------------------------------
   Reference tables
   --------------------------------------------------------------------- */
.reference-grid { display: flex; flex-direction: column; gap: 22px; }
.ref-table h4 { font-family: var(--font-display); font-size: 0.95rem; margin: 0 0 10px; color: var(--text-dim); }
.ref-table__scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.ref-table table { border-collapse: collapse; width: 100%; font-family: var(--font-mono); font-size: 12.5px; }
.ref-table th, .ref-table td { padding: 8px 10px; text-align: center; border-bottom: 1px solid var(--border-soft); border-right: 1px solid var(--border-soft); white-space: nowrap; }
.ref-table thead th { background: var(--bg-elevated); color: var(--gold); font-weight: 600; }
.ref-table tbody th { background: var(--bg-elevated); color: var(--teal); }
.ref-table td:last-child, .ref-table th:last-child { border-right: none; }

.reference-extra {
  margin-top: 22px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px;
}
.reference-extra__card {
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  border-radius: var(--radius-md);
  padding: 16px;
}
.reference-extra__card h4 { margin: 0 0 10px; font-family: var(--font-display); font-size: 0.95rem; }
.reference-extra__card code { font-family: var(--font-mono); font-size: 12.5px; color: var(--gold); line-height: 1.7; display: block; }
.reference-extra__card p { margin: 10px 0 0; font-size: 12px; color: var(--text-faint); }

/* ---------------------------------------------------------------------
   Footer
   --------------------------------------------------------------------- */
.site-footer {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 30px 20px 50px;
  color: var(--text-faint);
  font-size: 12.5px;
  border-top: 1px solid var(--border-soft);
}

/* ---------------------------------------------------------------------
   Responsive
   --------------------------------------------------------------------- */
@media (max-width: 560px) {
  .hero { padding: 56px 18px 40px; }
  .panel { padding: 20px; }
  .nibble-tile { width: 62px; height: 62px; }
  .before-after { justify-content: center; }
  .button-row { flex-direction: column; }
  .button-row .btn { width: 100%; }
}

/* Respect reduced motion preference */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
