/* ============================================================
   Theme support: light (default) and dark.
   The theme is set as data-theme="light|dark" on <html> by the
   inline script in _includes/head.html, before first paint.
   Light theme = the existing styles; this file only adds the
   toggle button and the dark overrides.
   ============================================================ */

/* ---------- Toggle button ---------- */

.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    padding: 0;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.35);
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    cursor: pointer;
    transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.theme-toggle:hover,
.theme-toggle:focus-visible {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.65);
    outline: none;
}
.theme-toggle svg { width: 16px; height: 16px; fill: currentColor; }
.theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

/* Desktop: sits right of the search box */
.theme-toggle--desktop { margin-left: 10px; flex: 0 0 auto; }

/* Scrolled (white) navbar on desktop */
.navbar-custom.is-fixed .theme-toggle,
.navbar-custom.is-visible .theme-toggle {
    border-color: rgba(0, 0, 0, 0.18);
    background: rgba(0, 0, 0, 0.04);
    color: #404040;
}
.navbar-custom.is-fixed .theme-toggle:hover,
.navbar-custom.is-visible .theme-toggle:hover {
    background: rgba(0, 0, 0, 0.08);
    color: #0085a1;
}

/* Mobile: next to the hamburger, navbar is white there */
.theme-toggle--mobile {
    float: right;
    margin: 8px 8px 8px 0;
    border-color: rgba(0, 0, 0, 0.18);
    background: transparent;
    color: #404040;
}
.theme-toggle--mobile:hover,
.theme-toggle--mobile:focus-visible {
    background: rgba(0, 0, 0, 0.06);
    border-color: rgba(0, 0, 0, 0.3);
    color: #0085a1;
}
/* Mobile home button: top left, same look as the mobile theme toggle */
.home-btn--mobile {
    float: left;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    margin: 8px 0 8px 8px;
    border: 1px solid rgba(0, 0, 0, 0.18);
    border-radius: 50%;
    color: #404040;
    transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.home-btn--mobile svg { width: 16px; height: 16px; fill: currentColor; }
.home-btn--mobile:hover,
.home-btn--mobile:focus-visible {
    background: rgba(0, 0, 0, 0.06);
    border-color: rgba(0, 0, 0, 0.3);
    color: #0085a1;
    outline: none;
}
[data-theme="dark"] .home-btn--mobile { color: var(--text); border-color: var(--border); }
[data-theme="dark"] .home-btn--mobile:hover,
[data-theme="dark"] .home-btn--mobile:focus-visible { color: var(--accent); background: rgba(255, 255, 255, 0.06); }

@media only screen and (min-width: 768px) {
    .theme-toggle--mobile,
    .home-btn--mobile { display: none; }
}
@media only screen and (max-width: 767px) {
    .theme-toggle--desktop { display: none; }
}

/* ============================================================
   Dark theme
   ============================================================ */

[data-theme="dark"] {
    --bg: #16181c;
    --surface: #1f2228;
    --surface-2: #262a31;
    --text: #d3d7dd;
    --text-strong: #eef0f3;
    --muted: #979ea8;
    --border: #2f343c;
    --accent: #4fb8cf;
    --accent-strong: #6fcbe0;
    color-scheme: dark;
}

[data-theme="dark"] body {
    background-color: var(--bg);
    color: var(--text);
}
[data-theme="dark"] h1, [data-theme="dark"] h2, [data-theme="dark"] h3,
[data-theme="dark"] h4, [data-theme="dark"] h5, [data-theme="dark"] h6 {
    color: var(--text-strong);
}
/* Header titles sit on the dark header images and stay white */
[data-theme="dark"] .intro-header h1,
[data-theme="dark"] .intro-header h2,
[data-theme="dark"] .intro-header .subheading { color: #fff; }

[data-theme="dark"] a { color: var(--text-strong); }
[data-theme="dark"] a:hover,
[data-theme="dark"] a:focus { color: var(--accent); }
[data-theme="dark"] .post-content a { color: var(--accent-strong) !important; }
[data-theme="dark"] .intro-header .post-heading .meta a { color: #fff; }

[data-theme="dark"] hr { border-top-color: var(--border); }
[data-theme="dark"] hr.small { border-color: #fff; }
[data-theme="dark"] .text-muted { color: var(--muted); }

[data-theme="dark"] blockquote {
    color: var(--muted);
    border-color: var(--border);
}

/* Post images: many diagrams are transparent PNGs with dark lines */
[data-theme="dark"] .post-content img { background-color: #fff; border-radius: 4px; }

/* Tables in posts */
[data-theme="dark"] table th,
[data-theme="dark"] table td { border-color: var(--border) !important; }
[data-theme="dark"] .table-striped > tbody > tr:nth-of-type(odd) { background-color: var(--surface); }

/* ---------- Navbar ---------- */

/* Mobile navbar is solid white in light theme */
[data-theme="dark"] .navbar-custom { background: var(--surface); border-color: var(--border); }
[data-theme="dark"] .navbar-default .navbar-collapse { border-color: var(--border); }
[data-theme="dark"] .navbar-default .navbar-toggle { border-color: var(--border); }
[data-theme="dark"] .navbar-default .navbar-toggle:hover,
[data-theme="dark"] .navbar-default .navbar-toggle:focus { background-color: var(--surface-2); }
[data-theme="dark"] .navbar-default .navbar-toggle .icon-bar { background-color: var(--text); }
[data-theme="dark"] .navbar-default .navbar-nav > li > a { color: var(--text); }
[data-theme="dark"] .navbar-default .navbar-nav > li > a:hover,
[data-theme="dark"] .navbar-default .navbar-nav > li > a:focus { color: var(--accent); }
[data-theme="dark"] .theme-toggle--mobile { color: var(--text); border-color: var(--border); }

@media only screen and (min-width: 768px) {
    [data-theme="dark"] .navbar-custom { background: transparent; border-color: transparent; }
    [data-theme="dark"] .navbar-custom .nav li a { color: #fff; }
}
@media only screen and (min-width: 1170px) {
    [data-theme="dark"] .navbar-custom.is-fixed {
        background-color: rgba(31, 34, 40, 0.92);
        border-bottom-color: var(--border);
    }
    [data-theme="dark"] .navbar-custom.is-fixed .nav li a { color: var(--text); }
    [data-theme="dark"] .navbar-custom.is-fixed .nav li a:hover,
    [data-theme="dark"] .navbar-custom.is-fixed .nav li a:focus { color: var(--accent); }
    [data-theme="dark"] .navbar-custom.is-fixed .theme-toggle,
    [data-theme="dark"] .navbar-custom.is-visible .theme-toggle {
        color: var(--text);
        border-color: var(--border);
        background: rgba(255, 255, 255, 0.04);
    }
}

/* Search box on the scrolled / mobile navbar */
[data-theme="dark"] .navbar-custom.is-fixed #search-input,
[data-theme="dark"] .navbar-custom.is-visible #search-input {
    background: rgba(255, 255, 255, 0.06);
    border-color: var(--border);
    color: var(--text);
}
[data-theme="dark"] .navbar-custom.is-fixed .search-submit-btn,
[data-theme="dark"] .navbar-custom.is-visible .search-submit-btn {
    border-color: var(--border);
    color: var(--muted);
}
@media only screen and (max-width: 767px) {
    [data-theme="dark"] #search-input,
    [data-theme="dark"] #search-input:focus {
        background: rgba(255, 255, 255, 0.06);
        border-color: var(--border);
        color: var(--text);
    }
    [data-theme="dark"] #search-input::placeholder { color: var(--muted); }
    [data-theme="dark"] .search-submit-btn { border-color: var(--border); color: var(--muted); }
}

/* ---------- Post list ---------- */

[data-theme="dark"] .post-preview > a { color: var(--text-strong); }
[data-theme="dark"] .post-preview > a:hover,
[data-theme="dark"] .post-preview > a:focus { color: var(--accent); }
[data-theme="dark"] .post-preview > .post-meta { color: var(--muted); }
[data-theme="dark"] .post-preview > .post-meta > a { color: var(--text); }

[data-theme="dark"] .pager li > a,
[data-theme="dark"] .pager li > span {
    background-color: var(--surface);
    border-color: var(--border);
    color: var(--text);
}
[data-theme="dark"] .pager li > a:hover,
[data-theme="dark"] .pager li > a:focus {
    background-color: #0085a1;
    border-color: #0085a1;
    color: #fff;
}

[data-theme="dark"] .btn-default {
    background-color: var(--surface);
    border-color: var(--border);
    color: var(--text);
}
[data-theme="dark"] .form-control {
    background-color: var(--surface);
    border-color: var(--border);
    color: var(--text);
}

/* ---------- Footer ---------- */

[data-theme="dark"] footer .fa-stack .fa-circle { color: var(--surface-2); }
[data-theme="dark"] footer .fa-stack .fa-inverse { color: var(--text); }
[data-theme="dark"] footer a:hover .fa-circle { color: #0085a1; }
[data-theme="dark"] footer a:hover .fa-inverse { color: #fff; }

/* ---------- Search results page ---------- */

[data-theme="dark"] .search-page-status { color: var(--muted); border-bottom-color: var(--border); }
[data-theme="dark"] .search-page-status strong,
[data-theme="dark"] .search-page-status em { color: var(--text-strong); }
[data-theme="dark"] .search-page-result { border-bottom-color: var(--border); }
[data-theme="dark"] .search-page-title a { color: var(--text-strong); }
[data-theme="dark"] .search-page-title a:hover { color: var(--accent); }
[data-theme="dark"] .search-page-meta { color: var(--muted); }
[data-theme="dark"] .search-page-excerpt { color: var(--text); }
[data-theme="dark"] .search-page-excerpt a { color: var(--accent-strong); }
[data-theme="dark"] .search-page-excerpt code,
[data-theme="dark"] .search-page-excerpt pre { background: var(--surface); }

/* ---------- About page social buttons ---------- */

[data-theme="dark"] .social-links a { color: var(--text); border-color: var(--border); }
[data-theme="dark"] .social-links a.github:hover,
[data-theme="dark"] .social-links a.github:focus { background: #f0f2f5; border-color: #f0f2f5; color: #16181c; }
[data-theme="dark"] .social-links a.x:hover,
[data-theme="dark"] .social-links a.x:focus { background: #f0f2f5; border-color: #f0f2f5; color: #000; }

/* ---------- Code ---------- */

[data-theme="dark"] code {
    background-color: var(--surface-2);
    color: #f0a3b8;
}
[data-theme="dark"] pre code { background: transparent; color: inherit; }
[data-theme="dark"] pre,
[data-theme="dark"] .highlight pre,
[data-theme="dark"] .highlight .hll {
    background-color: #0d1117;
    border-color: var(--border);
    color: #c9d1d9;
}
[data-theme="dark"] .highlight { background: transparent; }

/* GitHub dark palette for Rouge tokens */
[data-theme="dark"] .highlight .c,
[data-theme="dark"] .highlight .cm,
[data-theme="dark"] .highlight .c1,
[data-theme="dark"] .highlight .cs,
[data-theme="dark"] .highlight .cp { color: #8b949e; }
[data-theme="dark"] .highlight .err { color: #f85149; background-color: transparent; }
[data-theme="dark"] .highlight .k,
[data-theme="dark"] .highlight .kc,
[data-theme="dark"] .highlight .kd,
[data-theme="dark"] .highlight .kn,
[data-theme="dark"] .highlight .kp,
[data-theme="dark"] .highlight .kr,
[data-theme="dark"] .highlight .o,
[data-theme="dark"] .highlight .ow { color: #ff7b72; }
[data-theme="dark"] .highlight .kt,
[data-theme="dark"] .highlight .nc,
[data-theme="dark"] .highlight .nn { color: #ffa657; }
[data-theme="dark"] .highlight .m,
[data-theme="dark"] .highlight .mf,
[data-theme="dark"] .highlight .mh,
[data-theme="dark"] .highlight .mi,
[data-theme="dark"] .highlight .mo,
[data-theme="dark"] .highlight .il { color: #79c0ff; }
[data-theme="dark"] .highlight .s,
[data-theme="dark"] .highlight .sb,
[data-theme="dark"] .highlight .sc,
[data-theme="dark"] .highlight .sd,
[data-theme="dark"] .highlight .s1,
[data-theme="dark"] .highlight .s2,
[data-theme="dark"] .highlight .se,
[data-theme="dark"] .highlight .sh,
[data-theme="dark"] .highlight .si,
[data-theme="dark"] .highlight .sx { color: #a5d6ff; }
[data-theme="dark"] .highlight .sr { color: #7ee787; }
[data-theme="dark"] .highlight .ss { color: #79c0ff; }
[data-theme="dark"] .highlight .n,
[data-theme="dark"] .highlight .w { color: #c9d1d9; }
[data-theme="dark"] .highlight .na,
[data-theme="dark"] .highlight .no,
[data-theme="dark"] .highlight .nv,
[data-theme="dark"] .highlight .vc,
[data-theme="dark"] .highlight .vg,
[data-theme="dark"] .highlight .vi,
[data-theme="dark"] .highlight .nb,
[data-theme="dark"] .highlight .bp { color: #79c0ff; }
[data-theme="dark"] .highlight .nf,
[data-theme="dark"] .highlight .ne { color: #d2a8ff; }
[data-theme="dark"] .highlight .nt { color: #7ee787; }
[data-theme="dark"] .highlight .ni { color: #ffa657; }
[data-theme="dark"] .highlight .gd { color: #ffdcd7; background-color: #67060c; }
[data-theme="dark"] .highlight .gi { color: #aff5b4; background-color: #033a16; }
[data-theme="dark"] .highlight .gd .x,
[data-theme="dark"] .highlight .gi .x { color: inherit; background-color: transparent; }
[data-theme="dark"] .highlight .gh,
[data-theme="dark"] .highlight .gu { color: #79c0ff; }
[data-theme="dark"] .highlight .gr,
[data-theme="dark"] .highlight .gt { color: #f85149; }
[data-theme="dark"] .highlight .go,
[data-theme="dark"] .highlight .gp { color: #8b949e; }
