/* Light / dark theme.
   The light theme is main.css, unchanged. Every dark rule below is scoped to
   html[data-theme="dark"], so nothing here touches the light theme except the
   toggle button itself. The theme is set in base.html before the CSS loads
   (no flash) and saved in localStorage under "theme". */

/* Toggle button (both themes) */
.theme-toggle {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.1rem;
    height: 2.1rem;
    padding: 0;
    border: 1px solid var(--nic_main);
    border-radius: 4px;
    background: transparent;
    color: var(--nic_main);
    cursor: pointer;
}
.theme-toggle:hover {
    background: var(--nic_main);
    color: #fff;
}
.theme-toggle:focus-visible {
    outline: 2px solid var(--nic_blue);
    outline-offset: 2px;
}
.theme-toggle svg {
    width: 1.1rem;
    height: 1.1rem;
}
.theme-toggle .icon-sun { display: none; }
html[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
html[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
.search-and-toggle {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

/* Dark theme */
html[data-theme="dark"] {
    --nic_main: #e6e6e6;
    --nic_red: #e6e6e6;
    --dark_bg: #121212;
    --dark_surface: #1e1e1e;
    --dark_raised: #2a2a2a;
    --dark_line: #3a3a3a;
    color-scheme: dark;
}

html[data-theme="dark"] body,
html[data-theme="dark"] #content {
    background: var(--dark_bg);
    color: var(--nic_main);
}

html[data-theme="dark"] ::selection { background: #e6e6e6; color: #121212; }
html[data-theme="dark"] ::-moz-selection { background: #e6e6e6; color: #121212; }

/* Header */
html[data-theme="dark"] .header_image { filter: invert(1); }
html[data-theme="dark"] #banner nav { background: #000; border: 1px solid var(--dark_line); }
html[data-theme="dark"] #banner nav a:link,
html[data-theme="dark"] #banner nav a:visited { color: #e6e6e6; }
html[data-theme="dark"] #banner nav a:hover,
html[data-theme="dark"] #banner nav a:active,
html[data-theme="dark"] #banner nav .active a:link,
html[data-theme="dark"] #banner nav .active a:visited {
    background: #e6e6e6;
    color: #000;
}
html[data-theme="dark"] .theme-toggle:hover { color: #121212; }

/* Footer */
html[data-theme="dark"] #contentinfo { background-color: #000; color: #e6e6e6; border-top: 1px solid var(--dark_line); }
html[data-theme="dark"] #contentinfo a,
html[data-theme="dark"] #contentinfo h3 { color: #e6e6e6; }

/* Tables */
html[data-theme="dark"] thead th { background-color: var(--dark_raised); color: #fff; border-bottom-color: var(--dark_line); }
html[data-theme="dark"] tbody td { border-bottom-color: var(--dark_line); }

/* Lists of notes, titles, table of contents */
html[data-theme="dark"] .entry-title a:link,
html[data-theme="dark"] .entry-title a:visited { color: #e6e6e6; background-color: transparent; }
html[data-theme="dark"] .hentry,
html[data-theme="dark"] li:first-child .hentry,
html[data-theme="dark"] #content > .hentry { border-top-color: var(--dark_raised); border-left-color: var(--dark_raised); }
html[data-theme="dark"] .toc { background: var(--dark_surface); color: #ddd; border-left-color: #888; }
html[data-theme="dark"] .toc li,
html[data-theme="dark"] .toctitle { color: #ddd; }

/* Tags and internal note links */
html[data-theme="dark"] .link_tag:link,
html[data-theme="dark"] .link_tag:visited,
html[data-theme="dark"] .tag { background-color: var(--dark_raised); color: #fff; }
html[data-theme="dark"] .link_tag:hover { background-color: #e6e6e6; color: #121212; }
html[data-theme="dark"] .nic_link { border-color: #888; }
html[data-theme="dark"] .nic_link:before { background-color: #000; color: #e6e6e6; }
html[data-theme="dark"] .nic_link a { background-color: var(--dark_surface); }
html[data-theme="dark"] .nic_link a:visited { color: #8ab4f8; }

/* Pagination */
html[data-theme="dark"] .pagination-link:hover,
html[data-theme="dark"] .pagination-link:focus { background: #e6e6e6; color: #121212; }
html[data-theme="dark"] .pagination-link-disabled { color: #666; border-color: #444; }

/* Note components */
html[data-theme="dark"] .datestamp-update { color: #e6e6e6; }
html[data-theme="dark"] .nicai-signature { background-color: var(--dark_surface); color: #bbb; }
html[data-theme="dark"] #about-author { background: var(--dark_surface); }
html[data-theme="dark"] #comments-list blockquote,
html[data-theme="dark"] #comments-list li:nth-child(2n) blockquote { background: var(--dark_surface); }
html[data-theme="dark"] .illustration,
html[data-theme="dark"] .iphone,
html[data-theme="dark"] .book,
html[data-theme="dark"] .album { box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.7); }
html[data-theme="dark"] .shadow { box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.7); }
html[data-theme="dark"] .clipboard-button { background-color: var(--dark_raised); border-color: #666; color: #bbb; }
html[data-theme="dark"] .clipboard-button > svg { fill: #bbb; }
html[data-theme="dark"] .clipboard-button:hover { background-color: #3a3a3a; }
html[data-theme="dark"] .entry-content a:not(.link_tag):not(.nic_link a) { color: #ff6b5b; }
html[data-theme="dark"] code { background-color: #262626; }
html[data-theme="dark"] pre { background-color: #1a1a1a; border: 1px solid var(--dark_raised); }
html[data-theme="dark"] pre code { background-color: transparent; }

/* Images with transparent or white backgrounds stay readable on a light card */
html[data-theme="dark"] .link_logo_box { background: #fff; border-radius: 3px; }

/* Pagefind search */
html[data-theme="dark"] .pagefind-ui {
    --pagefind-ui-primary: #e6e6e6;
    --pagefind-ui-text: #e6e6e6;
    --pagefind-ui-background: #1e1e1e;
    --pagefind-ui-border: #555;
    --pagefind-ui-tag: #2a2a2a;
}
html[data-theme="dark"] #search .pagefind-ui__search-input,
html[data-theme="dark"] #search .pagefind-ui__drawer {
    background: var(--dark_surface);
    color: #e6e6e6;
}
html[data-theme="dark"] #search .pagefind-ui__result-excerpt,
html[data-theme="dark"] #search .pagefind-ui__message { color: #bbb; }
html[data-theme="dark"] #search mark { background: #6b5b00; color: #fff; }

@media (max-width: 600px) {
    .search-and-toggle { width: 100%; }
    .search-and-toggle #search { flex: 1 1 auto; width: auto; }
}
