/* Portfolio themes. Images, brand artwork and teletext keep their own colors. */
html[data-portfolio-theme="light"] {
  --bg: #f6f7f7;
  --card-bg: #ffffff;
  --border: #cdd5d9;
  --accent: #0077b3;
  --portfolio-ink: #23292b;
  --portfolio-muted: #59656b;
}
html[data-portfolio-theme="light"] body { background: var(--bg); color: var(--portfolio-ink); }
html[data-portfolio-theme="light"] :is(.nav-item.active, .thought-text, .thought-symbol, .article-link, .back, .excerpt, .period-year, .project-content, .subproject-name, .ql-editor) { color: var(--portfolio-ink); }
html[data-portfolio-theme="light"] :is(.nav-pill, .card, .project-content pre, .ql-editor pre) { background: var(--card-bg); }
html[data-portfolio-theme="light"] .nav { border-color: var(--border); }
html[data-portfolio-theme="light"] :is(.period-line, .articles-divider) { background: var(--border); }
html[data-portfolio-theme="light"] :is(.article-page-excerpt, .article-time, .date, .project-content blockquote, .ql-editor blockquote) { color: var(--portfolio-muted); }
html[data-portfolio-theme="light"] .article-quote { color: var(--portfolio-ink) !important; }
html[data-portfolio-theme="light"] .ql-editor p.caption { color: var(--portfolio-muted) !important; }
html[data-portfolio-theme="light"] :is(.project-content a, .ql-editor a, .excerpt a, .thought-text a, .like-count) { color: var(--accent); }
html[data-portfolio-theme="light"] :is(.nav-item:hover, .article-link:hover) { color: var(--accent); }
html[data-portfolio-theme="light"] :is(.project-content blockquote, .ql-editor blockquote, .article-quote) { border-left-color: var(--accent) !important; }
/* The monochrome Luna link mark needs its dark variant on a light surface. */
html[data-portfolio-theme="light"] .link-logo img[src$="/luna-logo-2309.png"] { filter: brightness(0); }

/* The whole 50 × 50 CSS pixel plate is a single fixed toggle. */
.theme-switch {
  position: fixed; left: max(24px, env(safe-area-inset-left)); bottom: max(24px, env(safe-area-inset-bottom));
  z-index: 10000; display: block; padding: 0; border: 0; border-radius: 2px;
  background: transparent; color: inherit; appearance: none; cursor: pointer;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
  width: 50px; height: 50px; flex: 0 0 50px;
  isolation: isolate;
  --switch-top: url(#switch-raised-face);
  --switch-bottom: url(#switch-recessed-face);
  --switch-top-lip: .85;
  --switch-bottom-lip: .18;
}
.theme-switch svg { display: block; width: 50px; height: 50px; overflow: visible; pointer-events: none; }
.theme-switch[aria-checked="true"] {
  --switch-top: url(#switch-recessed-face);
  --switch-bottom: url(#switch-raised-face);
  --switch-top-lip: .18;
  --switch-bottom-lip: .85;
}
.theme-switch:focus { outline: none; }
.theme-switch:focus-visible { outline: 2px solid var(--accent, #00aeff); outline-offset: 5px; }
.theme-switch__top { fill: var(--switch-top); }
.theme-switch__bottom { fill: var(--switch-bottom); }
.theme-switch__top-lip { opacity: var(--switch-top-lip); }
.theme-switch__bottom-lip { opacity: var(--switch-bottom-lip); }
@media (max-width: 768px) {
  .theme-switch { left: max(16px, env(safe-area-inset-left)); bottom: max(16px, env(safe-area-inset-bottom)); }
}
@media (forced-colors: active) {
  .theme-switch { outline: 1px solid ButtonText; }
  .theme-switch svg { forced-color-adjust: none; }
  .theme-switch[aria-checked="true"] { outline: 2px solid Highlight; }
}

/* Reference: 73HkaOoBSjc, 00:03–00:06. At 300 ms the ends glow faintly;
   around 567 ms the room is dimly lit; at 1735–1768 ms the tube strikes and
   reaches steady light. The last part of the 3 s sequence stays fully lit. */
html.portfolio-lamp-on body::after {
  content: ""; position: fixed; inset: 0; z-index: 9999;
  pointer-events: none; opacity: 0;
  background: radial-gradient(ellipse at 35% 0%,
    rgba(14, 13, 11, .96) 0%, rgba(6, 6, 5, .98) 65%, rgba(4, 4, 4, .985) 100%);
}
html.portfolio-lamp-lit body::after {
  animation: portfolio-lamp-ignite 2700ms linear both;
}
@keyframes portfolio-lamp-ignite {
  0%, 9% { opacity: 1; }
  9.9% { opacity: .88; }
  11.1%, 42% { opacity: .865; }
  43.3%, 51.9% { opacity: .85; }
  53.15% { opacity: .06; }
  54.4%, 100% { opacity: 0; }
}
@media (prefers-reduced-motion: reduce), (forced-colors: active) {
  html.portfolio-lamp-on body::after { display: none; animation: none; }
}

/* The original 50px switch remains in the document, hidden for easy restoration. */
.legacy-theme-switch[hidden] { display: none !important; }
.theme-icon-toggle {
  display: inline-grid; place-items: center; flex: none;
  inline-size: 36px; block-size: 36px;
  margin: 0; padding: 0; border: 0; border-radius: 0;
  color: inherit; background: transparent; appearance: none;
  cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent;
  z-index: 10000;
}
.theme-icon-toggle svg { display: block; inline-size: 20px; block-size: 20px; pointer-events: none; }
.theme-icon-toggle:focus-visible { outline: 2px solid currentColor; outline-offset: 3px; }
/* 26px presentation; the original SVGs and 20px rules above remain intact.
   Set this variable to 20px to restore the preceding size. */
:root { --portfolio-control-icon-size: 26px; }
:is(.theme-icon-toggle, .tt-toggle) svg {
  inline-size: var(--portfolio-control-icon-size);
  block-size: var(--portfolio-control-icon-size);
}

/* One viewport anchor for all five public page templates. Match the homepage
   1440px wrapper and its responsive gutters; never depend on a title width. */
:root { --portfolio-controls-inset: 40px; }
.portfolio-controls {
  position: fixed;
  top: max(38px, env(safe-area-inset-top));
  right: max(var(--portfolio-controls-inset), calc((100vw - 1440px) / 2 + 40px), env(safe-area-inset-right));
  z-index: 10000;
  display: flex; align-items: center; gap: 8px;
  inline-size: 80px; block-size: 36px;
  color: inherit;
}
@media (max-width: 1100px) { :root { --portfolio-controls-inset: 24px; } }
@media (max-width: 768px) { :root { --portfolio-controls-inset: 16px; } }
@media (max-width: 480px) { :root { --portfolio-controls-inset: 12px; } }
@media (max-width: 600px) {
  /* Reserve the first row for the fixed controls on narrow navigation pages. */
  body:has(> .portfolio-controls) .nav-wrap { padding-top: 90px; }
}
