html[data-theme="dark"] {
  color-scheme: dark;
  --theme-ground: #0b0b0c;
  --theme-sheet: #171718;
  --theme-ink: #f0ede8;
  --theme-muted: #c1bdb7;
  --theme-line: #444446;
  --theme-accent: #f58377;
  background: var(--theme-ground);
}

/* Dark reading palette. */
html[data-theme="dark"] body {
  --paper: var(--theme-ground);
  --ink: var(--theme-ink);
  --muted: var(--theme-muted);
  --line: var(--theme-line);
  --accent: var(--theme-accent);
  --red: var(--theme-accent);
  --blue: #a9bfff;
  background-color: var(--paper);
  color: var(--ink);
}

html[data-theme] {
  --theme-grain: url("assets/paper-grain.png");
}

html[data-theme] body {
  --paper-wash: color-mix(in srgb, var(--paper) 54%, transparent);
  background-image: linear-gradient(var(--paper-wash), var(--paper-wash)), var(--theme-grain);
}
html[data-theme] :is(.home-enter, .editorial-index) { background-color: transparent; }

/* Put grain on the paper layers so the photographs and artwork retain their finish. */
html[data-theme="light"] .editorial-project-view .binder-page::after {
  background-image: linear-gradient(#faf9f37d, #faf9f37d), var(--theme-grain), linear-gradient(122deg, #fff9, #f4f0e570 56%, #ede8da51);
  background-size: auto, 345px, auto;
}

html[data-theme="light"] .editorial-project-view .binding-leaf {
  background-image: var(--theme-grain), linear-gradient(90deg, #fff7, transparent 64%, #66583b0f), var(--binder-fiber);
  background-size: 345px, auto, 430px;
  background-blend-mode: normal, normal, multiply;
}

html[data-theme="light"] .sheet-stack .sheet-stock {
  background-image: var(--theme-grain), linear-gradient(135deg, #fff5, transparent 43%, #6257470c), var(--fiber);
  background-size: 320px, auto, 220px;
  background-blend-mode: normal, normal, multiply;
}

html[data-theme="light"] .case-preview-dialog.image-review { background-image: var(--theme-grain); }

html[data-theme="dark"] .brand-mark .brand-image {
  filter: brightness(0) invert(.94);
}

html[data-theme="dark"] body .brand-mark:is(:hover, :focus-visible, .is-over-content) .brand-image {
  filter: url(#wordmark-contour) invert(.94);
}

html[data-theme="dark"] .brand-mark:focus-visible { outline-color: var(--theme-accent); }
html[data-theme="dark"] :is(#site-header, #site-footer) a:hover { color: var(--theme-accent); }

#theme-switch {
  position: fixed;
  z-index: 995;
  right: max(1.25rem, env(safe-area-inset-right));
  bottom: max(.6rem, env(safe-area-inset-bottom));
  display: inline-flex;
  align-items: center;
  gap: clamp(.125rem, .7vw, .65rem);
  isolation: isolate;
}
#theme-switch[hidden] { display: none; }

.theme-key {
  position: relative;
  isolation: isolate;
  display: grid;
  grid-template-columns: 2rem;
  place-content: center;
  width: max(44px, 2.75rem);
  min-height: max(44px, 2.75rem);
  margin: 0;
  cursor: pointer;
}
.theme-key input {
  position: absolute;
  z-index: 1;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: inherit;
}
.theme-keycap {
  pointer-events: none;
}
.theme-keycap svg {
  width: .75rem;
  height: .75rem;
  filter: drop-shadow(0 .6px 0 var(--key-imprint));
}
.theme-key input:focus-visible + .theme-keycap,
.filter-switch a:focus-visible .filter-keycap {
  outline: 2px solid var(--red);
  outline-offset: 3px;
}
/* Project and theme keys share a fixed seat and a pressed, molded face. */
#theme-switch,
.filter-switch {
  --key-ink: #322f27;
  --key-light: #faf5e8;
  --key-stock: #e7e1d1;
  --key-shade: #cec6b3;
  --key-rim: #918875;
  --key-well: #5a5549;
  --key-scuff: #a28e70;
  --key-polish: #f8f0d9;
  --key-imprint: #fff9e5a6;
}
html[data-theme="dark"] #theme-switch,
html[data-theme="dark"] .filter-switch {
  --key-ink: #f2ecdf;
  --key-light: #696961;
  --key-stock: #45463f;
  --key-shade: #33352e;
  --key-rim: #6a685b;
  --key-well: #1c1d19;
  --key-scuff: #ae9f82;
  --key-polish: #b2ac97;
  --key-imprint: #151611b3;
}
.theme-key::before,
.filter-switch a::before {
  content: "";
  grid-area: 1 / 1;
  margin: 1px -1px -2px;
  border: 1px solid var(--key-rim);
  border-radius: 4px;
  background: var(--key-well);
  box-shadow: 0 1px 1px #17140f52, 1px 2px 3px #1e1a143e;
  pointer-events: none;
}
.theme-keycap,
.filter-keycap {
  position: relative;
  grid-area: 1 / 1;
  display: grid;
  place-items: center;
  box-sizing: border-box;
  min-height: 1.3125rem;
  color: var(--key-ink);
  border: 1px solid;
  border-color: var(--key-light) var(--key-shade) var(--key-rim) var(--key-shade);
  border-radius: 3px;
  background:
    url("assets/paper-grain.png") var(--grain-origin, 0 0) / 112px,
    radial-gradient(100% 110% at 23% -32%, var(--key-light), transparent 85%),
    linear-gradient(173deg, var(--key-stock) 20%, var(--key-shade) 78%, var(--key-stock));
  box-shadow: inset .5px 1px 1px var(--key-light), inset -1px -1px 1px #221d163a, 0 1px 1px #1c19114d;
  text-shadow: 0 .6px 0 var(--key-imprint);
  transform: translateY(-1px);
  transition: transform 105ms ease-out, box-shadow 105ms ease-out;
}
.theme-keycap::before,
.filter-keycap::before {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  pointer-events: none;
  background:
    radial-gradient(ellipse 4px 1px at var(--wear-top, 15%) 1px, var(--key-scuff) 12%, transparent 96%),
    radial-gradient(ellipse 1.4px .8px at calc(var(--wear-top, 15%) + 5px) 1px, var(--key-scuff), transparent),
    radial-gradient(ellipse 1.2px 3px at calc(100% - 1px) var(--wear-side, 64%), var(--key-polish) 18%, transparent 93%),
    radial-gradient(ellipse 6px 1.3px at var(--wear-bottom, 79%) calc(100% - .75px), var(--key-polish) 20%, transparent);
}
.theme-key:last-child,
.filter-switch a[data-bookmark="product"] {
  --grain-origin: 23px 45px;
  --wear-top: 71%;
  --wear-bottom: 23%;
  --wear-side: 34%;
}
.filter-switch a[data-bookmark="creative"] {
  --grain-origin: 65px 13px;
  --wear-top: 34%;
  --wear-bottom: 89%;
  --wear-side: 72%;
}
.theme-key input:checked + .theme-keycap,
.theme-key:active .theme-keycap,
.filter-switch a:is([aria-current], :active) .filter-keycap {
  border-color: var(--key-rim) var(--key-shade) var(--key-shade);
  background:
    url("assets/paper-grain.png") var(--grain-origin, 0 0) / 112px,
    linear-gradient(173deg, var(--key-shade) 18%, var(--key-stock) 92%);
  box-shadow: inset 1px 1.5px 2px #211e174f, inset -.5px -.5px 1px var(--key-light);
  transform: translateY(1px);
}
.theme-key input:checked + .theme-keycap::after,
.filter-switch a[aria-current] .filter-keycap::after {
  content: "";
  position: absolute;
  bottom: 1.5px;
  width: 5px;
  height: 1px;
  border-radius: 1px;
  background: currentColor;
  box-shadow: 0 .6px 0 var(--key-imprint);
}
@media (hover: hover) {
  .theme-key:hover input:not(:checked) + .theme-keycap,
  .filter-switch a:hover:not([aria-current]) .filter-keycap { filter: brightness(1.05); }
}
@media (forced-colors: active) {
  .theme-key::before, .theme-keycap::before,
  .filter-switch a::before, .filter-keycap::before { display: none; }
  .theme-key input:checked + .theme-keycap { border: 2px solid ButtonText; }
  .filter-switch a[aria-current] .filter-keycap { border: 2px solid ButtonText; text-decoration: underline; }
  .theme-key input:focus-visible + .theme-keycap,
  .filter-switch a:focus-visible .filter-keycap { outline-color: Highlight; }
}

@media (max-width: 700px) {
  #theme-switch {
    right: max(.75rem, env(safe-area-inset-right));
    bottom: max(.75rem, env(safe-area-inset-bottom));
  }


  /* Leave narrow text columns and campaign images unobstructed. */
  body:is([data-page="about"], [data-page="project"]) #theme-switch {
    position: static;
    display: flex;
    width: fit-content;
    margin: .5rem var(--page-gutter) max(1rem, env(safe-area-inset-bottom)) auto;
  }
}

@media (hover: hover) and (pointer: fine) {
  html[data-theme="dark"] body,
  html[data-theme="dark"] body * {
    cursor: url("assets/cursor-dot-dark.svg") 12 12, auto !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  .theme-keycap, .filter-keycap { transition: none; }
}

@media print {
  #theme-switch { display: none; }
}

/* Lift the animated ink off its pale canvas while keeping the portrait in full colour. */
html[data-theme="dark"] .home-motion:is([src="assets/work-across-motion.gif"], [src="assets/work-across-black-refined.gif"]) {
  filter: url(#night-lettering);
  mix-blend-mode: normal;
}

html[data-theme="light"] .home-motion:is([src="assets/work-across-motion.gif"], [src="assets/work-across-black-refined.gif"]) {
  filter: url(#night-lettering) brightness(.075);
  mix-blend-mode: normal;
}

html[data-theme="dark"] .alerts-visual .visual-footnote,
html[data-theme="dark"] .alert-sequence span {
  color: var(--theme-muted);
}

html[data-theme="dark"] .alert-sequence > div {
  border-color: var(--theme-line);
}

/* The index sits on charcoal. The archive objects keep their own inks and stock. */
html[data-theme="dark"] .editorial-index {
  --index-muted: var(--theme-muted);
  color: var(--theme-ink);
}

html[data-theme="dark"] .editorial-index .index-item {
  color: var(--theme-ink);
}

html[data-theme="dark"] .editorial-index .index-item:is(:hover, :focus-visible, .is-linked) {
  color: var(--theme-accent);
}

html[data-theme="dark"] .editorial-index .sheet-stack.is-linked .sheet-title,
html[data-theme="dark"] .editorial-index .sheet-link:focus-visible .sheet-title {
  color: color-mix(in srgb, var(--theme-accent) 70%, var(--theme-ink));
}

html[data-theme="dark"] .editorial-index :is(.index-item, .sheet-link):focus-visible {
  outline: 2px solid var(--theme-accent);
}

html[data-theme="dark"] .editorial-index .sheet-link {
  color: var(--theme-ink);
  filter: none;
}

html[data-theme="dark"] .sheet-stack .sheet-stock {
  background-color: #202021;
  background-image: var(--theme-grain), linear-gradient(136deg, #ffffff09, transparent 58%, #11121429), var(--fiber);
  box-shadow: inset 0 0 0 1px #ffffff19, 1px 2px 3px #0005, 3px 8px 12px -6px #0009;
}

html[data-theme="dark"] .sheet-stack .sheet-underleaf {
  background-color: #2d2c2d;
  background-image: var(--theme-grain), linear-gradient(154deg, #ffffff0d, transparent 58%, #191a1926), var(--fiber);
  border-top-color: #ffffff28;
}

html[data-theme="dark"] .sheet-stack :is(.sheet-stock, .sheet-underleaf) {
  background-size: 320px, auto, 220px;
  background-blend-mode: normal, normal, multiply;
}

html[data-theme="dark"] .sheet-stack .sheet-mark {
  color: var(--theme-accent);
}

html[data-theme="dark"] .cover-independent-mark img,
html[data-theme="dark"] .sheet-stack .cover-company-mark--muko img {
  filter: brightness(0) invert(.94);
}

/* Reverse the letterform and return the dot to the green hue range. */
html[data-theme="dark"] .sheet-stack .cover-company-mark--deloitte img {
  filter: invert(1) hue-rotate(180deg);
}

html[data-theme="dark"] .sheet-stack .sheet-tracing {
  --vellum-wash: linear-gradient(112deg, #f5f1df19, #dad8cd05 70%);
  background-color: #b5b0a56b;
  border-color: #e8e4da5c #28262345 #24231f66 #f5f0e269;
  box-shadow: 1px 2px 3px #11111169, 3px 6px 9px -4px #0006;
}

html[data-theme="dark"] .sheet-stack .sheet-tracing::after {
  box-shadow: inset .7px .7px 0 #f8f4e545, inset -.7px -.7px 0 #4a494237;
}

html[data-theme="dark"] .sheet-stack .sheet-plate {
  color: #181817;
}

html[data-theme="dark"] .sheet-stack .sheet-plate:has(img) {
  mix-blend-mode: normal;
  opacity: 1;
}

html[data-theme="dark"] .sheet-stack .sheet-data {
  --card-stock: #eadfc9;
  --contact-shadow: #09080780;
}

/* The charcoal stock sits behind the case study and its original artwork. */
html[data-theme="dark"] :is(.editorial-project-view, .case-study, .case-preview-dialog) {
  --paper: var(--theme-sheet);
  --ink: var(--theme-ink);
  --muted: var(--theme-muted);
  --red: var(--theme-accent);
  --binder-stock: var(--theme-sheet);
  --binder-rule: var(--theme-line);
  color: var(--ink);
}

html[data-theme="dark"] .editorial-project-view .binding-leaf {
  background-color: var(--binder-stock);
  background-image: var(--theme-grain), linear-gradient(90deg, #ffffff09, transparent 66%, #0002), var(--binder-fiber);
  background-size: 345px, auto, 430px;
  background-blend-mode: normal, normal, multiply;
  box-shadow: 0 0 0 1px #ffffff14, 1px 3px 0 -1px #454547, 2px 6px 0 -3px #353537, 3px 10px 13px -9px #000a;
}

html[data-theme="dark"] .editorial-project-view .binder-page::before {
  background: var(--theme-grain) 0 0 / 345px, var(--binder-fiber) 0 0 / 430px var(--binder-stock);
  background-blend-mode: normal, multiply;
  border-color: #ffffff1a;
  box-shadow: 1px 2px 4px #0004;
}

html[data-theme="dark"] .editorial-project-view .binder-page::after {
  background: linear-gradient(128deg, #ffffff04, transparent 56%, #00000008);
  border-color: #ffffff13 #ffffff0d #00000030;
  box-shadow: 1px 2px 2px #0003, 3px 8px 16px -8px #0008;
}

html[data-theme="dark"] .editorial-project-view .binder-veil {
  background-color: #ffffff06;
  background-image: var(--vellum-grain), linear-gradient(107deg, #ffffff0b, transparent);
  border-color: #ffffff1c #ffffff12 #0003;
  box-shadow: 1px 2px 4px #0004;
}

html[data-theme="dark"] .veil-mark .cover-company-mark--muko img {
  filter: brightness(0) invert(.94);
}

html[data-theme="dark"] .veil-mark .cover-company-mark--deloitte img {
  filter: invert(1) hue-rotate(180deg) brightness(1.13);
}

html[data-theme="dark"] .case-not-for-sale blockquote { color: var(--theme-ink); }
html[data-theme="dark"] :is(.nfs-colophon, .paper-end) { border-color: var(--theme-line); }

html[data-theme="dark"] .case-preview-dialog.image-review {
  border-color: var(--theme-line);
  background-color: var(--theme-sheet);
  background-image: var(--theme-grain);
}
html[data-theme="dark"] .case-preview-dialog.image-review::backdrop { background: #111214d6; }

html[data-theme="dark"] .muko-steps button { color: var(--theme-muted); }
html[data-theme="dark"] .muko-steps button:disabled { color: #a49e98; }
html[data-theme="dark"] .muko-steps button:is(:hover:not(:disabled), [aria-pressed="true"]) {
  color: var(--theme-accent);
}

/* Keep the products’ UI and native form controls on the original art direction. */
html[data-theme="dark"] :is(.muko-site-preview, .muko-workspace, .lepere-piece, .alerts-stage, .alert-trigger-stage) {
  color-scheme: light;
  --red: #a63227;
}
html[data-theme="dark"] .alert-trigger-stage { color: var(--alert-ink); }

html[data-theme="dark"] .lepere-piece {
  padding: clamp(12px, 3cqw, 28px);
  border-radius: 14px;
  background: #f8f7f2;
}
