/* =====================================================
   Crypto Simulator — Design System
   Dark Mode · Glassmorphism · Modern Typography
   ===================================================== */

/* ---------- CSS Variables ---------- */
:root {
    /* Base palette */
    --bg-primary:    #09090b;
    --bg-secondary:  #18181b;
    --bg-card:       rgba(255, 255, 255, 0.03);
    --bg-card-hover: rgba(255, 255, 255, 0.06);

    /* Accent colors */
    --accent-violet:  #e11d48;
    --accent-indigo:  #be123c;
    --accent-cyan:    #fb923c;
    --accent-teal:    #fdba74;
    --accent-emerald: #10b981;
    --accent-amber:   #f59e0b;
    --accent-rose:    #f43f5e;
    --accent-purple:  #a855f7;
    --accent-blue:    #3b82f6;
    --accent-orange:  #f97316;

    /* Gradient shortcuts */
    --gradient-primary: linear-gradient(135deg, var(--accent-violet), var(--accent-cyan));
    --gradient-card:    linear-gradient(135deg, rgba(225, 29, 72,.08), rgba(251, 146, 60,.05));

    /* Text */
    --text-primary:   #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted:     #64748b;

    /* Borders */
    --border-subtle:  rgba(255, 255, 255, 0.07);
    --border-accent:  rgba(225, 29, 72, 0.30);

    /* Spacing */
    --radius-sm:  8px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --radius-xl: 28px;

    /* Shadows */
    --shadow-card: 0 8px 32px rgba(0, 0, 0, 0.40);
    --shadow-glow: 0 0 60px rgba(225, 29, 72, 0.12);

    /* Font */
    --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
}

/* ---------- Reset / Base ---------- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
}

body {
    font-family: var(--font-sans);
    color: var(--text-primary);
    background: var(--bg-primary);
    min-height: 100vh;
    line-height: 1.6;
    overflow-x: hidden;
    position: relative;
}

/* ---------- Background effects ---------- */
.bg-effects {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

.bg-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(120px);
    opacity: 0.35;
}

.orb-1 {
    width: 600px; height: 600px;
    background: radial-gradient(circle, var(--accent-violet), transparent 70%);
    top: -200px; left: -100px;
    animation: float1 20s ease-in-out infinite;
}

.orb-2 {
    width: 500px; height: 500px;
    background: radial-gradient(circle, var(--accent-cyan), transparent 70%);
    bottom: -150px; right: -100px;
    animation: float2 25s ease-in-out infinite;
}

.orb-3 {
    width: 350px; height: 350px;
    background: radial-gradient(circle, var(--accent-indigo), transparent 70%);
    top: 40%; left: 50%;
    animation: float3 18s ease-in-out infinite;
}

@keyframes float1 {
    0%, 100% { transform: translate(0, 0) scale(1); }
    33%      { transform: translate(60px, 40px) scale(1.08); }
    66%      { transform: translate(-30px, 70px) scale(0.95); }
}

@keyframes float2 {
    0%, 100% { transform: translate(0, 0) scale(1); }
    33%      { transform: translate(-50px, -30px) scale(1.1); }
    66%      { transform: translate(40px, -60px) scale(0.92); }
}

@keyframes float3 {
    0%, 100% { transform: translate(-50%, 0) scale(1); }
    50%      { transform: translate(-50%, -40px) scale(1.15); }
}

/* ---------- Layout ---------- */
.container {
    width: 100%;
    max-width: 960px;
    margin: 0 auto;
    padding: 0 24px;
    position: relative;
    z-index: 1;
}

.container.wide {
    max-width: 1100px;
}

/* ---------- Navbar ---------- */
.navbar {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(7, 7, 20, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-subtle);
    padding: 0 24px;
    transition: box-shadow 0.3s ease;
}

.navbar.scrolled {
    box-shadow: 0 4px 30px rgba(0,0,0,.5);
}

.navbar-inner {
    max-width: 1100px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 64px;
}

.navbar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--text-primary);
    cursor: pointer;
}

.navbar-brand .brand-icon {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--gradient-primary);
    border-radius: var(--radius-sm);
    color: white;
}

.navbar-brand .brand-icon svg {
    width: 18px;
    height: 18px;
}

.navbar-brand .brand-text {
    font-weight: 700;
    font-size: 1.1rem;
    letter-spacing: -0.01em;
}

.navbar-brand .brand-text span {
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.navbar-links {
    display: flex;
    align-items: center;
    gap: 4px;
    list-style: none;
}

.navbar-links a {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    text-decoration: none;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.navbar-links a svg {
    width: 16px;
    height: 16px;
    opacity: 0.7;
}

.navbar-links a:hover {
    color: var(--text-primary);
    background: rgba(255,255,255,.05);
}

.navbar-links a.active {
    color: var(--accent-violet);
    background: rgba(225, 29, 72,.1);
}

.navbar-links a.active svg {
    opacity: 1;
}

.nav-hamburger {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-sm);
}

.nav-hamburger:hover {
    background: rgba(255,255,255,.05);
}

.nav-hamburger svg {
    width: 24px;
    height: 24px;
}

/* ---------- Landing / Hero Section ---------- */
.page { display: none; }
.page.active { display: block; }

.hero {
    text-align: center;
    padding: 80px 0 48px;
    position: relative;
    z-index: 1;
}

.hero-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 16px;
    border-radius: 50px;
    border: 1px solid var(--border-accent);
    background: rgba(225, 29, 72,.06);
    font-size: 0.78rem;
    font-weight: 600;
    color: #fecdd3;
    letter-spacing: 0.04em;
    margin-bottom: 24px;
}

.hero-badge svg {
    width: 14px;
    height: 14px;
}

.hero h1 {
    font-size: 3.2rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    line-height: 1.15;
    margin-bottom: 16px;
}

.hero h1 .gradient-text {
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.hero-subtitle {
    font-size: 1.1rem;
    color: var(--text-secondary);
    max-width: 600px;
    margin: 0 auto 48px;
    line-height: 1.7;
}

/* ---------- Module Cards Grid (Landing) ---------- */
.modules-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 48px;
}

.module-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 28px;
    cursor: pointer;
    transition: all 0.35s ease;
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    box-shadow: var(--shadow-card);
    text-decoration: none;
    color: inherit;
    position: relative;
    overflow: hidden;
}

.module-card::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, transparent, rgba(255,255,255,.02));
    opacity: 0;
    transition: opacity 0.35s ease;
}

.module-card:hover {
    border-color: var(--border-accent);
    transform: translateY(-4px);
    box-shadow: var(--shadow-card), var(--shadow-glow);
}

.module-card:hover::before {
    opacity: 1;
}

.module-card-icon {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    margin-bottom: 16px;
    position: relative;
    z-index: 1;
}

.module-card-icon svg {
    width: 24px;
    height: 24px;
}

.module-card-icon.des   { background: rgba(99,102,241,.15); color: #fda4af; }
.module-card-icon.sdes  { background: rgba(251, 146, 60,.15);  color: #67e8f9; }
.module-card-icon.aes   { background: rgba(225, 29, 72,.15); color: #fecdd3; }
.module-card-icon.saes  { background: rgba(16,185,129,.15); color: #6ee7b7; }

.module-card h3 {
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 8px;
    position: relative;
    z-index: 1;
}

.module-card p {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.5;
    margin-bottom: 14px;
    position: relative;
    z-index: 1;
}

.module-card-meta {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    position: relative;
    z-index: 1;
}

.meta-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 600;
    background: rgba(255,255,255,.04);
    border: 1px solid rgba(255,255,255,.06);
    color: var(--text-muted);
}

.meta-chip svg {
    width: 12px;
    height: 12px;
}

/* ---------- Module Page Header ---------- */
.module-header {
    padding: 40px 0 28px;
    text-align: center;
    position: relative;
    z-index: 1;
}

.module-back {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    background: rgba(255,255,255,.04);
    border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    font-size: 0.82rem;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-bottom: 24px;
}

.module-back svg {
    width: 16px;
    height: 16px;
}

.module-back:hover {
    color: var(--text-primary);
    border-color: var(--accent-violet);
    background: rgba(225, 29, 72,.06);
}

.module-header h1 {
    font-size: 2.2rem;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.module-header h1 .accent {
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.module-header .module-subtitle {
    color: var(--text-secondary);
    font-size: 0.92rem;
    margin-top: 6px;
}

/* ---------- Cards ---------- */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 32px;
    margin-bottom: 28px;
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    box-shadow: var(--shadow-card);
    transition: border-color 0.3s ease;
}

.card:hover {
    border-color: var(--border-accent);
}

.section-title {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 24px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.section-title::before {
    content: '';
    width: 4px;
    height: 22px;
    border-radius: 4px;
    background: var(--gradient-primary);
    flex-shrink: 0;
}

/* ---------- Mode Selector ---------- */
.mode-selector {
    display: flex;
    gap: 12px;
    margin-bottom: 28px;
}

.mode-option {
    flex: 1;
    cursor: pointer;
}

.mode-option input[type="radio"] {
    display: none;
}

.mode-label {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 20px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
    background: rgba(255, 255, 255, 0.02);
    font-weight: 600;
    font-size: 0.95rem;
    transition: all 0.3s ease;
    text-align: center;
}

.mode-label svg {
    width: 18px;
    height: 18px;
}

.mode-option input:checked + .mode-label {
    background: linear-gradient(135deg, rgba(225, 29, 72,.15), rgba(251, 146, 60,.10));
    border-color: var(--accent-violet);
    box-shadow: 0 0 20px rgba(225, 29, 72,.15), inset 0 1px 0 rgba(255,255,255,.05);
}

.mode-label:hover {
    border-color: rgba(225, 29, 72,.4);
    background: rgba(255, 255, 255, 0.04);
}

/* ---------- Form Elements ---------- */
.form-group {
    margin-bottom: 22px;
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.form-group input[type="text"] {
    width: 100%;
    padding: 14px 18px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 1.05rem;
    font-weight: 500;
    letter-spacing: 0.12em;
    transition: all 0.3s ease;
    outline: none;
}

.form-group input[type="text"]::placeholder {
    color: var(--text-muted);
    font-weight: 400;
    letter-spacing: 0.05em;
}

.form-group input[type="text"]:focus {
    border-color: var(--accent-violet);
    box-shadow: 0 0 0 3px rgba(225, 29, 72,.15);
    background: rgba(255, 255, 255, 0.06);
}

.form-group input[type="text"].error {
    border-color: var(--accent-rose);
    box-shadow: 0 0 0 3px rgba(244,63,94,.15);
}

.input-hint {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 6px;
    font-size: 0.78rem;
    color: var(--text-muted);
}

.char-counter {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    color: var(--text-muted);
}

.char-counter.complete { color: var(--accent-emerald); }
.char-counter.over     { color: var(--accent-rose); }

/* ---------- Input Format Toggle ---------- */
.format-toggle {
    display: flex;
    gap: 4px;
    margin-bottom: 16px;
    background: rgba(255,255,255,.03);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: 3px;
    width: fit-content;
}

.format-btn {
    padding: 6px 14px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.78rem;
    font-weight: 600;
    font-family: var(--font-sans);
    cursor: pointer;
    transition: all 0.2s ease;
}

.format-btn.active {
    background: rgba(225, 29, 72,.15);
    color: #fecdd3;
}

.format-btn:hover:not(.active) {
    color: var(--text-secondary);
}

/* ---------- Buttons ---------- */
.button-group {
    display: flex;
    gap: 14px;
    margin-top: 28px;
}

.btn {
    padding: 14px 32px;
    border-radius: var(--radius-md);
    border: none;
    font-family: var(--font-sans);
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    position: relative;
    overflow: hidden;
}

.btn svg {
    width: 18px;
    height: 18px;
}

.btn::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255,255,255,.1), transparent);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.btn:hover::after { opacity: 1; }

.btn-primary {
    flex: 1;
    background: var(--gradient-primary);
    color: white;
    box-shadow: 0 4px 20px rgba(225, 29, 72,.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 30px rgba(225, 29, 72,.4);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-secondary);
    border: 1px solid var(--border-subtle);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.10);
    color: var(--text-primary);
    border-color: rgba(255,255,255,.15);
}

.btn-sm {
    padding: 8px 16px;
    font-size: 0.8rem;
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
}

.btn-outline:hover {
    border-color: var(--accent-violet);
    color: var(--accent-violet);
    background: rgba(225, 29, 72,.06);
}

/* ---------- Error Message ---------- */
.error-message {
    background: rgba(244, 63, 94, 0.10);
    border: 1px solid rgba(244, 63, 94, 0.30);
    border-radius: var(--radius-md);
    padding: 14px 20px;
    color: #fda4af;
    font-size: 0.9rem;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    animation: fadeSlideIn 0.3s ease;
}

.error-message svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

/* ---------- Result Display ---------- */
.result-card {
    border-color: rgba(16, 185, 129, 0.20);
    background: linear-gradient(135deg, rgba(16,185,129,.04), rgba(251, 146, 60,.03));
}

.result-display {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.result-item {
    text-align: center;
}

.result-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--accent-emerald);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.result-label svg {
    width: 18px;
    height: 18px;
}

.result-values {
    display: flex;
    gap: 20px;
    justify-content: center;
    flex-wrap: wrap;
}

.result-value {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 16px 28px;
    text-align: center;
    min-width: 200px;
    flex: 1;
}

.value-label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 8px;
}

.value-text {
    font-size: 1.4rem;
    font-weight: 700;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.mono {
    font-family: var(--font-mono);
    letter-spacing: 0.15em;
}

/* ---------- Steps Section ---------- */
.steps-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.steps-header .section-title {
    margin-bottom: 0;
}

/* ---------- Step Cards ---------- */
.step-card {
    margin-bottom: 14px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
    overflow: hidden;
    transition: border-color 0.3s ease;
}

.step-card:hover {
    border-color: rgba(255,255,255,.12);
}

.step-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    cursor: pointer;
    transition: background 0.2s ease;
    user-select: none;
}

.step-header:hover {
    background: rgba(255, 255, 255, 0.03);
}

.step-tag {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 0.9rem;
}

.step-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

/* Color coding for different step types */
.badge-key       { background: rgba(225, 29, 72,.18); color: #fecdd3; }
.badge-sub       { background: rgba(16,185,129,.18); color: #6ee7b7; }
.badge-shift     { background: rgba(245,158,11,.18); color: #fcd34d; }
.badge-mix       { background: rgba(168,85,247,.18); color: #d8b4fe; }
.badge-addrk     { background: rgba(251, 146, 60,.18);  color: #67e8f9; }
.badge-initial   { background: rgba(99,102,241,.18); color: #fda4af; }
.badge-perm      { background: rgba(249,115,22,.18); color: #fdba74; }
.badge-feistel   { background: rgba(236,72,153,.18); color: #f9a8d4; }
.badge-sbox      { background: rgba(14,165,233,.18); color: #7dd3fc; }
.badge-xor       { background: rgba(234,179,8,.18);  color: #fde047; }
.badge-round     { background: rgba(59,130,246,.18); color: #93c5fd; }

.step-toggle {
    font-size: 0.8rem;
    color: var(--text-muted);
    transition: transform 0.3s ease;
    display: flex;
    align-items: center;
}

.step-toggle svg {
    width: 16px;
    height: 16px;
    transition: transform 0.3s ease;
}

.step-card.open .step-toggle svg {
    transform: rotate(180deg);
}

.step-body {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s ease, padding 0.3s ease;
    padding: 0 20px;
}

.step-card.open .step-body {
    max-height: 5000px;
    padding: 4px 20px 20px;
}

/* ---------- State Comparison Layout ---------- */
.state-comparison {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    flex-wrap: wrap;
    margin: 12px 0;
}

.state-block {
    text-align: center;
}

.state-block-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 8px;
}

.state-arrow {
    font-size: 1.4rem;
    color: var(--text-muted);
    flex-shrink: 0;
}

.state-op-label {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.state-op-label .op-name {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--accent-violet);
}

/* ---------- State Matrix 2×2 ---------- */
.state-matrix {
    display: grid;
    gap: 3px;
    width: fit-content;
    margin: 0 auto;
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 1px solid rgba(255,255,255,.08);
}

.state-matrix.m2x2 { grid-template-columns: 1fr 1fr; }
.state-matrix.m4x4 { grid-template-columns: 1fr 1fr 1fr 1fr; }

.state-cell {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.04);
    gap: 2px;
    transition: background 0.2s ease;
}

.state-matrix.m2x2 .state-cell {
    width: 70px;
    height: 60px;
}

.state-matrix.m4x4 .state-cell {
    width: 52px;
    height: 46px;
}

.state-cell:hover {
    background: rgba(255, 255, 255, 0.08);
}

.cell-hex {
    font-family: var(--font-mono);
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-primary);
}

.state-matrix.m4x4 .cell-hex {
    font-size: 0.9rem;
}

.cell-bin {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    color: var(--text-muted);
    letter-spacing: 0.05em;
}

.state-matrix.m4x4 .cell-bin {
    font-size: 0.55rem;
}

/* Color variations for cells */
.state-cell.c0 { background: rgba(225, 29, 72,.08); }
.state-cell.c1 { background: rgba(251, 146, 60,.08); }
.state-cell.c2 { background: rgba(168,85,247,.08); }
.state-cell.c3 { background: rgba(16,185,129,.08); }

/* ---------- Key Expansion / Data Tables ---------- */
.ke-table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 0.85rem;
}

.ke-table th {
    text-align: left;
    padding: 10px 14px;
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-subtle);
}

.ke-table td {
    padding: 10px 14px;
    border-bottom: 1px solid rgba(255,255,255,.03);
    color: var(--text-secondary);
}

.ke-table tr:last-child td {
    border-bottom: none;
}

.ke-table .mono-val {
    font-family: var(--font-mono);
    font-weight: 500;
    color: var(--text-primary);
    letter-spacing: 0.08em;
}

.ke-table .desc-text {
    color: var(--text-secondary);
    font-size: 0.82rem;
}

.ke-table .calc-text {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    color: var(--text-muted);
    word-break: break-all;
}

.ke-keys-summary {
    display: flex;
    gap: 12px;
    margin-top: 16px;
    flex-wrap: wrap;
}

.ke-key-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(225, 29, 72,.08);
    border: 1px solid rgba(225, 29, 72,.15);
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    flex: 1;
    min-width: 100px;
}

.ke-key-chip .chip-label {
    font-weight: 700;
    font-size: 0.85rem;
    color: #fecdd3;
}

.ke-key-chip .chip-value {
    font-family: var(--font-mono);
    font-size: 0.82rem;
    color: var(--text-primary);
    letter-spacing: 0.06em;
}

/* ---------- Bit/Binary Display ---------- */
.bit-display {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    justify-content: center;
    margin: 8px 0;
}

.bit-cell {
    width: 28px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255,255,255,.04);
    border: 1px solid rgba(255,255,255,.06);
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
}

.bit-cell.highlight {
    background: rgba(225, 29, 72,.12);
    border-color: rgba(225, 29, 72,.25);
    color: #fecdd3;
}

.bit-group {
    display: flex;
    gap: 2px;
    margin: 0 4px;
}

/* ---------- GF Detail Calculations ---------- */
.gf-details {
    margin-top: 16px;
    padding: 16px;
    background: rgba(168,85,247,.04);
    border: 1px solid rgba(168,85,247,.12);
    border-radius: var(--radius-sm);
}

.gf-details-title {
    font-size: 0.8rem;
    font-weight: 700;
    color: #d8b4fe;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 12px;
}

.gf-column {
    margin-bottom: 14px;
}

.gf-column:last-child {
    margin-bottom: 0;
}

.gf-column-title {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.gf-calc-line {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--text-secondary);
    padding: 3px 0;
    padding-left: 12px;
}

.gf-calc-line .gf-highlight {
    color: var(--accent-purple);
    font-weight: 600;
}

.gf-calc-line .gf-result {
    color: var(--accent-emerald);
    font-weight: 700;
}

/* ---------- Reference Tables ---------- */
.reference-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.ref-block {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 20px;
    overflow-x: auto;
}

.ref-block-title {
    font-size: 0.85rem;
    font-weight: 700;
    margin-bottom: 14px;
    color: var(--text-primary);
}

.ref-table {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--font-mono);
    font-size: 0.78rem;
}

.ref-table th {
    padding: 6px 8px;
    font-weight: 600;
    color: var(--text-muted);
    text-align: center;
    border-bottom: 1px solid var(--border-subtle);
    font-size: 0.7rem;
    text-transform: uppercase;
}

.ref-table td {
    padding: 6px 8px;
    text-align: center;
    border-bottom: 1px solid rgba(255,255,255,.02);
    color: var(--text-primary);
    font-weight: 500;
}

.ref-table tr:hover td {
    background: rgba(225, 29, 72,.06);
}

.ref-small-table {
    border-collapse: collapse;
    font-family: var(--font-mono);
    margin: 0 auto;
}

.ref-small-table td {
    width: 50px;
    height: 40px;
    text-align: center;
    font-size: 1rem;
    font-weight: 600;
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
}

.ref-info {
    margin-top: 14px;
    font-size: 0.78rem;
    color: var(--text-muted);
    line-height: 1.6;
}

.ref-info code {
    font-family: var(--font-mono);
    background: rgba(255,255,255,.06);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.76rem;
    color: var(--accent-cyan);
}

/* DES S-Box reference table (smaller cells for 4×16) */
.ref-table.compact td,
.ref-table.compact th {
    padding: 4px 6px;
    font-size: 0.72rem;
}

/* ---------- Permutation Display ---------- */
.perm-display {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    justify-content: center;
    margin: 8px 0;
    font-family: var(--font-mono);
}

.perm-cell {
    width: 30px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255,255,255,.04);
    border-radius: 4px;
    font-size: 0.72rem;
    color: var(--text-secondary);
    border: 1px solid rgba(255,255,255,.05);
}

/* ---------- Info Box ---------- */
.info-box {
    padding: 14px 18px;
    border-radius: var(--radius-sm);
    background: rgba(99,102,241,.06);
    border: 1px solid rgba(99,102,241,.15);
    font-size: 0.82rem;
    color: var(--text-secondary);
    line-height: 1.6;
    margin: 12px 0;
}

.info-box strong {
    color: #fda4af;
}

/* ---------- Footer ---------- */
footer {
    text-align: center;
    padding: 40px 0;
    color: var(--text-muted);
    font-size: 0.82rem;
    position: relative;
    z-index: 1;
    border-top: 1px solid var(--border-subtle);
    margin-top: 20px;
}

footer a {
    color: var(--accent-violet);
    text-decoration: none;
}

footer a:hover {
    text-decoration: underline;
}

/* ---------- Utility ---------- */
.hidden {
    display: none !important;
}

.text-center { text-align: center; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }

/* ---------- Animations ---------- */
@keyframes fadeSlideIn {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.animate-in {
    animation: fadeSlideIn 0.5s ease forwards;
}

/* Stagger children */
.stagger > * {
    animation: fadeSlideIn 0.4s ease forwards;
    opacity: 0;
}

.stagger > *:nth-child(1)  { animation-delay: 0.05s; }
.stagger > *:nth-child(2)  { animation-delay: 0.10s; }
.stagger > *:nth-child(3)  { animation-delay: 0.15s; }
.stagger > *:nth-child(4)  { animation-delay: 0.20s; }
.stagger > *:nth-child(5)  { animation-delay: 0.25s; }
.stagger > *:nth-child(6)  { animation-delay: 0.30s; }
.stagger > *:nth-child(7)  { animation-delay: 0.35s; }
.stagger > *:nth-child(8)  { animation-delay: 0.40s; }
.stagger > *:nth-child(9)  { animation-delay: 0.45s; }
.stagger > *:nth-child(10) { animation-delay: 0.50s; }
.stagger > *:nth-child(11) { animation-delay: 0.55s; }
.stagger > *:nth-child(12) { animation-delay: 0.60s; }

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar {
    width: 8px;
}
::-webkit-scrollbar-track {
    background: var(--bg-primary);
}
::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,.12);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(255,255,255,.2);
}

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
    .hero h1 {
        font-size: 2.2rem;
    }

    .hero-subtitle {
        font-size: 0.95rem;
    }

    .modules-grid {
        grid-template-columns: 1fr;
    }

    .module-header h1 {
        font-size: 1.8rem;
    }

    .container {
        padding: 0 16px;
    }

    .card {
        padding: 22px 18px;
        border-radius: var(--radius-md);
    }

    .mode-selector {
        flex-direction: column;
        gap: 8px;
    }

    .button-group {
        flex-direction: column;
    }

    .result-values {
        flex-direction: column;
    }

    .state-comparison {
        gap: 12px;
    }

    .state-matrix.m2x2 .state-cell {
        width: 58px;
        height: 50px;
    }

    .state-matrix.m4x4 .state-cell {
        width: 42px;
        height: 38px;
    }

    .state-matrix.m4x4 .cell-hex {
        font-size: 0.75rem;
    }

    .reference-grid {
        grid-template-columns: 1fr;
    }

    .ke-keys-summary {
        flex-direction: column;
    }

    .value-text {
        font-size: 1.1rem;
    }

    .navbar-links {
        display: none;
        position: absolute;
        top: 64px;
        left: 0;
        right: 0;
        background: rgba(7, 7, 20, 0.95);
        backdrop-filter: blur(20px);
        flex-direction: column;
        padding: 12px;
        border-bottom: 1px solid var(--border-subtle);
        gap: 2px;
    }

    .navbar-links.open {
        display: flex;
    }

    .nav-hamburger {
        display: block;
    }
}

@media (max-width: 480px) {
    .hero {
        padding: 48px 0 32px;
    }

    .hero h1 {
        font-size: 1.8rem;
    }

    .state-matrix.m2x2 .state-cell {
        width: 50px;
        height: 44px;
    }

    .state-matrix.m4x4 .state-cell {
        width: 36px;
        height: 34px;
    }

    .cell-hex {
        font-size: 0.9rem;
    }

    .cell-bin {
        font-size: 0.6rem;
    }

    .step-header {
        padding: 12px 14px;
    }

    .step-body {
        padding-left: 14px;
        padding-right: 14px;
    }

    .step-card.open .step-body {
        padding-left: 14px;
        padding-right: 14px;
    }

    .module-card {
        padding: 20px;
    }
}
