/* Flixal mobile menu: a bottom sheet on <dialog class="sheet" id="menu-sheet">.
 * Pairs with js/sheet.js. Open and close are CSS transitions (with @starting-style and
 * allow-discrete for display/overlay), so either can be grabbed and reversed mid-flight.
 * js/sheet.js only writes inline transform and the --sheet-* properties during a drag.
 */

/* Token fallbacks. :where() keeps them at zero specificity, so site.css always wins. */
:where(:root) {
  --purple: #8D55AD;
  --purple-ink: #4E2A66;
  --purple-wash: #F3ECF8;
  --orange: #FFAE56;
  --mint: #A1E4A9;
  --card: #FFFFFF;
  --ink: #1B1326;
  --line: #E6DEEF;
  --radius-l: 32px;
  --font: "Outfit", system-ui, sans-serif;
  --ease-out: cubic-bezier(.2, .8, .2, 1);
}

/* Page scroll is locked by CSS while the menu is open. */
html:has(.sheet[open]:not(.is-closing)) {
  overflow: hidden;
  scrollbar-gutter: stable;
}

.sheet {
  --sheet-pad: 24px;
  --sheet-dur: 260ms;                  /* close; .sheet[open] sets the open duration */
  --sheet-ease: var(--ease-out);
  position: fixed;
  inset: auto 0 0 0;
  box-sizing: border-box;
  width: 100%;
  max-width: 560px;
  height: auto;
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  margin: 0 auto;
  padding: 0 var(--sheet-pad) max(20px, env(safe-area-inset-bottom));
  border: 0;
  border-radius: var(--radius-l) var(--radius-l) 0 0;
  background: var(--card);
  color: var(--ink);
  font-family: var(--font);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  /* The sheet owns vertical drags while its content is not scrolled (see data-scroll below). */
  touch-action: none;
  /* Solid fill under the bottom edge, so pulling the sheet up past rest shows no gap. */
  box-shadow: 0 64px 0 var(--card);
  transform: translateY(100%);
  transition:
    transform var(--sheet-dur) var(--sheet-ease),
    overlay var(--sheet-dur) allow-discrete,
    display var(--sheet-dur) allow-discrete;
}
.sheet[open] {
  --sheet-dur: 380ms;
  transform: translateY(0);
}
/* js/sheet.js slides the sheet out with this class while the dialog is still open, then closes it. */
.sheet.is-closing {
  --sheet-dur: 260ms;
  transform: translateY(100%);
}
@starting-style {
  .sheet[open] { transform: translateY(100%); }
}

.sheet::backdrop {
  background: rgb(27 19 38 / .42);
  opacity: 0;
  transition:
    opacity var(--sheet-dur, 260ms) var(--sheet-ease, cubic-bezier(.2, .8, .2, 1)),
    overlay var(--sheet-dur, 260ms) allow-discrete,
    display var(--sheet-dur, 260ms) allow-discrete;
}
.sheet[open]::backdrop {
  opacity: var(--sheet-backdrop, 1);    /* js/sheet.js dims it as the sheet is dragged down */
  transition-duration: var(--sheet-dur, 380ms);
}
.sheet.is-closing::backdrop { opacity: 0; }
@starting-style {
  .sheet[open]::backdrop { opacity: 0; }
}

/* Held by a finger: the sheet follows the pointer, no transition. */
.sheet.is-held,
.sheet.is-held::backdrop { transition: none; }
.sheet.is-dragging { cursor: grabbing; will-change: transform; }

/* Scrollable content: at the top, a finger moving down drags the sheet and a finger moving up
 * scrolls the content; once scrolled, the content scrolls both ways and only the handle drags. */
.sheet[data-scroll="top"] { touch-action: pan-down; }
.sheet[data-scroll="scrolled"] { touch-action: pan-y; }

@supports (corner-shape: squircle) {
  .sheet {
    corner-shape: squircle;
    border-radius: calc(var(--radius-l) * 1.6) calc(var(--radius-l) * 1.6) 0 0;
  }
}

/* Handle: 44x5 pill, centred in a full-width 44px hit area. */
.sheet__handle {
  position: relative;
  height: 44px;
  margin: 0 calc(var(--sheet-pad) * -1);
  touch-action: none;
  cursor: grab;
}
.sheet__handle::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 44px;
  height: 5px;
  margin: -2.5px 0 0 -22px;
  border-radius: 999px;
  background: var(--line);
}

/* Links: full-bleed rows, so the active tab sits on the sheet's left edge. */
.sheet__links {
  display: flex;
  flex-direction: column;
  margin: 0 calc(var(--sheet-pad) * -1);
}
.sheet__links a {
  position: relative;
  display: flex;
  align-items: center;
  box-sizing: border-box;
  min-height: 56px;
  padding: 10px var(--sheet-pad);
  color: var(--ink);
  font-family: var(--font);
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.01em;
  text-decoration: none;
  -webkit-user-drag: none;
}
.sheet__links a + a::after {
  content: "";
  position: absolute;
  top: 0;
  left: var(--sheet-pad);
  right: var(--sheet-pad);
  height: 1px;
  background: var(--line);
}
.sheet__links a.is-active::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 0;
  width: 8px;
  height: 22px;
  margin-top: -11px;
  border-radius: 0 8px 8px 0;
  background: var(--mint);
}
.sheet:not(.is-dragging) .sheet__links a:active { background: var(--purple-wash); }
@media (hover: hover) {
  .sheet:not(.is-dragging) .sheet__links a:hover { color: var(--purple); }
}
.sheet__links a:focus-visible {
  outline: 2px solid var(--purple);
  outline-offset: -4px;
  border-radius: 16px;
}

/* CTA. Two classes so it wins over .btn whatever order the stylesheets load in. */
.sheet .sheet__cta {
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  width: 100%;
  min-height: 56px;
  margin: 16px 0 0;
  padding: 0 24px;
  border: 0;
  border-radius: 16px;
  background: var(--orange);
  color: var(--ink);
  font-family: var(--font);
  font-size: 1.125rem;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: 0;
  text-decoration: none;
  box-shadow: none;
  transition: transform 120ms var(--ease-out);
  -webkit-user-drag: none;
}
.sheet .sheet__cta:hover { background: var(--orange); color: var(--ink); }
.sheet:not(.is-dragging) .sheet__cta:active { transform: scale(.98); }
.sheet .sheet__cta:focus-visible {
  outline: 2px solid var(--purple-ink);
  outline-offset: 3px;
}

/* Reduced motion: no slide, a 150ms opacity fade only. */
@media (prefers-reduced-motion: reduce) {
  .sheet {
    transform: none;
    opacity: 0;
    transition:
      opacity 150ms linear,
      overlay 150ms allow-discrete,
      display 150ms allow-discrete;
  }
  .sheet[open] { opacity: 1; }
  .sheet.is-closing { transform: none; opacity: 0; }
  .sheet::backdrop,
  .sheet[open]::backdrop {
    transition:
      opacity 150ms linear,
      overlay 150ms allow-discrete,
      display 150ms allow-discrete;
  }
  .sheet.is-held::backdrop { transition: none; }
  @starting-style {
    .sheet[open] { transform: none; opacity: 0; }
  }
}
