/* =====================================================================
   DARK PREVIEW: midnight blue-black, switchable with the nav toggle.
   Loaded after restyle.css, only in the preview copy of the site.
   Everything dark sits under html[data-mode="dark"]; without it the site
   is the normal light one.
   ===================================================================== */
:root[data-mode="dark"],
:root[data-mode="dark"][data-theme="light"],
:root[data-mode="dark"][data-theme="dark"]{
  --r-bg:#0A0F1C;          /* midnight, almost black */
  --r-surface:#121A2B;     /* plates and pills, one step up */
  --r-ink:#E6E9F0;
  --r-mute:#8C95AB;
  --r-hair:#1F2840;
  color-scheme:dark;
}
:root[data-mode="dark"]{background:var(--r-bg)!important;color:var(--r-ink)}
/* the page colour lives on <html>; body stays see-through so the carousel's
   curved edges (a layer just behind the body) aren't painted over */
:root[data-mode="dark"] body{background:transparent!important;color:var(--r-ink)}
:root[data-mode="dark"] body.on-cream,:root[data-mode="dark"] body.scrollable{background:transparent!important}
:root[data-mode="dark"] ::selection{background:#2B3A63;color:#fff}

/* switching: colours ease across instead of snapping */
html.r-mode-anim,html.r-mode-anim body,html.r-mode-anim body *{
  transition:background-color .45s ease,color .45s ease,border-color .45s ease,fill .45s ease!important;
}

/* ---------- the contact pill: on hover it went black-on-black ---------- */
:root[data-mode="dark"] body > nav .links a[href^="mailto:"]:hover{
  background:#FFFFFF;color:var(--r-bg);
}

/* ---------- images drawn on white ----------
   Sketches and charts: flip them to light lines on the midnight ground
   (invert, then turn the hues back so blue ink stays blue), and let screen
   drop the black that was white. Photos and screenshots can't be flipped,
   so they sit on their own rounded white card instead. */
:root[data-mode="dark"] .cst img:is([src$="nv-loop.webp"],[src$="nv2-hand-notes.webp"],[src$="nv2-engine.webp"],
  [src$="nv2-infinity.webp"],[src$="galls-flow-before.png"],[src$="galls-flow-after.png"],
  [src$="ab-timeline.png"],[src$="ab-infinity.png"]){
  filter:invert(1) hue-rotate(180deg) brightness(1.05)!important;
  mix-blend-mode:screen!important;
}
:root[data-mode="dark"] .cst img:is([src$="nv-whatsapp.webp"],[src$="ab-board.png"]){
  mix-blend-mode:normal!important;border-radius:var(--r-radius)!important;
}
/* photos and screen mockups: take the edge off the brightest whites */
:root[data-mode="dark"] :is(.cst img,#work img,.abv-board img,#meanwhile .mw-panel img){filter:brightness(.92)}
:root[data-mode="dark"] :is(#work .proj-frame,.cst .cst-shot){background-color:var(--r-surface)}

/* =====================================================================
   THE TOGGLE: a soft tray. A raised rim around a sunken floor, and a
   matte, rounded-square knob resting in it. One material, no colour:
   the light falls from the top left, so the floor is shaded at its top
   edge and the knob casts a soft shadow down and to the right.
   ===================================================================== */
.r-mode{
  --w:54px;--h:30px;--rim:3px;--k:calc(var(--h) - var(--rim) * 2 - 2px);
  position:relative;flex:none;
  width:var(--w);height:var(--h);margin:0 12px 0 2px;padding:0;border:0;
  border-radius:999px;cursor:pointer;align-self:center;
  /* the rim: lit on top, a touch darker underneath */
  background:linear-gradient(180deg,#FFFFFF 0%,#ECEBE8 100%);
  box-shadow:
    0 1px 2px rgba(0,0,0,.10),
    0 4px 10px rgba(0,0,0,.06),
    inset 0 0 0 .5px rgba(0,0,0,.08);
  -webkit-tap-highlight-color:transparent;
}
.r-mode:focus-visible{outline:2px solid var(--r-ink);outline-offset:3px}
/* the floor: sunk inside the rim, shaded where the rim overhangs it */
.r-mode-glow{
  position:absolute;inset:var(--rim);border-radius:999px;
  /* light: a warm, sunlit floor, soft apricot fading to butter yellow */
  background:linear-gradient(100deg,#FFCF9A 0%,#FFE1A8 55%,#FFEDC2 100%);
  box-shadow:
    inset 0 2px 3px rgba(150,80,0,.18),
    inset 2px 0 4px rgba(0,0,0,.05),
    inset 0 0 0 .5px rgba(0,0,0,.10);
}
/* the knob: a soft rounded square, matte, sitting on the floor */
.r-mode-knob{
  position:absolute;top:calc(var(--rim) + 1px);left:calc(var(--rim) + 1px);
  width:var(--k);height:var(--k);
  border-radius:42%;
  background:linear-gradient(160deg,#FBFAF8 0%,#EFEEEA 100%);
  box-shadow:
    0 1px 1px rgba(0,0,0,.10),
    1px 3px 6px rgba(0,0,0,.14),
    inset 0 1px 0 rgba(255,255,255,.95),
    inset 0 -1px 1px rgba(0,0,0,.05);
  transform:translateX(0);
  transition:transform .5s cubic-bezier(.3,1.25,.5,1),background .45s ease,box-shadow .45s ease,width .2s ease;
}
.r-mode:hover .r-mode-knob{box-shadow:0 1px 1px rgba(0,0,0,.10),1px 4px 9px rgba(0,0,0,.17),inset 0 1px 0 rgba(255,255,255,.95),inset 0 -1px 1px rgba(0,0,0,.05)}
.r-mode:active .r-mode-knob{width:calc(var(--k) + 3px)}
/* dark mode: same object in midnight material, knob slid across */
:root[data-mode="dark"] .r-mode{
  background:linear-gradient(180deg,#273149 0%,#151C2D 100%);
  box-shadow:0 1px 2px rgba(0,0,0,.5),0 4px 10px rgba(0,0,0,.35),inset 0 0 0 .5px rgba(255,255,255,.08);
}
:root[data-mode="dark"] .r-mode-glow{
  /* dark: a deep blue-grey floor, like dusk */
  background:linear-gradient(100deg,#2C3548 0%,#3A4459 60%,#465068 100%);
  box-shadow:inset 0 2px 3px rgba(0,0,0,.6),inset 2px 0 4px rgba(0,0,0,.3),inset 0 0 0 .5px rgba(255,255,255,.05);
}
:root[data-mode="dark"] .r-mode-knob{
  transform:translateX(calc(var(--w) - var(--k) - var(--rim) * 2 - 2px));
  background:linear-gradient(160deg,#5A6683 0%,#3A4560 100%);
  box-shadow:0 1px 1px rgba(0,0,0,.4),1px 3px 6px rgba(0,0,0,.5),inset 0 1px 0 rgba(255,255,255,.14),inset 0 -1px 1px rgba(0,0,0,.25);
}
@media (prefers-reduced-motion:reduce){ .r-mode-knob{transition:none} }
@media (max-width:560px){ .r-mode{--w:46px;--h:26px;margin:0 6px 0 0} }
