/* The public site's colour preference leaves article content and images intact. */
:root{color-scheme:light}
.theme-toggle{display:inline-flex;align-items:center;justify-content:center;flex:0 0 44px;width:44px;height:44px;padding:10px;border:1px solid #e2e9f5;border-radius:13px;background:#f5f8fe;color:#5c6e93;transition:background-color .18s,color .18s,border-color .18s}
.theme-toggle:hover{background:#eaf1ff;border-color:#ccdaf5;color:#3868ee}
.theme-toggle:focus-visible{outline:3px solid #f5c84c;outline-offset:3px}
.theme-toggle svg{display:block;flex-shrink:0;width:22px;height:22px;pointer-events:none}
.theme-toggle .theme-icon-sun{display:none}
html[data-theme="dark"] .theme-toggle .theme-icon-moon{display:none}
html[data-theme="dark"] .theme-toggle .theme-icon-sun{display:block}
.header-end{gap:10px}

/* Keep every header action reachable, including on small phones. */
@media(min-width:901px) and (max-width:1280px){
  .site-header{column-gap:24px}
  .header-end .header-note{display:none}
}
@media(min-width:601px) and (max-width:900px){
  .site-header{display:grid;grid-template-columns:auto minmax(0,1fr) auto;gap:12px 16px}
  .site-brand{grid-column:1;grid-row:1}
  .site-nav{grid-column:2;grid-row:1;justify-self:center;gap:14px}
  .header-search{grid-column:1/-1;grid-row:2;width:100%;min-width:0}
  .header-end{grid-column:3;grid-row:1;margin-left:0}
  .header-end .header-note{display:none}
}
@media(max-width:600px){
  .site-header{grid-template-columns:minmax(0,1fr) auto 48px;column-gap:8px}
  .header-end{gap:4px}
  .theme-toggle{border-radius:12px}
}

@media screen{
  html[data-theme="dark"]{
    color-scheme:dark;
    --ink:#e7edf8;
    --muted:#a7b5cc;
    --blue:#99baff;
    --bg:#101827;
    --line:#33435c;
    --theme-surface:#192538;
    --theme-raised:#223148;
    --theme-hover:#293c58;
    --theme-action:#3b65ce;
  }
  html[data-theme="dark"] ::selection{background:#3d5c93;color:#fff}
  html[data-theme="dark"] :is(.site-header,.welcome-card,.post-card,.compact-card,.reading-card,.library-list,.archive-list,.search-panel,.empty-state,.recommended-reading,.project-card){background:var(--theme-surface)}
  html[data-theme="dark"] :is(.site-nav,.welcome-copy p,.header-note,.site-footer,.eyebrow){color:var(--muted)}
  html[data-theme="dark"] .site-nav>a:hover,
  html[data-theme="dark"] .site-nav>a.nav-current,
  html[data-theme="dark"] .nav-articles-toggle:hover,
  html[data-theme="dark"] .nav-articles[open]>.nav-articles-toggle,
  html[data-theme="dark"] .nav-articles:has(.nav-current)>.nav-articles-toggle{color:var(--blue)}
  html[data-theme="dark"] .handwritten{color:#a0baff}
  html[data-theme="dark"] .about-card{background:linear-gradient(135deg,#2b4d9e,#253f80)}
  html[data-theme="dark"] :is(.home-card-media,.home-compact-media,.hero-carousel,.project-cover){background:#233650}
  html[data-theme="dark"] :is(.section-heading,.archive-item,.header-search-results>li+li){border-color:var(--line)}
  html[data-theme="dark"] :is(.post-card:hover,.recommended-reading-card:hover){box-shadow:0 10px 26px #0003}

  /* Navigation and category colours preserve the existing colour families. */
  html[data-theme="dark"] :is(.nav-articles-panel,.nav-custom-panel,.header-search-panel,.notifications-panel){background:var(--theme-surface);border-color:var(--line);box-shadow:0 14px 40px #0005}
  html[data-theme="dark"] .nav-articles-toggle:before{background:#99baff12}
  html[data-theme="dark"] :is(.nav-custom-toggle,.nav-custom-panel .nav-category,.category-custom,.post-tags .category-custom){background:#2b374b;color:#c2ccdd}
  html[data-theme="dark"] :is(.nav-custom[open]>.nav-custom-toggle,.nav-custom:has(.nav-current)>.nav-custom-toggle){color:var(--blue)}
  html[data-theme="dark"] .category-link{color:var(--ink)}
  html[data-theme="dark"] .category-all{background:var(--theme-raised);color:var(--ink)}
  html[data-theme="dark"] .nav-category.category-all{border-color:var(--line)}
  html[data-theme="dark"] :is(.category-notes,.post-tags .category-notes){background:#243d5a;color:#b4d7ff}
  html[data-theme="dark"] :is(.category-essays,.post-tags .category-essays){background:#493044;color:#f1bed8}
  html[data-theme="dark"] :is(.category-projects,.post-tags .category-projects){background:#393151;color:#d5c1fa}
  html[data-theme="dark"] :is(.category-life,.post-tags .category-life){background:#463d25;color:#f4dc98}
  html[data-theme="dark"] :is(.category-library,.post-tags .category-library){background:#213f3c;color:#a9dfd1}
  html[data-theme="dark"] :is(.post-tags a,.topic-tags a){background:#293b59;color:#b7cdff}
  html[data-theme="dark"] .category-link:hover{box-shadow:0 3px 12px #0003}
  html[data-theme="dark"] .nav-category.nav-current,
  html[data-theme="dark"] .nav-category[aria-current="page"]{border-color:currentColor}

  /* Search, notifications and the colour switch share dark control surfaces. */
  html[data-theme="dark"] .theme-toggle{background:var(--theme-raised);border-color:var(--line);color:#f0d58a}
  html[data-theme="dark"] .theme-toggle:hover{background:var(--theme-hover);border-color:#57729c;color:#ffe9a7}
  html[data-theme="dark"] .header-search-form{background:linear-gradient(var(--theme-surface),var(--theme-surface)) padding-box,linear-gradient(110deg,#9b79e4,#b96ac8 52%,#e57c9b) border-box}
  html[data-theme="dark"] .header-search-form:focus-within{box-shadow:0 0 0 3px #b8a6ef26}
  html[data-theme="dark"] .header-search-form>button{color:#c0b2ff}
  html[data-theme="dark"] .header-search-form>button:hover{color:#dfd6ff}
  html[data-theme="dark"] .header-search-form>input::placeholder,
  html[data-theme="dark"] .search-form input::placeholder{color:var(--muted)}
  html[data-theme="dark"] :is(.search-form input,.article-share-manual input){background:#141f31;border-color:var(--line);color:var(--ink)}
  html[data-theme="dark"] :is(.header-search-results a:hover,.header-search-results a:focus-visible,.notifications-item:hover,.notifications-item:focus-visible,.notifications-close:hover,.notifications-back:hover){background:var(--theme-hover)}
  html[data-theme="dark"] :is(.notifications-toggle,.notifications-close,.notifications-back){color:var(--muted)}
  html[data-theme="dark"] .notifications-toggle:hover,
  html[data-theme="dark"] .notifications-toggle[aria-expanded="true"]{background:var(--theme-raised);color:var(--blue)}
  html[data-theme="dark"] .notifications-dot{box-shadow:0 0 0 2px var(--theme-surface)}
  html[data-theme="dark"] :is(.header-search-retry,.notifications-retry,.retry-search){background:#2b3e60;color:#c0d4ff}
  html[data-theme="dark"] .search-load-error{color:#edc095}
  html[data-theme="dark"] .skip-link{background:#e7edf8;color:#101827}

  /* Reading surfaces include rich text, tables, linked cards and code blocks. */
  html[data-theme="dark"] :is(.gh-content a,.text-link,.article-interaction-retry){color:var(--blue)}
  html[data-theme="dark"] .gh-content blockquote{background:#21314a;border-left-color:#6d94dd;color:#c3d0e6}
  html[data-theme="dark"] .gh-content code{background:#2a3a51;color:#e0eafe}
  html[data-theme="dark"] .gh-content pre{background:#111b2b;color:#e0eafe}
  html[data-theme="dark"] .gh-content pre code{background:transparent;color:inherit}
  html[data-theme="dark"] :is(.copy-code,.kg-bookmark-card,.kg-callout-card,.toc){background:var(--theme-raised);border-color:var(--line);color:var(--ink)}
  html[data-theme="dark"] .gh-content :is(td,th){border-color:var(--line)}
  html[data-theme="dark"] .gh-content th{background:var(--theme-raised);color:var(--ink)}
  html[data-theme="dark"] .gh-content mark{background:#544720;color:#ffeca0}
  html[data-theme="dark"] .gh-content li[data-type="taskItem"]>label input{accent-color:var(--blue)}
  html[data-theme="dark"] .library-item h2 span{color:var(--muted)}
  html[data-theme="dark"] .pagination a{background:var(--theme-raised);color:var(--blue)}
  html[data-theme="dark"] .pagination a:hover{background:var(--theme-hover)}
  html[data-theme="dark"] :is(.primary-button,.search-form button,.kg-button-card a,.project-visit){background:var(--theme-action);color:#fff}
  html[data-theme="dark"] .project-visit:hover{background:#4873dd}

  /* Related reading, project links and the floating article actions. */
  html[data-theme="dark"] :is(.post-navigation-link,.recommended-reading-card,.article-share-manual){background:var(--theme-raised);border-color:var(--line);color:var(--ink)}
  html[data-theme="dark"] .recommended-reading{border-color:var(--line)}
  html[data-theme="dark"] :is(.post-navigation-link:hover,.recommended-reading-card:hover){background:var(--theme-hover);border-color:#4d6791}
  html[data-theme="dark"] .recommended-reading-card strong{color:var(--ink)}
  html[data-theme="dark"] .recommended-reading-card time{color:var(--muted)}
  html[data-theme="dark"] .project-record{background:#293b59;color:#bed2ff}
  html[data-theme="dark"] .project-record:hover{background:#334b71}
  html[data-theme="dark"] .article-interaction-bar{background:var(--theme-surface);border-color:var(--line);box-shadow:0 5px 26px #0005}
  html[data-theme="dark"] .article-interaction-button{color:#bac7dc}
  html[data-theme="dark"] .article-interaction-button:hover{background:var(--theme-hover);color:var(--ink)}
  html[data-theme="dark"] .article-interaction-button[data-article-comment][aria-expanded="true"]{background:#293e62;color:var(--blue)}
  html[data-theme="dark"] .article-like-button[aria-pressed="true"]{color:#ff9fb3}
  html[data-theme="dark"] .article-like-button[aria-pressed="true"]:hover{background:#492e40;color:#ffb7c6}
  /* Comments already use a readable charcoal palette in both themes. */
  html[data-theme="dark"] .article-comments .article-interaction-retry{color:#ffffffc7}
  html[data-theme="dark"] .article-comments .article-interaction-retry:hover{color:#fff}

  @media(max-width:600px){
    html[data-theme="dark"] .site-nav{background:var(--theme-surface);box-shadow:0 15px 30px #0005}
    html[data-theme="dark"] :is(.nav-custom-panel,.nav-custom.opens-left>.nav-custom-panel){box-shadow:none}
  }
}

@media(prefers-reduced-motion:reduce){.theme-toggle{transition:none}}
@media print{.theme-toggle{display:none!important}}
