/* 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,
#links {
  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 + Contact, side by side, bottom centre */
#links {
  left: 50%;
  bottom: calc(22px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 30px;
  white-space: nowrap;
  transition: opacity .3s ease;
}
#instagram,
#contact-open {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 4px;
  border: 0;
  background: none;
  color: inherit;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .14em;
  text-transform: uppercase;
  text-decoration: none;
  cursor: pointer;
  transition: opacity .25s ease;
}
#instagram:hover,
#contact-open:hover { opacity: .6; }
#instagram:focus-visible,
#contact-open: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 */
.lb-open #links,
.contact-open #links { 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; }

/* ---------- Layer 20: contact drawer ---------- */
#contact {
  position: fixed;
  inset: 0;
  z-index: 20;
  visibility: hidden;
  transition: visibility 0s linear .6s;
}
#contact.open { visibility: visible; transition-delay: 0s; }
#contact-veil {
  position: absolute;
  inset: 0;
  background: var(--bg);
  opacity: 0;
  transition: opacity .5s ease;
}
#contact.open #contact-veil { opacity: .7; }
#contact-drawer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 26px 24px calc(34px + env(safe-area-inset-bottom));
  background: var(--bg);
  color: var(--fg);
  border-top: 1px solid var(--fg);
  transform: translateY(100%);
  transition: transform .6s var(--ease), background-color .6s ease, color .6s ease;
}
#contact.open #contact-drawer { transform: translateY(0); }
#contact-drawer > * { max-width: 560px; margin-left: auto; margin-right: auto; }
#contact-drawer header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 30px;
}
#contact-title,
#contact-close,
#contact-drawer label,
#cf-submit,
#cf-status,
.field-error,
#contact-thanks {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .14em;
  text-transform: uppercase;
}
#contact-title { margin: 0; font-weight: 400; }
#contact-close {
  padding: 6px 0;
  border: 0;
  background: none;
  color: inherit;
  cursor: pointer;
  transition: opacity .2s ease;
}
#contact-close:hover { opacity: .5; }

#contact-form {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 26px 28px;
}
.field { display: flex; flex-direction: column; min-width: 0; }
.field label { opacity: .55; margin-bottom: 10px; }
.field input {
  width: 100%;
  padding: 4px 0 9px;
  border: 0;
  border-bottom: 1px solid rgba(128, 128, 128, .5);                       /* older browsers */
  border-bottom: 1px solid color-mix(in srgb, var(--fg) 35%, transparent);
  border-radius: 0;
  background: transparent;
  color: var(--fg);
  font-family: var(--sans);
  font-size: 16px;                  /* 16px stops iPhones zooming in on the field */
  outline: none;
  transition: border-color .25s ease;
  -webkit-appearance: none;
  appearance: none;
}
.field input:focus { border-bottom-color: var(--fg); }
.field.invalid input { border-bottom-color: #c0392b; }
.field-error { min-height: 1em; margin: 8px 0 0; color: #c0392b; letter-spacing: .08em; text-transform: none; }
:root[data-theme="dark"] .field-error,
:root[data-theme="dark"] .field.invalid input { color: #ff8a7a; border-bottom-color: #ff8a7a; }
:root[data-theme="dark"] .field.invalid input { color: var(--fg); }

.trap { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }

.form-foot {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 22px;
}
#cf-submit {
  padding: 14px 34px;
  border: 1px solid var(--fg);
  background: var(--fg);
  color: var(--bg);
  cursor: pointer;
  transition: background-color .25s ease, color .25s ease, opacity .25s ease;
}
#cf-submit:hover { background: transparent; color: var(--fg); }
#cf-submit:disabled { opacity: .45; cursor: default; }
#cf-submit:focus-visible { outline: 1px solid var(--fg); outline-offset: 3px; }
#cf-status { margin: 0; letter-spacing: .08em; text-transform: none; opacity: .7; }
#cf-status.error { color: #c0392b; opacity: 1; }
:root[data-theme="dark"] #cf-status.error { color: #ff8a7a; }

#contact-thanks p { margin: 6px 0 4px; line-height: 2; }

@media (max-width: 700px) {
  #contact-form { grid-template-columns: 1fr; gap: 20px; }
  #contact-drawer header { margin-bottom: 22px; }
  #cf-submit { flex: 0 0 auto; }
}
@media (max-width: 380px) {
  #links { gap: 20px; }
}

/* ---------- 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; }
}
