/* Freentity invitation — the reading surface and its navigation chrome.
   The four .design-page crops are never restyled below 720px so the published
   Figma artwork stays pixel-identical to the approved PDF. */

.invitation {
  display: block;
  width: 100%;
  min-height: 100vh;
  min-height: 100svh;
  outline: none;
}

html[data-state="sealed"] .invitation,
html[data-state="opening"] .invitation {
  display: none;
}

/* ------------------------------------------------------------ reading canvas */

.reader-stage {
  position: relative;
  display: block;
  width: 100%;
}

.reader {
  display: grid;
  width: min(100%, 402px);
  margin: 0 auto;
  padding: 0 0 max(88px, calc(env(safe-area-inset-bottom) + 78px));
  gap: 14px;
}

.design-page {
  position: relative;
  width: 100%;
  aspect-ratio: var(--page-ratio);
  opacity: 0;
  background: #fff;
  box-shadow:
    0 18px 42px rgb(25 55 43 / 13%),
    0 2px 8px rgb(25 55 43 / 8%);
  transform: translateY(20px);
  transform-origin: center top;
  transition:
    opacity 580ms ease,
    transform 760ms var(--ease-settle);
}

/* The first page must sit flush at the very top the moment the gate leaves,
   so it fades in without ever displacing its own top edge. */
.design-page[data-page="1"] {
  transform: none;
}

.design-page.is-visible {
  opacity: 1;
  transform: none;
}

.design-page__crop {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.design-page__crop > img {
  position: absolute;
  top: var(--image-top);
  left: 0;
  display: block;
  width: 100%;
  height: var(--image-height);
  max-width: none;
  object-fit: cover;
  object-position: 50% 0;
  user-select: none;
  pointer-events: none;
}

/* -------------------------------------------------------------- progress bar */

.reader-progress {
  position: fixed;
  z-index: 12;
  top: 0;
  right: 0;
  left: 0;
  height: 2px;
  background: rgb(23 60 47 / 8%);
  opacity: 0;
  transition: opacity 400ms ease;
  pointer-events: none;
}

.reader-progress.is-active {
  opacity: 1;
}

.reader-progress__bar {
  display: block;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, var(--green-500), var(--green-300));
  transform: scaleX(var(--reading-progress, 0));
  transform-origin: left center;
}

/* -------------------------------------------------------------- header bar */

.reader-bar {
  position: fixed;
  z-index: 9;
  top: 0;
  right: 0;
  left: 0;
  display: flex;
  height: 52px;
  padding: 0 max(14px, env(safe-area-inset-right)) 0 max(14px, env(safe-area-inset-left));
  border-bottom: 1px solid rgb(23 60 47 / 8%);
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: rgb(252 253 252 / 88%);
  backdrop-filter: blur(14px) saturate(1.2);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  opacity: 0;
  transform: translateY(-100%);
  transition: opacity 320ms ease, transform 420ms var(--ease-expo);
  pointer-events: none;
}

.reader-bar.is-visible {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

.reader-bar__brand {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--green-600);
  font-size: .86rem;
  font-weight: 600;
  letter-spacing: .06em;
  text-decoration: none;
}

.reader-bar__brand img {
  width: 26px;
  height: 26px;
}

.reader-bar__brand:hover {
  color: var(--green-800);
}

.reader-bar__brand:focus-visible {
  outline: 2px solid var(--green-500);
  outline-offset: 4px;
  border-radius: 4px;
}

.reader-bar__section {
  margin: 0;
  color: #4a5651;
  font-size: .7rem;
  letter-spacing: .18em;
  white-space: nowrap;
}

/* ------------------------------------------------------- tool dock (< 1200px) */

.reader-rail {
  position: fixed;
  z-index: 10;
  inset: auto 0 0;
  display: flex;
  padding: 0 12px max(12px, env(safe-area-inset-bottom));
  justify-content: center;
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 460ms ease, transform 560ms var(--ease-expo);
  pointer-events: none;
}

.reader-rail.is-visible {
  opacity: 1;
  transform: none;
}

.rail__brand,
.rail__facts,
.rail__nav {
  display: none;
}

.rail__tools {
  display: flex;
  padding: 5px;
  border: 1px solid rgb(23 60 47 / 10%);
  border-radius: 999px;
  background: rgb(252 253 252 / 88%);
  box-shadow:
    0 14px 34px rgb(12 42 32 / 16%),
    0 2px 6px rgb(12 42 32 / 8%);
  backdrop-filter: blur(16px) saturate(1.2);
  -webkit-backdrop-filter: blur(16px) saturate(1.2);
  gap: 2px;
  pointer-events: auto;
}

.tool {
  display: flex;
  min-width: 76px;
  min-height: 46px;
  padding: 7px 12px 6px;
  border: 0;
  border-radius: 999px;
  appearance: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--green-600);
  background: transparent;
  font-size: .72rem;
  font-weight: 500;
  letter-spacing: .04em;
  line-height: 1;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 220ms ease, color 220ms ease, transform 220ms var(--ease-expo);
}

.tool svg {
  display: block;
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentcolor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.6;
}

.tool:hover {
  color: var(--green-800);
  background: rgb(23 60 47 / 7%);
}

.tool:active {
  transform: scale(.96);
}

.tool:focus-visible {
  outline: 2px solid var(--green-500);
  outline-offset: 2px;
}

/* -------------------------------------------------------------------- toast */

.reader-toast {
  position: fixed;
  z-index: 11;
  bottom: max(84px, calc(env(safe-area-inset-bottom) + 74px));
  left: 50%;
  margin: 0;
  padding: 10px 18px;
  border-radius: 999px;
  color: var(--stone-50);
  background: rgb(12 42 32 / 94%);
  box-shadow: 0 12px 30px rgb(12 42 32 / 26%);
  font-size: .8rem;
  letter-spacing: .04em;
  opacity: 0;
  transform: translate(-50%, 8px);
  transition: opacity 260ms ease, transform 320ms var(--ease-expo);
  pointer-events: none;
}

.reader-toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ------------------------------------------------------------- small phones */

@media (max-width: 430px) {
  .reader {
    gap: 10px;
  }

  .design-page {
    box-shadow: 0 10px 24px rgb(25 55 43 / 10%);
  }

  .tool {
    min-width: 68px;
    font-size: .68rem;
  }
}

/* ------------------------------------------------- tablet and small desktop */

@media (min-width: 720px) {
  .reader-stage::before {
    position: absolute;
    z-index: -1;
    inset: 0;
    background:
      repeating-linear-gradient(0deg, rgb(23 60 47 / 4%) 0 1px, transparent 1px 52px),
      repeating-linear-gradient(90deg, rgb(23 60 47 / 4%) 0 1px, transparent 1px 52px);
    mask-image: linear-gradient(180deg, #000 0%, transparent 42%);
    -webkit-mask-image: linear-gradient(180deg, #000 0%, transparent 42%);
    content: "";
    pointer-events: none;
  }

  .reader {
    width: min(100% - 64px, 520px);
    padding: clamp(44px, 6vh, 72px) 0 clamp(104px, 12vh, 140px);
    gap: clamp(20px, 3vh, 30px);
  }

  .design-page {
    border-radius: 2px;
    outline: 1px solid rgb(23 60 47 / 7%);
    outline-offset: -1px;
    box-shadow:
      0 30px 66px rgb(25 55 43 / 15%),
      0 3px 12px rgb(25 55 43 / 8%);
  }
}

/* ------------------------------------------------------------- desktop rail */

@media (min-width: 1200px) {
  .reader {
    width: min(100% - 96px, 588px);
  }
}

@media (min-width: 1200px) and (min-height: 640px) {
  .reader-bar {
    display: none;
  }

  .reader-rail {
    /* Centred inside the gutter left of the reading column, so the composition
       stays balanced instead of hugging the viewport edge.
       Gutter = 50vw - halfColumn(294px); rail is 246px wide. */
    inset: 50% auto auto max(24px, calc((50vw - 540px) / 2));
    display: grid;
    width: 246px;
    max-height: calc(100svh - 56px);
    padding: 0;
    overflow: auto;
    align-content: safe center;
    gap: 26px;
    justify-content: stretch;
    transform: translateY(calc(-50% + 12px));
    pointer-events: auto;
  }

  .reader-rail.is-visible {
    transform: translateY(-50%);
  }

  .rail__brand {
    display: flex;
    margin: 0;
    align-items: center;
    gap: 12px;
  }

  .rail__brand img {
    width: 38px;
    height: 38px;
  }

  .rail__brand-text {
    display: grid;
    color: var(--green-600);
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: .05em;
    line-height: 1.25;
  }

  .rail__brand-text em {
    color: #4a5651;
    font-size: .62rem;
    font-style: normal;
    font-weight: 500;
    letter-spacing: .3em;
  }

  .rail__facts {
    display: grid;
    margin: 0;
    padding: 18px 0 0;
    border-top: 1px solid rgb(23 60 47 / 12%);
    gap: 14px;
  }

  .rail__facts dt {
    color: #4a5651;
    font-size: .62rem;
    font-weight: 600;
    letter-spacing: .26em;
  }

  .rail__facts dd {
    margin: 5px 0 0;
    color: var(--green-600);
    font-size: .84rem;
    line-height: 1.6;
  }

  .rail__nav {
    display: grid;
    padding: 18px 0 0;
    border-top: 1px solid rgb(23 60 47 / 12%);
    gap: 2px;
  }

  .rail__nav button {
    position: relative;
    display: flex;
    padding: 9px 10px 9px 0;
    border: 0;
    appearance: none;
    align-items: baseline;
    gap: 12px;
    color: #4a5651;
    background: transparent;
    font-size: .82rem;
    letter-spacing: .04em;
    text-align: left;
    cursor: pointer;
    transition: color 220ms ease, padding-left 300ms var(--ease-expo);
  }

  .rail__nav button i {
    font-size: .62rem;
    font-style: normal;
    font-weight: 600;
    letter-spacing: .14em;
    opacity: .7;
  }

  .rail__nav button:hover {
    padding-left: 6px;
    color: var(--green-700);
  }

  .rail__nav button:focus-visible {
    outline: 2px solid var(--green-500);
    outline-offset: 2px;
    border-radius: 2px;
  }

  .rail__nav button[aria-current="true"] {
    padding-left: 12px;
    color: var(--green-700);
    font-weight: 600;
  }

  .rail__nav button[aria-current="true"]::before {
    position: absolute;
    top: 50%;
    left: 0;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--green-500);
    content: "";
    transform: translateY(-50%);
  }

  .rail__tools {
    display: grid;
    padding: 18px 0 0;
    border: 0;
    border-top: 1px solid rgb(23 60 47 / 12%);
    border-radius: 0;
    background: none;
    box-shadow: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    gap: 2px;
  }

  .tool {
    min-width: 0;
    min-height: 40px;
    padding: 9px 12px;
    border-radius: 6px;
    flex-direction: row;
    justify-content: flex-start;
    gap: 10px;
    font-size: .82rem;
    font-weight: 500;
    text-align: left;
  }

  .reader-toast {
    bottom: 32px;
  }
}

/* ------------------------------------------------------------------- motion */

@media (prefers-reduced-motion: reduce) {
  .design-page,
  .reader-bar,
  .reader-rail,
  .reader-toast,
  .tool,
  .rail__nav button {
    transition-duration: .01ms;
  }
}

@media print {
  .invitation {
    display: block !important;
  }

  .reader-progress,
  .reader-bar,
  .reader-rail,
  .reader-toast {
    display: none !important;
  }

  .reader-stage::before {
    display: none !important;
  }

  .reader {
    width: 100%;
    padding: 0;
    gap: 0;
  }

  .design-page {
    opacity: 1;
    outline: none;
    box-shadow: none;
    transform: none;
    break-after: page;
  }
}
