:root {
    --bg: #07111f;
    --bg-soft: #0d1b2d;
    --surface: rgba(11, 20, 35, 0.82);
    --surface-strong: rgba(10, 18, 31, 0.94);
    --border: rgba(255, 255, 255, 0.12);
    --text: #edf4ff;
    --muted: rgba(237, 244, 255, 0.72);
    --accent: #44d7b6;
    --accent-2: #5b8cff;
    --accent-3: #ffb84d;
    --shadow: 0 24px 80px rgba(0, 0, 0, 0.35);
}

html {
    scroll-behavior: smooth;
}

body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    color: var(--text);
    font-family: 'Inter', sans-serif;
    background:
        radial-gradient(circle at top left, rgba(91, 140, 255, 0.18), transparent 34%),
        radial-gradient(circle at top right, rgba(68, 215, 182, 0.16), transparent 32%),
        linear-gradient(180deg, #06101c 0%, #0a1523 45%, #060b13 100%);
    position: relative;
    overflow-x: hidden;
}

body::before,
body::after {
    content: '';
    position: fixed;
    inset: auto;
    border-radius: 999px;
    filter: blur(60px);
    pointer-events: none;
    opacity: 0.35;
    z-index: 0;
}

body::before {
    width: 260px;
    height: 260px;
    left: -80px;
    top: 8%;
    background: rgba(91, 140, 255, 0.45);
}

body::after {
    width: 300px;
    height: 300px;
    right: -100px;
    top: 45%;
    background: rgba(68, 215, 182, 0.32);
}

.page-backdrop,
.page-grid {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
}

.page-grid {
    background-image: linear-gradient(rgba(255, 255, 255, 0.04) 1px, transparent 1px), linear-gradient(90deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px);
    background-size: 64px 64px;
    mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.55), transparent 92%);
    opacity: 0.22;
}

main,
nav {
    position: relative;
    z-index: 1;
}

main {
    flex: 1 0 auto;
}

.site-footer {
    margin-top: auto;
    position: relative;
    z-index: 1;
}

.site-footer-text {
    color: var(--muted);
    letter-spacing: 0.02em;
    font-size: 0.92rem;
}

body[data-theme="light"] .site-footer-text {
    color: rgba(11,18,32,0.62);
}

.navbar-brand,
.hero-copy h1,
.hero-panel h2,
.section-title,
.mini-title,
.result-hero h1 {
    font-family: 'Space Grotesk', sans-serif;
}

.navbar-brand {
    letter-spacing: 0.02em;
}

.hero-shell {
    display: grid;
    grid-template-columns: 1.3fr 0.9fr;
    gap: 1.5rem;
    align-items: stretch;
}

.hero-copy,
.hero-panel,
.glass-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 28px;
    backdrop-filter: blur(18px);
    box-shadow: var(--shadow);
}

.hero-copy {
    padding: 2rem;
}

.hero-copy h1,
.result-hero h1 {
    font-size: clamp(2.2rem, 4vw, 4.2rem);
    line-height: 1.02;
    margin-top: 0.75rem;
    margin-bottom: 1rem;
}

.hero-copy p,
.panel-text,
.section-subtitle,
.parameter-note,
.text-secondary,
.recent-item small,
.feature-list,
.empty-state {
    color: var(--muted) !important;
}

.eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.18em;
    font-size: 0.74rem;
    color: #a9d9ff;
}

.hero-metrics,
.result-stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.75rem;
}

.metric-card,
.stat-card {
    padding: 1rem;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.metric-card strong,
.stat-card strong {
    display: block;
    font-size: 1.15rem;
}

.metric-card span,
.stat-card span {
    display: block;
    color: var(--muted);
    font-size: 0.86rem;
}

.hero-panel {
    padding: 1.75rem;
}

.panel-label,
.soft-badge {
    letter-spacing: 0.08em;
    text-transform: uppercase;
    font-size: 0.72rem;
}

.panel-list {
    padding: 1rem;
    border-radius: 18px;
    background: rgba(68, 215, 182, 0.08);
    border: 1px solid rgba(68, 215, 182, 0.18);
}

.formula-box {
    padding: 1rem 1.1rem;
    border-radius: 14px;
    background: linear-gradient(180deg, rgba(91,140,255,0.06), rgba(68,215,182,0.03));
    border: 1px solid rgba(91, 140, 255, 0.14);
    display: flex;
    gap: 0.8rem;
    align-items: center;
}

.formula-box .formula-icon {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    display: inline-grid;
    place-items: center;
    background: rgba(91,140,255,0.14);
    color: #eaf8ff;
    font-weight: 700;
    flex: 0 0 44px;
}

.formula-box strong {
    display: block;
    font-size: 1.02rem;
    line-height: 1.2;
    color: var(--text);
}

.formula-box .math-expression {
    display: block;
    font-family: 'Space Grotesk', serif;
    font-size: 1.04rem;
    color: var(--text);
    white-space: normal;
    word-break: break-word;
}

.formula-box .parameter-note {
    margin-bottom: 0.3rem;
    color: var(--muted);
}

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

.hill-block .matrix-and-result {
    align-items: center;
}

.math-inline {
    font-size: 1rem;
}

.math-display {
    margin-top: 0.5rem;
    margin-bottom: 0.5rem;
    text-align: center;
}

.hill-details summary {
    cursor: pointer;
    list-style: none;
}

.hill-details summary {
    display: inline-block;
    padding: 0.45rem 0.7rem;
    border-radius: 10px;
    background: rgba(255,255,255,0.03);
    border: 1px solid rgba(255,255,255,0.04);
    color: var(--muted);
    transition: background 160ms ease, transform 120ms ease;
}

.hill-details[open] summary {
    background: rgba(91,140,255,0.12);
    color: var(--text);
    transform: translateY(-2px);
}

.hill-details summary:hover {
    background: rgba(255,255,255,0.05);
}

/* Small matrix compact style */
.small-matrix .matrix-row {
    gap: 0.4rem;
}

.small-matrix .matrix-cell {
    min-height: 2.2rem;
    font-size: 0.95rem;
    padding: 0.4rem 0.5rem;
    border-radius: 8px;
}

.hill-block .math-inline {
    font-size: 1.02rem;
}

.hill-details summary .caret {
    display: inline-block;
    margin-left: 0.5rem;
    transition: transform 180ms ease;
}

/* rotate caret when details open */
.hill-details[open] summary .caret {
    transform: rotate(90deg);
}

.mod-badge {
    display: inline-block;
    padding: 0.35rem 0.6rem;
    border-radius: 8px;
    background: rgba(91,140,255,0.12);
    color: var(--text);
    border: 1px solid rgba(91,140,255,0.12);
    font-weight: 700;
    margin-right: 0.35rem;
}

/* display-mode math responsive sizing */
.math-display {
    font-size: 1.02rem;
}

@media (max-width: 575.98px) {
    .math-display { font-size: 0.9rem; }
    .matrix-cell { min-height: 2rem; font-size: 0.9rem; }
}

/* subtle expand animation */
.hill-details[open] .hill-equations {
    animation: fadeInUp 220ms ease both;
}

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

.math-result {
    color: var(--muted);
}

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

.matrix-cell {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 3rem;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    font-weight: 700;
}

.mini-stack {
    display: grid;
    gap: 0.75rem;
}

.mini-chip,
.quick-action,
.recent-item,
.step-item {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 18px;
}

.mini-chip {
    padding: 0.9rem 1rem;
}

.mini-chip span {
    display: block;
    font-weight: 700;
}

.mini-chip small,
.quick-action {
    color: var(--muted);
    font-size: 0.9rem;
}

.shadow-panel {
    box-shadow: var(--shadow);
}

.glass-card,
.quick-action,
.recent-item,
.step-item,
.metric-card,
.stat-card,
.algorithm-panel {
    transition: transform 180ms ease, border-color 180ms ease, background-color 180ms ease;
}

.glass-card:hover,
.quick-action:hover,
.recent-item:hover,
.step-item:hover,
.metric-card:hover,
.stat-card:hover,
.algorithm-panel:hover {
    transform: translateY(-2px);
    border-color: rgba(91, 140, 255, 0.35);
}

.section-title,
.mini-title {
    letter-spacing: -0.03em;
}

.form-control,
.form-select {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    box-shadow: none;
}

.form-select option {
    background-color: #f7fbff;
    color: #0b1220;
}

.form-select option:checked,
.form-select option:hover,
.form-select option:focus {
    background-color: #dbeafe;
    color: #0b1220;
}

.form-control:focus,
.form-select:focus {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text);
    border-color: rgba(91, 140, 255, 0.6);
    box-shadow: 0 0 0 0.2rem rgba(91, 140, 255, 0.18);
}

.form-control::placeholder {
    color: rgba(237, 244, 255, 0.45);
}

.btn {
    border-radius: 14px;
    font-weight: 600;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent-2), #7d5fff);
    border: none;
    box-shadow: 0 16px 32px rgba(91, 140, 255, 0.25);
}

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

.btn-outline-light {
    border-color: rgba(255, 255, 255, 0.18);
}

.algorithm-panel {
    padding: 1rem;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.panel-card-title {
    font-weight: 700;
    margin-bottom: 0.85rem;
}

.parameter-note {
    font-size: 0.9rem;
}

.char-counter {
    font-size: 0.86rem;
    color: var(--muted);
}

.helper-row,
.quick-actions,
.feature-list,
.step-stack,
.recent-stack {
    display: grid;
    gap: 0.75rem;
}

.feature-list {
    padding-left: 1rem;
    margin-bottom: 0;
}

.quick-action {
    width: 100%;
    padding: 0.9rem 1rem;
    text-align: left;
}

.recent-item {
    padding: 1rem;
}

.result-output {
    min-height: 180px;
    font-size: 1.05rem;
    letter-spacing: 0.02em;
}

.step-item {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.85rem;
    padding: 0.9rem 1rem;
}

.step-index {
    width: 2rem;
    height: 2rem;
    border-radius: 999px;
    background: rgba(68, 215, 182, 0.16);
    color: #dbfff6;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
}

.step-item.active {
    transform: translateY(-4px);
    border-color: rgba(91,140,255,0.28);
    box-shadow: 0 8px 24px rgba(0,0,0,0.25);
}

.matrix-cell.highlight {
    transform: scale(1.06);
    background: linear-gradient(135deg, rgba(91,140,255,0.18), rgba(68,215,182,0.12));
    border-color: rgba(91,140,255,0.4);
    transition: transform 220ms ease, background 220ms ease, border-color 220ms ease;
}

.row-equation.highlight {
    color: var(--accent-2);
    font-weight: 700;
}

.table-dark {
    --bs-table-bg: transparent;
    --bs-table-color: var(--text);
    --bs-table-striped-bg: rgba(255, 255, 255, 0.03);
    --bs-table-hover-bg: rgba(91, 140, 255, 0.09);
    border-color: rgba(255, 255, 255, 0.08);
}

.history-table-wrap {
    border-radius: 22px;
    overflow: hidden;
}

.empty-state {
    padding: 1.2rem;
    border-radius: 18px;
    border: 1px dashed rgba(255, 255, 255, 0.15);
    text-align: center;
}

.toast {
    border-radius: 16px;
}

@media (max-width: 991.98px) {
    .hero-shell {
        grid-template-columns: 1fr;
    }

    .hero-metrics,
    .result-stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 575.98px) {
    .hero-copy,
    .hero-panel,
    .glass-card {
        border-radius: 22px;
    }

    .hero-metrics,
    .result-stats {
        grid-template-columns: 1fr;
    }

    .hero-copy,
    .hero-panel {
        padding: 1.25rem;
    }
}

/* Light theme overrides */
body[data-theme="light"] {
    --bg: #f8fafc;
    --bg-soft: #ffffff;
    --surface: rgba(255, 255, 255, 0.9);
    --surface-strong: rgba(255, 255, 255, 1);
    --border: rgba(11, 20, 35, 0.06);
    --text: #0b1220;
    --muted: rgba(11, 18, 32, 0.6);
    --accent: #0ea5a4;
    --accent-2: #2563eb;
    --accent-3: #f59e0b;
    --shadow: 0 12px 40px rgba(10, 18, 31, 0.06);
    background: linear-gradient(180deg, #ffffff 0%, #f3f7fb 100%);
}

/* Light-theme component overrides for readable contrasts */
body[data-theme="light"] .glass-card,
body[data-theme="light"] .hero-panel,
body[data-theme="light"] .metric-card,
body[data-theme="light"] .stat-card,
body[data-theme="light"] .mini-chip,
body[data-theme="light"] .algorithm-panel,
body[data-theme="light"] .quick-action,
body[data-theme="light"] .recent-item,
body[data-theme="light"] .step-item {
    background: var(--surface-strong);
    border: 1px solid var(--border);
    color: var(--text);
}

body[data-theme="light"] .form-control,
body[data-theme="light"] .form-select {
    background: #ffffff;
    color: var(--text);
    border: 1px solid rgba(11,20,35,0.06);
}

body[data-theme="light"] .form-control::placeholder {
    color: rgba(11,18,32,0.36);
}

body[data-theme="light"] .form-select {
    background-image: none;
}

body[data-theme="light"] .form-select:focus,
body[data-theme="light"] .form-control:focus {
    box-shadow: 0 0 0 0.15rem rgba(37,99,235,0.08);
    border-color: rgba(37,99,235,0.24);
}

body[data-theme="light"] .form-select option {
    background-color: #ffffff;
    color: #0b1220;
}

body[data-theme="light"] .mini-chip,
body[data-theme="light"] .quick-action {
    background: #ffffff;
    border: 1px solid rgba(11,20,35,0.04);
    color: var(--text);
}

body[data-theme="light"] .btn-outline-light {
    color: var(--text);
    background: transparent;
    border-color: rgba(11,20,35,0.08);
}

body[data-theme="light"] .btn-outline-light:hover {
    background: rgba(37,99,235,0.06);
}

body[data-theme="light"] .matrix-cell {
    background: #f7f9fc;
    border: 1px solid rgba(11,20,35,0.06);
    color: var(--text);
}

body[data-theme="light"] .parameter-note,
body[data-theme="light"] .panel-text,
body[data-theme="light"] .text-secondary,
body[data-theme="light"] .feature-list,
body[data-theme="light"] .empty-state {
    color: rgba(11,18,32,0.6) !important;
}

body[data-theme="light"] .badge.text-bg-light {
    background: rgba(11,20,35,0.06);
    color: var(--text);
}

/* Ensure KaTeX rendered math uses dark text in light mode */
body[data-theme="light"] .math-expression,
body[data-theme="light"] .katex {
    color: var(--text);
}

/* Improve formula box visibility in light theme */
body[data-theme="light"] .formula-box {
    background: linear-gradient(180deg, #fbfdff 0%, #f7fbff 100%);
    border: 1px solid rgba(11,20,35,0.06);
    box-shadow: 0 6px 18px rgba(10,18,32,0.04);
}

body[data-theme="light"] .formula-box .formula-icon {
    background: rgba(37,99,235,0.12);
    color: #0b1220;
}

body[data-theme="light"] .formula-box strong,
body[data-theme="light"] .formula-box .math-expression {
    color: #07111f;
}

body[data-theme="light"] .formula-box .parameter-note {
    color: rgba(11,18,32,0.56);
}

/* Ensure select options remain readable in dark and light */
.form-select option {
    /* Dark-theme defaults for native option list: dark bg, light text */
    background-color: rgba(11, 18, 32, 0.98);
    color: var(--text);
}

.form-select option:checked,
.form-select option:hover,
.form-select option:focus {
    background-color: rgba(91, 140, 255, 0.12);
    color: var(--text);
}

/* Light theme: ensure options remain readable */
body[data-theme="light"] .form-select option {
    background-color: #ffffff;
    color: #0b1220;
}

body[data-theme="light"] .form-select option:checked,
body[data-theme="light"] .form-select option:hover,
body[data-theme="light"] .form-select option:focus {
    background-color: #dbeafe;
    color: #0b1220;
}

/* Additional thorough light-theme fixes for readability */
body[data-theme="light"] {
    --muted: rgba(11, 18, 32, 0.72);
}

/* Eyebrow and headings in light mode should be slightly darker for contrast */
body[data-theme="light"] .eyebrow {
    color: rgba(11,18,32,0.56);
}

body[data-theme="light"] .section-title,
body[data-theme="light"] .hero-copy h1,
body[data-theme="light"] .result-hero h1,
body[data-theme="light"] .mini-title,
body[data-theme="light"] .panel-card-title {
    color: #07111f;
}

/* Ensure textarea/result-output is readable */
body[data-theme="light"] .result-output {
    background: #ffffff;
    color: #0b1220;
    border: 1px solid rgba(11,20,35,0.06);
}

/* Toast contrast in light mode */
body[data-theme="light"] .toast {
    background: #fff;
    color: #0b1220;
    border: 1px solid rgba(11,20,35,0.06);
}

/* Step index contrast */
body[data-theme="light"] .step-index {
    background: rgba(37,99,235,0.08);
    color: #0b1220;
}

/* Ensure badges (secondary) visible */
body[data-theme="light"] .badge.bg-secondary {
    background: rgba(11,20,35,0.06);
    color: #0b1220;
}

/* Buttons primary and outline contrast tweaks */
body[data-theme="light"] .btn-primary {
    box-shadow: 0 12px 24px rgba(37,99,235,0.06);
}

/* quick-action and mini-chip text contrast */
body[data-theme="light"] .quick-action,
body[data-theme="light"] .mini-chip {
    color: #0b1220;
}

/* ensure details summary in light mode looks like a button */
body[data-theme="light"] .hill-details summary {
    background: rgba(11,20,35,0.04);
    border: 1px solid rgba(11,20,35,0.04);
    color: #0b1220;
}