/* =========================================================
   The Garden (v6): styles.css (base layer)
   Tokens, reset, scene layout, buttons, loader, section index, print.
   Plain text only in comments.
   ========================================================= */

/* Fonts: Playfair Display (names, titles, numerals), Montserrat (body and labels), Amiri Quran and Noto Nastaliq Urdu
   (Arabic and Urdu). All loaded from Google Fonts in index.html. */

/* 1. Tokens ---------------------------------------------- */
:root {
  /* Palette: blush bridal. Ivory, blush and dusty rose for light, deep plum for dark, champagne gold for accents.
     --emerald, --night and --night-deep keep their old names so existing selectors still resolve. */
  --night: #3d0f17;
  --night-deep: #1c0a0d;
  --emerald: #3d0f17;
  --plum-hi: #6e1a28;
  --ivory: #f8f2ea;
  --white: #ffffff;
  --paper: #fbf7f1;
  --ink: #2a1215;
  --plum: #6e1a28;
  --rose: #c48a86;
  --rose-lo: #8f5a56;
  --ink-soft: #5e4245;
  --ivory-soft: #cfc8bc;
  --gold: #b8955a;
  --gold-hi: #d9bf8a;
  --gold-lo: #8c6a3a;
  --gold-deep: #8c6a3a;
  --ground: #1c0a0d;
  --aubergine: #3d0f17;
  --mauve: #8f3a44;
  --blush: #ecd3cc;
  --oxblood: #3d0f17;
  --garnet: #6e1a28;
  --wine: #8f3a44;
  --crimson: #9b1c2c;

  /* Gold is always foil. The dark-stop foil is used for text on parchment. */
  --foil-grad: linear-gradient(135deg, #8c6a3a 0%, #d9bf8a 35%, #b8955a 55%, #f3e6c4 75%, #8c6a3a 100%);
  --foil-ink: linear-gradient(135deg, #2a1215 0%, #6e1a28 40%, #6e1a28 62%, #2a1215 100%);
  /* Script foil: champagne for names and titles over the dark film. */
  --foil-script: linear-gradient(100deg, #b8955a 0%, #f3e6c4 35%, #d9bf8a 55%, #fbf7f1 75%, #b8955a 100%);
  /* Title foil on light paper: plum with a faint champagne sheen (legible first, shiny second). */
  --foil-script-paper: linear-gradient(100deg, #2a1215 0%, #6e1a28 40%, #2a1215 60%, #6e1a28 100%);

  /* Fonts */
  --f-display: 'Playfair Display', Georgia, 'Times New Roman', serif;
  --f-script: 'Playfair Display', Georgia, 'Times New Roman', serif;
  --f-italic: 'Playfair Display', Georgia, 'Times New Roman', serif;
  --f-body: 'Montserrat', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --f-arabic: 'Amiri Quran', 'Amiri', 'Scheherazade New', serif;
  --f-urdu: 'Noto Nastaliq Urdu', 'Amiri', 'Scheherazade New', serif;

  /* Easing */
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --ease-io: cubic-bezier(.65, .05, .36, 1);

  /* Scene heights */
  --h-overture: 160vh;
  --h-opening: 200vh;
  --h-passage: 60vh;
  --h-chapter: 150vh;

  /* Section index and rail (desktop values; phones override below) */
  --index-h: 0px;
  --rail-w: 76px;

  /* Z-index map */
  --z-stage: 0;
  --z-atmos: 5;
  --z-journey: 10;
  --z-index: 20;
  --z-sky: 30;
  --z-toggle: 60;
  --z-loader: 80;
  --z-dev: 90;
}

/* Under 960px: bottom bar instead of the right rail. */
@media (max-width: 959px) {
  :root {
    --index-h: calc(58px + env(safe-area-inset-bottom, 0px));
    --rail-w: 0px;
  }
}

/* Foil text fallback: solid gold where background-clip: text is missing. */
@supports not ((background-clip: text) or (-webkit-background-clip: text)) {
  #overture .ov-names, #opening .names-visual, #garden .chapter__title, .sheet__title {
    color: #8c6a3a;
    -webkit-text-fill-color: #8c6a3a;
    background: none;
  }
}

/* 2. Reset and base -------------------------------------- */
*,
*::before,
*::after { box-sizing: border-box; }

[hidden] { display: none !important; }

html {
  background: var(--night-deep);
  scroll-behavior: auto;
  scroll-padding-top: 0;
  scroll-padding-bottom: var(--index-h);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100svh;
  background: var(--night-deep);
  color: var(--ivory);
  font-family: var(--f-body);
  font-weight: 300;
  font-size: 1.25rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

img { display: block; max-width: 100%; height: auto; }
figure, p, h1, h2, h3, ol, ul, dl, dd { margin: 0; }
a { color: inherit; }
button { font: inherit; font-weight: 400; color: inherit; }

.svg-defs { position: absolute; width: 0; height: 0; overflow: hidden; }

.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

:focus-visible { outline: 2px solid var(--gold-hi); outline-offset: 3px; }

/* Headings focused by script (tabindex=-1) get no ring: they are not controls. */
[tabindex="-1"]:focus { outline: none; }

/* 3. Scenes and pins ------------------------------------- */
.journey {
  position: relative;
  z-index: var(--z-journey);
}

.scene { position: relative; }

.scene__pin,
.chapter__pin {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100svh;
  height: 100dvh;
}

#overture { height: var(--h-overture); }
#opening { height: var(--h-opening); }
#passage { height: var(--h-passage); }
.chapter { height: var(--h-chapter); }

/* 4. Film stage (fixed, behind everything) ---------------- */
.stage {
  position: fixed;
  top: 0; right: 0; bottom: 0; left: 0; inset: 0;
  z-index: var(--z-stage);
  overflow: hidden;
  background: var(--night-deep);
  pointer-events: none;
}

.stage__poster,
.stage__film {
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0; inset: 0;
  width: 100%;
  height: 100%;
}

.stage__grade,
.stage__vignette,
.stage__grain,
.stage__flash {
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0; inset: 0;
  pointer-events: none;
}

#atmos { z-index: var(--z-atmos); }

/* 5. Buttons and links ----------------------------------- */
/* Default .btn: ink on parchment (buttons live on paper cards). */
.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 46px;
  padding: 0 26px;
  border: 1px solid var(--gold-lo);
  border-radius: 2px;
  background: rgba(255, 255, 255, .45);
  color: var(--ink);
  font-family: var(--f-body);
  font-size: .75rem;
  font-weight: 500;
  letter-spacing: .18em;
  text-transform: uppercase;
  text-decoration: none;
  cursor: pointer;
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, .35), inset 0 0 0 4px rgba(140, 106, 58, .35), 0 3px 8px -5px rgba(28,10,13, .45);
  transition: background .3s ease, color .3s ease, transform .25s var(--ease-out), box-shadow .3s ease;
}

/* Hover styles only on real hover devices: iOS keeps :hover stuck after a tap. */
@media (hover: hover) {
  .btn:not(:disabled):not([aria-disabled="true"]):hover {
    background: var(--emerald);
    color: var(--ivory);
    transform: translateY(-2px);
    box-shadow: inset 0 0 0 3px rgba(217, 191, 138, .25), 0 8px 16px -8px rgba(28,10,13, .6);
  }
}

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 1;
  color: var(--ink-soft);
  border-color: var(--mauve);
  border-style: dashed;
  background: transparent;
  cursor: not-allowed;
  box-shadow: none;
}
.btn--gold:disabled,
.btn--gold[aria-disabled="true"] {
  color: var(--ivory-soft);
  border-color: var(--mauve);
  background: rgba(28,10,13, .55);
}

/* Gold-on-dark variant for buttons placed on the night film. */
.btn--gold {
  border-color: rgba(217, 191, 138, .7);
  background: rgba(28,10,13, .55);
  color: var(--gold-hi);
}

@media (hover: hover) {
  .btn--gold:not(:disabled):not([aria-disabled="true"]):hover {
    background: var(--gold-hi);
    color: var(--night);
  }
}

/* Seal: deep plum, filled, with a champagne label (replaces the old wax red). */
.btn--seal {
  color: #d9bf8a;
  border-color: #1c0a0d;
  border-radius: 999px;
  background: radial-gradient(circle at 38% 32%, #6e1a28 0%, #3d0f17 58%, #1c0a0d 100%);
  box-shadow: 0 4px 10px -4px rgba(28,10,13, .7), inset 0 1px 0 rgba(217, 191, 138, .25);
}

@media (hover: hover) {
  .btn--seal:not(:disabled):not([aria-disabled="true"]):hover {
    background: radial-gradient(circle at 38% 32%, #8f3a44 0%, #6e1a28 55%, #1c0a0d 100%);
    color: #fbf7f1;
  }
}

.btn--seal svg {
  flex: none;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  transition: transform .5s var(--ease-out);
}

@media (hover: hover) {
  .btn--seal:not(:disabled):hover svg { transform: rotate(90deg); }
}

/* Link: text only, gold hairline underline, 44px touch target. Gold-on-dark by default. */
.link {
  min-height: 44px;
  padding: 0 10px;
  border: 0;
  background: none;
  font-family: var(--f-body);
  font-size: .75rem;
  font-weight: 400;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--gold-hi);
  text-decoration: underline;
  text-decoration-color: rgba(217, 191, 138, .55);
  text-underline-offset: 5px;
  cursor: pointer;
}

/* Ink-on-paper variant for links on parchment. */
.sheet .link,
.chapter__card .link,
.parchment .link {
  color: var(--ink);
  text-decoration-color: rgba(140, 106, 58, .8);
}

/* Focus rings on parchment are ink-gold, not the bright gold used on the night film. */
.sheet :focus-visible,
.chapter__card :focus-visible,
.parchment :focus-visible { outline-color: var(--gold-lo); }

/* 6. Loader: Bismillah and a progress ring --------------- */
#loader {
  position: fixed;
  top: 0; right: 0; bottom: 0; left: 0; inset: 0;
  z-index: var(--z-loader);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background:
    radial-gradient(ellipse 60% 50% at 50% 42%, rgba(110,26,40, .28) 0%, rgba(110,26,40, 0) 70%),
    var(--night-deep);
  color: var(--gold);
  text-align: center;
  transition: opacity .9s var(--ease-io), transform .9s var(--ease-io), visibility 0s linear 0s;
}

.loader__bismillah {
  max-width: 92vw;
  margin: 0;
  font-family: var(--f-arabic);
  font-size: clamp(22px, 5vw, 34px);
  line-height: 1.9;
  color: var(--gold-hi);
  direction: rtl;
}

.loader__ring {
  width: 112px;
  height: 112px;
  margin: 28px 0 22px;
  overflow: visible;
  color: var(--gold);
}

.loader__track {
  fill: none;
  stroke: rgba(184, 149, 90, .22);
  stroke-width: 1.2;
}

.loader__arc {
  fill: none;
  stroke: var(--gold-hi);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-dasharray: 1;
  stroke-dashoffset: calc(1 - var(--load, 0));
  transform: rotate(-90deg);
  transform-box: view-box;
  transform-origin: 50% 50%;
  transition: stroke-dashoffset .4s var(--ease-out);
}

.loader__label {
  font-family: var(--f-body);
  font-size: .75rem;
  font-weight: 400;
  letter-spacing: .3em;
  text-transform: uppercase;
  color: var(--gold-hi);
}

/* Loaded: fade and scale out, then drop out of hit testing and the accessibility tree. */
html.loaded #loader {
  opacity: 0;
  transform: scale(1.04);
  visibility: hidden;
  pointer-events: none;
  transition: opacity .9s var(--ease-io), transform .9s var(--ease-io), visibility 0s linear .9s;
}

/* Still mode: no transition at all. */
html.still #loader,
html.still #loader * { transition: none !important; }

/* 7. Section index: right rail on desktop, bottom bar on phones --- */
.index {
  position: fixed;
  z-index: var(--z-index);
  top: 50%;
  right: max(18px, env(safe-area-inset-right, 0px));
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
}

.index__link {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  min-width: 44px;
  min-height: 44px;
  text-decoration: none;
  color: var(--ivory);
}

.index__charm {
  flex: none;
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 50%;
  color: var(--gold-hi);
  background: rgba(28,10,13, .78);
  box-shadow: inset 0 0 0 1px rgba(217, 191, 138, .6);
  transition: background .35s ease, box-shadow .35s ease, color .35s ease, filter .35s ease;
}

/* Label flies out to the left of the charm; visible on hover, focus and current. */
.index__label {
  position: absolute;
  right: calc(100% + 12px);
  top: 50%;
  padding: 5px 12px;
  white-space: nowrap;
  background: rgba(28,10,13, .92);
  border: 1px solid rgba(217, 191, 138, .45);
  font-family: var(--f-body);
  font-size: .75rem;
  font-weight: 400;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--gold-hi);
  opacity: 0;
  pointer-events: none;
  transform: translate(6px, -50%);
  transition: opacity .3s ease, transform .35s var(--ease-out);
}

.index__link[aria-current="true"] .index__label {
  opacity: 1;
  transform: translate(0, -50%);
}
.index__link:focus-visible .index__label,
.index__link[aria-current="true"] .index__label {
  opacity: 1;
  transform: translate(0, -50%);
}

@media (hover: hover) {
  .index__link:hover .index__label {
    opacity: 1;
    transform: translate(0, -50%);
  }
}

/* Current section: filled emerald disc with a bright gold rim. */
.index__link[aria-current="true"] .index__charm {
  color: var(--gold-hi);
  background: radial-gradient(circle at 35% 30%, #6e1a28 0%, #3d0f17 55%, #1c0a0d 100%);
  box-shadow: inset 0 0 0 1px var(--gold-hi), 0 0 16px rgba(217, 191, 138, .45);
}

.index__link:focus-visible { outline-offset: 4px; }

@media (max-width: 959px) {
  .index {
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    height: var(--index-h);
    padding-inline: env(safe-area-inset-left, 0px) env(safe-area-inset-right, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    transform: none;
    flex-direction: row;
    align-items: stretch;
    gap: 0;
    /* v22 perf: no backdrop-filter. At 94 percent opacity the blur showed through as a 6 percent tint, yet iOS re-blurred
       the film, the petal canvas and the scrolling cards under the bar on every frame. */
    background: rgba(28,10,13, .94);
    border-top: 1px solid rgba(217, 191, 138, .45);
    box-shadow: 0 -10px 24px -12px rgba(0, 0, 0, .6);
  }

  .index__link {
    flex: 1 1 0;
    flex-direction: column;
    justify-content: center;
    gap: 3px;
    min-width: 44px;
    min-height: 44px;
  }

  .index__charm {
    width: 22px;
    height: 22px;
    background: none;
    box-shadow: none;
  }

  /* Labels sit under the charm and are always visible. Sizes are capped in px with min(): the same at the default 16 px
     root, but a larger root font (browser text size) can no longer push the six labels into each other or off screen. */
  .index__label {
    position: static;
    padding: 0;
    border: 0;
    background: none;
    transform: none;
    opacity: 1;
    font-size: min(.75rem, 12px);
    letter-spacing: .04em;
    color: #d9bf8a;
    pointer-events: auto;
  }

  /* Six items: at 380px and under each slot is 63px or less, so labels shrink to keep OPENING inside its slot. */
  @media (max-width: 380px) {
    .index__label {
      font-size: min(.6875rem, 11px);
      letter-spacing: .02em;
    }
  }

  /* Narrow phones (320 to 340px): 10px labels so OPENING fits its slot. */
  @media (max-width: 340px) {
    .index__label {
      font-size: min(.625rem, 10px);
    }
  }

  /* Six items only: side gutter and slightly smaller labels so OPENING clears the screen edge and its neighbour. */
  .index.hn6 {
    padding-inline: max(10px, env(safe-area-inset-left, 0px)) max(10px, env(safe-area-inset-right, 0px));
  }
  .index.hn6 .index__link { min-width: 0; }
  .index.hn6 .index__label {
    font-size: min(.6875rem, 11px);
    letter-spacing: .01em;
  }
  @media (max-width: 340px) {
    .index.hn6 {
      padding-inline: max(8px, env(safe-area-inset-left, 0px)) max(8px, env(safe-area-inset-right, 0px));
    }
    .index.hn6 .index__label { font-size: min(.5938rem, 9.501px); letter-spacing: 0; }
  }
  /* 300 px and under (150 percent page zoom on a 393 px phone, 262 px wide): 8 px labels (12 device px at that zoom) in
     42 px slots, so OPENING still clears its neighbour. */
  @media (max-width: 300px) {
    .index.hn6 { padding-inline: max(4px, env(safe-area-inset-left, 0px)) max(4px, env(safe-area-inset-right, 0px)); }
    .index__label,
    .index.hn6 .index__label { font-size: min(.5rem, 8px); letter-spacing: 0; }
  }

  .index__link[aria-current="true"] .index__charm {
    background: none;
    box-shadow: none;
    filter: drop-shadow(0 0 6px rgba(217, 191, 138, .6));
  }

  /* Focus and current keep the same label position as the others (beats the rail rule above). */
  .index__link[aria-current="true"] .index__label {
    opacity: 1;
    transform: none;
  }
  .index__link:focus-visible .index__label {
    opacity: 1;
    transform: none;
  }

  @media (hover: hover) {
    .index__link:hover .index__label {
      opacity: 1;
      transform: none;
    }
  }

  .index__link[aria-current="true"] .index__label { color: var(--gold-hi); }
}

/* 8. Form fields and anchors ----------------------------- */
input,
textarea,
select,
fieldset {
  scroll-margin-top: 24px;
}

/* 9. Dev banner (shown only with ?dev) ------------------- */
#dev-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: var(--z-dev);
  padding: 6px 12px;
  background: #3d0f17;
  color: #fbf7f1;
  font-family: ui-monospace, Consolas, 'Courier New', monospace;
  font-size: .72rem;
  line-height: 1.4;
}

/* Phones: the banner sits above the index bar so it never covers the motion toggle. */
@media (max-width: 959px) {
  #dev-banner {
    top: auto;
    bottom: calc(var(--index-h) + 8px);
    max-height: 30vh;
    overflow: auto;
  }
}

/* 10. Motion toggle and sky layers sit above the journey ---- */
.motion-toggle { z-index: var(--z-toggle); }

/* 11. Print: the whole invitation on paper, no film ------ */
@media print {
  @page { margin: 12mm; }

  html,
  body {
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
    background: #fff !important;
    color: var(--ink) !important;
  }

  #stage,
  #loader,
  #atmos,
  #index,
  #passage,
  #dev-banner,
  .motion-toggle,
  button[aria-label="Animations"],
  .illum__deco,
  [class^="lf-"],
  [class*=" lf-"],
  .lf-fleck,
  .lf-ripple,
  .lf-under,
  .lf-glint,
  .lf-steam {
    display: none !important;
  }

  .journey { z-index: auto !important; }

  .scene,
  .chapter {
    height: auto !important;
  }

  .scene__pin,
  .chapter__pin {
    position: static !important;
    height: auto !important;
  }

  /* Print flows the whole invitation top to bottom: nothing stays absolutely placed,
     so no text box can land on another. Cards keep their own containing block. */
  main :where(*) {
    position: static !important;
  }

  main :where(.illum, .parchment, .sheet, .chapter, .chapter__card) {
    position: relative !important;
  }

  .chapter,
  .sheet {
    break-inside: avoid;
  }

  .parchment {
    left: 0 !important;
    top: 0 !important;
    width: auto !important;
    height: auto !important;
  }

  /* Everything plain and visible: no transforms, filters or masks. */
  *,
  *::before,
  *::after {
    opacity: 1 !important;
    transform: none !important;
    filter: none !important;
    clip-path: none !important;
    mask: none !important;
    -webkit-mask: none !important;
    transition: none !important;
    animation: none !important;
    text-shadow: none !important;
  }

  .sheet,
  .chapter__card {
    position: relative !important;
    top: auto !important;
    left: auto !important;
    right: auto !important;
    bottom: auto !important;
    width: auto !important;
    max-width: 100% !important;
    min-height: 0 !important;
    margin: 0 0 24px !important;
    padding: 24px 32px !important;
    box-shadow: none !important;
    break-inside: avoid;
  }

  .btn,
  .link,
  .ov-hint,
  .ov-hint__glyph {
    display: none !important;
  }

  /* Gold foil text would print as a solid box: names go plain ink. */
  .names,
  .amp,
  .names__groom,
  .names__bride {
    background: none !important;
    -webkit-background-clip: border-box !important;
    background-clip: border-box !important;
    -webkit-text-fill-color: var(--ink) !important;
    color: var(--ink) !important;
  }
}

/* Fixed-speed scenes (step.js): no rubber-band or pull-to-refresh fighting a scene move. */
html.stepped, html.stepped body { overscroll-behavior-y: none; }
