/* ThreadEngine — documentation styles.

   Three columns: the navigation on the left, the page in the middle at a reading width, and
   "On this page" on the right (built by nav.js from the page's h2s; hidden on narrow screens).

   Theming: every colour is a variable. :root is the light theme, :root[data-theme="dark"] the
   dark one; nav.js sets data-theme from localStorage, falling back to the OS preference.

   Language: every page carries both languages. Text in one language is marked lang="en" or
   lang="pl" (a span, a paragraph, or a whole <div> per language), and the inactive one is
   hidden by the rule at the bottom. nav.js switches the `lang-pl` class on <html>. */

:root {
    --bg: #ffffff;
    --bg-soft: #f7f8fa;
    --text: #1f2328;
    --text-soft: #424a53;
    --text-muted: #6e7781;
    --link: #0b6bcb;
    --accent: #f26a1b;
    --accent-soft: rgba(242, 106, 27, 0.10);
    --accent-text: #ffffff;
    --rule: #e6e8eb;

    --sidebar-bg: #fbfbfc;
    --sidebar-border: #e6e8eb;
    --sidebar-text: #3d444d;
    --sidebar-muted: #8b949e;
    --sidebar-hover: #eef0f3;

    --code-bg: #f1f3f5;
    --code-text: #1f2328;
    --pre-bg: #f6f8fa;
    --pre-border: #e3e6ea;

    --table-border: #e6e8eb;
    --th-bg: #f6f8fa;
    --mono-blue: #0b6bcb;

    --note-bg: #fff8eb;
    --note-border: #f0b429;
    --note-strong: #8a5a00;
    --sig-bg: #f6f8fa;
    --sig-border: #0b6bcb;

    --tok-kw: #cf222e;
    --tok-type: #8250df;
    --tok-str: #0a3069;
    --tok-num: #0550ae;
    --tok-com: #6e7781;
    --tok-pp: #953800;

    --shadow: 0 1px 2px rgba(31, 35, 40, 0.06), 0 6px 20px rgba(31, 35, 40, 0.06);
    --radius: 10px;
    --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --mono: "JetBrains Mono", "Cascadia Code", Consolas, "SF Mono", Menlo, monospace;
}

:root[data-theme="dark"] {
    --bg: #0f1115;
    --bg-soft: #151820;
    --text: #e3e6eb;
    --text-soft: #c2c8d0;
    --text-muted: #8b93a0;
    --link: #6cb6ff;
    --accent: #ff7d32;
    --accent-soft: rgba(255, 125, 50, 0.14);
    --rule: #252a33;

    --sidebar-bg: #12141a;
    --sidebar-border: #222630;
    --sidebar-text: #c2c8d0;
    --sidebar-muted: #6e7681;
    --sidebar-hover: #1d212a;

    --code-bg: #1d2129;
    --code-text: #dfe3e8;
    --pre-bg: #161a21;
    --pre-border: #262b35;

    --table-border: #252a33;
    --th-bg: #161a21;
    --mono-blue: #6cb6ff;

    --note-bg: #231f14;
    --note-border: #b8912a;
    --note-strong: #e8b84f;
    --sig-bg: #161a21;
    --sig-border: #6cb6ff;

    --tok-kw: #ff7b72;
    --tok-type: #d2a8ff;
    --tok-str: #a5d6ff;
    --tok-num: #79c0ff;
    --tok-com: #8b949e;
    --tok-pp: #ffa657;

    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; scroll-padding-top: 24px; }
html, body {
    margin: 0; padding: 0;
    font-family: var(--font);
    font-size: 15px; line-height: 1.65;
    color: var(--text); background: var(--bg);
    -webkit-font-smoothing: antialiased;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
::selection { background: var(--accent-soft); }

.layout { display: flex; min-height: 100vh; }

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
aside.sidebar {
    width: 280px; flex: 0 0 280px;
    background: var(--sidebar-bg); color: var(--sidebar-text);
    border-right: 1px solid var(--sidebar-border);
    padding: 22px 16px 40px; overflow-y: auto;
    position: sticky; top: 0; height: 100vh;
}
aside.sidebar .brand { display: flex; align-items: center; gap: 10px; margin: 0 4px 2px; }
aside.sidebar .brand-mark {
    width: 30px; height: 30px; border-radius: 8px; flex: none;
    background: linear-gradient(135deg, var(--accent), #ffb347);
    display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 15px;
    box-shadow: 0 4px 12px var(--accent-soft);
}
aside.sidebar h1 { font-size: 15px; margin: 0; letter-spacing: 0.02em; color: var(--text); font-weight: 700; }
aside.sidebar .subtitle { font-size: 12px; color: var(--sidebar-muted); margin: 0 4px 16px 44px; }

.sidebar-toolbar { display: flex; gap: 8px; margin: 0 0 14px; }
.segmented {
    display: inline-flex; flex: 1; padding: 3px; border-radius: 8px;
    background: var(--sidebar-hover); border: 1px solid var(--sidebar-border);
}
.segmented button, .icon-btn {
    font: inherit; font-size: 12px; font-weight: 600; cursor: pointer;
    border: 0; background: transparent; color: var(--sidebar-muted);
    padding: 4px 10px; border-radius: 6px; flex: 1;
}
.segmented button.on { background: var(--bg); color: var(--text); box-shadow: var(--shadow); }
.icon-btn {
    flex: none; width: 36px; padding: 0;
    background: var(--sidebar-hover); border: 1px solid var(--sidebar-border); border-radius: 8px;
    font-size: 15px; color: var(--sidebar-text);
}
.icon-btn:hover, .segmented button:hover { color: var(--text); }

.nav-search {
    width: 100%; font: inherit; font-size: 13px;
    padding: 8px 10px 8px 32px; margin: 0 0 12px;
    border-radius: 8px; border: 1px solid var(--sidebar-border);
    background: var(--bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' fill='none' stroke='%238b949e' stroke-width='2'%3E%3Ccircle cx='6' cy='6' r='4.5'/%3E%3Cpath d='M9.5 9.5 13 13'/%3E%3C/svg%3E") no-repeat 11px center;
    color: var(--text); outline: none;
}
.nav-search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

aside.sidebar nav { font-size: 13.5px; }
aside.sidebar nav .group {
    margin: 18px 6px 6px; color: var(--sidebar-muted); text-transform: uppercase;
    font-size: 11px; letter-spacing: 0.08em; font-weight: 700;
}
aside.sidebar nav a {
    display: block; color: var(--sidebar-text); padding: 5px 10px; border-radius: 6px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    border-left: 2px solid transparent;
}
aside.sidebar nav a:hover { background: var(--sidebar-hover); text-decoration: none; color: var(--text); }
aside.sidebar nav a.active {
    background: var(--accent-soft); color: var(--accent); font-weight: 600;
    border-left-color: var(--accent); border-radius: 0 6px 6px 0;
}
aside.sidebar nav .badge {
    font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 99px; margin-left: 6px;
    background: var(--accent); color: #fff; vertical-align: 1px;
}
aside.sidebar nav .empty { font-size: 12px; color: var(--sidebar-muted); padding: 6px 10px; }

/* ── Content ─────────────────────────────────────────────────────────────── */
main.content { flex: 1; min-width: 0; padding: 40px 56px 96px; max-width: 920px; }

.breadcrumbs { font-size: 12.5px; color: var(--text-muted); margin-bottom: 10px; }
.breadcrumbs a { color: var(--text-muted); }
.breadcrumbs a:hover { color: var(--link); }

h1.page {
    font-size: 34px; line-height: 1.2; margin: 0 0 18px; font-weight: 750; letter-spacing: -0.02em;
    padding-bottom: 16px; border-bottom: 1px solid var(--rule);
}
h1.page .kind {
    display: inline-block; vertical-align: middle; margin-left: 10px;
    font-size: 12px; font-weight: 600; letter-spacing: 0.02em;
    color: var(--accent); background: var(--accent-soft);
    padding: 3px 10px; border-radius: 99px;
}
h2 {
    margin: 44px 0 12px; font-size: 22px; font-weight: 700; letter-spacing: -0.01em;
    color: var(--text); position: relative;
}
h3 { margin: 28px 0 8px; font-size: 17px; font-weight: 650; color: var(--text); }
h2 .anchor, h3 .anchor {
    position: absolute; left: -22px; opacity: 0; color: var(--text-muted);
    font-weight: 400; text-decoration: none; transition: opacity .15s;
}
h3 { position: relative; }
h2:hover .anchor, h3:hover .anchor { opacity: 1; }

p { margin: 10px 0; color: var(--text-soft); }
main.content > p:first-of-type, .lead { font-size: 16.5px; color: var(--text-soft); }
strong { color: var(--text); }

code {
    font-family: var(--mono); font-size: 0.86em;
    background: var(--code-bg); padding: 2px 6px; border-radius: 5px; color: var(--code-text);
}

pre {
    position: relative;
    background: var(--pre-bg); border: 1px solid var(--pre-border); border-radius: var(--radius);
    padding: 16px 18px; overflow-x: auto; font-size: 13.5px; line-height: 1.6;
    margin: 16px 0; color: var(--code-text);
}
pre code { background: transparent; padding: 0; color: inherit; font-size: inherit; }
pre .copy-btn {
    position: absolute; top: 8px; right: 8px;
    font: 600 11px var(--font); cursor: pointer;
    padding: 4px 9px; border-radius: 6px;
    color: var(--text-muted); background: var(--bg); border: 1px solid var(--pre-border);
    opacity: 0; transition: opacity .15s;
}
pre:hover .copy-btn { opacity: 1; }
pre .copy-btn.done { color: #1a7f37; border-color: #1a7f37; }

/* Tokens from nav.js's C++ highlighter. */
.tok-kw   { color: var(--tok-kw); }
.tok-type { color: var(--tok-type); }
.tok-str  { color: var(--tok-str); }
.tok-num  { color: var(--tok-num); }
.tok-com  { color: var(--tok-com); font-style: italic; }
.tok-pp   { color: var(--tok-pp); }

table {
    border-collapse: separate; border-spacing: 0; width: 100%; margin: 14px 0 20px;
    font-size: 13.5px; border: 1px solid var(--table-border); border-radius: var(--radius);
    overflow: hidden;
}
th, td { text-align: left; padding: 9px 14px; border-bottom: 1px solid var(--table-border); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
th { background: var(--th-bg); font-weight: 650; color: var(--text); font-size: 12.5px; }
tbody tr:hover td, table tr:hover td { background: var(--bg-soft); }
table.props td:first-child, table.params td:first-child, table.api td:first-child {
    font-family: var(--mono); font-size: 12.5px; color: var(--mono-blue); width: 32%;
}
table.props td:nth-child(2), table.params td:nth-child(2) {
    font-family: var(--mono); font-size: 12.5px; color: var(--text-muted); white-space: nowrap; width: 22%;
}

.signature {
    background: var(--sig-bg); border: 1px solid var(--pre-border); border-left: 3px solid var(--sig-border);
    border-radius: 0 var(--radius) var(--radius) 0;
    padding: 12px 16px; font-family: var(--mono); font-size: 13px; margin: 14px 0;
    white-space: pre-wrap; color: var(--text);
}

.note, .tip, .warn {
    position: relative;
    background: var(--note-bg); border: 1px solid transparent; border-left: 4px solid var(--note-border);
    border-radius: 0 var(--radius) var(--radius) 0;
    padding: 12px 16px; margin: 18px 0; font-size: 14px; color: var(--text-soft);
}
.note strong { color: var(--note-strong); }
.note p { margin: 8px 0; }
.note p:first-child { margin-top: 0; }
.note p:last-child  { margin-bottom: 0; }
.tip  { background: rgba(26, 127, 55, 0.08); border-left-color: #1a7f37; }
.warn { background: rgba(207, 34, 46, 0.07); border-left-color: #cf222e; }

.section-tag {
    display: inline-block; background: var(--accent); color: var(--accent-text);
    font-size: 11px; font-weight: 600; padding: 1px 8px; border-radius: 99px; margin-left: 6px; vertical-align: middle;
}

/* Index cards. */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; margin: 16px 0 8px; }
.card {
    display: block; padding: 14px 16px; border-radius: var(--radius);
    border: 1px solid var(--rule); background: var(--bg); color: var(--text);
    transition: border-color .15s, box-shadow .15s, transform .15s;
}
.card:hover { border-color: var(--accent); box-shadow: var(--shadow); transform: translateY(-1px); text-decoration: none; }
.card b { display: block; font-size: 14.5px; margin-bottom: 3px; }
.card span.d { display: block; font-size: 13px; color: var(--text-muted); line-height: 1.45; }

ul, ol { padding-left: 24px; margin: 10px 0; color: var(--text-soft); }
li { margin: 5px 0; }
hr { border: none; border-top: 1px solid var(--rule); margin: 32px 0; }

/* ── On this page ────────────────────────────────────────────────────────── */
aside.toc {
    flex: 0 0 230px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
    padding: 44px 20px 40px 8px; font-size: 13px;
}
aside.toc .toc-title {
    font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
    color: var(--text-muted); margin: 0 0 10px 12px;
}
aside.toc a {
    display: block; color: var(--text-muted); padding: 4px 12px; border-left: 2px solid var(--rule);
    line-height: 1.4;
}
aside.toc a:hover { color: var(--text); text-decoration: none; }
aside.toc a.on { color: var(--accent); border-left-color: var(--accent); }

/* ── Mobile ──────────────────────────────────────────────────────────────── */
.mobile-bar { display: none; }
@media (max-width: 1240px) { aside.toc { display: none; } }
@media (max-width: 860px) {
    .layout { display: block; }
    .mobile-bar {
        display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 20;
        padding: 10px 16px; background: var(--sidebar-bg); border-bottom: 1px solid var(--sidebar-border);
        font-weight: 700;
    }
    .mobile-bar button { font-size: 18px; background: none; border: 0; color: var(--text); cursor: pointer; }
    aside.sidebar {
        position: fixed; z-index: 30; left: 0; top: 0; transform: translateX(-100%);
        transition: transform .2s; box-shadow: var(--shadow);
    }
    body.nav-open aside.sidebar { transform: none; }
    main.content { padding: 24px 18px 64px; }
    h1.page { font-size: 27px; }
    h2 .anchor, h3 .anchor { display: none; }

    /* Three narrow columns are unreadable on a phone: name and type share a line, the
       description gets the full width under them. */
    table.props tr, table.params tr, table.api tr {
        display: grid; grid-template-columns: minmax(0, 1fr) auto;
        border-bottom: 1px solid var(--table-border);
    }
    table.props tr:last-child, table.params tr:last-child, table.api tr:last-child { border-bottom: 0; }
    table.props td, table.params td, table.api td, table.api th {
        border-bottom: 0; width: auto !important; white-space: normal !important;
    }
    table.props td:nth-child(3), table.params td:nth-child(3), table.api td:nth-child(3) {
        grid-column: 1 / -1; padding-top: 0;
    }
    table.api tr:first-child th:nth-child(3) { display: none; }
}

/* ── Bilingual content ───────────────────────────────────────────────────── */
:root:not(.lang-pl) [lang="pl"] { display: none !important; }
:root.lang-pl [lang="en"] { display: none !important; }

kbd {
    font-family: var(--mono); font-size: 0.82em; padding: 1px 6px; border-radius: 5px;
    border: 1px solid var(--rule); border-bottom-width: 2px; background: var(--bg-soft); color: var(--text);
}
