/* Mr. Matthew's Wedding Speech — shared styles */

:root {
  --cream: #faf7f2;
  --paper: #fffdf9;
  --ink: #2b2a26;
  --muted: #6e695f;
  --green: #2f4f3e;
  --green-deep: #22392d;
  --sage: #8a9a85;
  --gold: #b8975a;
  --gold-deep: #9a7c45;
  --gold-soft: #e3d5b6;
  --rule: #e8e1d3;
  --shadow: 0 10px 30px rgba(43, 42, 38, 0.10), 0 2px 6px rgba(43, 42, 38, 0.06);

  --font-display: "Cormorant Garamond", "Playfair Display", Georgia, serif;
  --font-body: "EB Garamond", "Lora", Georgia, serif;

  --w-text: 720px;
  --w-wide: 900px;
  --gutter: 1rem;
  --space-1: 0.5rem;
  --space-2: 1rem;
  --space-3: 1.5rem;
  --space-4: 2.5rem;
  --space-5: 4rem;
  --radius: 10px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--cream);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 1.2rem;
  line-height: 1.65;
  overflow-x: hidden;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

img {
  max-width: 100%;
}

a {
  color: var(--green);
  text-decoration-color: var(--gold-soft);
  text-underline-offset: 0.2em;
}

a:hover {
  text-decoration-color: var(--gold);
}

:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 4px;
  border-radius: 2px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Small-caps, letterspaced labels used throughout */
.label,
.eyebrow,
.section-label,
.site-nav a,
.clicker-label,
.btn-text {
  font-family: var(--font-body);
  font-variant-caps: small-caps;
  letter-spacing: 0.2em;
  text-transform: lowercase;
}

/* ---------- Header ---------- */

.site-header {
  padding: var(--space-3) var(--gutter) var(--space-2);
  text-align: center;
  border-bottom: 1px solid var(--rule);
  background: var(--cream);
}

.wordmark {
  font-family: var(--font-display);
  font-size: 1.45rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--green);
  text-decoration: none;
}

.wordmark:hover {
  color: var(--green-deep);
}

.site-nav {
  margin-top: var(--space-2);
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-4);
}

.site-nav a {
  font-size: 0.95rem;
  color: var(--muted);
  text-decoration: none;
  padding: 0.25rem 0;
  border-bottom: 1px solid transparent;
}

.site-nav a:hover {
  color: var(--green);
  border-bottom-color: var(--gold-soft);
}

.site-nav a[aria-current="page"] {
  color: var(--green);
  border-bottom-color: var(--gold);
}

/* ---------- Ornaments ---------- */

.ornament {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  margin: var(--space-3) auto;
  max-width: 320px;
  color: var(--gold);
  font-size: 1rem;
  line-height: 1;
}

.ornament::before,
.ornament::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--gold);
  opacity: 0.6;
}

.rule {
  width: 100%;
  max-width: var(--w-text);
  margin: var(--space-5) auto;
  border: 0;
  border-top: 1px solid var(--rule);
}

/* ---------- Hero ---------- */

.hero {
  text-align: center;
  padding: clamp(2.5rem, 7vw, 5rem) var(--gutter) var(--space-3);
}

.eyebrow {
  margin: 0 0 var(--space-2);
  font-size: 1rem;
  color: var(--gold-deep);
}

.hero h1,
.page-title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 500;
  font-size: clamp(2.5rem, 7.5vw, 4.5rem);
  line-height: 1.05;
  color: var(--green);
  letter-spacing: -0.005em;
  text-wrap: balance;
}

.hero-sub {
  margin: var(--space-2) auto 0;
  max-width: 34ch;
  font-style: italic;
  font-size: 1.2rem;
  color: var(--muted);
}

.hero-figure {
  margin: var(--space-3) auto 0;
  max-width: 420px;
}

.hero-figure img {
  aspect-ratio: 4 / 5;
  object-fit: cover;
  object-position: 50% 53%;
}

/* ---------- Photo frames ---------- */

.figure {
  margin: var(--space-4) auto;
  width: 100%;
}

.figure img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: var(--radius);
}

.frame {
  padding: 10px;
  background: var(--paper);
  border-radius: calc(var(--radius) + 6px);
  box-shadow: var(--shadow);
}

.frame img {
  border-radius: var(--radius);
}

.figure figcaption {
  margin-top: 0.85rem;
  text-align: center;
  font-style: italic;
  font-size: 1.05rem;
  color: var(--muted);
}

.figure--wide {
  max-width: var(--w-wide);
}

.figure--portrait {
  max-width: 480px;
}

.figure--square {
  max-width: 480px;
}

/* Very tall portraits (e.g. 757x1600) stay a column, not a tower. */
.figure--tall {
  max-width: 400px;
}

.figure-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
  align-items: start;
  max-width: var(--w-wide);
  margin: var(--space-4) auto;
}

.figure-grid .figure {
  margin: 0;
}

/* Landscape pairs share a 4:3 frame; per-image object-position keeps faces in. */
.figure-grid--landscape img {
  aspect-ratio: 4 / 3;
  object-fit: cover;
}

@media (max-width: 640px) {
  .figure-grid {
    grid-template-columns: 1fr;
  }
}

/* ---------- Speech article ---------- */

main {
  flex: 1;
}

.article {
  padding: 0 var(--gutter) var(--space-5);
}

.speech-section {
  max-width: var(--w-wide);
  margin: 0 auto;
  padding-top: var(--space-4);
}

.speech-section > p,
.speech-section > .section-label {
  max-width: var(--w-text);
  margin-left: auto;
  margin-right: auto;
}

.section-label {
  margin: 0 auto var(--space-3);
  text-align: center;
  font-size: 1rem;
  font-weight: 500;
  color: var(--gold-deep);
}

.speech-section > p {
  margin-top: 0;
  margin-bottom: 1.25em;
}

.speech-section > p:first-of-type {
  margin-top: 0;
}

.lead {
  font-family: var(--font-display);
  font-size: 1.9rem;
  font-weight: 500;
  text-align: center;
  color: var(--green);
}

.quote-emph {
  font-weight: 500;
  color: var(--green);
}

.pullquote {
  max-width: var(--w-text);
  margin: var(--space-4) auto;
  padding: var(--space-3) var(--space-2);
  border-top: 1px solid var(--gold);
  border-bottom: 1px solid var(--gold);
  text-align: center;
}

.pullquote p {
  margin: 0;
  font-family: var(--font-display);
  font-style: italic;
  font-size: clamp(1.75rem, 4.5vw, 2.5rem);
  line-height: 1.25;
  color: var(--green);
}

.closing {
  text-align: center;
  margin-top: var(--space-4);
}

.closing-names {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.6rem, 4vw, 2.1rem);
  font-weight: 500;
  color: var(--green);
}

/* ---------- Footer ---------- */

.site-footer {
  border-top: 1px solid var(--rule);
  padding: var(--space-3) var(--gutter) var(--space-4);
  text-align: center;
  color: var(--muted);
  font-size: 1rem;
}

.site-footer p {
  margin: 0 0 var(--space-2);
}

.site-footer .site-nav {
  margin-top: 0;
}

/* ---------- Clicker ---------- */

.clicker {
  text-align: center;
  padding: clamp(2rem, 6vw, 4rem) var(--gutter) var(--space-5);
  max-width: var(--w-text);
  margin: 0 auto;
}

.clicker-count {
  display: block;
  margin: var(--space-3) 0 0;
  font-family: var(--font-display);
  font-weight: 500;
  font-size: clamp(4.5rem, 20vw, 7.5rem);
  line-height: 1;
  color: var(--green);
  font-variant-numeric: tabular-nums;
}

.clicker-label {
  display: block;
  margin-top: 0.25rem;
  font-size: 1rem;
  color: var(--gold-deep);
}

.clicker-stage {
  position: relative;
  display: inline-block;
  margin: var(--space-4) auto var(--space-3);
  padding: 12px;
}

.clicker-face {
  position: relative;
  display: block;
  width: clamp(220px, 70vw, 300px);
  aspect-ratio: 1 / 1;
  padding: 0;
  margin: 0;
  border: 4px solid var(--gold);
  border-radius: 50%;
  background: var(--paper);
  box-shadow: 0 0 0 7px var(--cream), 0 0 0 8px var(--gold-soft), var(--shadow);
  cursor: pointer;
  overflow: visible;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  transform-origin: 50% 60%;
}

.clicker-face:focus-visible {
  outline-offset: 12px;
}

.clicker-face img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border-radius: 50%;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
}

.clicker-face.is-popping {
  animation: pop 200ms cubic-bezier(0.2, 0.8, 0.3, 1.2);
}

@keyframes pop {
  0% { transform: scale(1); }
  35% { transform: scale(0.92, 0.88); }
  70% { transform: scale(1.05, 1.07); }
  100% { transform: scale(1); }
}

.clicker-float {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.9rem;
  color: var(--gold-deep);
  text-shadow: 0 1px 0 var(--paper);
  transform: translate(-50%, -50%);
  animation: float-up 850ms ease-out forwards;
}

@keyframes float-up {
  from { opacity: 1; translate: 0 0; }
  to { opacity: 0; translate: 0 -110px; }
}

/* Anchored over the face's top edge so milestones stay in view while clicking. */
.clicker-toast {
  position: absolute;
  top: 12px; /* matches .clicker-stage padding, so center = face top edge */
  left: 50%;
  z-index: 2;
  width: max-content;
  max-width: min(90vw, 28rem);
  margin: 0;
  padding: 0.55rem 1.25rem;
  background: var(--paper);
  border: 1px solid var(--gold-soft);
  border-radius: 999px;
  box-shadow: var(--shadow);
  font-family: var(--font-display);
  font-style: italic;
  font-size: clamp(1.2rem, 4vw, 1.5rem);
  line-height: 1.25;
  color: var(--green);
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -30%);
  transition: opacity 300ms ease, transform 300ms ease;
}

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

.clicker-controls {
  display: flex;
  justify-content: center;
  gap: var(--space-4);
  margin-top: var(--space-3);
}

.btn-text {
  background: none;
  border: 0;
  padding: 0.25rem 0;
  font-size: 0.95rem;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 1px solid var(--gold-soft);
}

.btn-text:hover {
  color: var(--green);
  border-bottom-color: var(--gold);
}

/* Toggle buttons: a solid gold underline shows the "on" state. */
.btn-text[aria-pressed="true"] {
  color: var(--green);
  border-bottom: 2px solid var(--gold);
}

.btn-text[aria-pressed="false"] {
  text-decoration: line-through;
  text-decoration-thickness: 1px;
}

/* ---------- Rage (clicker page only) ---------- */
/* `--rage` (0..1) is set on <html> by clicker.js; `data-rage-level` on [data-clicker]. */

.page-clicker {
  --rage-red: #b3141c;
  --rage-deep: #4a0609;
  --rage-ember: #ff7a00;
}

/* Fixed red wash behind everything; opacity tracks rage so the cream bleeds to red. */
/* Ramped so the red is deep enough for cream text by the time it flips (TEXT_FLIP_RAGE). */
.page-clicker::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: radial-gradient(circle at 50% 40%, var(--rage-red), var(--rage-deep));
  opacity: min(1, var(--rage, 0) * 1.4);
  transition: opacity 150ms linear;
}

.page-clicker .site-header {
  background: transparent;
}

.page-clicker,
.page-clicker .wordmark,
.page-clicker .site-nav a,
.page-clicker .eyebrow,
.page-clicker .page-title,
.page-clicker .hero-sub,
.page-clicker .clicker-count,
.page-clicker .clicker-label,
.page-clicker .btn-text,
.page-clicker .site-header,
.page-clicker .site-footer {
  transition: color 150ms linear, border-color 150ms linear;
}

/* On the pink wash before the flip, muted and gold text would fall below 2:1; use ink. */
/* `is-warm` is set on <body> by clicker.js between WARM_TEXT_RAGE and TEXT_FLIP_RAGE. */
.page-clicker.is-warm {
  --muted: var(--ink);
  --gold-deep: var(--ink);
}

/* Once the page is mostly red, flip the text to cream so it stays legible. */
/* `is-red` is set on <body> by clicker.js once rage passes TEXT_FLIP_RAGE. */
.page-clicker.is-red {
  --ink: var(--cream);
  --muted: #efdcd4;
  --green: var(--cream);
  --gold-deep: #f3cf93;
  --gold: #f3cf93;
  --gold-soft: rgba(243, 207, 147, 0.5);
  --rule: rgba(250, 247, 242, 0.25);
}

.page-clicker.is-red .clicker-count {
  color: #fff;
}

/* The toast keeps its paper card, so it keeps the original ink regardless of rage. */
.page-clicker .clicker-toast {
  color: var(--green-deep);
}

.rage-bar {
  width: min(100%, 220px);
  height: 4px;
  margin: var(--space-2) auto 0;
  border-radius: 999px;
  background: rgba(43, 42, 38, 0.12);
  overflow: hidden;
}

.rage-bar span {
  display: block;
  height: 100%;
  width: calc(var(--rage, 0) * 100%);
  border-radius: inherit;
  background: linear-gradient(90deg, var(--gold-soft), var(--rage-ember) 45%, var(--rage-red));
  transition: width 120ms linear;
}

/* Face anger: red tint grows with rage via filter, plus an inner vignette. */
.page-clicker .clicker-face img {
  filter: saturate(calc(1 + var(--rage, 0) * 1.2)) contrast(calc(1 + var(--rage, 0) * 0.35))
    sepia(calc(var(--rage, 0) * 0.5)) hue-rotate(calc(var(--rage, 0) * -25deg));
  transition: filter 150ms linear;
}

.page-clicker .clicker-face::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  pointer-events: none;
  background: radial-gradient(
    circle at 50% 50%,
    rgba(179, 20, 28, 0) 42%,
    rgba(179, 20, 28, 0.55) 78%,
    rgba(74, 6, 9, 0.9) 100%
  );
  opacity: var(--rage, 0);
  transition: opacity 150ms linear;
}

[data-rage-level="hot"] .clicker-face img {
  --shake: 1;
  animation: shake 120ms linear infinite;
}

[data-rage-level="inferno"] .clicker-face img {
  --shake: 2.2;
  animation: shake 80ms linear infinite;
}

@keyframes shake {
  0% { translate: 0 0; rotate: 0deg; }
  25% { translate: calc(-1.2px * var(--shake, 1)) calc(0.8px * var(--shake, 1)); rotate: calc(-0.5deg * var(--shake, 1)); }
  50% { translate: calc(1.2px * var(--shake, 1)) calc(-0.8px * var(--shake, 1)); rotate: calc(0.5deg * var(--shake, 1)); }
  75% { translate: calc(-0.8px * var(--shake, 1)) calc(-1.2px * var(--shake, 1)); rotate: calc(-0.35deg * var(--shake, 1)); }
  100% { translate: calc(0.8px * var(--shake, 1)) calc(1.2px * var(--shake, 1)); rotate: calc(0.4deg * var(--shake, 1)); }
}

/* Eye flames. left/top/width/--flame-tilt are set per face by clicker.js. */
.flame {
  position: absolute;
  left: 50%;
  top: 40%;
  width: 18%;
  aspect-ratio: 1 / 1.6;
  z-index: 1;
  pointer-events: none;
  transform-origin: 50% 85%;
  transform: translate(-50%, -85%) rotate(var(--flame-tilt, 0deg));
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  background: radial-gradient(
    ellipse at 50% 88%,
    #fff6c2 0%,
    #ffd23a 20%,
    #ff8a00 46%,
    #e8321c 70%,
    rgba(122, 15, 15, 0) 100%
  );
  filter: blur(0.5px) drop-shadow(0 0 6px var(--rage-ember));
  mix-blend-mode: screen;
  opacity: 0;
  scale: 0.3;
  transition: opacity 180ms ease, scale 220ms cubic-bezier(0.2, 0.8, 0.3, 1.2);
  animation: flame-sway 450ms ease-in-out infinite alternate;
}

.flame::before,
.flame::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 8%;
  width: 56%;
  height: 72%;
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  background: radial-gradient(ellipse at 50% 92%, #fffbe0 0%, #ffe066 38%, #ff9a1f 72%, rgba(255, 122, 0, 0) 100%);
  transform-origin: 50% 100%;
  transform: translateX(-50%);
  animation: flicker 380ms ease-in-out infinite alternate;
}

.flame::after {
  width: 36%;
  height: 50%;
  animation-duration: 470ms;
  animation-delay: -210ms;
}

/* Flames are invisible while calm; pause their animations rather than run them at opacity 0. */
[data-rage-level="calm"] .flame,
[data-rage-level="calm"] .flame::before,
[data-rage-level="calm"] .flame::after {
  animation-play-state: paused;
}

[data-rage-level="warm"] .flame {
  opacity: 0.8;
  scale: 0.6;
}

[data-rage-level="hot"] .flame {
  opacity: 1;
  scale: 1;
}

[data-rage-level="inferno"] .flame {
  opacity: 1;
  scale: 1.18;
  box-shadow: 0 0 10px 3px rgba(255, 170, 0, 0.55);
  animation: flame-sway 350ms ease-in-out infinite alternate, sparks 520ms ease-in-out infinite alternate;
}

@keyframes flame-sway {
  0% { transform: translate(-50%, -85%) rotate(var(--flame-tilt, 0deg)) scaleY(0.94) skewX(-3deg); }
  100% { transform: translate(-50%, -85%) rotate(var(--flame-tilt, 0deg)) scaleY(1.06) skewX(3deg); }
}

@keyframes flicker {
  0% { transform: translateX(-50%) scaleY(0.9) skewX(-5deg); opacity: 0.8; }
  50% { transform: translateX(-46%) scaleY(1.1) skewX(3deg); opacity: 1; }
  100% { transform: translateX(-54%) scaleY(0.97) skewX(6deg); opacity: 0.9; }
}

@keyframes sparks {
  0% { box-shadow: 0 0 8px 2px rgba(255, 170, 0, 0.5), 0 -14px 3px -2px rgba(255, 220, 90, 0.35); }
  100% { box-shadow: 0 0 16px 6px rgba(255, 140, 0, 0.75), 0 -26px 5px -1px rgba(255, 230, 120, 0.6); }
}

/* ---------- Scroll reveal (JS only; no-op under reduced motion) ---------- */

@media (prefers-reduced-motion: no-preference) {
  html.js [data-reveal] {
    opacity: 0;
    transform: translateY(14px);
    transition: opacity 600ms ease, transform 600ms ease;
  }

  html.js [data-reveal].is-visible {
    opacity: 1;
    transform: none;
  }
}

@media print {
  html.js [data-reveal] {
    opacity: 1;
    transform: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  /* No shake or flicker; flames stay as static shapes, glow is constant. */
  .page-clicker .clicker-face img,
  .flame,
  .flame::before,
  .flame::after {
    animation: none !important;
  }
}
