/* =========================================================
   The Unhinged Oracle — visual design
   ========================================================= */

/* ---------- 1. Fonts (stored in the "fonts" folder) ---------- */
@font-face {
  font-family: "Cormorant Garamond";
  src: url("fonts/cormorant-garamond.woff2") format("woff2");
  font-weight: 300 700;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Cormorant Garamond";
  src: url("fonts/cormorant-garamond-italic.woff2") format("woff2");
  font-weight: 300 700;
  font-style: italic;
  font-display: swap;
}

/* ---------- 2. Colours (change them here) ---------- */
:root {
  /* The two upper clouds: their widths, and how far they're nudged up off the
     top edge (only on short, wide screens, where vertical space is tight). */
  --cloud-a-width: clamp(210px, 50vw, 470px);
  --cloud-b-width: clamp(205px, 48vw, 460px);
  --cloud-lift: 0px;
  /* Where the upper clouds end (their lowest painted point), worked out from
     the artwork's proportions: the reveal message always starts below this. */
  --cloud-band: calc(max(var(--cloud-a-width) * 0.481, var(--cloud-b-width) * 0.531) - var(--cloud-lift));

  --ink:        #5e1424;              /* burgundy printing ink */
  --ink-soft:   rgba(94, 20, 36, 0.55);
  --ink-faint:  rgba(94, 20, 36, 0.28);
  --paper:      #f1dfbf;
  --paper-light:#fbf1dc;
  --velvet:     #3b0b16;
  --velvet-deep:#1f050b;

  --serif: "Cormorant Garamond", "Cormorant", Garamond, "Hoefler Text", Georgia, serif;
}

/* ---------- 3. Page basics ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
}

body {
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: clamp(0px, 5vw, 64px) 0;
  color: var(--ink);
  font-family: var(--serif);
  /* plain parchment colour underneath, in case the background layer is still loading */
  background-color: var(--paper);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ---------- Shared background: parchment, clouds and gold sparkles ----------
   One fixed layer behind the homepage, the cookie opening and the fortune
   reveal alike. It never moves, fades or reloads between them. */
/* The background is part of the PAGE (not fixed to the window): it covers the
   whole page and scrolls together with the content, like one illustration. */
body {
  position: relative;
}

.backdrop {
  position: absolute;
  inset: 0;
  min-height: 100vh;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
  background-color: var(--paper);
  background-image: url("images/parchment.svg");
  background-size: 100% 100%;
}

/* Each cloud is pinned to its corner or edge and shifted by a share of its
   OWN size, so the same part of every cloud shows on every screen size.
   Only the width is set, so the artwork is never stretched. */
.backdrop__cloud {
  position: absolute;
  height: auto;
  max-width: none;
}

.backdrop__cloud--a { left: 0;  top: 0;     width: var(--cloud-a-width); transform: translate(-20%, calc(-16% - var(--cloud-lift))); }
.backdrop__cloud--b { right: 0; top: 0;     width: var(--cloud-b-width); transform: translate(22%, calc(-4% - var(--cloud-lift))); }
.backdrop__cloud--c { left: 0;  top: 43vh;  width: clamp(170px, 42vw, 380px); transform: translateX(-36%); }
.backdrop__cloud--d { right: 0; top: 29vh;  width: clamp(165px, 40vw, 370px); transform: translateX(34%); }
.backdrop__cloud--e { left: 0;  bottom: 0;  width: clamp(185px, 45vw, 400px); transform: translate(-22%, 12%); }
.backdrop__cloud--f { right: 0; bottom: 6%; width: clamp(145px, 34vw, 300px); transform: translateX(20%); }

/* On phones the wordmark and tagline span almost the full width, so the
   middle-right cloud sits a little lower (just below the tagline) and a
   little further off the edge, to keep the text clear. */
@media (max-width: 640px) {
  .backdrop__cloud--d { top: 40vh; transform: translateX(42%); }
}

/* Very small phones: the two lower clouds tuck a little further into the
   corners, so they stay clear of the fortune slip and the Share button. */
@media (max-width: 360px) {
  .backdrop__cloud--e { transform: translate(-34%, 30%); }
  .backdrop__cloud--f { bottom: 0; transform: translate(40%, 10%); }
}

/* ...and on the shortest of them (e.g. 320×568) they sink lower still. */
@media (max-width: 360px) and (max-height: 600px) {
  .backdrop__cloud--e { transform: translate(-42%, 56%); }
  .backdrop__cloud--f { transform: translate(40%, 40%); }
}

/* Tall tablets: the reveal message is larger and sits lower, so the
   middle-right cloud sits lower too (as on phones), just beneath it. */
@media (min-width: 700px) and (min-height: 1000px) and (orientation: portrait) {
  .backdrop__cloud--d { top: 40vh; transform: translateX(42%); }
}

/* Short, wide screens (laptops): to make room, the two upper clouds lift a
   little off the top edge, and the cookie area gets slightly less padding. */
@media (min-width: 641px) and (max-height: 850px) {
  :root { --cloud-lift: clamp(0px, (850px - 100vh) * 0.3, 60px); }
  .backdrop__cloud--c { transform: translateX(-48%); }
}

.backdrop__star {
  position: absolute;
  fill: #b08a4a;
  opacity: 0.75;
}

img {
  display: block;
  max-width: 100%;
}

/* ---------- 4. The parchment card ---------- */
.card {
  position: relative;
  isolation: isolate;
  overflow: hidden;         /* keeps the separating cookie halves inside the card */
  width: 100%;
  max-width: 640px;
  padding: clamp(40px, 8vw, 64px) clamp(28px, 7vw, 64px) clamp(48px, 9vw, 72px);
  text-align: center;
  /* sits on the shared parchment-and-cloud background (see .backdrop) */
  z-index: 1;
  background: none;
  border-radius: 3px;
}

/* ---------- 5. Printed double border ---------- */
.frame {
  position: absolute;
  inset: 14px;
  z-index: -1;
  pointer-events: none;
  --line: var(--ink-soft);
  /* Outer rule (stops short of the corners) */
  background:
    linear-gradient(var(--line), var(--line)) center top    / calc(100% - 56px) 1px no-repeat,
    linear-gradient(var(--line), var(--line)) center bottom / calc(100% - 56px) 1px no-repeat,
    linear-gradient(var(--line), var(--line)) left center   / 1px calc(100% - 56px) no-repeat,
    linear-gradient(var(--line), var(--line)) right center  / 1px calc(100% - 56px) no-repeat;
}

/* Inner, finer rule */
.frame::before {
  content: "";
  position: absolute;
  inset: 6px;
  --line: var(--ink-faint);
  background:
    linear-gradient(var(--line), var(--line)) center top    / calc(100% - 57px) 1px no-repeat,
    linear-gradient(var(--line), var(--line)) center bottom / calc(100% - 57px) 1px no-repeat,
    linear-gradient(var(--line), var(--line)) left center   / 1px calc(100% - 57px) no-repeat,
    linear-gradient(var(--line), var(--line)) right center  / 1px calc(100% - 57px) no-repeat;
}

.corner {
  position: absolute;
  width: 44px;
  height: 44px;
  opacity: 0.8;
}

.corner--tl { top: 0;    left: 0; }
.corner--tr { top: 0;    right: 0;  transform: scaleX(-1); }
.corner--bl { bottom: 0; left: 0;   transform: scaleY(-1); }
.corner--br { bottom: 0; right: 0;  transform: scale(-1, -1); }

/* ---------- 6. Wordmark and tagline ---------- */
.moon {
  width: clamp(76px, 18vw, 104px);
  margin: 0 auto clamp(10px, 2.5vw, 18px);
  opacity: 0.9;
}

.wordmark {
  margin: 0;
  font-weight: 500;
  line-height: 0.86;
  color: var(--ink);
  /* a faint highlight below the letters, like ink pressed into paper */
  text-shadow: 0 1px 0 rgba(255, 246, 228, 0.55);
}

.wordmark__the {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.9em;
  margin-bottom: 0.2em;
  font-size: clamp(1.15rem, 3.4vw, 1.45rem);
  font-style: italic;
  font-weight: 500;
  letter-spacing: 0.02em;
}

.wordmark__the::before,
.wordmark__the::after {
  content: "";
  width: clamp(36px, 10vw, 64px);
  height: 1px;
  background: var(--ink-soft);
}

.wordmark__line {
  display: block;
  font-size: clamp(3.2rem, 14.5vw, 6rem);
  text-transform: uppercase;
}

.wordmark__line--1 {
  letter-spacing: 0.03em;
  padding-left: 0.03em;   /* balances the space after the last letter */
}

/* Wider spacing so "ORACLE" lines up with "UNHINGED" as one block */
.wordmark__line--2 {
  letter-spacing: 0.2em;
  padding-left: 0.2em;
}

.rule {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: clamp(18px, 4vw, 26px) auto clamp(12px, 3vw, 16px);
}

.rule::before,
.rule::after {
  content: "";
  width: clamp(48px, 14vw, 84px);
  height: 1px;
  background: var(--ink-soft);
}

.rule__lozenge {
  width: 6px;
  height: 6px;
  border: 1px solid var(--ink);
  transform: rotate(45deg);
}

.tagline {
  margin: 0;
  font-size: clamp(1.3rem, 4.4vw, 1.7rem);
  font-style: italic;
  font-weight: 500;
  letter-spacing: 0.005em;
}

/* ---------- 7. The cookie ---------- */
.cookie-stage {
  position: relative;
  display: grid;
  place-items: center;
  margin: clamp(8px, 3vw, 20px) auto 0;
  padding: clamp(36px, 9vw, 56px) 0 clamp(20px, 5vw, 32px);
}

.astrolabe {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(118%, 600px);
  max-width: none;
  transform: translate(-50%, -50%);
  opacity: 0.32;
  z-index: -1;
}

.cookie {
  position: relative;
  z-index: 1;               /* above the glow, below the slip */
  width: min(84%, 420px);
}

/* Homepage cookie: its shadow layer sets the size; the cookie sits on top */
.cookie__shadow {
  width: 100%;
  height: auto;
}

.cookie__whole {
  position: absolute;
  inset: 0;
  width: 100%;
  height: auto;
}

/* ---------- Reveal screen cookie: two halves that break apart ----------
   The movement itself is choreographed in script.js. */
.reveal-cookie {
  aspect-ratio: 450 / 340;
}

.cookie__half {
  position: absolute;
  inset: 0;
  will-change: transform;
  /* each half carries its own small contact shadow, which follows its shape */
  filter:
    drop-shadow(1px 2px 1.5px rgba(80, 42, 14, 0.22))
    drop-shadow(3px 9px 8px rgba(80, 42, 14, 0.12));
}

.cookie__half img {
  display: block;
  width: 100%;
  height: auto;
}

/* Left half: everything to the left of the fold. It pivots on its outer foot. */
.cookie__half--left {
  transform-origin: 20% 80%;
}

/* The split follows the front fold of cookie-body.webp. Between 13% and 67%
   down it wavers slightly behind the fold, so the back of the cookie
   breaks with a gently uneven edge rather than a clean cut. The two shapes
   share exactly the same line, so the cookie looks whole until it breaks. */
.cookie__half--left img {
  clip-path: polygon(
    0 0, 48.25% 0%, 48.85% 5%, 49.42% 10%, 49.95% 13%, 50.24% 16%,
    49.91% 19%, 50.16% 22%, 49.7% 25%, 49.69% 28%, 49.6% 31%, 48.7% 34%,
    47.92% 37%, 47.8% 40%, 47.05% 43%, 46.8% 46%, 45.95% 49%, 45.15% 52%,
    45.05% 55%, 44.5% 58%, 44.45% 61%, 44% 64%, 44.15% 67%, 43.3% 72%,
    43.3% 80%, 43.7% 84%, 44.2% 88%, 45.1% 92%, 46.7% 96%, 47.7% 100%,
    0 100%
  );
}

/* Right half: everything to the right of the fold. It pivots on its outer foot. */
.cookie__half--right {
  transform-origin: 78% 92%;
}

.cookie__half--right img {
  clip-path: polygon(
    48.1% 0, 100% 0, 100% 100%, 48% 100%, 47% 96%, 45.4% 92%,
    44.5% 88%, 44% 84%, 43.6% 80%, 43.6% 72%, 44% 67%, 43.85% 64%,
    44.3% 61%, 44.35% 58%, 44.9% 55%, 45% 52%, 45.8% 49%, 46.65% 46%,
    46.9% 43%, 47.65% 40%, 47.77% 37%, 48.55% 34%, 49.45% 31%, 49.54% 28%,
    49.55% 25%, 50.01% 22%, 49.76% 19%, 50.09% 16%, 49.8% 13%, 49.27% 10%,
    48.7% 5%, 48.1% 0%
  );
}

/* Soft shadows on the "table", one under each half, cast down and to the right */
.ground-shadow {
  position: absolute;
  border-radius: 50%;
  background: radial-gradient(ellipse at center,
    rgba(85, 45, 15, 0.38) 0%, rgba(85, 45, 15, 0.16) 45%, transparent 72%);
  filter: blur(3px);
  will-change: transform, opacity;
  pointer-events: none;
}

.ground-shadow--left  { left: 4%;  top: 66%; width: 48%; height: 22%; }
.ground-shadow--right { left: 42%; top: 72%; width: 60%; height: 28%; }

/* Crumbs (hidden until the cookie breaks) */
.crumb {
  position: absolute;
  left: 45%;
  top: 66%;
  width: 4px;
  height: 3px;
  border-radius: 45% 55% 50% 40%;
  background: #c98a45;
  box-shadow: inset -1px -1px 0 rgba(110, 60, 20, 0.35);
  opacity: 0;
  pointer-events: none;
}

/* ---------- The paper fortune slip ----------
   Folded in three: the outer panels fold over the middle one and open in 3D.
   It starts tucked inside the cookie (behind the halves). */
.slip {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 0;
  width: min(94%, 470px);
  opacity: 0;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.slip__paper {
  position: relative;
  perspective: 1400px;
  transform-style: preserve-3d;
  color: var(--ink);
}

/* A soft shadow under the paper; script.js widens it as the slip opens */
.slip__shadow {
  position: absolute;
  inset: 10% 4% -8% 4%;
  background: rgba(60, 30, 10, 0.34);
  filter: blur(14px);
  border-radius: 6px;
  transform: translateZ(-2px) scaleX(0.34);
  opacity: 0;
}

/* An invisible copy of the content that gives the slip its height */
.slip__sizer {
  visibility: hidden;
}

/* The printed paper itself */
/* The fortune receives screen-reader focus once it is revealed (see script.js).
   That focus is for assistive technology only, so it draws no outline. */
#slip-readable:focus {
  outline: none;
}

.slip__content {
  position: relative;
  padding: clamp(18px, 4.5vw, 26px) clamp(20px, 5.5vw, 34px) clamp(14px, 3.5vw, 18px);
  background-color: #f9f0dc;
  background-image: linear-gradient(180deg, #fcf6e8 0%, #f3e5c9 100%);
}

/* A fine printed rule just inside the edge of the slip */
.slip__content::before {
  content: "";
  position: absolute;
  inset: 6px;
  border: 1px solid var(--ink-faint);
  pointer-events: none;
}

.slip__panel {
  position: absolute;
  top: 0;
  bottom: 0;
  width: calc(100% / 3);
  transform-style: preserve-3d;
}

.slip__panel--left   { left: 0;              transform-origin: 100% 50%; }
.slip__panel--middle { left: calc(100% / 3); }
.slip__panel--right  { left: calc(200% / 3); transform-origin: 0 50%; }

.slip__face {
  position: absolute;
  inset: 0;
  overflow: hidden;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

/* Each face shows its own third of the full-width printed paper */
.slip__face .slip__content {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 300%;
}

.slip__panel--left   .slip__content { left: 0; }
.slip__panel--middle .slip__content { left: -100%; }
.slip__panel--right  .slip__content { left: -200%; }

/* The plain back of each outer panel (what you see while it's folded) */
.slip__face--back {
  transform: rotateY(180deg);
  background: linear-gradient(180deg, #f8eedb 0%, #eedfc1 100%);
}

/* Soft shading along the folds */
.slip__face::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.slip__panel--left  .slip__face--front::after { background: linear-gradient(270deg, rgba(120, 80, 40, 0.10), transparent 12%); }
.slip__panel--middle .slip__face::after       { background: linear-gradient(90deg, rgba(120, 80, 40, 0.08), transparent 10%, transparent 90%, rgba(120, 80, 40, 0.08)); }
.slip__panel--right .slip__face--front::after { background: linear-gradient(90deg, rgba(120, 80, 40, 0.10), transparent 12%); }
.slip__face--back::after                      { background: linear-gradient(90deg, rgba(120, 80, 40, 0.12), transparent 30%, transparent 70%, rgba(120, 80, 40, 0.12)); }

/* Folded: both outer panels lie over the middle one */
.slip__panel--left  { transform: translateZ(2px) rotateY(180deg); }
.slip__panel--right { transform: translateZ(1px) rotateY(-180deg); }

.slip__category {
  margin: 0 0 10px;
  font-size: clamp(0.68rem, 2.2vw, 0.78rem);
  font-weight: 600;
  letter-spacing: 0.26em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.slip__text {
  margin: 0;
  font-size: clamp(1.15rem, 4.2vw, 1.45rem);
  font-weight: 500;
  line-height: 1.3;
  text-wrap: balance;
}

.slip__rule {
  display: flex;
  justify-content: center;
  margin-top: 12px;
}

/* ---------- Discreet sound switch (reveal screen only) ---------- */
.sound-toggle {
  position: absolute;
  top: clamp(12px, 2.5vw, 22px);
  right: clamp(12px, 2.5vw, 22px);
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  color: var(--ink);
  /* a soft parchment disc keeps the icon visible over the top-right cloud */
  background: rgba(250, 240, 222, 0.72);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  opacity: 0.6;
  transition: opacity 0.3s ease;
}

.sound-toggle:hover,
.sound-toggle:focus-visible {
  opacity: 0.9;
}

.sound-toggle:focus-visible {
  outline: 1px solid var(--ink);
  outline-offset: 2px;
}

.sound-toggle svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sound-toggle__cross { display: none; }
.sound-toggle[aria-pressed="true"] .sound-toggle__waves { display: none; }
.sound-toggle[aria-pressed="true"] .sound-toggle__cross { display: inline; }

/* ---------- 8. Prompt and category selectors ---------- */
.prompt {
  margin: 0 0 clamp(18px, 4vw, 24px);
  font-size: clamp(1.4rem, 5vw, 1.85rem);
  font-style: italic;
  font-weight: 500;
  color: var(--ink);
}

.categories {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: clamp(8px, 2.5vw, 16px);
}

.category {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: clamp(96px, 22vw, 116px);
  padding: 14px 6px;
  cursor: pointer;
  font-family: var(--serif);
  color: var(--ink);
  background: rgba(255, 246, 228, 0.18);
  border: 1px solid var(--ink-soft);
  border-radius: 1px;
  /* thin second rule inside the plate */
  box-shadow: inset 0 0 0 3px rgba(0, 0, 0, 0), inset 0 0 0 4px var(--ink-faint);
  transition: background-color 0.35s ease, color 0.35s ease, box-shadow 0.35s ease;
}

.category__numeral {
  font-size: clamp(0.95rem, 2.8vw, 1.1rem);
  font-style: italic;
  font-weight: 500;
  line-height: 1;
  opacity: 0.75;
}

.category__label {
  max-width: 8.5em;
  font-size: clamp(0.8rem, 2.7vw, 1.02rem);
  font-weight: 600;
  letter-spacing: 0.16em;
  line-height: 1.35;
  text-transform: uppercase;
}

.category:hover,
.category.is-selected {
  color: var(--paper-light);
  background-color: var(--ink);
  box-shadow: inset 0 0 0 3px var(--ink), inset 0 0 0 4px rgba(251, 241, 220, 0.45);
}

/* After a choice: the other two plates fade back and nothing is clickable */
.categories.is-locked .category {
  cursor: default;
  transition: opacity 0.6s ease, background-color 0.35s ease, color 0.35s ease, box-shadow 0.35s ease;
}

.categories.is-locked .category:not(.is-selected) {
  opacity: 0.35;
  color: var(--ink);
  background-color: rgba(255, 246, 228, 0.18);
  box-shadow: inset 0 0 0 3px rgba(0, 0, 0, 0), inset 0 0 0 4px var(--ink-faint);
}

/* A category whose fortunes have all been received (until the next cycle) */
.category.is-used-up,
.category.is-used-up:hover {
  opacity: 0.4;
  cursor: default;
  color: var(--ink);
  background-color: rgba(255, 246, 228, 0.18);
  box-shadow: inset 0 0 0 3px rgba(0, 0, 0, 0), inset 0 0 0 4px var(--ink-faint);
}

/* The note explaining it (takes no space while empty) */
.categories__note {
  max-width: 30em;
  margin: 16px auto 0;
  font-size: clamp(1rem, 3.4vw, 1.1rem);
  font-style: italic;
  font-weight: 500;
  line-height: 1.35;
  color: var(--ink);
  text-wrap: balance;
}

.categories__note:empty {
  display: none;
}

.category:focus-visible {
  outline: 1px solid var(--ink);
  outline-offset: 4px;
}

/* ---------- 9. The reveal screen (after a category is chosen) ---------- */

/* The homepage gently steps away... */
.card {
  transition: opacity 0.6s ease, transform 0.8s cubic-bezier(0.22, 1, 0.36, 1);
}

body.is-revealing .card {
  opacity: 0;
  transform: scale(0.97);
}

/* No scrolling behind the reveal screen */
html.is-locked,
html.is-locked body {
  overflow: hidden;
}

/* ...and a clean, quiet screen takes its place */
.reveal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  /* Older iPhones (Safari before 17.6) don't understand "safe center" and would
     skip it entirely, so plain centring is given first as their fallback. */
  justify-content: center;
  justify-content: safe center;
  gap: clamp(8px, 2vh, 20px);
  /* The top padding keeps the message below the upper clouds, with breathing
     room; extra space at the bottom balances the Share button below the slip. */
  padding: calc(var(--cloud-band) + 28px) clamp(16px, 5vw, 40px) var(--reveal-bottom, 24px);
  overflow: hidden;
  text-align: center;
  color: var(--ink);
  font-family: var(--serif);
  /* see-through: the shared parchment-and-cloud background shows behind it */
  background: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.8s ease 0.2s, visibility 0s linear 1s;
}

body.is-revealing .reveal {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.8s ease 0.2s, visibility 0s;
}

.reveal__message {
  margin: 0;
  max-width: 22em;
  font-size: clamp(1.3rem, 4.6vw, 1.9rem);
  font-style: italic;
  font-weight: 500;
  line-height: 1.25;
  text-wrap: balance;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.9s ease 0.7s, transform 0.9s ease 0.7s;
}

body.is-revealing .reveal__message {
  opacity: 1;
  transform: none;
}

.reveal__stage {
  width: min(100%, 560px);
  margin: 0;
  padding: clamp(40px, 8vh, 72px) 0;
}

@media (min-width: 641px) and (max-height: 850px), (max-height: 600px) {
  .reveal__stage {
    padding: clamp(20px, 4vh, 40px) 0;
  }
}

.reveal__stage .cookie {
  width: min(78%, 420px);
  opacity: 0;
  transform: translateY(12px) scale(0.96);
  transition: opacity 0.9s ease 0.9s, transform 1.1s cubic-bezier(0.22, 1, 0.36, 1) 0.9s;
}

body.is-revealing .reveal__stage .cookie {
  opacity: 1;
  transform: none;
}

/* ---------- Returning visitor: the universe has already spoken ----------
   The page opens straight onto today's opened cookie — no homepage,
   no transition, no animation. */
html.has-spoken .card {
  display: none;
}

html.has-spoken,
html.has-spoken body {
  overflow: hidden;
}

html.has-spoken .reveal,
html.has-spoken .reveal__message,
html.has-spoken .reveal__stage .cookie {
  opacity: 1;
  visibility: visible;
  transform: none;
  transition: none;
}

/* No sound plays on a return visit, so no sound switch either */
html.has-spoken .sound-toggle {
  display: none;
}

/* ---------- Sharing ---------- */
.share {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-top: clamp(18px, 3vh, 28px);
  opacity: 0;
  visibility: hidden;
  transform: translateY(6px);
  transition: opacity 0.7s ease, transform 0.7s ease, visibility 0s linear 0.7s;
}

.share.is-visible {
  opacity: 1;
  visibility: visible;
  transform: none;
  pointer-events: auto;
  transition: opacity 0.7s ease, transform 0.7s ease, visibility 0s;
}

.share__button {
  padding: 12px 26px 11px;
  cursor: pointer;
  font-family: var(--serif);
  font-size: clamp(0.8rem, 2.6vw, 0.9rem);
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink);
  background: rgba(255, 248, 234, 0.55);
  border: 1px solid var(--ink-soft);
  border-radius: 1px;
  box-shadow: inset 0 0 0 3px rgba(0, 0, 0, 0), inset 0 0 0 4px var(--ink-faint);
  transition: background-color 0.3s ease, color 0.3s ease, box-shadow 0.3s ease;
}

.share__button:hover,
.share__button[aria-busy="true"] {
  color: var(--paper-light);
  background-color: var(--ink);
  box-shadow: inset 0 0 0 3px var(--ink), inset 0 0 0 4px rgba(251, 241, 220, 0.45);
}

.share__button:focus-visible,
.share__option:focus-visible {
  outline: 1px solid var(--ink);
  outline-offset: 4px;
}

/* Fallback choices, shown only when the image can't be shared directly */
.share__options {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 4px 0;
}

.share__options[hidden] {
  display: none;
}

.share__option {
  padding: 4px 10px;
  cursor: pointer;
  font-family: var(--serif);
  font-size: clamp(0.95rem, 3.4vw, 1.05rem);
  font-style: italic;
  font-weight: 500;
  color: var(--ink);
  background: none;
  border: none;
  text-decoration: underline;
  text-decoration-color: var(--ink-faint);
  text-underline-offset: 4px;
}

.share__option:hover {
  text-decoration-color: var(--ink);
}

/* little dots between the options */
.share__option + .share__option::before {
  content: "·";
  display: inline-block;
  margin: 0 12px 0 -6px;
  color: var(--ink-soft);
  text-decoration: none;
}

.share__option[hidden] {
  display: none;
}

.share__note {
  min-height: 1.3em;
  max-width: 24em;
  margin: 0;
  text-wrap: balance;
  font-size: 0.95rem;
  font-style: italic;
  color: var(--ink-soft);
}

/* ---------- 10. Phones ---------- */
@media (max-width: 640px) {
  body {
    padding: 0;
  }

  .card {
    min-height: 100vh;
    border-radius: 0;
  }

  /* Reveal screen on phones: a bigger cookie, a slightly narrower slip */
  .reveal__stage .cookie {
    width: 80%;
  }

  .slip {
    width: 88%;
  }
}

@media (max-width: 380px) {
  .category__label {
    letter-spacing: 0.1em;
  }
}

/* Very small phones (320–360px): a larger cookie and a slimmer, slightly
   smaller slip that rests lower (see script.js), so the halves stay visible */
@media (max-width: 360px) {
  .reveal {
    --reveal-bottom: 72px;
  }

  /* 82% keeps both halves fully on screen throughout the break
     (about 5px to spare at 320px and 360px) */
  .reveal__stage .cookie {
    width: 82%;
  }

  .slip {
    width: 82%;
  }

  .slip__content {
    padding: 16px 16px 12px;
  }

  .slip__category {
    margin-bottom: 7px;
  }

  .slip__text {
    font-size: 1.05rem;
  }
}

/* The shortest small phones (e.g. 320×568): a little more room under the
   Share button, which hangs below the slip */
@media (max-width: 360px) and (max-height: 600px) {
  .reveal {
    --reveal-bottom: 110px;
  }
}

/* Tall portrait screens (tablets): everything on the reveal screen a little
   larger, so it fills the space with intent rather than floating small */
@media (min-width: 700px) and (min-height: 1000px) and (orientation: portrait) {
  .reveal {
    gap: 3vh;
    --reveal-bottom: 0px;
  }

  .reveal__message {
    font-size: 2.2rem;
  }

  .reveal__stage {
    width: min(100%, 680px);
  }

  .reveal__stage .cookie {
    width: min(78%, 520px);
  }

  .slip {
    width: min(94%, 570px);
  }

  .slip__category {
    font-size: 0.86rem;
  }

  .slip__text {
    font-size: 1.75rem;
  }

  .share__button {
    font-size: 1rem;
  }
}

/* The largest tablets (e.g. 12.9-inch iPad) */
@media (min-width: 950px) and (min-height: 1250px) and (orientation: portrait) {
  .reveal__message {
    font-size: 2.5rem;
  }

  .reveal__stage {
    width: min(100%, 780px);
  }

  .reveal__stage .cookie {
    width: min(78%, 600px);
  }

  .slip {
    width: min(94%, 650px);
  }

  .slip__text {
    font-size: 2rem;
  }
}

/* ---------- 11. For people who prefer less motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .card,
  .reveal,
  .reveal__message,
  .reveal__stage .cookie {
    transition-duration: 0.01s !important;
    transition-delay: 0s !important;
  }
}
