.portfolio-theme-toggle {
  display: inline-grid;
  place-items: center;
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid currentColor;
  border-color: color-mix(in srgb, currentColor 22%, transparent);
  border-radius: 50%;
  background: transparent;
  color: inherit;
  cursor: pointer;
}

.portfolio-theme-toggle:hover {
  background: color-mix(in srgb, currentColor 9%, transparent);
}

.portfolio-theme-toggle:focus-visible { outline: 2px solid currentColor; outline-offset: 3px; }
.portfolio-theme-icons { display: grid; place-items: center; width: 24px; height: 24px; }
.portfolio-theme-toggle svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.portfolio-theme-toggle .theme-sun,
[data-theme="dark"] .portfolio-theme-toggle .theme-moon { display: none; }
[data-theme="dark"] .portfolio-theme-toggle .theme-sun { display: block; }
.portfolio-footer__preferences {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
}
.theme-page-footer { margin-top: 32px; text-align: center; }

@media screen and (prefers-reduced-motion: no-preference) {
  :root[data-theme-transition] {
    --theme-fade-duration: 280ms;
  }

  [data-theme-transition]::view-transition { pointer-events: none; overflow: clip; }
  [data-theme-transition]::view-transition-group(root),
  [data-theme-transition]::view-transition-old(root) { animation: none; }
  [data-theme-transition]::view-transition-image-pair(root) { isolation: auto; }
  [data-theme-transition]::view-transition-old(root),
  [data-theme-transition]::view-transition-new(root) { mix-blend-mode: normal; }
  [data-theme-transition]::view-transition-new(root) {
    animation: portfolio-theme-fade var(--theme-fade-duration) ease-in-out both;
  }

  [data-theme-transition] .portfolio-theme-icons { view-transition-name: portfolio-theme-icon; }
  [data-theme-transition]::view-transition-group(portfolio-theme-icon) {
    overflow: clip;
    animation: none;
    z-index: 2;
  }
  [data-theme-transition]::view-transition-old(portfolio-theme-icon),
  [data-theme-transition]::view-transition-new(portfolio-theme-icon) {
    mix-blend-mode: normal;
    animation: var(--theme-icon-animation) 180ms ease-out both;
  }
  [data-theme-transition]::view-transition-old(portfolio-theme-icon) { --theme-icon-animation: portfolio-theme-icon-out; }
  [data-theme-transition]::view-transition-new(portfolio-theme-icon) { --theme-icon-animation: portfolio-theme-icon-in; }

  @keyframes portfolio-theme-fade {
    from { opacity: 0; }
    to { opacity: 1; }
  }

  @keyframes portfolio-theme-icon-out {
    to { transform: translateX(-45%); opacity: 0; }
  }

  @keyframes portfolio-theme-icon-in {
    from { transform: translate(45%, 15%); opacity: 0; }
  }
}

@media screen {
  :root[data-theme="dark"] {
    color-scheme: dark;
    background: var(--theme-page);
    --theme-page: #161718;
    --theme-surface: #202225;
    --theme-raised: #2a2d31;
    --theme-ink: #efefed;
    --theme-muted: #b8b9bf;
    --theme-line: #41444a;
    --theme-link: #c3caff;
    --portfolio-ink: var(--theme-ink);
    --portfolio-copy: var(--theme-muted);
    --portfolio-line: var(--theme-line);
    --paper: var(--theme-page);
    --ink: var(--theme-ink);
    --muted: var(--theme-muted);
    --line: var(--theme-line);
    --surface: var(--theme-surface);
    --accent: var(--theme-link);
    --editorial-paper: var(--theme-page);
    --editorial-ink: var(--theme-ink);
    --editorial-muted: var(--theme-muted);
    --editorial-line: var(--theme-line);
    --editorial-accent: var(--theme-link);
    --lt-paper: var(--theme-page);
    --lt-ink: var(--theme-ink);
    --lt-muted: var(--theme-muted);
    --lt-line: var(--theme-line);
    --lt-accent: #e4abc0;
    --lt-chapter: var(--theme-raised);
    --lt-surface: var(--theme-surface);
    --wivlo-ink: var(--theme-ink);
    --wivlo-text: var(--theme-muted);
    --wivlo-muted: var(--theme-muted);
    --wivlo-line: var(--theme-line);
    --wivlo-surface: var(--theme-surface);
    --wivlo-accent: #aac7ff;
    --wivlo-accent-soft: #28364c;
  }

  :root[data-theme="dark"] ::selection {
    background-color: #36374b;
    color: var(--theme-ink);
  }

  [data-theme="dark"] body:not(.project-snapside) {
    background: var(--theme-page);
    color: var(--theme-ink);
  }

  [data-theme="dark"] :is(.site-header, body .project-page-header) {
    background: rgb(22 23 24 / 96%);
    color: var(--theme-ink);
    border-color: var(--theme-line);
  }

  [data-theme="dark"] :is(.site-header, .project-page-header) :is(.brand, .back-link, nav a) { color: var(--theme-ink); }
  [data-theme="dark"] :is(.site-header, .project-page-header) nav a:is(:hover, :focus-visible, [aria-current]) {
    color: var(--theme-link);
    background: var(--theme-raised);
  }

  [data-theme="dark"] body .portfolio-footer { color: var(--theme-muted); }
  [data-theme="dark"] body .portfolio-footer :is(a, .lang-button, .portfolio-footer__copyright) { color: var(--theme-muted); }
  [data-theme="dark"] body .portfolio-footer :is(a, .lang-button):hover { color: var(--theme-ink); }
  [data-theme="dark"] .portfolio-footer__contacts a::before { filter: brightness(0) invert(.82); }
  [data-theme="dark"] body .portfolio-footer .lang-button:is(:hover, .active, [aria-pressed="true"]) {
    background: var(--theme-raised);
    color: var(--theme-ink);
  }

  [data-theme="dark"] .home-intro.page-shell {
    background: linear-gradient(115deg, #242b3c, #2a242e);
  }

  [data-theme="dark"] .home-intro-portrait { border-color: #575562; }
  [data-theme="dark"] .intro-profile.page-shell { border-color: var(--theme-line); }
  [data-theme="dark"] :is(.intro-bio .hero-description, .home-toolstrip .tools-label, .github-activity) { color: var(--theme-muted); }
  [data-theme="dark"] .github-activity [data-level="0"] { fill: #2a2d2b; }
  [data-theme="dark"] .github-activity [data-level="1"] { fill: #2d503e; }
  [data-theme="dark"] .github-activity [data-level="2"] { fill: #3b7150; }
  [data-theme="dark"] .github-activity [data-level="3"] { fill: #5c9a6f; }
  [data-theme="dark"] .github-activity [data-level="4"] { fill: #90c39a; }
  [data-theme="dark"] :is(.tool-mark, .lt-case-tool-mark) img:is([src$="/notion.svg"], [src$="/cursor.svg"]) {
    filter: invert(.88);
  }

  [data-theme="dark"] .selected-projects .project-panel { --project-card-ink: var(--theme-ink); }
  [data-theme="dark"] .selected-projects .panel-mongram { --project-card-surface: #273129; }
  [data-theme="dark"] .selected-projects .panel-snapside { --project-card-surface: #252624; }
  [data-theme="dark"] .selected-projects .panel-wivlo { --project-card-surface: #272e42; }

  [data-theme="dark"] :is(.home-case-card, .lt-case-entry, .lt-related-card) { --case-card-surface: #30272e; }
  [data-theme="dark"] .lt-related-card-mongram { --case-card-surface: #273129; }
  [data-theme="dark"] :is([href="lalatulle-navigation.html"], [data-project-href="lalatulle-navigation.html"]) { --case-card-surface: #282c39; }
  [data-theme="dark"] :is([href="lalatulle-first-view.html"], [data-project-href="lalatulle-first-view.html"]) { --case-card-surface: #2e293c; }
  [data-theme="dark"] :is([href="lalatulle-experiment.html"], [data-project-href="lalatulle-experiment.html"]) { --case-card-surface: #352c25; }

  [data-theme="dark"] .lt-case-page { --lt-cover-surface: #30272e; --lt-cover-ink: #eac4d5; }
  [data-theme="dark"] .lt-detail-navigation { --lt-cover-surface: #282c39; --lt-cover-ink: #bfcef4; }
  [data-theme="dark"] .lt-detail-first-view { --lt-cover-surface: #2e293c; --lt-cover-ink: #d8c5eb; }
  [data-theme="dark"] .lt-detail-experiment { --lt-cover-surface: #352c25; --lt-cover-ink: #e7c9a6; }

  [data-theme="dark"] .project-lalatulle .lt-case-result {
    --lt-result-bg: #272327;
    --lt-result-surface: #302a30;
    --lt-result-summary: #3a2e37;
    --lt-result-ink: var(--theme-ink);
    --lt-result-muted: var(--theme-muted);
    --lt-result-line: #52444e;
    --lt-result-accent: #ebb3c9;
  }

  [data-theme="dark"] .project-lalatulle :is(.ln-google-search, .ln-cover-image) { background: var(--theme-surface); }
  [data-theme="dark"] .project-lalatulle :is(.ln-priority li, .ln-live-button) { background: var(--theme-raised); color: var(--theme-ink); }
  [data-theme="dark"] .project-lalatulle :is(.ln-priority-icon, .ln-priority li b) { color: var(--lt-accent); }
  [data-theme="dark"] .lt-detail-first-view .lt-detail-art { background: var(--lt-cover-surface); }

  [data-theme="dark"] body .portfolio-next-section { --next-bg: var(--theme-surface); --next-ink: var(--theme-ink); }
  [data-theme="dark"] .project-mongram .n-section .result-conclusion { background: #2c3830; color: var(--theme-ink); }
  [data-theme="dark"] .wivlo-case-study-page :is(.mode-workspace button, .end-to-end-flow) { background: #303b57; color: var(--theme-ink); }
  [data-theme="dark"] .wivlo-case-study-page :is(
    .product-thesis article:not(.is-accent), .broken-workflow article, .review-analysis-card:not(.is-ai),
    .research-patterns article, .research-workflow, .positioning-rail article:not(.is-current),
    .mode-card, .mock-editor, .co-write-model aside b, .delegate-model > div, .interface-gallery figcaption,
    .wivlo-ia-global b, .wivlo-ia-context, .wivlo-ia-output, .wivlo-ia-editor, .wivlo-system-layer
  ) { background: var(--theme-raised); }

  [data-theme="dark"] :is(.project-edition, .project-edition span) { color: var(--theme-muted); }
  [data-theme="dark"] body .project-hero :is(.case-kicker, .case-lead, .case-meta span) { color: var(--theme-muted); }
  [data-theme="dark"] body .project-hero .project-hero-copy > :is(h1, h2) { color: var(--theme-ink); }
  [data-theme="dark"] body .project-hero .case-links a { color: var(--theme-link); border-color: currentColor; }
  [data-theme="dark"] :is(.case-image-placeholder, .project-trami .media-placeholder) {
    background: var(--theme-raised);
    border-color: var(--theme-line);
  }
  [data-theme="dark"] :is(.case-image-placeholder, .project-trami .media-placeholder) > :is(span, small, strong) { color: var(--theme-muted); }

  [data-theme="dark"] :is(.ln-return-categories li, .ln-nav-changes > div) {
    background: var(--theme-raised);
    border-color: var(--theme-line);
  }
  [data-theme="dark"] .lt-priority-scale { color: var(--theme-muted); }
  /* Keep the palette used to illustrate the original click patterns. */
  [data-theme="dark"] .lt-search-mock { color: #34252a; }

  [data-theme="dark"] body.project-mongram {
    --n-ink: var(--theme-ink);
    --n-muted: var(--theme-muted);
    --n-paper: var(--theme-surface);
    --n-sage: #29342c;
    --n-line: var(--theme-line);
  }
  [data-theme="dark"] .project-mongram .mg-hero .mg-hero-screens { background: #29342c; }
  [data-theme="dark"] .project-mongram :is(.mg-brand .mg-brand-name, .n-project-links a, .n-section .mg-poodle-heading h3) { color: var(--theme-ink); }
  [data-theme="dark"] .project-mongram :is(
    .mg-hero-copy .hero-lead, .mg-hero-copy .eyebrow, .mg-hero-copy p, .mg-cover-meta :is(p, .eyebrow), .mg-sharing-note,
    .n-section .mg-case-summary, .n-section .mg-design-label, .n-section .mg-evidence-note,
    .mg-evidence-comparison figcaption, .mg-home-note, .n-scenario-art figcaption, .n-section .mg-poodle-note
  ) { color: var(--theme-muted); }
  [data-theme="dark"] .project-mongram :is(.mg-family-testing, .mg-poodle-gallery) { background: var(--theme-surface); }
  [data-theme="dark"] .project-mongram :is(.mg-family-case, .n-project-links a:hover) { background: var(--theme-raised); }
  [data-theme="dark"] .project-mongram .n-section.n-dark { background: #1e2420; color: var(--theme-ink); }
  /* The gallery includes hand-drawn dark strokes on light tiles. */
  [data-theme="dark"] .project-mongram .mg-poodle-card { color: #292929; }

  [data-theme="dark"] .wivlo-case-study-page :is(
    .overview-section, .case-index a, .research-synthesis, .broken-workflow, .positioning-rail article:not(.is-current),
    .usage-insight, .decision-table article > div, .strategy-decisions article, .wivlo-mobile-shot
  ) { background: var(--theme-surface); }
  [data-theme="dark"] .wivlo-case-study-page :is(.case-index a:hover, .product-thesis article.is-accent, .positioning-rail article.is-current) {
    background: var(--wivlo-accent-soft);
  }
  [data-theme="dark"] .wivlo-case-study-page :is(
    .case-index small, .research-synthesis blockquote, .review-analysis-card footer a, .broken-workflow > i, .interface-main figcaption span,
    .learning-section .evidence-method, .learning-section .evidence-caption, .learning-section .scope-note,
    .learning-section .usage-details p, .learning-section .usage-insight p, .learning-section .usage-metrics p,
    .learning-section .usage-next p, .learning-section .usage-records p, .learning-section .return-grid :is(span, p)
  ) { color: var(--theme-muted); }
  [data-theme="dark"] body.wivlo-product-page :is(.product-flow-stage, .product-task-flow li, .ai-architecture small) { color: var(--theme-muted); }
  [data-theme="dark"] .wivlo-case-study-page .case-index span { color: var(--wivlo-accent); }
  [data-theme="dark"] .wivlo-case-study-page .wivlo-component-samples button { color: #16233c; }

  [data-theme="dark"] body.project-moneymate {
    --mm-muted: var(--theme-muted);
    --mm-ink: var(--theme-ink);
    --mm-line: var(--theme-line);
    --mm-mint: #29352f;
    --mm-header: rgb(22 23 24 / 96%);
  }
  [data-theme="dark"] .project-moneymate :is(.mm-screen-stage, .mm-screen-stage.mm-lilac) { background: var(--theme-raised); }

  [data-theme="dark"] .project-trami { --trami-orange: #f2bb73; --trami-orange-soft: #382d22; }
  [data-theme="dark"] .project-trami :is(
    .participant-card, .field-synthesis, .synthesis-node, .synthesis-decision, .trami-comparison article:not(.is-trami),
    .trami-choice-map article:not(.is-selected), .trami-experience-flow article:not(:first-child), .choice-steps i
  ) { background: var(--theme-raised); border-color: var(--theme-line); }
  [data-theme="dark"] .project-trami :is(.choice-steps b, .trami-experience-flow article:first-child :is(span, strong, p)) { color: #291a0f; }
  [data-theme="dark"] .project-trami .choice-steps i { color: var(--theme-muted); }
  [data-theme="dark"] .project-trami .participant-tag.lifestyle { background: #9c3a21; }
  [data-theme="dark"] .project-trami .participant-tag.usability { background: #2658a4; }
}

@media print {
  .portfolio-theme-toggle { display: none; }
}
