:root {
    --font-sans: 'Inter', system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --gradient: linear-gradient(135deg, #4f46e5 0%, #7c3aed 50%, #06b6d4 100%);
    --card-bg: #ffffff;
    --body-bg: #f8fafc;
    --text: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --nav-bg: rgba(255, 255, 255, 0.85);
    --shadow: 0 4px 24px rgba(15, 23, 42, 0.08);
    --section-alt: #f1f5f9;
}

[data-bs-theme="dark"] {
    --card-bg: #1e293b;
    --body-bg: #0f172a;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --border: #334155;
    --nav-bg: rgba(15, 23, 42, 0.9);
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
    --section-alt: #1e293b;
}

* { box-sizing: border-box; }

body {
    font-family: var(--font-sans);
    background: var(--body-bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

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

.main-content { flex: 1; }

/* Navbar */
.navbar-custom {
    background: var(--nav-bg);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
}

.navbar-brand {
    font-weight: 600;
    color: var(--text) !important;
}

.brand-icon {
    width: 36px;
    height: 36px;
    background: var(--gradient);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
}

.nav-link { color: var(--text-muted) !important; font-weight: 500; }
.nav-link:hover { color: var(--primary) !important; }

.btn-theme-toggle {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--card-bg);
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.btn-theme-toggle:hover {
    border-color: var(--primary);
    color: var(--primary);
}

/* Hero */
.hero-section {
    padding: 4rem 0 3rem;
    background: radial-gradient(ellipse at 30% 0%, rgba(79, 70, 229, 0.12), transparent 60%),
                radial-gradient(ellipse at 70% 50%, rgba(6, 182, 212, 0.08), transparent 50%);
}

.hero-badge {
    background: rgba(79, 70, 229, 0.15);
    color: var(--primary);
    font-weight: 600;
    padding: 0.5rem 1rem;
}

.hero-title {
    font-size: clamp(2rem, 5vw, 3rem);
    font-weight: 700;
    line-height: 1.2;
}

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

.hero-subtitle {
    font-size: 1.125rem;
    color: var(--text-muted);
    max-width: 540px;
}

.hero-visual { display: flex; justify-content: center; padding: 2rem; }

.cipher-orbit {
    position: relative;
    width: 220px;
    height: 220px;
}

.orbit-center {
    position: absolute;
    inset: 50%;
    transform: translate(-50%, -50%);
    width: 64px;
    height: 64px;
    background: var(--gradient);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 1.5rem;
    z-index: 2;
    box-shadow: var(--shadow);
}

.orbit-item {
    position: absolute;
    width: 44px;
    height: 44px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
    font-size: 1.1rem;
    top: 50%;
    left: 50%;
    transform: rotate(calc(var(--i) * 72deg)) translateY(-90px) rotate(calc(var(--i) * -72deg)) translate(-50%, -50%);
    animation: orbit-pulse 3s ease-in-out infinite;
    animation-delay: calc(var(--i) * 0.2s);
    box-shadow: var(--shadow);
}

@keyframes orbit-pulse {
    0%, 100% { transform: rotate(calc(var(--i) * 72deg)) translateY(-90px) rotate(calc(var(--i) * -72deg)) translate(-50%, -50%) scale(1); }
    50% { transform: rotate(calc(var(--i) * 72deg)) translateY(-95px) rotate(calc(var(--i) * -72deg)) translate(-50%, -50%) scale(1.08); }
}

/* Cards */
.cipher-card {
    display: block;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 1.75rem;
    height: 100%;
    transition: all 0.3s ease;
    color: var(--text);
}

.cipher-card:hover {
    border-color: var(--primary);
    transform: translateY(-4px);
    box-shadow: var(--shadow);
}

.cipher-card-icon {
    width: 48px;
    height: 48px;
    background: rgba(79, 70, 229, 0.12);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
    font-size: 1.4rem;
    margin-bottom: 1rem;
}

.cipher-card h3 { font-size: 1.15rem; font-weight: 600; margin-bottom: 0.5rem; }
.cipher-card p { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 1rem; }
.cipher-card-link { color: var(--primary); font-weight: 500; font-size: 0.9rem; }

.section-title { font-weight: 700; }
.bg-section-alt { background: var(--section-alt); }

.feature-box { padding: 1.5rem; }
.feature-icon { font-size: 2rem; color: var(--primary); margin-bottom: 0.75rem; display: block; }

/* Panel */
.panel-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: var(--shadow);
}

.panel-header {
    background: transparent;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    padding: 1rem 1.25rem;
}

.cipher-header {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.cipher-header-icon {
    width: 56px;
    height: 56px;
    background: var(--gradient);
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 1.5rem;
}

.formula-box {
    background: rgba(79, 70, 229, 0.08);
    border: 1px solid rgba(79, 70, 229, 0.2);
    border-radius: 10px;
    padding: 0.75rem 1rem;
    font-family: var(--font-mono);
    font-size: 1rem;
    text-align: center;
}

.formula-badge { font-family: var(--font-mono); font-size: 0.75rem; }

.result-text {
    font-family: var(--font-mono);
    background: var(--body-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.75rem;
    word-break: break-all;
    min-height: 48px;
}

.result-output {
    border-color: rgba(79, 70, 229, 0.4);
    background: rgba(79, 70, 229, 0.06);
    font-weight: 500;
}

/* Steps */
.steps-container { max-height: 480px; overflow-y: auto; }

.step-item {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    animation: step-fade-in 0.4s ease forwards;
    opacity: 0;
}

.step-item:last-child { border-bottom: none; }

@keyframes step-fade-in {
    from { opacity: 0; transform: translateX(-8px); }
    to { opacity: 1; transform: translateX(0); }
}

.step-num {
    width: 28px;
    height: 28px;
    background: var(--primary);
    color: #fff;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 600;
    margin-right: 0.75rem;
}

.step-calc {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: var(--primary);
    margin-top: 0.35rem;
}

/* Matrix tables */
.matrix-table {
    font-family: var(--font-mono);
    font-size: 0.9rem;
}

.matrix-table td, .matrix-table th {
    text-align: center;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    min-width: 40px;
}

.matrix-table .highlight-cell {
    background: rgba(79, 70, 229, 0.2);
    font-weight: 600;
}

.hill-matrix-grid {
    display: grid;
    gap: 0.5rem;
}

.hill-matrix-grid.size-2 { grid-template-columns: repeat(2, 1fr); }
.hill-matrix-grid.size-3 { grid-template-columns: repeat(3, 1fr); }

.playfair-matrix {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 2px;
    max-width: 280px;
}

.playfair-cell {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--body-bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-family: var(--font-mono);
    font-weight: 600;
    font-size: 0.95rem;
    transition: background 0.2s;
}

.playfair-cell.active {
    background: rgba(79, 70, 229, 0.25);
    border-color: var(--primary);
    color: var(--primary);
}

.vigenere-table-wrap {
    max-height: 200px;
    overflow: auto;
    font-size: 0.65rem;
    font-family: var(--font-mono);
}

.vigenere-table td {
    padding: 2px 4px;
    border: 1px solid var(--border);
    text-align: center;
    min-width: 18px;
}

.fade-in { animation: fade-in 0.5s ease; }
@keyframes fade-in {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.placeholder-card { border-style: dashed; }

.footer-custom {
    border-top: 1px solid var(--border);
    padding: 1.5rem 0;
    margin-top: 2rem;
    color: var(--text-muted);
}

.history-table td, .history-table th {
    vertical-align: middle;
    border-color: var(--border);
}

.text-truncate-cell {
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
}

.btn-primary:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
}

[data-bs-theme="dark"] .form-control,
[data-bs-theme="dark"] .form-select {
    background: #0f172a;
    border-color: var(--border);
    color: var(--text);
}

[data-bs-theme="dark"] .breadcrumb-item a { color: #818cf8; }
