/* Colours are set in js/config.js (colours.light / colours.dark); these are fallbacks */
:root {
  --bg: #ffffff;
  --fg: #111111;
  --radius: 0px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --serif: "Cormorant Garamond", "Cormorant", Garamond, Georgia, serif;
  --sans: "Helvetica Neue", Helvetica, Arial, sans-serif;
  --mono: "Space Mono", "SFMono-Regular", Menlo, Consolas, monospace;
  --edge: calc(22px + env(safe-area-inset-top));
}
:root[data-theme="dark"] {
  --bg: #111111;
  --fg: #f2f2f2;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  transition: background-color .6s ease, color .6s ease;
}

/* ---------- Layer 1: waterfall ---------- */
#stage {
  position: fixed;
  inset: 0;
  z-index: 1;
  overflow: hidden;
  touch-action: none;           /* touch drags move the waterfall, not the page */
}
.tile {
  position: absolute;
  top: 0;
  left: 0;
  overflow: hidden;
  border-radius: var(--radius);
  cursor: zoom-in;
  will-change: transform;
  opacity: 0;
  transition: opacity .9s ease;
}
.tile.ready { opacity: 1; }
.tile img,
.tile video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

/* ---------- Layer 11: name, mode toggle, Instagram ----------
   White + "difference" blending = always the inverse of what's beneath:
   black on the white page, white on the dark page, negative over images. */
#name,
#theme-toggle,
#instagram {
  position: fixed;
  z-index: 11;
  color: #fff;
  mix-blend-mode: difference;
}

#name {
  top: var(--edge);
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  padding-left: .32em;          /* balances the trailing letter-spacing so it sits truly centred */
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 400;
  letter-spacing: .32em;
  line-height: 1;
  text-transform: uppercase;
  white-space: nowrap;
  pointer-events: none;
  user-select: none;
}

/* iOS-style switch. Drawn in white/black and inverted by the blend:
   light mode = black outline + black knob on the left,
   dark mode  = white track + dark knob on the right. */
#theme-toggle {
  top: calc(var(--edge) - 4px);
  right: 22px;
  width: 36px;
  height: 21px;
  padding: 0;
  border: 1px solid currentColor;
  border-radius: 999px;
  background: transparent;
  cursor: pointer;
  transition: background-color .35s var(--ease);
}
#theme-toggle span {                    /* the knob */
  position: absolute;
  top: 2px;
  left: 2px;
  width: 15px;
  height: 15px;
  border-radius: 999px;
  background: #fff;
  transition: left .35s var(--ease), width .2s var(--ease), background-color .35s var(--ease);
}
#theme-toggle[aria-checked="true"] { background: #fff; }
#theme-toggle[aria-checked="true"] span { left: 17px; background: #000; }
#theme-toggle:hover span,
#theme-toggle:active span { width: 19px; }                              /* knob stretches, like iOS */
#theme-toggle[aria-checked="true"]:hover span,
#theme-toggle[aria-checked="true"]:active span { left: 13px; }          /* …towards the middle */
#theme-toggle:hover { box-shadow: 0 0 0 3px rgba(255, 255, 255, .18); }
#theme-toggle:focus-visible { outline: 1px solid currentColor; outline-offset: 3px; }

#instagram {
  left: 50%;
  bottom: calc(22px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 4px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .14em;
  text-transform: uppercase;
  text-decoration: none;
  transition: opacity .25s ease;
}
#instagram:hover { opacity: .6; }
#instagram:focus-visible { outline: 1px solid currentColor; outline-offset: 4px; }
#instagram span:empty { display: none; }

/* ---------- Layer 10: lightbox ---------- */
#lightbox {
  position: fixed;
  inset: 0;
  z-index: 10;
  visibility: hidden;
  cursor: zoom-out;
}
#lightbox.visible { visibility: visible; }
#lb-backdrop {
  position: absolute;
  inset: 0;
  background: var(--bg);
  opacity: 0;
  transition: opacity .5s ease, background-color .6s ease;
}
#lightbox.open #lb-backdrop { opacity: .94; }
#lb-media {
  position: fixed;
  overflow: hidden;
  border-radius: var(--radius);
  transition: left .55s var(--ease), top .55s var(--ease),
              width .55s var(--ease), height .55s var(--ease);
}
#lb-media.no-anim { transition: none; }
#lb-media img,
#lb-media video {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: opacity .35s ease;
}
#lb-media .lb-in,
#lb-media .lb-out { opacity: 0; }
#lightbox.closing-fade #lb-media { opacity: 0; transition: opacity .35s ease; }

/* prev / next row under the enlarged photo */
#lb-nav {
  position: fixed;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--fg);
  opacity: 0;
  transition: opacity .4s ease;
  cursor: default;
}
#lb-nav[hidden] { display: none; }
#lightbox.open #lb-nav { opacity: 1; transition-delay: .3s; }
#lb-nav button {
  padding: 6px 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  cursor: pointer;
  transition: opacity .2s ease;
}
#lb-nav button:hover { opacity: .45; }
#lb-nav button:focus-visible { outline: 1px solid currentColor; outline-offset: 3px; }
#lb-count { opacity: .5; white-space: pre; }

/* hide the Instagram link while a photo is enlarged — prev / next sits in that space */
#instagram { transition: opacity .3s ease; }
.lb-open #instagram { opacity: 0; pointer-events: none; }
#lb-caption {
  position: fixed;
  left: 0;
  right: 0;
  margin: 0;
  padding: 0 24px;
  text-align: center;
  font-family: var(--serif);
  font-style: italic;
  font-size: 16px;
  opacity: 0;
  transition: opacity .4s ease;
  pointer-events: none;
}
#lightbox.open #lb-caption:not(:empty) { opacity: .8; transition-delay: .3s; }
#lb-sound {
  position: fixed;
  right: 22px;
  bottom: calc(22px + env(safe-area-inset-bottom));
  display: none;
  padding: 0;
  border: 0;
  background: none;
  color: var(--fg);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .14em;
  text-transform: uppercase;
  cursor: pointer;
}
#lightbox.open.is-video #lb-sound { display: block; }

/* ---------- Custom cursor (mouse devices only) ---------- */
#cursor { display: none; }
.custom-cursor,
.custom-cursor * { cursor: none !important; }
.custom-cursor #cursor {
  display: block;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 100;
  pointer-events: none;
  will-change: transform;
}
#cursor span {
  position: absolute;
  left: -21px;
  top: -21px;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--fg);
  transform: scale(.381);               /* 16px when idle */
  transition: transform .3s var(--ease), opacity .2s ease, background-color .6s ease;
}
#cursor.on-image span { transform: scale(1); }   /* 42px over an image */
#cursor.hidden span { opacity: 0; }

@media (max-width: 480px) {
  #name { font-size: 11px; letter-spacing: .26em; padding-left: .26em; }
}

@media (prefers-reduced-motion: reduce) {
  #lb-media { transition-duration: .01s; }
}
