/* Global & Theme Definitions */
:root, [data-theme="dark"] {
    --theme-mode: dark;
    --bg-page: #0b1120;
    --bg-surface: #111827;
    --bg-surface-secondary: #1f2937;
    --border-subtle: #374151;
    --border-strong: #4b5563;
    --text-primary: #f9fafb;
    --text-secondary: #9ca3af;
    --text-muted: #6b7280;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --accent-text: #ffffff;
    --input-bg: #0b1120;
    --input-border: #374151;
    --btn-inactive-bg: #1f2937;
    --btn-inactive-border: #374151;
    --btn-inactive-text: #f3f4f6;
    --btn-inactive-hover: #374151;
    --shadow-card: 0 4px 20px rgba(0, 0, 0, 0.4);
    --canvas-bg: #0b1120;
    --canvas-grid: rgba(255, 255, 255, 0.05);
    --canvas-axes: #94a3b8;
    --canvas-text: #f8fafc;
    --canvas-unit-circle: rgba(56, 189, 248, 0.35);
    --canvas-region-fill0: rgba(59, 130, 246, 0.35);
    --canvas-region-fill1: rgba(139, 92, 246, 0.2);
    --canvas-region-fill2: rgba(236, 72, 153, 0.12);
    --canvas-region-stroke: #60a5fa;
    --canvas-farey-root: #ffffff;
    --canvas-farey-stroke: #0b1120;
    --canvas-trail: #f472b6;
    --canvas-base-point: #60a5fa;
}

[data-theme="light"] {
    --theme-mode: light;
    --bg-page: #f8fafc;
    --bg-surface: #ffffff;
    --bg-surface-secondary: #f1f5f9;
    --border-subtle: #e2e8f0;
    --border-strong: #cbd5e1;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-text: #ffffff;
    --input-bg: #ffffff;
    --input-border: #cbd5e1;
    --btn-inactive-bg: #ffffff;
    --btn-inactive-border: #cbd5e1;
    --btn-inactive-text: #1e293b;
    --btn-inactive-hover: #f1f5f9;
    --shadow-card: 0 2px 10px rgba(0, 0, 0, 0.06);
    --canvas-bg: #ffffff;
    --canvas-grid: #e2e8f0;
    --canvas-axes: #334155;
    --canvas-text: #0f172a;
    --canvas-unit-circle: rgba(37, 99, 235, 0.3);
    --canvas-region-fill0: rgba(37, 99, 235, 0.22);
    --canvas-region-fill1: rgba(99, 102, 241, 0.14);
    --canvas-region-fill2: rgba(147, 51, 234, 0.08);
    --canvas-region-stroke: #1d4ed8;
    --canvas-farey-root: #0f172a;
    --canvas-farey-stroke: #ffffff;
    --canvas-trail: #db2777;
    --canvas-base-point: #2563eb;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-page);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    overflow-y: auto;
    transition: background-color 0.2s ease, color 0.2s ease;
}

body.app-page {
    height: 100vh;
    overflow: hidden;
}

/* Top Navigation Component */
hub-nav {
    display: block;
    width: 100%;
}

/* REAL Top Navigation Bar */
.top-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 64px;
    min-height: 64px;
    padding: 0 1.5rem;
    background: var(--bg-surface);
    border-bottom: 2px solid var(--border-subtle);
    box-shadow: var(--shadow-card);
    z-index: 50;
    flex-shrink: 0;
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    text-decoration: none;
}

.nav-logo-badge {
    background: linear-gradient(135deg, #2563eb 0%, #7c3aed 100%);
    color: #ffffff;
    font-weight: 800;
    font-size: 0.85rem;
    padding: 0.35rem 0.65rem;
    border-radius: 8px;
    letter-spacing: 0.05em;
    box-shadow: 0 2px 6px rgba(37, 99, 235, 0.35);
}

.nav-brand-text {
    display: flex;
    flex-direction: column;
}

.nav-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.nav-subtitle {
    font-size: 0.72rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Nav Center: Real Buttons */
.nav-center {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.nav-button {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.55rem 1.15rem;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    background: var(--btn-inactive-bg);
    border: 1px solid var(--btn-inactive-border);
    color: var(--btn-inactive-text);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    transition: all 0.18s cubic-bezier(0.4, 0, 0.2, 1);
}

.nav-button:hover {
    background: var(--btn-inactive-hover);
    color: var(--text-primary);
    border-color: var(--accent);
    transform: translateY(-1px);
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.12);
}

.nav-button:active {
    transform: translateY(0);
}

.nav-button.active {
    background: var(--accent);
    color: #ffffff;
    border-color: var(--accent-hover);
    box-shadow: 0 2px 10px rgba(37, 99, 235, 0.4);
}

.nav-button .nav-btn-icon {
    font-size: 1rem;
    display: inline-block;
}

/* Nav Right: Theme Toggle Buttons */
.nav-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.theme-switch-group {
    display: flex;
    align-items: center;
    background: var(--bg-surface-secondary);
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    padding: 0.2rem;
    gap: 0.2rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.theme-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.4rem 0.75rem;
    border-radius: 6px;
    font-size: 0.78rem;
    font-weight: 600;
    border: 1px solid transparent;
    cursor: pointer;
    background: transparent;
    color: var(--text-secondary);
    font-family: inherit;
    transition: all 0.15s ease;
}

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

.theme-btn.active {
    background: var(--bg-surface);
    color: var(--text-primary);
    border-color: var(--border-strong);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
}

/* App Container */
.app-container {
    display: flex;
    height: calc(100vh - 64px);
    padding: 1.25rem;
    gap: 1.25rem;
}

.glass {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: 14px;
    box-shadow: var(--shadow-card);
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

/* Sidebar for Trace Polytope Gallery */
.sidebar {
    width: 360px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-header {
    padding: 1.25rem;
    border-bottom: 1px solid var(--border-subtle);
}

.sidebar-header h2 {
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 0.85rem;
    color: var(--text-primary);
}

.search-container input {
    width: 100%;
    padding: 0.65rem 0.9rem;
    border-radius: 8px;
    border: 1px solid var(--input-border);
    background: var(--input-bg);
    color: var(--text-primary);
    font-size: 0.9rem;
    outline: none;
    transition: all 0.2s ease;
}

.search-container input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}

.filters-container {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.filters-container select {
    flex: 1;
    padding: 0.45rem;
    border-radius: 6px;
    border: 1px solid var(--input-border);
    background: var(--input-bg);
    color: var(--text-primary);
    font-size: 0.75rem;
    outline: none;
    cursor: pointer;
    text-align: center;
    font-weight: 500;
}

.filters-container select:focus {
    border-color: var(--accent);
}

.filters-container select option {
    background: var(--bg-surface);
    color: var(--text-primary);
}

.plot-list {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
}

.plot-list::-webkit-scrollbar {
    width: 6px;
}
.plot-list::-webkit-scrollbar-track {
    background: transparent;
}
.plot-list::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 4px;
}

.plot-item {
    padding: 0.85rem;
    border-radius: 10px;
    background: var(--bg-surface-secondary);
    border: 1px solid var(--border-subtle);
    cursor: pointer;
    transition: all 0.15s ease;
}

.plot-item:hover {
    border-color: var(--accent);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.plot-item.active {
    background: rgba(37, 99, 235, 0.15);
    border-color: var(--accent);
}

.plot-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.4rem;
}

.badge {
    font-size: 0.7rem;
    padding: 0.2rem 0.5rem;
    border-radius: 6px;
    font-weight: 700;
    text-transform: uppercase;
}

.badge.sniep { 
    background: rgba(37, 99, 235, 0.15); 
    color: var(--accent); 
    border: 1px solid rgba(37, 99, 235, 0.3);
}

.badge.rniep { 
    background: rgba(16, 185, 129, 0.15); 
    color: #10b981; 
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.plot-type {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.plot-vertices {
    font-family: monospace;
    font-size: 0.9rem;
    word-break: break-all;
    color: var(--text-primary);
}

.stage {
    flex: 1;
    position: relative;
    border-radius: 14px;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    box-shadow: var(--shadow-card);
}

.plot-frame {
    width: 100%;
    height: 100%;
    border-radius: 14px;
    background: #ffffff;
    transition: opacity 0.3s ease;
}

.plot-frame.hidden {
    opacity: 0;
    pointer-events: none;
    position: absolute;
}

.welcome-msg {
    padding: 2rem 3rem;
    text-align: center;
}

.welcome-msg h3 {
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.welcome-msg p {
    color: var(--text-secondary);
}


/* --- NIEP Hub Landing Page Styles --- */
.hub-page {
    overflow-y: auto !important;
    height: auto !important;
    min-height: 100vh;
}

.hub-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 3rem 1.5rem 5rem 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 4rem;
}

/* Hero Section */
.hub-hero {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 2.5rem 1rem 1rem 1rem;
}

.hero-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.35rem 0.9rem;
    border-radius: 9999px;
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    background: rgba(37, 99, 235, 0.1);
    color: var(--accent);
    border: 1px solid rgba(37, 99, 235, 0.25);
    margin-bottom: 1.25rem;
}

.hero-title {
    font-size: 2.75rem;
    font-weight: 800;
    line-height: 1.15;
    letter-spacing: -0.02em;
    color: var(--text-primary);
    max-width: 850px;
    margin-bottom: 1.25rem;
}

.hero-subtitle {
    font-size: 1.15rem;
    line-height: 1.6;
    color: var(--text-secondary);
    max-width: 720px;
    margin-bottom: 2.25rem;
}

.hero-cta-group {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    justify-content: center;
}

.hero-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.4rem;
    border-radius: 10px;
    font-size: 0.95rem;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.2s ease;
    cursor: pointer;
}

.hero-btn.primary {
    background: var(--accent);
    color: #ffffff;
    border: 1px solid var(--accent-hover);
    box-shadow: 0 4px 14px rgba(37, 99, 235, 0.35);
}

.hero-btn.primary:hover {
    background: var(--accent-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(37, 99, 235, 0.45);
}

.hero-btn.secondary {
    background: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid var(--border-strong);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.hero-btn.secondary:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
}

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

.hero-btn.tertiary:hover {
    color: var(--text-primary);
}

/* Tools Section */
.hub-tools-section, .hub-theory-section {
    display: flex;
    flex-direction: column;
}

.section-title {
    font-size: 1.85rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.35rem;
    letter-spacing: -0.01em;
}

.section-subtitle {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: 1.75rem;
}

.tools-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr));
    gap: 2rem;
}

@media (max-width: 640px) {
    .tools-grid {
        grid-template-columns: 1fr;
        gap: 1.25rem;
    }
}

.tool-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: var(--shadow-card);
    display: flex;
    flex-direction: column;
    transition: transform 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
}

.tool-card:hover {
    transform: translateY(-4px);
    border-color: var(--accent);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.15);
}

.tool-card-banner {
    padding: 1.75rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-subtle);
}

.karpelevich-banner {
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.15) 0%, rgba(124, 58, 237, 0.15) 100%);
}

.polytope-banner {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.15) 0%, rgba(37, 99, 235, 0.15) 100%);
}

.profile-banner {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.15) 0%, rgba(124, 58, 237, 0.15) 100%);
}

.realizer-banner {
    background: linear-gradient(135deg, rgba(236, 72, 153, 0.15) 0%, rgba(99, 102, 241, 0.15) 100%);
}

.banner-icon {
    font-size: 2.4rem;
}

.banner-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    justify-content: flex-end;
}

.mini-tag {
    font-size: 0.72rem;
    font-weight: 600;
    padding: 0.25rem 0.6rem;
    border-radius: 6px;
    background: var(--bg-surface);
    border: 1px solid var(--border-strong);
    color: var(--text-secondary);
}

.tool-card-body {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    flex: 1;
}

.tool-card-title {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.75rem;
}

.tool-card-desc {
    font-size: 0.92rem;
    line-height: 1.55;
    color: var(--text-secondary);
    margin-bottom: 1.25rem;
    flex: 1;
}

.tool-card-features {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    margin-bottom: 1.5rem;
    padding-top: 0.85rem;
    border-top: 1px solid var(--border-subtle);
}

.feature-item {
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-primary);
}

.tool-card-footer {
    margin-top: auto;
}

.tool-launch-btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.2rem;
    border-radius: 10px;
    font-size: 0.92rem;
    font-weight: 700;
    text-decoration: none;
    transition: all 0.2s ease;
}

.tool-launch-btn.primary {
    background: var(--accent);
    color: #ffffff;
}

.tool-launch-btn.primary:hover {
    background: var(--accent-hover);
}

.tool-launch-btn.secondary {
    background: var(--bg-surface-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-strong);
}

.tool-launch-btn.secondary:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.tool-launch-btn .arrow {
    font-size: 1.1rem;
    transition: transform 0.2s ease;
}

.tool-launch-btn:hover .arrow {
    transform: translateX(4px);
}

/* Theory Cards */
.theory-cards-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
}

.theory-info-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: 14px;
    padding: 1.5rem;
    box-shadow: var(--shadow-card);
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.info-card-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.info-number {
    font-size: 1.2rem;
    font-weight: 800;
    font-family: monospace;
    color: var(--accent);
    background: rgba(37, 99, 235, 0.1);
    padding: 0.2rem 0.5rem;
    border-radius: 6px;
}

.info-card-header h3 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.theory-info-card p {
    font-size: 0.88rem;
    line-height: 1.6;
    color: var(--text-secondary);
}

.theory-info-card code {
    background: var(--bg-surface-secondary);
    border: 1px solid var(--border-subtle);
    padding: 0.15rem 0.35rem;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.82rem;
    color: var(--text-primary);
}

/* Hub Footer */
hub-footer {
    display: block;
}
.hub-footer {
    border-top: 1px solid var(--border-subtle);
    padding-top: 2.5rem;
    padding-bottom: 2rem;
    margin-top: 3rem;
}

.footer-container {
    max-width: 1280px;
    margin: 0 auto 2.5rem;
    padding: 0 1.5rem;
    display: grid;
    grid-template-columns: 1.8fr 1fr 1fr 1fr;
    gap: 2.5rem;
}

@media (max-width: 960px) {
    .footer-container {
        grid-template-columns: 1fr 1fr;
        gap: 2rem;
    }
}

@media (max-width: 540px) {
    .footer-container {
        grid-template-columns: 1fr;
        gap: 1.75rem;
    }
}

.footer-brand .footer-logo {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--text-primary);
    text-decoration: none;
    margin-bottom: 0.75rem;
}

.footer-brand .footer-tagline {
    font-size: 0.88rem;
    color: var(--text-secondary);
    line-height: 1.55;
    margin: 0 0 1rem 0;
    max-width: 320px;
}

.footer-brand-links {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.footer-ext-link {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.8rem;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.82rem;
    font-weight: 500;
    text-decoration: none;
    transition: all 0.2s ease;
}

.footer-ext-link:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--bg-surface-secondary);
    transform: translateY(-1px);
}

.footer-col-title {
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    display: block;
    margin-bottom: 0.85rem;
}

.footer-links-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.footer-links-group a {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.87rem;
    transition: color 0.15s ease;
}

.footer-links-group a:hover {
    color: var(--accent);
}

.footer-bottom {
    max-width: 1280px;
    margin: 0 auto;
    padding: 1.5rem 1.5rem 0;
    border-top: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem 1.5rem;
    color: var(--text-muted);
    font-size: 0.82rem;
}

.footer-bottom-links {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem 0.75rem;
}

.footer-bottom-links a {
    color: var(--text-muted);
    text-decoration: none;
    transition: color 0.15s ease;
}

.footer-bottom-links a:hover {
    color: var(--accent);
}

@media (max-width: 640px) {
    .footer-bottom {
        flex-direction: column;
        text-align: center;
        gap: 0.75rem;
    }
    .footer-bottom-links {
        justify-content: center;
    }
}
/* Site Development Disclaimer Banner */
.dev-disclaimer-banner {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    padding: 0.85rem 1.25rem;
    background: rgba(245, 158, 11, 0.12);
    border: 1px solid rgba(245, 158, 11, 0.35);
    border-radius: 12px;
    margin-bottom: 2rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.dev-disclaimer-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem 0.65rem;
    border-radius: 6px;
    background: #d97706;
    color: #ffffff;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    white-space: nowrap;
    flex-shrink: 0;
}

.dev-disclaimer-text {
    font-size: 0.92rem;
    line-height: 1.5;
    color: var(--text-primary);
    margin: 0;
}

@media (max-width: 640px) {
    .dev-disclaimer-banner {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
}

/* Theory Section Enhancements */
.hub-theory-section {
    display: flex;
    flex-direction: column;
    gap: 3.5rem;
    margin-top: 1.5rem;
}

.theory-subsection {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.theory-subheading-group {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.theory-subheading {
    font-size: 1.45rem;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.theory-sub-desc {
    font-size: 0.95rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.theory-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.6rem;
    border-radius: 6px;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    width: fit-content;
}

.theory-badge.foundation {
    background: rgba(59, 130, 246, 0.15);
    color: #60a5fa;
    border: 1px solid rgba(59, 130, 246, 0.3);
}

.theory-badge.milestone {
    background: rgba(16, 185, 129, 0.15);
    color: #10b981;
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.theory-badge.geometry {
    background: rgba(168, 85, 247, 0.15);
    color: #c084fc;
    border: 1px solid rgba(168, 85, 247, 0.3);
}

.theory-badge.modern {
    background: rgba(245, 158, 11, 0.15);
    color: #f59e0b;
    border: 1px solid rgba(245, 158, 11, 0.3);
}

.theory-formula {
    background: var(--bg-surface-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    padding: 0.85rem 1.15rem;
    font-size: 0.92rem;
    color: var(--text-primary);
    line-height: 1.6;
    margin: 0.5rem 0;
    overflow-x: auto;
}

.theory-formula mjx-container[jax="CHTML"][display="true"] {
    margin: 0.25rem 0 !important;
}

/* Bibliography Grid & Cards */
.bib-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 1.5rem;
}

.bib-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    padding: 1.4rem;
    box-shadow: var(--shadow-card);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 1rem;
    transition: all 0.2s ease;
}

.bib-card:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

.bib-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.bib-year {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-muted);
}

.bib-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.4;
    margin: 0;
}

.bib-authors {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--accent);
    margin: 0;
}

.bib-venue {
    font-size: 0.82rem;
    color: var(--text-secondary);
    line-height: 1.5;
    margin: 0;
    font-style: italic;
}

.bib-actions {
    display: flex;
    gap: 0.6rem;
    margin-top: auto;
}

.bib-link {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.35rem 0.75rem;
    border-radius: 6px;
    font-size: 0.78rem;
    font-weight: 600;
    text-decoration: none;
    background: var(--bg-surface-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-subtle);
    transition: all 0.18s ease;
}

.bib-link:hover {
    background: var(--accent);
    color: #ffffff;
    border-color: var(--accent);
}


/* ==========================================================================
   Stacked Core Formulation & Equation Polish
   ========================================================================== */

.theory-cards-container.stacked {
    grid-template-columns: 1fr;
    gap: 1.5rem;
}

.theory-cards-container.stacked .theory-info-card {
    padding: 1.75rem 2rem;
}

/* Subproblems 2x2 Grid inside Card 02 */
.subproblems-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 1rem;
    margin-top: 0.5rem;
}

.subproblem-item {
    background: var(--bg-surface-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: 10px;
    padding: 1rem 1.15rem;
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    transition: transform 0.2s ease, border-color 0.2s ease;
}

.subproblem-item:hover {
    border-color: var(--border-hover);
    transform: translateY(-2px);
}

.subproblem-tag {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--accent);
    background: rgba(37, 99, 235, 0.1);
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    width: fit-content;
}

.subproblem-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}

.subproblem-desc {
    font-size: 0.85rem;
    line-height: 1.55;
    color: var(--text-secondary);
    margin: 0;
}

/* Conditions Grid inside Card 03 */
.conditions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1rem;
    margin-top: 0.5rem;
}

.condition-card {
    background: var(--bg-surface-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: 10px;
    padding: 1.1rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    transition: transform 0.2s ease, border-color 0.2s ease;
}

.condition-card:hover {
    border-color: var(--border-hover);
    transform: translateY(-2px);
}

.condition-header {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.condition-num {
    font-family: monospace;
    font-weight: 800;
    font-size: 0.8rem;
    color: var(--accent);
    background: rgba(37, 99, 235, 0.12);
    padding: 0.15rem 0.45rem;
    border-radius: 4px;
}

.condition-title {
    font-size: 0.92rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}

.condition-formula {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: 6px;
    padding: 0.65rem 0.85rem;
    margin: 0.25rem 0;
    text-align: center;
    font-size: 0.9rem;
    overflow-x: auto;
    scrollbar-width: thin;
}

.condition-formula mjx-container[jax="CHTML"][display="true"] {
    margin: 0.15rem 0 !important;
}

.condition-note {
    font-size: 0.82rem;
    color: var(--text-muted);
    line-height: 1.5;
    margin: 0;
}

/* Deep-Dive Callout Banner */
.deep-dive-callout {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1.5rem;
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.08) 0%, rgba(139, 92, 246, 0.08) 100%);
    border: 1px solid rgba(37, 99, 235, 0.25);
    border-radius: 14px;
    padding: 1.35rem 1.75rem;
    margin-top: 1.5rem;
    flex-wrap: wrap;
}

.deep-dive-callout-text {
    flex: 1;
    min-width: 280px;
}

.deep-dive-callout-text h4 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0 0 0.3rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.deep-dive-callout-text p {
    font-size: 0.88rem;
    color: var(--text-secondary);
    line-height: 1.55;
    margin: 0;
}

.deep-dive-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.75rem 1.4rem;
    background: var(--accent);
    color: #ffffff !important;
    font-weight: 600;
    font-size: 0.9rem;
    border-radius: 8px;
    text-decoration: none;
    transition: all 0.2s ease;
    white-space: nowrap;
    box-shadow: 0 4px 14px rgba(37, 99, 235, 0.3);
}

.deep-dive-btn:hover {
    background: var(--accent-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(37, 99, 235, 0.4);
}

.deep-dive-btn .arrow {
    transition: transform 0.2s ease;
}

.deep-dive-btn:hover .arrow {
    transform: translateX(4px);
}

/* ==========================================================================
   Comprehensive Problem Background & Deep-Dive Page Styles
   ========================================================================== */

.deepdive-container {
    max-width: 1360px;
    width: 92%;
    margin: 0 auto;
    padding: 2.5rem 2rem 5rem;
}

.deepdive-breadcrumb {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

.deepdive-breadcrumb a {
    color: var(--accent);
    text-decoration: none;
    transition: color 0.15s ease;
}

.deepdive-breadcrumb a:hover {
    text-decoration: underline;
}

.deepdive-hero {
    margin-bottom: 2.5rem;
    text-align: left;
}

.deepdive-hero .hero-badge {
    margin-bottom: 0.85rem;
}

.deepdive-hero .hero-title {
    font-size: 2.5rem;
    line-height: 1.2;
    margin-bottom: 1rem;
}

.deepdive-hero .hero-subtitle {
    font-size: 1.15rem;
    line-height: 1.65;
    color: var(--text-secondary);
    max-width: 860px;
}

/* Quick Navigation / Table of Contents */
.deepdive-toc {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    padding: 1.25rem 1.5rem;
    margin-bottom: 3rem;
    box-shadow: var(--shadow-card);
}

.deepdive-toc-title {
    font-size: 0.9rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin: 0 0 0.85rem;
    display: flex;
    align-items: center;
    gap: 0.45rem;
}

.deepdive-toc-links {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem 1.2rem;
    list-style: none;
    padding: 0;
    margin: 0;
}

.deepdive-toc-links a {
    font-size: 0.88rem;
    color: var(--text-secondary);
    text-decoration: none;
    transition: color 0.15s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.deepdive-toc-links a:hover {
    color: var(--accent);
}

/* Article Sections */
.deepdive-section {
    margin-bottom: 3.5rem;
    scroll-margin-top: 5rem;
}

.deepdive-section-header {
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-subtle);
    padding-bottom: 0.75rem;
    display: flow-root;
}

.deepdive-section-title {
    font-size: 1.7rem;
    font-weight: 800;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.65rem;
    margin: 0 0 0.4rem;
}

.deepdive-section-desc {
    font-size: 0.95rem;
    color: var(--text-secondary);
    margin: 0;
    line-height: 1.6;
}

.deepdive-text {
    font-size: 0.95rem;
    line-height: 1.75;
    color: var(--text-secondary);
    margin-bottom: 1.2rem;
}

.deepdive-text strong {
    color: var(--text-primary);
}

/* Mathematical Callout Boxes */
.math-callout {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-left: 4px solid var(--accent);
    border-radius: 10px;
    padding: 1.4rem 1.6rem;
    margin: 1.5rem 0;
    box-shadow: var(--shadow-card);
    display: flow-root;
}

.math-callout.definition {
    border-left-color: #3b82f6;
    background: linear-gradient(to right, rgba(59, 130, 246, 0.04), var(--bg-surface));
}

.math-callout.theorem {
    border-left-color: #10b981;
    background: linear-gradient(to right, rgba(16, 185, 129, 0.04), var(--bg-surface));
}

.math-callout.conjecture {
    border-left-color: #f59e0b;
    background: linear-gradient(to right, rgba(245, 158, 11, 0.04), var(--bg-surface));
}

.math-callout.milestone {
    border-left-color: #8b5cf6;
    background: linear-gradient(to right, rgba(139, 92, 246, 0.04), var(--bg-surface));
}

.math-callout.question {
    border-left-color: #6366f1;
    background: linear-gradient(to right, rgba(99, 102, 241, 0.04), var(--bg-surface));
}

.math-callout.proposition {
    border-left-color: #0284c7;
    background: linear-gradient(to right, rgba(2, 132, 199, 0.04), var(--bg-surface));
}

.math-callout.lemma {
    border-left-color: #14b8a6;
    background: linear-gradient(to right, rgba(20, 184, 166, 0.04), var(--bg-surface));
}

.math-callout-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.math-callout-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0;
}

.math-callout-tag {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.2rem 0.55rem;
    border-radius: 4px;
}

.math-callout.definition .math-callout-tag {
    background: rgba(59, 130, 246, 0.15);
    color: #3b82f6;
}

.math-callout.theorem .math-callout-tag {
    background: rgba(16, 185, 129, 0.15);
    color: #10b981;
}

.math-callout.conjecture .math-callout-tag {
    background: rgba(245, 158, 11, 0.15);
    color: #f59e0b;
}

.math-callout.milestone .math-callout-tag {
    background: rgba(139, 92, 246, 0.15);
    color: #8b5cf6;
}

.math-callout.question .math-callout-tag {
    background: rgba(99, 102, 241, 0.15);
    color: #6366f1;
}

.math-callout.proposition .math-callout-tag {
    background: rgba(2, 132, 199, 0.15);
    color: #0284c7;
}

.math-callout.lemma .math-callout-tag {
    background: rgba(20, 184, 166, 0.15);
    color: #14b8a6;
}

/* LaTeX formula selection and copy tool */
mjx-container {
    user-select: text !important;
    -webkit-user-select: text !important;
}

.display-math-container {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 1.25rem 0;
    overflow-x: auto;
    padding: 0.35rem 0;
}

.display-math-container mjx-container {
    margin: 0 !important;
}

.copy-latex-btn {
    position: absolute;
    right: 0.25rem;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, background 0.15s ease, color 0.15s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    background: var(--bg-surface-secondary);
    border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    border-radius: 6px;
    padding: 0.22rem 0.55rem;
    font-size: 0.72rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-weight: 600;
    cursor: pointer;
    z-index: 10;
}

.display-math-container:hover .copy-latex-btn {
    opacity: 1;
    pointer-events: auto;
}

.copy-latex-btn:hover {
    background: var(--accent);
    color: #ffffff;
    border-color: var(--accent);
}

.copy-latex-btn.copied {
    background: #059669 !important;
    color: #ffffff !important;
    border-color: #059669 !important;
}

.latex-toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: #111827;
    color: #f9fafb;
    border: 1px solid #374151;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-size: 0.82rem;
    font-weight: 500;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
    opacity: 0;
    pointer-events: none;
    transition: all 0.25s ease;
    z-index: 9999;
}

.latex-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Dimension Solvability Grid */
.dim-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.25rem;
    margin: 1.5rem 0;
}

.dim-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    padding: 1.4rem;
    box-shadow: var(--shadow-card);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.dim-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.dim-number {
    font-size: 1.35rem;
    font-weight: 800;
    font-family: monospace;
    color: var(--accent);
}

.dim-status {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
}

.dim-status.solved {
    background: rgba(16, 185, 129, 0.15);
    color: #10b981;
}

.dim-status.open {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
}

.dim-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}

.dim-desc {
    font-size: 0.88rem;
    line-height: 1.6;
    color: var(--text-secondary);
    margin: 0;
}

/* Tool Integration Callouts on Problem Background Page */
.deepdive-tools-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.25rem;
    margin: 2rem 0;
}

.deepdive-tool-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    padding: 1.4rem;
    box-shadow: var(--shadow-card);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 1rem;
    transition: transform 0.2s ease, border-color 0.2s ease;
}

.deepdive-tool-card:hover {
    transform: translateY(-3px);
    border-color: var(--accent);
}

.deepdive-tool-icon {
    font-size: 1.8rem;
}

.deepdive-tool-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0 0 0.35rem;
}

.deepdive-tool-desc {
    font-size: 0.86rem;
    line-height: 1.55;
    color: var(--text-secondary);
    margin: 0;
}


/* ==========================================================================
   Major Open Problems Section Styles
   ========================================================================== */

.open-problems-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 1.5rem;
}

.open-problem-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: 14px;
    padding: 1.5rem;
    box-shadow: var(--shadow-card);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 1rem;
    transition: transform 0.2s ease, border-color 0.2s ease;
    position: relative;
    overflow: hidden;
}

.open-problem-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, #ec4899, #8b5cf6);
}

.open-problem-card:hover {
    transform: translateY(-2px);
    border-color: rgba(236, 72, 153, 0.4);
}

.open-problem-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.open-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    background: rgba(236, 72, 153, 0.15);
    color: #ec4899;
    border: 1px solid rgba(236, 72, 153, 0.3);
}

.open-badge.conjecture {
    background: rgba(245, 158, 11, 0.15);
    color: #f59e0b;
    border-color: rgba(245, 158, 11, 0.3);
}

.open-badge.frontier {
    background: rgba(139, 92, 246, 0.15);
    color: #8b5cf6;
    border-color: rgba(139, 92, 246, 0.3);
}

.open-badge.geometry {
    background: rgba(16, 185, 129, 0.15);
    color: #10b981;
    border-color: rgba(16, 185, 129, 0.3);
}

.open-problem-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}

.open-problem-desc {
    font-size: 0.88rem;
    line-height: 1.6;
    color: var(--text-secondary);
    margin: 0;
}

.open-challenge-box {
    background: var(--bg-surface-secondary);
    border-left: 3px solid #ec4899;
    border-radius: 0 8px 8px 0;
    padding: 0.7rem 0.95rem;
    font-size: 0.82rem;
    color: var(--text-secondary);
    line-height: 1.5;
    margin-top: auto;
}

.open-challenge-box strong {
    color: var(--text-primary);
}


/* ==========================================================================
   Theory Wiki Navigation & Infobox Styles
   ========================================================================== */

.wiki-subnav {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    padding: 0.65rem 0.9rem;
    margin-bottom: 2rem;
    box-shadow: var(--shadow-card);
}

.wiki-subnav-label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    padding: 0 0.5rem 0 0.2rem;
    border-right: 1px solid var(--border-subtle);
}

.wiki-tab {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.85rem;
    border-radius: 8px;
    font-size: 0.84rem;
    font-weight: 600;
    text-decoration: none;
    color: var(--text-secondary);
    background: transparent;
    border: 1px solid transparent;
    transition: all 0.18s ease;
}

.wiki-tab:hover {
    color: var(--text-primary);
    background: var(--bg-surface-secondary);
    border-color: var(--border-subtle);
}

.wiki-tab.active {
    background: rgba(37, 99, 235, 0.12);
    color: var(--accent);
    border-color: rgba(37, 99, 235, 0.3);
}

/* Wiki Article Layout with Quick Facts Infobox */
.wiki-layout {
    display: block;
    margin-bottom: 3rem;
}

.wiki-layout::after {
    content: '';
    display: table;
    clear: both;
}

.wiki-main-content {
    min-width: 0;
}

.wiki-infobox {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: 14px;
    padding: 1.5rem 1.4rem;
    box-shadow: var(--shadow-card);
    overflow: hidden;
}

@media (min-width: 961px) {
    .wiki-infobox {
        float: right;
        width: 360px;
        margin: 0.5rem 0 3rem 2.5rem;
        position: relative;
        z-index: 2;
    }
}

@media (max-width: 960px) {
    .wiki-infobox {
        float: none;
        width: 100%;
        margin: 0 0 2.5rem 0;
        padding: 1.4rem;
    }
}

.wiki-infobox-header {
    border-bottom: 1px solid var(--border-subtle);
    padding-bottom: 0.85rem;
    margin-bottom: 1rem;
    text-align: center;
}

.wiki-infobox-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    background: rgba(37, 99, 235, 0.12);
    color: var(--accent);
    margin-bottom: 0.5rem;
}

.wiki-infobox-title {
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--text-primary);
    margin: 0;
}

.wiki-infobox-subtitle {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin: 0.25rem 0 0;
}

.wiki-infobox-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
    table-layout: fixed;
}

.wiki-infobox-table tr {
    border-bottom: 1px solid var(--border-subtle);
}

.wiki-infobox-table tr:last-child {
    border-bottom: none;
}

.wiki-infobox-table th {
    text-align: left;
    padding: 0.65rem 0.5rem 0.65rem 0;
    color: var(--text-muted);
    font-weight: 600;
    vertical-align: top;
    width: 38%;
    word-break: break-word;
}

.wiki-infobox-table td {
    padding: 0.65rem 0 0.65rem 0.5rem;
    color: var(--text-primary);
    font-weight: 500;
    vertical-align: top;
    overflow-wrap: break-word;
    word-break: break-word;
}

.wiki-infobox-table td mjx-container {
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    vertical-align: middle;
}

.wiki-infobox-links {
    margin-top: 1rem;
    padding-top: 0.85rem;
    border-top: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}

.wiki-infobox-link {
    font-size: 0.82rem;
    color: var(--accent);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    transition: color 0.15s ease;
}

.wiki-infobox-link:hover {
    text-decoration: underline;
}

/* Wiki See Also Cards */
.wiki-see-also-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 1.25rem;
    margin-top: 1rem;
}

.wiki-see-also-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    padding: 1.2rem;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 0.75rem;
    text-decoration: none;
    transition: transform 0.2s ease, border-color 0.2s ease;
}

.wiki-see-also-card:hover {
    transform: translateY(-2px);
    border-color: var(--accent);
}

.wiki-see-also-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.45rem;
    margin: 0;
}

.wiki-see-also-desc {
    font-size: 0.82rem;
    color: var(--text-secondary);
    line-height: 1.5;
    margin: 0;
}

/* Feature Cards for Wiki Pages */
.feature-card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 1.25rem;
    margin: 1.5rem 0;
}

.feature-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    padding: 1.3rem;
    box-shadow: var(--shadow-card);
    transition: transform 0.2s ease, border-color 0.2s ease;
}

.feature-card:hover {
    transform: translateY(-2px);
    border-color: var(--accent);
}

.feature-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0 0 0.4rem 0;
}

.feature-desc {
    font-size: 0.88rem;
    line-height: 1.6;
    color: var(--text-secondary);
    margin: 0;
}

/* ==========================================================================
   Mobile Experience & Responsive Enhancements
   ========================================================================== */

/* Top Navigation Responsive Layout */
@media (max-width: 960px) {
    .top-nav {
        height: auto;
        min-height: auto;
        padding: 0.65rem 1rem;
        flex-wrap: wrap;
        row-gap: 0.5rem;
    }

    .nav-brand {
        flex: 1;
    }

    .nav-right {
        flex-shrink: 0;
    }

    .nav-center {
        width: 100%;
        order: 3;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        flex-wrap: nowrap;
        justify-content: flex-start;
        padding: 0.2rem 0 0.35rem 0;
        gap: 0.4rem;
    }

    .nav-center::-webkit-scrollbar {
        display: none;
    }

    .nav-button {
        flex-shrink: 0;
        white-space: nowrap;
        padding: 0.45rem 0.85rem;
        font-size: 0.82rem;
    }
}

@media (max-width: 480px) {
    .nav-subtitle {
        display: none;
    }

    .nav-title {
        font-size: 0.95rem;
    }

    .nav-logo-badge {
        font-size: 0.75rem;
        padding: 0.25rem 0.5rem;
    }

    .theme-btn {
        padding: 0.35rem 0.55rem;
        font-size: 0.72rem;
    }
}

/* Hub Container & Hero Typography Scaling */
@media (max-width: 768px) {
    .hub-container {
        padding: 1.5rem 1rem 3.5rem 1rem;
        gap: 2.5rem;
    }

    .hub-hero {
        padding: 1.5rem 0.5rem 0.5rem 0.5rem;
    }

    .hero-title {
        font-size: clamp(1.75rem, 6vw, 2.5rem);
    }

    .hero-subtitle {
        font-size: 1rem;
        line-height: 1.5;
        margin-bottom: 1.75rem;
    }

    .hero-cta-group {
        flex-direction: column;
        width: 100%;
        gap: 0.75rem;
    }

    .hero-cta-group .hero-cta-btn {
        width: 100%;
        justify-content: center;
    }

    .dev-disclaimer-banner {
        padding: 0.75rem 1rem;
        margin-bottom: 1.25rem;
    }

    .section-title {
        font-size: 1.45rem;
    }

    .feature-card-grid {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
    }

    .bib-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
}

/* Theory Wiki Subnav & Layout on Mobile */
@media (max-width: 768px) {
    .wiki-subnav {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        padding: 0.5rem 0.75rem;
        margin-bottom: 1.5rem;
    }

    .wiki-subnav::-webkit-scrollbar {
        display: none;
    }

    .wiki-subnav-label {
        flex-shrink: 0;
    }

    .wiki-tab {
        flex-shrink: 0;
        white-space: nowrap;
        padding: 0.35rem 0.7rem;
        font-size: 0.8rem;
    }

    .deepdive-hero .hero-title {
        font-size: 1.65rem !important;
    }

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

    .deepdive-section {
        margin-bottom: 2.5rem;
    }

    .deepdive-section-title {
        font-size: 1.3rem;
    }
}

@media (max-width: 600px) {
    .wiki-infobox {
        padding: 1.1rem 1rem;
    }

    .wiki-infobox-table th {
        width: 36%;
        font-size: 0.78rem;
    }

    .wiki-infobox-table td {
        font-size: 0.78rem;
    }
}

/* Trace Polytope Gallery Mobile Layout */
@media (max-width: 900px) {
    body.app-page {
        height: auto;
        min-height: 100vh;
        overflow-y: auto;
    }

    .app-container {
        flex-direction: column;
        height: auto;
        min-height: calc(100vh - 64px);
        padding: 0.75rem;
        gap: 1rem;
        overflow: visible;
    }

    .sidebar {
        width: 100%;
        max-height: 320px;
    }

    .sidebar-header {
        padding: 0.9rem;
    }

    .stage {
        width: 100%;
        min-height: 440px;
        height: 60vh;
    }
}

/* Responsive Data Tables */
.data-table-wrapper {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 1.25rem 0;
    border-radius: 8px;
    border: 1px solid var(--border-subtle);
}

.data-table {
    width: 100%;
    min-width: 520px;
    border-collapse: collapse;
    font-size: 0.84rem;
}

.data-table th {
    background: var(--bg-surface-secondary);
    padding: 0.7rem 0.9rem;
    text-align: left;
    font-weight: 700;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-subtle);
}

.data-table td {
    padding: 0.7rem 0.9rem;
    border-bottom: 1px solid var(--border-subtle);
    color: var(--text-primary);
}

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

.math-callout {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.math-callout p, .deepdive-text {
    overflow-wrap: break-word;
    word-break: break-word;
}

/* ==========================================================================
   Comprehensive Bibliography & Reusable Citations Component System
   ========================================================================== */

.bib-key {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.72rem;
    color: var(--text-muted);
    background: var(--bg-surface-secondary);
    padding: 0.15rem 0.45rem;
    border-radius: 4px;
    border: 1px solid var(--border-subtle);
    user-select: all;
}

.bib-note {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.55;
    margin: 0.65rem 0;
    padding: 0.5rem 0.85rem;
    background: var(--bg-surface-secondary);
    border-left: 3px solid var(--accent);
    border-radius: 0 6px 6px 0;
}

.bib-card:target {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.4), var(--shadow-card);
    animation: bibTargetPulse 2s ease-out;
}

@keyframes bibTargetPulse {
    0% {
        transform: scale(1.02);
        box-shadow: 0 0 0 5px rgba(99, 102, 241, 0.6);
    }
    100% {
        transform: scale(1);
    }
}

.cite-inline-ref {
    display: inline-block;
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
    padding: 0 0.2rem;
    border-radius: 3px;
    transition: background 0.15s ease, color 0.15s ease;
}

.cite-inline-ref:hover {
    background: rgba(99, 102, 241, 0.15);
    text-decoration: underline;
}

/* Floating BibTeX Notification Toast */
.bib-toast {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background: #0f172a;
    color: #f8fafc;
    border: 1px solid #334155;
    padding: 0.75rem 1.25rem;
    border-radius: 8px;
    font-size: 0.88rem;
    font-weight: 600;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
    z-index: 10000;
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 0.25s ease, transform 0.25s ease;
    pointer-events: none;
}

.bib-toast.show {
    opacity: 1;
    transform: translateY(0);
}

/* Comprehensive Bibliography Page Controls */
.bib-controls-wrapper {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: 14px;
    padding: 1.5rem;
    margin: 2rem 0 2.5rem;
    box-shadow: var(--shadow-card);
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.bib-search-row {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    align-items: center;
}

.bib-search-box {
    position: relative;
    flex: 1;
    min-width: 260px;
}

.bib-search-box svg {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

.bib-search-input {
    width: 100%;
    padding: 0.75rem 1rem 0.75rem 2.6rem;
    background: var(--bg-surface-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.92rem;
    font-family: inherit;
    transition: all 0.2s ease;
}

.bib-search-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.bib-search-input::placeholder {
    color: var(--text-muted);
}

.bib-sort-wrapper {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.bib-sort-label {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
}

.bib-sort-select {
    padding: 0.7rem 1.8rem 0.7rem 0.85rem;
    background: var(--bg-surface-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.86rem;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s ease;
}

.bib-sort-select:focus {
    outline: none;
    border-color: var(--accent);
}

.bib-filter-bar {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    align-items: center;
}

.bib-filter-pill {
    padding: 0.4rem 0.85rem;
    border-radius: 9999px;
    border: 1px solid var(--border-subtle);
    background: var(--bg-surface-secondary);
    color: var(--text-secondary);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.18s ease;
}

.bib-filter-pill:hover {
    color: var(--text-primary);
    border-color: var(--accent);
}

.bib-filter-pill.active {
    background: var(--accent);
    color: #ffffff;
    border-color: var(--accent);
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

.bib-status-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-subtle);
}

.bib-count-badge {
    font-size: 0.84rem;
    font-weight: 600;
    color: var(--text-muted);
}

.bib-export-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.5rem 1rem;
    background: var(--accent);
    color: #ffffff;
    border: none;
    border-radius: 6px;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.bib-export-btn:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
}
