:root {
  --paper: #E8C9B0;
  --ink: #1A1A1E;
  --ink-soft: rgba(26, 26, 30, 0.55);
  --red: #B8283A;
  --bg: var(--paper);
  --fg: var(--ink);
  --fg-soft: var(--ink-soft);
  --serif: "Cormorant Garamond", Georgia, "Times New Roman", serif;
}
/* dark: follow the phone's setting unless the toggle picked light; or forced by the toggle */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0E1A1F;
    --fg: #E9DCCF;
    --fg-soft: rgba(233, 220, 207, 0.55);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0E1A1F;
  --fg: #E9DCCF;
  --fg-soft: rgba(233, 220, 207, 0.55);
  color-scheme: dark;
}
:root[data-theme="light"] { color-scheme: light; }

/* ---------------------------------------------------------------- lantern toggle */
/* html.is-dark mirrors the effective theme (set before first paint, kept in sync by theme.js) */
.theme-toggle {
  --lantern-red: #B8283A;
  --lantern-ink: #1A1A1E;
  --lantern-paper: #F2E6D8;
  --lantern-w: 84px;                              /* lantern size (viewBox is 44 x 60) */
  --lantern-h: calc(var(--lantern-w) * 60 / 44);
  position: fixed;
  z-index: 10;
  top: env(safe-area-inset-top, 0px);            /* hangs from the top edge, below the notch */
  right: max(28px, env(safe-area-inset-right));
  width: calc(var(--lantern-w) + 10px);           /* tap target >= 44 x 44 */
  height: calc(var(--lantern-h) + 4px);
  padding: 0;
  border: 0;
  border-radius: 0 0 14px 14px;
  background: transparent;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  -webkit-tap-highlight-color: transparent;
}
.theme-toggle:focus-visible { outline: 2px solid var(--fg-soft); outline-offset: 2px; }
.theme-toggle:focus:not(:focus-visible) { outline: none; }

/* warm light the lit lantern casts on the page behind it */
.theme-toggle::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 53%;
  width: calc(var(--lantern-w) * 3.4);
  height: calc(var(--lantern-w) * 3.4);
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 176, 98, 0.22) 0%, rgba(255, 138, 61, 0.10) 38%, rgba(255, 138, 61, 0) 70%);
  opacity: 0;
  transition: opacity 0.6s ease;
  pointer-events: none;
}

.lantern-sway {                                   /* idle sway from the cord */
  display: block;
  width: var(--lantern-w);
  height: var(--lantern-h);
  transform-origin: 50% 0;
  animation: lantern-sway 3s ease-in-out infinite alternate;
}
.lantern {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
  transform-origin: 50% 0;
  filter: drop-shadow(0 0 0 rgba(255, 170, 90, 0)) drop-shadow(0 0 0 rgba(255, 138, 61, 0));
  transition: filter 0.6s ease;
}
.lantern-ink { fill: none; stroke: var(--lantern-ink); stroke-width: 1.3; stroke-linecap: round; }
.lantern-rib { stroke-width: 0.8; opacity: 0.75; }
.lantern-rim { stroke-width: 1.1; }
.lantern-ink-fill { fill: var(--lantern-ink); }
.lantern-body {                                   /* unlit: plain paper, slightly muted red */
  fill: #B8283A;
  fill: color-mix(in srgb, var(--lantern-red) 80%, var(--lantern-paper));
  transition: fill 0.6s ease;
}
.lantern-highlight { fill: none; stroke: var(--lantern-paper); stroke-width: 1.6; stroke-linecap: round; opacity: 0.55; }
.lantern-tassel { fill: none; stroke: var(--lantern-red); stroke-width: 1.2; stroke-linecap: round; }
.lantern-glow { opacity: 0; transition: opacity 0.6s ease; }

/* lit = dark mode */
.is-dark .lantern-body { fill: var(--lantern-red); }
.is-dark .lantern-glow { opacity: 1; }
.is-dark .theme-toggle::before { opacity: 1; }
.is-dark .lantern {
  filter: drop-shadow(0 0 6px rgba(255, 170, 90, 0.75)) drop-shadow(0 0 20px rgba(255, 138, 61, 0.45));
}

@media (max-width: 900px) { .theme-toggle { --lantern-w: 66px; right: max(18px, env(safe-area-inset-right)); } }
@media (max-width: 600px) { .theme-toggle { --lantern-w: 56px; right: max(10px, env(safe-area-inset-right)); } }

/* tap: one quick swing; switching to dark: the flame flickers on */
.theme-toggle.is-swinging .lantern { animation: lantern-swing 0.4s cubic-bezier(.3, .7, .4, 1); }
.theme-toggle.is-flickering .lantern-glow,
.theme-toggle.is-flickering::before { animation: lantern-flicker 0.7s linear; }

@keyframes lantern-sway  { from { transform: rotate(-4deg); } to { transform: rotate(4deg); } }
@keyframes lantern-swing {
  0% { transform: rotate(0); } 30% { transform: rotate(-16deg); } 62% { transform: rotate(9deg); }
  85% { transform: rotate(-3deg); } 100% { transform: rotate(0); }
}
@keyframes lantern-flicker {                       /* two quick flickers, then steady */
  0% { opacity: 0; } 12% { opacity: 1; } 22% { opacity: 0.15; } 34% { opacity: 0.95; }
  44% { opacity: 0.3; } 58%, 100% { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {          /* no sway or swing; the glow just fades */
  .lantern-sway,
  .theme-toggle.is-swinging .lantern,
  .theme-toggle.is-flickering .lantern-glow,
  .theme-toggle.is-flickering::before { animation: none; }
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--serif);
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.6s ease, color 0.6s ease;   /* theme change cross-fades */
}

/* ---------------------------------------------------------------- hero */
.hero {
  position: relative;
  height: 100vh;
  height: 100svh;                 /* phones: ignore the collapsing URL bar */
  min-height: 420px;
  overflow: hidden;
  display: grid;
  place-items: center;
}
#koi {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
.hero-title {
  position: relative;             /* above the canvas, centred in the koi circle */
  margin: 0;
  font-weight: 400;
  font-size: clamp(2rem, 7vw, 4.2rem);
  letter-spacing: 0.01em;
  line-height: 1;
  text-align: center;
  color: var(--fg);
  opacity: 0;
  transform: translateY(6px);
  animation: title-in 2.2s ease-out 0.6s forwards;
  pointer-events: none;
  text-shadow: 0 0 10px var(--bg);   /* keeps the title readable if a fin swims behind it */
  transition: color 0.6s ease, text-shadow 0.6s ease;
}
.hero-title span { font-style: italic; color: var(--fg-soft); font-size: 0.62em; vertical-align: 0.12em; }
.hero-title em { font-style: italic; font-weight: 500; }
@keyframes title-in { to { opacity: 1; transform: none; } }

.scroll-hint {
  position: absolute;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  color: var(--fg-soft);
  text-decoration: none;
  font-size: 0.95rem;
  letter-spacing: 0.18em;
  text-transform: lowercase;
  opacity: 0;
  animation: title-in 1.6s ease-out 2.4s forwards;
  padding: 8px 16px;              /* comfortable tap target */
  transition: color 0.6s ease;
}
.scroll-hint svg { animation: nudge 2.4s ease-in-out infinite; }
@keyframes nudge { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(5px); } }

@media (prefers-reduced-motion: reduce) {
  .hero-title, .scroll-hint { animation-duration: 0.01s; animation-delay: 0s; }
  .scroll-hint svg { animation: none; }
}

/* ---------------------------------------------------------------- shared */
:root { --red-soft: #D9576A; --line: rgba(26, 26, 30, 0.16); --card: rgba(255, 250, 244, 0.32); }
.is-dark { --line: rgba(233, 220, 207, 0.16); --card: rgba(255, 255, 255, 0.035); }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
main { padding: 0 20px; }

/* sections fade up as they scroll into view (page.js adds .is-visible) */
.reveal { opacity: 0; transform: translateY(18px); transition: opacity 1s ease, transform 1s ease; }
.reveal.is-visible { opacity: 1; transform: none; }
.no-js .reveal { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) { .reveal { opacity: 1; transform: none; transition: none; } }

/* ---------------------------------------------------------------- note */
.note {
  max-width: 34rem;
  margin: 0 auto;
  padding: clamp(72px, 14vh, 140px) 0 clamp(56px, 10vh, 100px);
  text-align: center;
}
.note-mark { color: var(--red-soft); opacity: 0.8; margin-bottom: 22px; }
.note-text {
  font-size: clamp(1.25rem, 4.6vw, 1.6rem);
  line-height: 1.55;
  font-style: italic;
  color: var(--fg);
  transition: color 0.6s ease;
}
.note-text p { margin: 0 0 0.9em; }
.note-text p:last-child { margin-bottom: 0; }

/* ---------------------------------------------------------------- locked card */
.locked { padding: 0 0 clamp(72px, 14vh, 140px); display: flex; justify-content: center; }
.lock-card {
  position: relative;
  width: 100%;
  max-width: 600px;
  border-radius: 12px;
  overflow: hidden;
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: 0 18px 50px -28px rgba(0, 0, 0, 0.45);
  transition: background-color 0.6s ease, border-color 0.6s ease;
}
/* blurred shapes behind the frosted face: hints at something hidden (purely decorative) */
@media (max-width: 600px) { .lock-card { border-radius: 10px; } }
.lock-veil { position: absolute; inset: 0; filter: blur(14px); opacity: 0.55; pointer-events: none; }
.lock-veil span { position: absolute; border-radius: 999px; }
.lock-veil span:nth-child(1) { left: 12%; top: 14%; width: 46%; height: 16px; background: var(--red-soft); opacity: 0.55; }
.lock-veil span:nth-child(2) { left: 18%; top: 30%; width: 64%; height: 12px; background: var(--fg-soft); opacity: 0.45; }
.lock-veil span:nth-child(3) { right: 10%; bottom: 22%; width: 120px; height: 120px; background: #B8283A; opacity: 0.35; }
.lock-veil span:nth-child(4) { left: 8%; bottom: 12%; width: 90px; height: 90px; background: var(--fg-soft); opacity: 0.3; }
.lock-face {
  position: relative;
  padding: 34px clamp(22px, 6vw, 56px) 26px;
  text-align: center;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.lock-icon { display: block; margin: 0 auto 14px; overflow: visible; }
.lock-icon .li-ring { fill: none; stroke: var(--fg-soft); stroke-width: 0.8; stroke-dasharray: 1.5 3; opacity: 0.7; transition: stroke 0.6s ease; }
.lock-icon .li-red { fill: #B8283A; }
.lock-icon .li-ink { fill: var(--fg); transition: fill 0.6s ease; }
.lock-icon .li-lock { fill: none; stroke: var(--fg); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; transition: stroke 0.6s ease; }
.lock-card h2 {
  margin: 0 0 22px;
  font-weight: 500;
  font-style: italic;
  font-size: clamp(1.45rem, 5.4vw, 1.75rem);
  line-height: 1.2;
}
.lock-form { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.lock-form input {
  width: 100%;
  max-width: 300px;
  padding: 10px 6px 8px;
  border: 0;
  border-bottom: 1.5px solid var(--fg-soft);
  border-radius: 0;
  background: transparent;
  color: var(--fg);
  font-family: var(--serif);
  font-size: 1.7rem;                /* >= 16px: phones don't zoom on focus */
  font-variant-numeric: lining-nums tabular-nums;
  letter-spacing: 0.12em;
  text-align: center;
  outline: none;
  transition: border-color 0.25s ease, color 0.6s ease;
}
.lock-form input::placeholder { color: var(--fg-soft); opacity: 0.6; letter-spacing: 0.1em; }
.lock-form input:focus { border-bottom-color: #B8283A; }
.lock-form input:disabled { opacity: 0.45; }
.lock-btn {
  min-width: 128px;
  min-height: 46px;                 /* comfortable tap target */
  padding: 0 26px;
  border: 1px solid var(--fg);
  border-radius: 999px;
  background: transparent;
  color: var(--fg);
  font-family: var(--serif);
  font-size: 1.15rem;
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: background-color 0.25s ease, color 0.25s ease, border-color 0.6s ease;
}
@media (hover: hover) {                          /* phones: no sticky hover after a tap */
  .lock-btn:hover:not(:disabled) { background: var(--fg); color: var(--bg); }
}
.lock-btn:active:not(:disabled) { background: var(--fg); color: var(--bg); }
.lock-btn:focus-visible { outline: 2px solid #B8283A; outline-offset: 3px; }
.lock-btn:disabled { opacity: 0.45; cursor: default; }
.lock-msg {
  min-height: 1.5em;                /* reserve space: no layout jump when a message appears */
  margin: 16px 0 0;
  font-size: 1.05rem;
  font-style: italic;
  color: var(--fg-soft);
  font-variant-numeric: tabular-nums;
}
.lock-msg.is-error { color: #B8283A; }
.is-dark .lock-msg.is-error { color: var(--red-soft); }
.lock-card.is-shake .lock-form { animation: shake 0.42s ease; }
@keyframes shake { 20%, 60% { transform: translateX(-7px); } 40%, 80% { transform: translateX(7px); } }
@media (prefers-reduced-motion: reduce) { .lock-card.is-shake .lock-form { animation: none; } }

/* ---------------------------------------------------------------- unlock reveal */
.lock-face, .lock-veil { transition: opacity 0.45s ease, filter 0.45s ease; }
.lock-card.is-opening .lock-face { opacity: 0; filter: blur(6px); }
.lock-card.is-opening .lock-veil { opacity: 0; }
.lock-secret {
  position: relative;
  padding: clamp(30px, 6vw, 46px) clamp(22px, 6vw, 56px);
  font-size: clamp(1.12rem, 3.9vw, 1.28rem);
  line-height: 1.7;
  text-align: center;
  outline: none;
  opacity: 0;
  filter: blur(10px);
  transform: translateY(8px);
  transition: opacity 0.9s ease, filter 0.9s ease, transform 0.9s ease;
}
.lock-card.is-unlocked .lock-secret { opacity: 1; filter: none; transform: none; }
.lock-card.no-anim .lock-secret, .lock-card.no-anim .lock-face, .lock-card.no-anim .lock-veil { transition: none; }
.lock-secret h3 { margin: 0 0 0.8em; font-weight: 500; font-style: italic; font-size: 1.45em; line-height: 1.25; }
.lock-secret p { margin: 0 0 1em; }
.lock-secret p:last-child { margin-bottom: 0; }
.lock-secret figure { margin: 1.4em 0; }
.lock-secret img { display: block; max-width: 100%; height: auto; margin: 0 auto; border-radius: 8px; }
@media (prefers-reduced-motion: reduce) {
  .lock-face, .lock-veil, .lock-secret { transition: opacity 0.3s ease; filter: none; transform: none; }
}

/* tiny koi + hearts drifting up on unlock */
.drift {
  position: absolute;
  bottom: 30%;
  z-index: 2;
  color: #B8283A;
  pointer-events: none;
  opacity: 0;
  animation: drift-up 3s ease-out forwards;
}
.drift-ink { color: var(--fg); }
.drift svg { display: block; transform: rotate(var(--rot, -90deg)); }
.drift:has(path[d^="M12"]) svg { transform: none; }          /* hearts stay upright */
@keyframes drift-up {
  0% { opacity: 0; transform: translate(0, 10px) scale(0.7); }
  15% { opacity: 0.95; }
  100% { opacity: 0; transform: translate(var(--dx, 0), -240px) scale(1.05); }
}

/* ---------------------------------------------------------------- footer */
.footer {
  padding: 28px 20px max(28px, env(safe-area-inset-bottom));
  text-align: center;
  font-size: 0.95rem;
  letter-spacing: 0.08em;
  color: var(--fg-soft);
  transition: color 0.6s ease;
}
