:root {
    --bg-color: #f8f9fa;
    --text-color: #212529;
    --primary-color: #c62828;
    /* Polish Red */
    --secondary-color: #343a40;
    --link-color: #c62828;
    --link-hover: #8e1c1c;
    --border-color: #dee2e6;
    --font-serif: 'Merriweather', 'Georgia', serif;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --max-width: 800px;
    --header-height: 60px;
}

body.dark-theme {
    --bg-color: #121212;
    --text-color: #e0e0e0;
    --primary-color: #ef5350;
    --secondary-color: #adb5bd;
    --link-color: #ef5350;
    --link-hover: #ff867c;
    --border-color: #333;
}

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

body {
    font-family: var(--font-serif);
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.8;
    font-size: 1.125rem;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* Typography */
h1,
h2,
h3,
h4,
h5,
h6 {
    font-family: var(--font-sans);
    font-weight: 700;
    line-height: 1.3;
    margin-bottom: 1rem;
    color: var(--text-color);
}

h1 {
    font-size: 2.5rem;
    margin-bottom: 1.5rem;
    padding-right: 140px;
    /* Prevent overlap with download buttons */
}

h2 {
    font-size: 2rem;
    border-bottom: 2px solid var(--primary-color);
    padding-bottom: 0.5rem;
    display: inline-block;
}

h3 {
    font-size: 1.5rem;
}

.subtitle {
    font-family: var(--font-sans);
    color: var(--secondary-color);
    font-size: 1rem;
    margin-top: -0.75rem;
    margin-bottom: 2rem;
}

a {
    color: var(--link-color);
    text-decoration: none;
    transition: color 0.2s;
}

a:hover {
    color: var(--link-hover);
    text-decoration: underline;
}

/* Layout */
.container {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 2rem 1.5rem;
    width: 100%;
    position: relative;
    /* For absolute positioning of download toolbar */
}

header {
    background: var(--bg-color);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(10px);
    background-color: rgba(248, 249, 250, 0.95);
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

body.dark-theme header {
    background-color: rgba(18, 18, 18, 0.95);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: var(--header-height);
    padding: 0 1.5rem;
    max-width: var(--max-width);
    margin: 0 auto;
}

.logo {
    font-family: var(--font-sans);
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--text-color);
}

.logo span {
    color: var(--primary-color);
}

.top-menu {
    margin-left: auto;
    margin-right: 1rem;
}

.top-menu a {
    color: var(--secondary-color);
    font-size: 0.9rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-family: var(--font-sans);
}

.top-menu a:hover {
    color: var(--primary-color);
    text-decoration: none;
}

#theme-toggle {
    background: none;
    border: none;
    color: var(--text-color);
    cursor: pointer;
    font-size: 1.2rem;
    padding: 0.5rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
}

#theme-toggle:hover {
    background-color: var(--border-color);
}

/* Navigation */
.breadcrumbs {
    font-family: var(--font-sans);
    font-size: 0.9rem;
    color: var(--secondary-color);
    margin-bottom: 2rem;
    padding-right: 140px;
    /* Prevent overlap with download buttons */
}

.breadcrumbs a {
    color: var(--secondary-color);
    text-decoration: none;
}

.breadcrumbs a:hover {
    color: var(--primary-color);
}

.breadcrumbs .separator {
    margin: 0 0.5rem;
    color: var(--border-color);
}

/* Content */
.article-content {
    margin-bottom: 3rem;
    background: var(--bg-color);
    position: relative;
    /* For absolute positioning if inside article */
}

.article-content p,
.article-content li {
    margin-bottom: 1.5rem;
}

.glossary-intro {
    margin-bottom: 1.5rem;
}

.glossary-index {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: 1rem 0 2rem;
}

.glossary-index a {
    display: inline-block;
    padding: 0.35rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 999px;
    font-family: var(--font-sans);
    font-size: 0.85rem;
    color: var(--secondary-color);
    background: white;
    text-decoration: none;
}

.glossary-index a:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
    text-decoration: none;
}

.glossary-section {
    margin-top: 2.5rem;
}

.glossary-section h3 {
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.section-icon {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: rgba(198, 40, 40, 0.08);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.section-icon svg {
    width: 18px;
    height: 18px;
    stroke: var(--primary-color);
    fill: none;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.section-desc {
    color: var(--secondary-color);
    margin-bottom: 1rem;
}

.glossary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 1rem;
    margin: 1rem 0 2rem;
}

.glossary-card {
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 1rem 1.1rem;
    background: var(--bg-color);
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.03);
}

.glossary-card h4 {
    font-family: var(--font-sans);
    font-size: 1.05rem;
    margin-bottom: 0.5rem;
}

.glossary-card p {
    margin-bottom: 0;
    font-size: 0.98rem;
}

body.dark-theme .glossary-index a {
    background-color: #1e1e1e;
    border-color: #333;
    color: var(--secondary-color);
}

body.dark-theme .section-icon {
    background: rgba(239, 83, 80, 0.15);
}

body.dark-theme .glossary-card {
    border-color: #333;
    background: #1a1a1a;
}

.article-navigation {
    display: flex;
    justify-content: space-between;
    margin-top: 4rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border-color);
    font-family: var(--font-sans);
}

.nav-link {
    display: flex;
    flex-direction: column;
    max-width: 45%;
}

.nav-link .label {
    font-size: 0.8rem;
    color: var(--secondary-color);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.25rem;
}

.nav-link .title {
    font-weight: 600;
}

.nav-link.next {
    align-items: flex-end;
    text-align: right;
}

/* Lists */
ul,
ol {
    margin-left: 1.5rem;
    margin-bottom: 1.5rem;
}

li {
    margin-bottom: 0.5rem;
}

/* TOC */
.chapter-list {
    list-style: none;
    margin: 0;
}

.chapter-list li {
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 1rem;
}

.chapter-list li:last-child {
    border-bottom: none;
}

.chapter-title {
    display: block;
    font-family: var(--font-sans);
    font-weight: 600;
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
}

.article-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
    gap: 0.5rem;
    list-style: none;
    margin: 0;
    margin-top: 0.5rem;
}

.article-list a {
    display: block;
    padding: 0.25rem;
    text-align: center;
    background: var(--border-color);
    color: var(--text-color);
    border-radius: 4px;
    font-family: var(--font-sans);
    font-size: 0.9rem;
    text-decoration: none;
}

.article-list a:hover {
    background: var(--primary-color);
    color: white;
}

/* Footer */
footer {
    margin-top: auto;
    border-top: 1px solid var(--border-color);
    padding: 2rem 0;
    text-align: center;
    color: var(--secondary-color);
    font-family: var(--font-sans);
    font-size: 0.9rem;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

main {
    animation: fadeIn 0.4s ease-out;
}

/* Download Toolbar */
.download-toolbar {
    margin: 0;
    /* Updated from 1rem 0 2rem 0 */
    padding: 0.5rem;
    background-color: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    position: absolute;
    top: 0;
    right: 0;
    z-index: 50;
    transform: translateY(-50%);
    /* Adjust based on exact placement needs, or relative to container padding */
}

/* Adjustment because parent .container has padding-top: 2rem */
.container>.download-toolbar {
    top: 2rem;
    right: 1.5rem;
    transform: none;
    background-color: transparent;
    /* Cleaner look */
    border: none;
}

/* For index page, we might need specific handling if not in .container or structure differs */

.download-label {
    font-size: 0.75rem;
    /* Smaller label */
    font-weight: 600;
    color: var(--secondary-color);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: none;
    /* Hide label to monitor space, or keep small */
}

.download-buttons {
    display: flex;
    gap: 0.5rem;
}

.btn-download {
    background-color: white;
    border: 1px solid var(--border-color);
    color: var(--text-color);
    padding: 0.4rem 0.8rem;
    /* Smaller padding */
    border-radius: 4px;
    font-family: var(--font-sans);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

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

/* Dark mode adjustment for buttons */
body.dark-theme .btn-download {
    background-color: #1e1e1e;
    border-color: #333;
    color: #e0e0e0;
}

body.dark-theme .btn-download:hover {
    background-color: var(--primary-color);
    color: white;
}
