/* "Answers to the big questions": four hand-drawn envelopes (WHO, WHAT, WHEN, HOW) that open one at a time.
   Markup and drawing: scripts/build-envelopes.mjs. Sequencing: envelopes.js.

   Two poses share one drawing:
   - Animated (.is-ready, set by the script): a stack of envelopes. One opens, its card rises, the word is
     highlighted, then it closes and the next opens.
   - Static (no script, or prefers-reduced-motion): all four open with their cards showing, two by two
     (one column on phones). Nothing moves, nothing is hidden.

   Linked after every other stylesheet on both the desktop page and /mobile/. Strokes match the stick-figure
   illustrations (round caps, 2.6 wide, ink). */
:root {
  --env-ink: #16161a;
  --env-paper: #fff;
  /* Buttons mirror the feature orbit's (values from ralph-orbit.css). */
  --env-btn-ink: #142941;
  --env-btn-outline: #31496c;
  --env-btn-hover: #eaf1fd;
  --env-btn-primary: linear-gradient(110deg, #091f46 0%, #123f85 60%, #387ee5 100%);
  --env-btn-primary-hover: linear-gradient(110deg, #12336b 0%, #2464c0 65%, #5698f3 100%);
  --env-btn-primary-border: #173d78;
  --env-btn-focus: #3e8bd6;
  /* Highlighter: the site's blue, as a bright translucent marker pen; never a raw neon. */
  --env-highlight: rgba(47, 107, 219, .5);
  --env-highlight: color-mix(in srgb, var(--blue, #2f6bdb) 50%, transparent);
}

/* ---------- Shared drawing ---------- */
.envelopes {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  width: 100%;
  min-width: 0;
  margin: 0;
  color: var(--env-ink);
}
.envelopes-text {  /* the same four answers for screen readers; the drawing is aria-hidden */
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  list-style: none;
}
.envelopes .env {
  display: block;
  position: relative;
  width: 100%;
  height: auto;
  aspect-ratio: 440 / 310;
  overflow: visible;
  fill: none;
  stroke: var(--env-ink);
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.envelopes .env .fill { fill: var(--env-paper); stroke: none; }
.envelopes .env .line { fill: none; }
.envelopes .env text {
  stroke: none;
  fill: var(--env-ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  text-anchor: middle;
}
.envelopes .env .env-label,
.envelopes .env .env-name { font-size: 27px; font-weight: 700; }
.envelopes .env .env-desc { font-size: 21px; font-weight: 500; }
.envelopes .env .env-mark { mix-blend-mode: multiply; }
.envelopes .env .env-mark path { fill: var(--env-highlight); stroke: none; }
.envelopes .env .env-flap-back,
.envelopes .env .env-flap-front { transform-box: view-box; transform-origin: 0 160px; }
.envelopes .env .env-mark { transform-box: fill-box; transform-origin: 0 50%; }

/* ---------- Static pose: every envelope open, cards showing ---------- */
.envelopes-stack {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(6px, 1.2vw, 16px) clamp(10px, 2vw, 24px);
  width: 100%;
}
/* Closed pose first (the base), then the open pose, which wins on equal specificity by coming later. */
.envelopes .env .env-flap-back { transform: scaleY(0); }
.envelopes .env .env-mark { transform: scaleX(0); }
.envelopes:not(.is-ready) .env .env-card,
.envelopes .env.is-open .env-card { transform: translateY(-118px); }
.envelopes:not(.is-ready) .env .env-flap-front,
.envelopes .env.is-open .env-flap-front { transform: scaleY(0); opacity: 0; }
.envelopes:not(.is-ready) .env .env-flap-back,
.envelopes .env.is-open .env-flap-back { transform: scaleY(1); }
.envelopes:not(.is-ready) .env .env-mark,
.envelopes .env.is-open .env-mark { transform: scaleX(1); }

@media (max-width: 600px) {
  .envelopes-stack { grid-template-columns: minmax(0, 1fr); max-width: 380px; margin-inline: auto; }
}

/* ---------- Animated pose: one stack, one envelope open at a time ---------- */
.envelopes.is-ready .envelopes-stack {
  display: flex;
  flex-direction: column;
  gap: 0;
  max-width: none;
}
/* Each box has 160 units of headroom for its open flap; neighbouring boxes overlap by that less a gap, so the
   stack keeps the proportions of the sketch (percentage margins are relative to the width). */
.envelopes.is-ready .env + .env { margin-top: -31.36%; }
.envelopes.is-ready .env { z-index: 1; }
.envelopes.is-ready .env.is-closing { z-index: 2; }
.envelopes.is-ready .env.is-open { z-index: 3; }

/* Closing (the default): card sinks, the flap folds back down. */
.envelopes.is-ready .env .env-mark       { transition: transform .2s ease-in; }
.envelopes.is-ready .env .env-card       { transition: transform .4s cubic-bezier(.5, 0, .75, 0); }
.envelopes.is-ready .env .env-flap-back  { transition: transform .22s ease-in .32s; }
.envelopes.is-ready .env .env-flap-front { transition: transform .28s ease-out .5s, opacity .2s ease .5s; }
/* Opening: flap folds up, the card rises, then the word is highlighted. */
.envelopes.is-ready .env.is-open .env-flap-front { transition: transform .2s ease-in, opacity .12s ease .1s; }
.envelopes.is-ready .env.is-open .env-flap-back  { transition: transform .32s cubic-bezier(.2, .9, .3, 1.15) .18s; }
.envelopes.is-ready .env.is-open .env-card       { transition: transform .65s cubic-bezier(.2, .9, .3, 1.12) .45s; }
.envelopes.is-ready .env.is-open .env-mark       { transition: transform .45s ease-out 1.05s; }
/* The closed envelope shows its name on the flap; the card carries it once open. */
.envelopes .env .env-name { opacity: 1; }
.envelopes.is-ready .env.is-open .env-name { opacity: 0; }
.envelopes:not(.is-ready) .env-name { opacity: 0; }

/* Height-bound: the stack must fit the window (about .53 wide per 1 tall), never narrower than 300px. */
@media (min-width: 751px) and (pointer: fine), (min-width: 751px) and (min-height: 601px) {
  html body main.page > #practices .ralph-section-frame--inbox > .envelopes {
    max-width: 100%;
    align-self: center;
    justify-self: center;
  }
  html body main.page > #practices .ralph-section-frame--inbox > .envelopes.is-ready {
    max-width: clamp(300px, calc((100dvh - var(--ralph-nav-height, 76px) - 150px) * .53), 100%);
  }
}
@media (max-width: 750px), (pointer: coarse) and (max-height: 600px) {
  html body main.page > #practices .ralph-section-frame--inbox > .envelopes { max-width: 100%; }
  html body main.page > #practices .ralph-section-frame--inbox > .envelopes.is-ready { max-width: 420px; margin-inline: auto; }
}

/* ---------- Controls: pause (WCAG 2.2.2) and, on phones, a button per envelope ---------- */
.envelopes-controls { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.envelopes-controls[hidden], .envelopes-tabs[hidden], .envelopes-toggle[hidden] { display: none; }
.envelopes-tabs { display: flex; flex: 1 1 auto; gap: 6px; min-width: 0; }
.envelopes-tabs button,
.envelopes-toggle {
  /* Same buttons as the feature orbit's controls (ralph-orbit.css): pill, 1.5px outline, bold 13px;
     the selected one is the dark-blue gradient pill. */
  font: 700 13px/1 Inter, ui-sans-serif, system-ui, sans-serif;
  height: 40px;
  padding: 0;
  border: 1.5px solid var(--env-btn-outline);
  border-radius: 999px;
  background: transparent;
  color: var(--env-btn-ink);
  cursor: pointer;
  transition: transform .15s, background .15s;
}
.envelopes-tabs button { flex: 1 1 0; min-width: 0; }
.envelopes-tabs button:hover,
.envelopes-toggle:hover { background: var(--env-btn-hover); transform: translateY(-2px); }
.envelopes-tabs button[aria-pressed="true"],
.envelopes-toggle {
  background: var(--env-btn-primary);
  border-color: var(--env-btn-primary-border);
  color: #fff;
  box-shadow: 0 8px 20px rgba(15, 30, 67, .22);
}
.envelopes-tabs button[aria-pressed="true"]:hover,
.envelopes-toggle:hover { background: var(--env-btn-primary-hover); }
.envelopes-toggle {
  flex: 0 0 auto;
  display: inline-grid;
  place-items: center;
  width: 40px;
}
.envelopes-toggle svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.envelopes-toggle .ico-play { display: none; fill: currentColor; }
.envelopes-toggle[data-state="paused"] .ico-pause { display: none; }
.envelopes-toggle[data-state="paused"] .ico-play { display: block; }
.envelopes-toggle:focus-visible,
.envelopes-tabs button:focus-visible { outline: 3px solid var(--env-btn-focus); outline-offset: 3px; }

/* ---------- Phones: one envelope-sized stage ----------
   The four envelopes sit on top of each other and one is shown at a time (it cycles by itself, or the
   buttons pick one). About a quarter of a screen instead of the whole stack. */
@media (max-width: 750px), (pointer: coarse) and (max-height: 600px) {
  .envelopes.is-stage { max-width: 420px; margin-inline: auto; }
  .envelopes.is-stage .envelopes-stack { display: grid; grid-template-columns: minmax(0, 1fr); max-width: none; gap: 0; }
  .envelopes.is-stage .env,
  .envelopes.is-stage.is-ready .env + .env { grid-area: 1 / 1; margin-top: 0; }
  .envelopes.is-stage .env { opacity: 0; pointer-events: none; transition: opacity .2s ease; }
  .envelopes.is-stage .env.is-current { opacity: 1; }
  .envelopes.is-stage .envelopes-controls { justify-content: stretch; }
  .envelopes.is-stage .envelopes-tabs button,
  .envelopes.is-stage .envelopes-toggle { height: var(--rm-tap, 44px); font-size: 13px; }
  .envelopes.is-stage .envelopes-toggle { width: var(--rm-tap, 44px); }
}

@media (prefers-reduced-motion: reduce) {
  .envelopes .env,
  .envelopes .env * { transition: none !important; }
  .envelopes-toggle { display: none !important; }
  .envelopes.is-stage .env { transition: none !important; }
}
@media (forced-colors: active) {
  .envelopes .env { stroke: CanvasText; }
  .envelopes .env .fill { fill: Canvas; }
  .envelopes .env text { fill: CanvasText; }
  .envelopes .env .env-mark { mix-blend-mode: normal; opacity: .5; }
  .envelopes .env .env-mark path { fill: Highlight; }
}
