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

:root {
    --bg: #ffffff;
    --bg-secondary: #f8f9fa;
    --text: #1a1a2e;
    --text-secondary: #555;
    --border: #e0e0e0;
    --accent: #2c5282;
    --accent-light: #ebf4ff;
    --accent-hover: #1a365d;
    --card-bg: #ffffff;
    --card-shadow: 0 1px 3px rgba(0,0,0,0.08);
    --card-shadow-hover: 0 4px 12px rgba(0,0,0,0.12);
    --tag-theme: #e8f5e9;
    --tag-technique: #e3f2fd;
    --tag-question: #fff3e0;
    --radius: 8px;
    --font: Georgia, 'Times New Roman', serif;
    --font-mono: 'SF Mono', 'Fira Code', monospace;
}

[data-theme="dark"] {
    --bg: #1a1a2e;
    --bg-secondary: #16213e;
    --text: #e0e0e0;
    --text-secondary: #a0a0a0;
    --border: #2a2a4a;
    --accent: #63b3ed;
    --accent-light: #1a365d;
    --accent-hover: #90cdf4;
    --card-bg: #16213e;
    --card-shadow: 0 1px 3px rgba(0,0,0,0.3);
    --card-shadow-hover: 0 4px 12px rgba(0,0,0,0.4);
    --tag-theme: #1b3a26;
    --tag-technique: #172a3e;
    --tag-question: #3a2a14;
}

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

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 20px;
}

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

/* ==================== Header ==================== */
header {
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    padding: 16px 0;
    position: sticky;
    top: 0;
    z-index: 100;
}

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

header h1 {
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--text);
}

header h1 a {
    color: inherit;
    text-decoration: none;
}

.header-author {
    font-size: 0.85rem;
    font-weight: 400;
    color: var(--text-secondary);
    margin-left: 4px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

#theme-toggle {
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
}
#theme-toggle svg {
    stroke: currentColor;
    fill: none;
    stroke-width: 1.5;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.btn-primary {
    background: var(--accent);
    color: white !important;
    padding: 8px 16px;
    border-radius: var(--radius);
    font-size: 0.85rem;
    font-family: var(--font);
    text-decoration: none;
    transition: background 0.2s;
}
.btn-primary:hover {
    background: var(--accent-hover);
    color: white !important;
}

/* ==================== Browse Tabs ==================== */
.browse-tabs {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    padding: 0;
}

.browse-tabs .container {
    display: flex;
    align-items: center;
    gap: 0;
}

.tab {
    background: none;
    border: none;
    padding: 14px 24px;
    font-family: var(--font);
    font-size: 0.95rem;
    color: var(--text-secondary);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}
.tab:hover {
    color: var(--text);
}
.tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
    font-weight: 600;
}

.search-box-inline {
    margin-left: auto;
    position: relative;
}

.search-box-inline input {
    font-family: var(--font);
    font-size: 0.9rem;
    padding: 8px 32px 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text);
    width: 220px;
    outline: none;
    transition: border-color 0.2s;
}
.search-box-inline input:focus {
    border-color: var(--accent);
}

#clear-search {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 2px 4px;
}

/* ==================== Category Grid ==================== */
main {
    flex: 1;
    padding: 20px 0;
}

.category-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.category-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 14px;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: var(--card-shadow);
    width: 155px;
    min-height: 80px;
}
.category-card:hover {
    box-shadow: var(--card-shadow-hover);
    border-color: var(--accent);
    transform: translateY(-1px);
}

.card-icon {
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 1.1rem;
    color: var(--accent);
    margin-bottom: 6px;
    letter-spacing: 0.5px;
    line-height: 1;
    opacity: 0.85;
}

.category-card h3 {
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--text);
    line-height: 1.25;
}

.question-card h3 {
    font-style: italic;
}

.section-count {
    font-size: 0.7rem;
    color: var(--text-secondary);
    font-family: var(--font-mono);
}

/* ==================== Back Button ==================== */
.back-btn {
    background: none;
    border: none;
    font-family: var(--font);
    font-size: 0.9rem;
    color: var(--accent);
    cursor: pointer;
    padding: 8px 0;
    margin-bottom: 16px;
    display: inline-block;
}
.back-btn:hover {
    color: var(--accent-hover);
}

/* ==================== Section View ==================== */
.section-view h2,
.section-detail h2,
#search-results-title {
    font-size: 1.5rem;
    margin-bottom: 24px;
    color: var(--text);
}

.chapter-group {
    margin-bottom: 24px;
}

.chapter-group-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-secondary);
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 4px;
}

.section-entry {
    padding: 10px 16px;
    cursor: pointer;
    border-radius: var(--radius);
    transition: background 0.15s;
}
.section-entry:hover {
    background: var(--accent-light);
}

.section-title {
    font-size: 0.95rem;
    color: var(--text);
}

.indent-0 { padding-left: 16px; }
.indent-1 { padding-left: 36px; }
.indent-2 { padding-left: 56px; }
.indent-3 { padding-left: 76px; }

/* ==================== Section Detail ==================== */
.detail-meta {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 24px;
}

.equations-section {
    margin-top: 24px;
}

.equations-section h3 {
    font-size: 1.1rem;
    margin-bottom: 16px;
    color: var(--text);
}

.equation-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px;
    margin-bottom: 12px;
    overflow-x: auto;
}

.equation-label {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.equation-content {
    font-size: 1rem;
}

/* ==================== Section Content ==================== */
.section-content {
    line-height: 1.8;
    font-size: 1rem;
    max-width: 800px;
}

.section-content p {
    margin-bottom: 1em;
}

.section-content .equation,
.section-content .MathJax_Display {
    margin: 1.2em 0;
    overflow-x: auto;
}

.footnote-ref {
    font-size: 0.75rem;
    vertical-align: super;
    color: var(--accent);
    cursor: pointer;
    font-family: var(--font-mono);
}

.footnote-ref:hover {
    text-decoration: underline;
}

.footnote-body {
    display: none;
    font-size: 0.85rem;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    border-left: 3px solid var(--accent);
    padding: 8px 12px;
    margin: 8px 0;
    border-radius: 0 var(--radius) var(--radius) 0;
    line-height: 1.5;
}

.footnote-body.visible {
    display: block;
}

.section-content a[href^="#"] {
    color: var(--accent);
    text-decoration: none;
    border-bottom: 1px dotted var(--accent);
}

.section-content a[href^="#"]:hover {
    border-bottom-style: solid;
}

.section-content a.cite-link {
    color: var(--accent);
    text-decoration: none;
    font-family: var(--font-mono);
    font-size: 0.85em;
    border-bottom: none;
}

.section-content a.cite-link:hover {
    text-decoration: underline;
}

.section-content img {
    max-width: 100%;
    margin: 1em 0;
}

.section-content h4 {
    font-size: 1.1rem;
    margin: 1.5em 0 0.5em;
}

/* ==================== Related Topics ==================== */
.related-topics {
    margin-top: 32px;
    padding-top: 24px;
    border-top: 1px solid var(--border);
}

.related-topics h3 {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.related-tag {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    margin: 4px 4px 4px 0;
    text-decoration: none;
    transition: opacity 0.2s;
}
.related-tag:hover {
    opacity: 0.8;
}

.tag-physicalThemes {
    background: var(--tag-theme);
    color: #2e7d32;
}
.tag-techniques {
    background: var(--tag-technique);
    color: #1565c0;
}
.tag-questions {
    background: var(--tag-question);
    color: #e65100;
}

[data-theme="dark"] .tag-physicalThemes { color: #81c784; }
[data-theme="dark"] .tag-techniques { color: #64b5f6; }
[data-theme="dark"] .tag-questions { color: #ffb74d; }

/* ==================== Footer ==================== */
footer {
    border-top: 1px solid var(--border);
    padding: 20px 0;
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* ==================== Responsive ==================== */
@media (max-width: 768px) {
    .category-grid {
        grid-template-columns: 1fr;
    }

    .browse-tabs .container {
        flex-wrap: wrap;
    }

    .search-box-inline {
        width: 100%;
        margin: 8px 0 0 0;
    }

    .search-box-inline input {
        width: 100%;
    }

    .tab {
        padding: 12px 16px;
        font-size: 0.9rem;
    }
}

/* LaTeX tables */
.latex-table {
    border-collapse: collapse;
    margin: 1em auto;
    font-size: 0.95em;
}
.latex-table th, .latex-table td {
    border: 1px solid #ccc;
    padding: 6px 12px;
    text-align: center;
}
.latex-table th {
    background: #f5f5f5;
    font-weight: 600;
}
