/*
 * Sunlit background and pull cord, ported from newa.sh.
 * Dark is any theme that is not data-theme="light" (the foundry's "default").
 */

/* ------------------------------------------------------- sunlit background */

/* The bounce light's colour, from the portfolio's Sunlight.astro. newa.css sets
   one value for every theme on html:root; set here on the layer itself, it
   wins by inheritance without needing more specificity. */
#dappled-light {
  --bounce-light: rgba(255, 255, 255, 0.3);
  pointer-events: none;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  width: 100vw;
  z-index: -1;
}

#glow {
  position: absolute;
  background: linear-gradient(309deg, var(--bounce-light), var(--bounce-light) 20%, transparent);
  transition: background 1s var(--timing-fn);
  height: 100%;
  width: 100%;
  opacity: 0.5;
}

#glow-bounce {
  content: "";
  position: absolute;
  background: linear-gradient(355deg, var(--bounce-light) 0%, transparent 30%, transparent 100%);
  transition: background 1s var(--timing-fn);
  opacity: 0.5;
  height: 100%;
  width: 100%;
  bottom: 0;
}

html:not([data-theme="light"]) #dappled-light {
  --bounce-light: rgba(197, 210, 255, 0.25);
}

/* The two themes are tuned to read about equally: dark's glow and shadow are
   held down, and light's shadow stays at 0.04 because muted text over it must
   keep 4.5:1 (portfolio Sunlight.astro). */
html:not([data-theme="light"]) #glow,
html:not([data-theme="light"]) #glow-bounce {
  opacity: 0.35;
}

.perspective {
  position: absolute;
  transition: transform 1.7s var(--timing-fn), opacity 4s ease;
  top: -30vh;
  right: 0;
  width: 80vw;
  height: 130vh;
  opacity: 0.04;
  background-blend-mode: darken;
  transform-origin: top right;
  transform-style: preserve-3d;
  transform: matrix3d(0.75, -0.0625, 0, 0.0008, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
}

html:not([data-theme="light"]) .perspective {
  opacity: 0.25;
  transform: matrix3d(0.8333, 0.0833, 0, 0.0003, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
}

#leaves {
  position: absolute;
  background-size: cover;
  background-repeat: no-repeat;
  bottom: -20px;
  right: -700px;
  width: 1600px;
  height: 1400px;
  background-image: var(--leaves-image, url(/foundry/theme/leaves.png));
  filter: url(#wind);
}

/* theme/sunlight.js, when loaded, draws the wind on the GPU and runs it only
   while it can be seen; the SVG filter is then the fallback where WebGL 2 is
   unavailable. Without the script the filter above applies as before. */
#leaves.wind-js {
  filter: none;
}
#leaves.wind-js.wind-fallback {
  filter: url(#wind);
}
#leaves.wind-gpu {
  background-image: none;
}

/* The leaves' slow 8s sway, the portfolio's `billow` (sunlight-wind.ts). */
@media (prefers-reduced-motion: no-preference) {
  #leaves {
    animation: leaves-billow 8s infinite;
  }
}
@keyframes leaves-billow {
  0% { transform: perspective(400px) rotateX(0deg) rotateY(0deg) scale(1); animation-timing-function: ease-in-out; }
  25% { transform: perspective(400px) rotateX(1deg) rotateY(2deg) scale(1.02); animation-timing-function: ease-in-out; }
  50% { transform: perspective(400px) rotateX(-4deg) rotateY(-2deg) scale(0.97); animation-timing-function: ease-in-out; }
  75% { transform: perspective(400px) rotateX(1deg) rotateY(-1deg) scale(1.04); animation-timing-function: ease-in-out; }
  100% { transform: perspective(400px) rotateX(0deg) rotateY(0deg) scale(1); }
}

#blinds {
  position: relative;
  width: 100%;
}

#blinds .shutter,
#blinds .bar {
  background-color: var(--shadow);
}

#blinds > .shutters {
  display: flex;
  flex-direction: column;
  align-items: end;
  gap: 60px;
}

#blinds > .vertical {
  top: 0;
  position: absolute;
  height: 100%;
  width: 100%;
  display: flex;
  justify-content: space-around;
}

.vertical > .bar {
  width: 5px;
  height: 100%;
  transform-origin: top;
  transition: transform 1s var(--timing-fn);
}

/* The slats thicken in the dark theme: 40px with a 60px gap becomes 80px
   with a 20px gap. The 100px pitch never changes, so each slat only scales
   from its top edge. The bars grow by the 40px the last slat adds to the
   2240px stack of 23 slats (portfolio Sunlight.astro). */
html:not([data-theme="light"]) .vertical > .bar {
  transform: scaleY(calc(2280 / 2240));
}

.shutter {
  width: 100%;
  height: 40px;
  transform-origin: top;
  transition: transform 1s var(--timing-fn);
}

html:not([data-theme="light"]) .shutter {
  transform: scaleY(2);
}

#progressive-blur {
  position: absolute;
  height: 100%;
  width: 100%;
}

#progressive-blur > div {
  position: absolute;
  height: 100%;
  width: 100%;
  inset: 0;
  backdrop-filter: blur(var(--blur-amount));
  mask-size: 100vw 100vh;
  mask-repeat: no-repeat;
  mask-image: linear-gradient(252deg, transparent, transparent var(--stop1), black var(--stop2), black);
}

#progressive-blur > div:nth-child(1) {
  --blur-amount: 6px;
  mask-image: none;
}
#progressive-blur > div:nth-child(2) {
  width: min(100%, calc(60vw + 20vh));
  --blur-amount: 12px;
  --stop1: 40%;
  --stop2: 80%;
}
#progressive-blur > div:nth-child(3) {
  width: min(100%, calc(60vw + 20vh));
  --blur-amount: 48px;
  --stop1: 40%;
  --stop2: 70%;
}
#progressive-blur > div:nth-child(4) {
  width: min(100%, calc(30vw + 10vh));
  --blur-amount: 96px;
  --stop1: 70%;
  --stop2: 80%;
}

@media (max-width: 767px) {
  #dappled-light {
    display: none !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  #leaves,
  #leaves.wind-js.wind-fallback {
    filter: none;
  }
}

/* -------------------------------------------------------------- pull cord */

.theme-cord {
  position: fixed;
  top: 0;
  left: calc(var(--sidebar-width) - 60px);
  z-index: 90;
  width: 60px;
  height: 320px;
  overflow: visible;
  pointer-events: none;
  user-select: none;
  color: #bbbbbb;
  transition: color 300ms;
}

html:not([data-theme="light"]) .theme-cord {
  color: #b4b4b4;
}

.theme-cord svg {
  display: block;
  overflow: visible;
}

.theme-cord-knob {
  position: absolute;
  top: 0;
  left: 5px;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  cursor: grab;
  pointer-events: auto;
  touch-action: none;
  will-change: transform;
}

.theme-cord-knob:active {
  cursor: grabbing;
}

.theme-cord-knob:focus-visible {
  outline: 2px solid var(--newa-accent);
  outline-offset: 2px;
}

/* Entry, from the portfolio's ThemeToggleCordClient: the cord fades in as it
   drops, and the ceiling anchor unfolds from the top. */
.theme-cord-visual {
  opacity: 0;
  transition: opacity 140ms ease-out;
}
.theme-cord--entered .theme-cord-visual {
  opacity: 1;
}
.theme-cord-anchor {
  opacity: 0;
  transform: translateY(-3px) scaleY(0.35);
  transform-box: fill-box;
  transform-origin: center top;
}
.theme-cord--entered .theme-cord-anchor {
  animation: theme-cord-anchor-enter 420ms cubic-bezier(0.22, 1, 0.36, 1) 80ms both;
}
@keyframes theme-cord-anchor-enter {
  to {
    opacity: 1;
    transform: translateY(0) scaleY(1);
  }
}
@media (prefers-reduced-motion: reduce) {
  .theme-cord-visual {
    opacity: 1;
    transition: none;
  }
  .theme-cord-anchor {
    opacity: 1;
    transform: none;
    animation: none;
  }
}

@media (max-width: 900px) {
  .theme-cord {
    display: none;
  }
}

/* The sunlit layer sits behind the page, so the page colour moves to <html>
   and the body stays transparent; otherwise the body paints over the layer. */
html {
  background-color: var(--newa-bg);
}
html body {
  background-color: transparent;
}

/* ----------------------------------------------------- scroll progress */
/* Ported from newa.sh. Colours match its neutral-300/700/200 Tailwind values. */

.scroll-progress {
  position: fixed;
  top: 50%;
  right: 0;
  z-index: 50;
  display: none;
  height: var(--scroll-indicator-height, 120px);
  transform: translateY(-50%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 150ms ease-out;
}

@media (min-width: 768px) {
  .scroll-progress {
    display: block;
  }
}

.scroll-progress.is-dragging {
  opacity: 1 !important;
}

.scroll-progress-hit {
  position: absolute;
  top: -24px;
  right: 0;
  width: var(--scroll-indicator-hitbox-width, 28px);
  height: calc(100% + 48px);
  box-sizing: border-box;
  padding: 24px calc(max(24px, 1.25vw) / 2 + 0.5px) 24px 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  cursor: grab;
}

.scroll-progress.is-dragging .scroll-progress-hit {
  cursor: grabbing;
}

.scroll-progress-track {
  position: relative;
  height: 100%;
  width: 1px;
}

.scroll-progress-line,
.scroll-progress-fill {
  position: absolute;
  top: 0;
  right: 0;
  height: 100%;
  width: 1px;
}

.scroll-progress-line {
  background: #d4d4d4;
}

.scroll-progress-fill {
  transform-origin: top;
  transform: scaleY(0);
  background: #404040;
  transition: transform 75ms ease-out;
  will-change: transform;
}

.scroll-progress.is-dragging .scroll-progress-line,
.scroll-progress.is-dragging .scroll-progress-fill {
  right: -1px;
  width: 3px;
  transition: none;
}

.scroll-progress.is-dragging .scroll-progress-line {
  transition: all 200ms;
}

html:not([data-theme="light"]) .scroll-progress-line {
  background: rgba(64, 64, 64, 0.8);
}

html:not([data-theme="light"]) .scroll-progress-fill {
  background: #e5e5e5;
}

.scroll-progress-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  cursor: grabbing;
  background: transparent;
  user-select: none;
}

body.scroll-progress-scrubbing {
  user-select: none;
  cursor: grabbing;
}

/* ------------------------------------------------- selection in fields */
/* selection-marker.js draws its stroke over the page's own text, and newa.css
   makes ::selection transparent once it is ready. A text field's selection is
   not part of the page's text, so the marker never draws there and the field
   would show no selection at all. Fields keep the native highlight in the
   marker's blue, as on the portfolio (src/styles/main.css). This lives here,
   not in newa.css, because it belongs with the ported newa.sh pieces; the
   extra element selector outranks newa.css's `body *::selection`. */
html.selection-marker-ready body :is(input, textarea)::selection {
  color: currentColor;
  background-color: #c2e5ff;
}
html.selection-marker-ready body :is(input, textarea)::-moz-selection {
  color: currentColor;
  background-color: #c2e5ff;
}
html.selection-marker-ready:not([data-theme="light"]) body :is(input, textarea)::selection {
  background-color: color-mix(in srgb, #0090ff 65%, transparent);
}
html.selection-marker-ready:not([data-theme="light"]) body :is(input, textarea)::-moz-selection {
  background-color: color-mix(in srgb, #0090ff 65%, transparent);
}

/* Native scrollbar hidden; scrolling still works. */
html,
body {
  scrollbar-width: none;
}
html::-webkit-scrollbar,
html *::-webkit-scrollbar,
body::-webkit-scrollbar {
  display: none !important;
  width: 0 !important;
  height: 0 !important;
}
