:root {
    --background: #ffffff;
    --text: #202124;
    --text-secondary: #5f6368;
    --banner: #ffffff;
    --top-menu: #282a35;
    --top-menu-hover: #000000;
    --sidebar: #f1f1f1;
    --sidebar-hover: #dddddd;
    --box-background: #f1f1f1;
    --formula-background: #ffffff;
    --border: #dddddd;
    --accent: #5E4294;
    --banner-height: 64px;
    --menu-height: 46px;
}

body.dark-mode {
    --background: #1d1f20;
    --text: #eeeeee;
    --text-secondary: #b8b8b8;
    --banner: #202225;
    --sidebar: #282a35;
    --sidebar-hover: #3d3f4a;
    --box-background: #282a35;
    --formula-background: #151617;
    --border: #44464f;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: "Inter", Arial, sans-serif;
    color: var(--text);
    background: var(--background);
    transition: background-color 0.2s ease, color 0.2s ease;
}
button, input { font: inherit; }
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Baner */
.site-banner {
    position: sticky;
    top: 0;
    z-index: 1100;
    height: var(--banner-height);
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 0 22px;
    border-bottom: 1px solid var(--border);
    background: var(--banner);
}
.site-name {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--text);
    font-size: 25px;
    font-weight: 700;
    text-decoration: none;
}
.site-logo {
    width: 32px;
    height: 32px;
    display: block;
    flex-shrink: 0;
}
.banner-tools {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 12px;
}
/* Przyciski języka */
.language-switcher {
    display: flex;
    gap: 12px;
}
.language-button {
    height: 38px;
    min-width: 42px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    background: var(--background);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}
.language-button:hover { background: var(--sidebar-hover); }
.language-button.active {
    color: white;
    border-color: var(--accent);
    background: var(--accent);
}

.search-box {
    position: relative;
    width: min(340px, 42vw);
}
.search-input {
    width: 100%;
    height: 38px;
    padding: 0 14px;
    border: 1px solid var(--border);
    border-radius: 6px;
    outline: none;
    color: var(--text);
    background: var(--background);
}
.search-input:focus { border-color: var(--accent); }
.search-results {
    position: absolute;
    top: calc(100% + 7px);
    right: 0;
    width: 100%;
    max-height: 320px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--background);
    box-shadow: 0 8px 24px rgba(0,0,0,0.16);
    z-index: 3000;
}
.search-result {
    display: block;
    width: 100%;
    padding: 11px 13px;
    border: 0;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    background: transparent;
    text-align: left;
    cursor: pointer;
}
.search-result:last-child { border-bottom: 0; }
.search-result:hover { background: var(--sidebar-hover); }
.search-result-title { display: block; font-weight: 600; }
.search-result-group { display: block; margin-top: 3px; color: var(--text-secondary); font-size: 12px; }
.search-empty { padding: 12px 13px; color: var(--text-secondary); font-size: 13px; }
.theme-button {
    flex-shrink: 0;
    width: 38px;
    height: 38px;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    background: var(--background);
    font-size: 24px;
    cursor: pointer;
}
.theme-button:hover { background: var(--sidebar-hover); }

/* Górne menu działów */
.top-menu {
    position: sticky;
    top: var(--banner-height);
    z-index: 1000;
    height: var(--menu-height);
    display: flex;
    align-items: center;
    background: var(--top-menu);
    white-space: nowrap;
}
.top-links {
    display: flex;
    align-items: center;
    min-width: 0;
    overflow-x: auto;
    scrollbar-width: none;
}
.top-links::-webkit-scrollbar { display: none; }
.top-links a {
    height: var(--menu-height);
    display: flex;
    align-items: center;
    padding: 0 18px;
    color: white;
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
}
.top-links a:hover { background: var(--top-menu-hover); }
.top-links a.active { background: var(--accent); }
.menu-button {
    flex-shrink: 0;
    height: var(--menu-height);
    padding: 0 18px;
    border: 0;
    color: white;
    background: transparent;
    font-size: 20px;
    cursor: pointer;
}
.menu-button:hover { background: var(--top-menu-hover); }

/* Sidebar */
.sidebar {
    position: fixed;
    top: calc(var(--banner-height) + var(--menu-height));
    left: 0;
    bottom: 0;
    width: 260px;
    padding: 8px 0 40px;
    background: var(--sidebar);
    overflow-y: auto;
    transition: transform 0.25s ease, background-color 0.2s ease;
}
.sidebar.closed { transform: translateX(-260px); }
.sidebar-group { margin: 3px 0; }
.sidebar-group-button {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 18px;
    border: 0;
    color: var(--text);
    background: transparent;
    font-size: 14px;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
}
.sidebar-group-button:hover { background: var(--sidebar-hover); }
.sidebar-arrow {
    flex-shrink: 0;
    margin-left: 10px;
    font-size: 11px;
    transition: transform 0.2s ease;
}
.sidebar-group.collapsed .sidebar-arrow { transform: rotate(-90deg); }
.sidebar-topics { overflow: hidden; }
.sidebar-topics a {
    display: block;
    padding: 7px 18px 7px 32px;
    color: var(--text);
    font-size: 13px;
    text-decoration: none;
}
.sidebar-topics a:hover { background: var(--sidebar-hover); }
.sidebar-topics a.active { color: white; background: var(--accent); }
.sidebar-group.collapsed .sidebar-topics { display: none; }

/* Treść */
.content {
    max-width: 1050px;
    min-height: 60vh;
    margin-left: 260px;
    padding: 45px 55px 80px;
    transition: margin-left 0.25s ease;
}
.content.full { margin-left: 0; }
.content section { scroll-margin-top: calc(var(--banner-height) + var(--menu-height) + 24px); }
.content section + section { margin-top: 60px; }
h1 { margin: 0 0 25px; font-size: 40px; font-weight: 500; }
h2 { margin: 0 0 18px; font-size: 28px; font-weight: 500; }
h3 { margin: 25px 0 12px; font-size: 20px; font-weight: 600; }
p { margin: 0 0 18px; font-size: 16px; line-height: 1.75; }
strong { font-weight: 600; }
.definition {
    margin: 22px 0;
    padding: 20px;
    border-left: 4px solid var(--accent);
    background: var(--box-background);
    line-height: 1.7;
}
.definition-title { display: block; margin-bottom: 8px; font-weight: 600; }

/* Wzory KaTeX: kompaktowe, ale bez obcinania złożonych wzorów */
.formula {
    margin: 18px 0;
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-left: 4px solid var(--accent);
    border-radius: 4px;
    background: var(--formula-background);
    overflow-x: auto;
    overflow-y: visible;
}
.formula .katex-display {
    margin: 0;
    padding: 4px 0;
    overflow: visible;
}
.formula .katex { line-height: 1.2; }

.example {
    margin: 25px 0;
    padding: 20px;
    border-radius: 5px;
    background: var(--box-background);
}
.example-title { margin: 0 0 12px; font-size: 18px; font-weight: 600; }
.example p:last-child { margin-bottom: 0; }
.content ul { margin: 15px 0 22px; padding-left: 25px; }
.content li { margin: 8px 0; line-height: 1.6; }

/* Stopka */
.footer {
    margin-left: 260px;
    padding: 36px 55px 20px;
    border-top: 1px solid var(--border);
    background: var(--box-background);
    transition: margin-left 0.25s ease;
}
.footer.full { margin-left: 0; }
.footer-grid {
    max-width: 1050px;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 28px;
}
.footer-grid strong { display: block; margin-bottom: 10px; }
.footer-grid p { margin: 0; color: var(--text-secondary); font-size: 13px; line-height: 1.7; }
.social-links a {
    color: inherit;
    text-decoration: none;
    transition: opacity 0.2s ease;
}
.social-links a:hover {
    opacity: 0.7;
}
.footer-bottom {
    max-width: 1050px;
    margin-top: 28px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 12px;
}
.overlay { display: none; }

@media (max-width: 768px) {
    :root { --banner-height: 60px; }
    .site-banner { padding: 0 14px; gap: 12px; }
    .site-name { font-size: 22px; }
    .banner-tools { gap: 8px; }
    .language-switcher { gap: 4px; }
    .language-button { min-width: 36px; padding: 0 7px; }
    /* Przyciski języka */
.language-switcher {
    display: flex;
    gap: 6px;
}
.language-button {
    height: 36px;
    min-width: 42px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    background: var(--background);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}
.language-button:hover { background: var(--sidebar-hover); }
.language-button.active {
    color: white;
    border-color: var(--accent);
    background: var(--accent);
}

.search-box { width: min(280px, 54vw); }
    .search-input { height: 36px; }
    .theme-button { width: 38px; height: 38px; }
    .sidebar {
        z-index: 2000;
        transform: translateX(-260px);
        box-shadow: 4px 0 15px rgba(0,0,0,0.25);
    }
    .sidebar.open { transform: translateX(0); }
    .content { margin-left: 0; padding: 35px 22px 70px; }
    .footer { margin-left: 0; padding: 30px 22px 18px; }
    .footer-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .overlay.show {
        display: block;
        position: fixed;
        top: calc(var(--banner-height) + var(--menu-height));
        right: 0;
        bottom: 0;
        left: 0;
        z-index: 1500;
        background: rgba(0,0,0,0.45);
    }
}

@media (max-width: 480px) {
    :root { --banner-height: auto; }
    .site-banner {
        position: relative;
        height: auto;
        min-height: 60px;
        flex-wrap: wrap;
        padding: 12px 14px;
    }
    .site-name { width: 100%; }
    .banner-tools { width: 100%; margin-left: 0; }
    /* Przyciski języka */
.language-switcher {
    display: flex;
    gap: 6px;
}
.language-button {
    height: 36px;
    min-width: 42px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    background: var(--background);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}
.language-button:hover { background: var(--sidebar-hover); }
.language-button.active {
    color: white;
    border-color: var(--accent);
    background: var(--accent);
}

.search-box { flex: 1; width: auto; }
    .top-menu { top: 0; }
    .sidebar { top: var(--menu-height); }
    .overlay.show { top: var(--menu-height); }
    .menu-button { padding-left: 14px; padding-right: 14px; }
    .top-links a { padding: 0 14px; font-size: 12px; }
    .content { padding: 28px 16px 60px; }
    .content section { scroll-margin-top: calc(var(--menu-height) + 18px); }
    h1 { font-size: 32px; }
    h2 { font-size: 24px; }
    p { font-size: 15px; }
    .formula { padding: 8px 10px; }
    .footer { padding: 26px 16px 16px; }
    .footer-grid { grid-template-columns: 1fr; gap: 22px; }
}

/* Logo, przycisk Tablic i strona główna */
.brand-tools { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.icon-button {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    background: var(--background);
    cursor: pointer;
}
.icon-button:hover { background: var(--sidebar-hover); }
.tables-button svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.7; }
.tables-button.active { color: #fff; border-color: var(--accent); background: var(--accent); }
body.home-view .sidebar { display: none; }
body.home-view .content, body.home-view .footer { margin-left: 0; }
.home { max-width: 1180px; }
.home-intro { margin-bottom: 34px; }
.home-intro h1 { margin-bottom: 12px; }
.home-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 22px; }
.home-card { border: 1px solid var(--border); border-radius: 8px; background: var(--box-background); overflow: hidden; }
.home-card-title { margin: 0; padding: 16px 18px; border-bottom: 3px solid var(--accent); font-size: 21px; font-weight: 600; }
.home-card-title button, .home-group-title, .home-topic-link {
    border: 0; padding: 0; color: var(--text); background: transparent; text-align: left; cursor: pointer;
}
.home-card-title button { font: inherit; font-weight: inherit; }
.home-card-title button:hover, .home-group-title:hover, .home-topic-link:hover { color: var(--accent); }
.home-card-body { padding: 16px 18px 20px; }
.home-group + .home-group { margin-top: 18px; }
.home-group-title { display: block; margin-bottom: 8px; font-size: 15px; font-weight: 600; }
.home-topic-list { margin: 0; padding: 0; list-style: none; }
.home-topic-list li { margin: 5px 0; }
.home-topic-link { font-size: 13px; line-height: 1.45; color: var(--text-secondary); }
.home-tables { margin-top: 34px; padding-top: 28px; border-top: 1px solid var(--border); }
.home-tables h2 { margin-bottom: 18px; }
.home-tables-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.home-table-link { padding: 14px; border: 1px solid var(--border); border-radius: 6px; color: var(--text); background: var(--box-background); text-align: left; cursor: pointer; }
.home-table-link:hover { border-color: var(--accent); }
@media (max-width: 900px) { .home-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } .home-tables-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 480px) {
    .brand-tools { width: 100%; justify-content: flex-start; }
    .site-name { width: auto; }
    .home-grid, .home-tables-grid { grid-template-columns: 1fr; }
}

/* v5: dostępność, nowe bloki i nawigacja */
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.note,.warning,.exercise { margin:22px 0; padding:18px 20px; border:1px solid var(--border); border-left:4px solid var(--accent); border-radius:4px; background:var(--box-background); }
.warning { border-left-style:double; border-left-width:6px; }
.note-title,.warning-title,.exercise-title,.definition-title { display:block; margin-bottom:8px; font-weight:700; }
.note p,.warning p,.exercise p,.definition p { margin-bottom:0; }
.solution { margin:18px 0; border:1px solid var(--border); border-radius:5px; background:var(--box-background); }
.solution summary { padding:14px 18px; font-weight:600; cursor:pointer; }
.solution p { padding:0 18px 16px; margin:0; }
.data-table-wrap { margin:22px 0; overflow-x:auto; }
.data-table { width:100%; border-collapse:collapse; min-width:480px; }
.data-table caption { padding:0 0 10px; text-align:left; font-weight:600; }
.data-table th,.data-table td { padding:11px 13px; border:1px solid var(--border); text-align:left; vertical-align:top; }
.data-table th { background:var(--box-background); }
.retry-button { padding:10px 14px; border:1px solid var(--border); border-radius:5px; color:var(--text); background:var(--background); cursor:pointer; }
.retry-button:hover { background:var(--sidebar-hover); }
.error-box { max-width:650px; padding:24px; border:1px solid var(--border); border-left:4px solid var(--accent); background:var(--box-background); }

/* Ustawienia systemowe i dostępność */
.theme-dark-bootstrap body:not(.dark-mode) {
    --background: #1d1f20;
    --text: #eeeeee;
    --text-secondary: #b8b8b8;
    --sidebar: #282a35;
    --sidebar-hover: #3d3f4a;
    --box-background: #282a35;
    --formula-background: #151617;
    --border: #44464f;
}
.noscript-message { padding: 12px 16px; background: var(--box-background); border-bottom: 1px solid var(--border); text-align: center; }
@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}


/* v7: nagłówki podtematów i kopiowanie bezpośrednich linków */
.topic-heading-row { display:flex; align-items:flex-start; justify-content:space-between; gap:16px; margin-top:0; }
.topic-heading-row h1,.topic-heading-row h2 { flex:1; min-width:0; }
.copy-link-button { flex:0 0 auto; display:inline-grid; place-items:center; width:36px; height:36px; margin-top:2px; padding:0; border:1px solid transparent; border-radius:5px; color:var(--text-secondary); background:transparent; cursor:pointer; font-size:22px; line-height:1; }
.copy-link-button:hover { color:var(--text); background:var(--sidebar-hover); }
.copy-link-button.copied { color:var(--accent); }
.loading-message { color:var(--text-secondary); }
@media (max-width:520px){ .topic-heading-row { gap:8px; } .copy-link-button { width:34px; height:34px; font-size:20px; } }

/* v8: semantyka grup, obsługa brakujących tematów i druk */
.group-page-title { margin-bottom: 28px; }
.not-found-box { margin-top: 12px; }


/* Strona startowa nie korzysta z bocznego menu. */
body.home-view .menu-button {
    display: none;
}

@media print {
    @page { margin: 16mm; }
    .site-banner, .top-menu, .sidebar, .overlay, .footer, .copy-link-button,
    .search-results, .noscript-message { display: none !important; }
    body, body.dark-mode { background: #fff; color: #000; }
    .content, .content.full, body.home-view .content {
        margin: 0 !important;
        padding: 0 !important;
        max-width: none;
    }
    .content section { break-inside: avoid-page; }
    .formula, .definition, .example, .note, .warning, .exercise, .solution,
    .data-table th, .data-table td { background: #fff !important; color: #000 !important; }
    .formula, .definition, .example, .note, .warning, .exercise, .solution { break-inside: avoid-page; }
    a { color: inherit; text-decoration: none; }
}
