/* ============================================================
   DECOR.CSS — Enrichment Pass 2
   Card decoration (frame · corners · crest · pattern) +
   richer ambient animation + directional scroll-reveals.
   Depends on tokens.css + base.css + home.css + enrich.css.
   Adds, never breaks. All looping motion stops under reduced-motion.
   ============================================================ */

/* ============================================================
   CARD DECORATION LAYER  (filled by decor.js into [data-decor])
   ============================================================ */
.card-decor {
  position: absolute; inset: 0; z-index: 1;
  border-radius: inherit; overflow: hidden; pointer-events: none;
  color: var(--accent, var(--rose));   /* currentColor = card accent */
}
/* keep real card content above the decoration */
.mk-card > :not(.card-decor),
.card-inside > :not(.card-decor),
.card-cover > :not(.card-decor),
.occ-preview > :not(.card-decor) { position: relative; z-index: 2; }

/* SVG ink/gold helpers (theme-aware via CSS, not presentation attrs) */
.card-decor .cd-ink    { stroke: currentColor; fill: none; }
.card-decor .cd-gold   { stroke: var(--gold);  fill: none; }
.card-decor .cd-gold-f { fill: var(--gold);    stroke: none; }
.card-decor .cd-ink-f  { fill: currentColor;   stroke: none; }

/* on a dark/coloured face (the hero cover) switch ink to soft white */
.card-cover .card-decor .cd-ink   { stroke: rgba(255,255,255,.7); }
.card-cover .card-decor .cd-ink-f { fill: rgba(255,255,255,.7); }
.card-cover .card-decor { color: rgba(255,255,255,.7); }

/* ---- background pattern (subtle, drifting) ---- */
.cd-pattern {
  position: absolute; inset: 0; background-repeat: repeat;
  background-size: 26px 26px; opacity: .06;
}
.in-view .cd-pattern { animation: cdDrift 34s linear infinite; }
@keyframes cdDrift { from { background-position: 0 0; } to { background-position: 0 260px; } }

/* ---- ornamental double frame ---- */
.cd-frame {
  position: absolute; inset: clamp(7px, 3.2%, 14px); border-radius: calc(var(--r-lg) - 8px);
  border: 1px solid color-mix(in srgb, var(--gold) 60%, transparent);
  box-shadow: inset 0 0 0 3px color-mix(in srgb, var(--surface) 0%, transparent),
              inset 0 0 0 4px color-mix(in srgb, var(--accent, var(--rose)) 22%, transparent);
}
.card-cover .cd-frame {
  border-color: color-mix(in srgb, var(--gold) 75%, #fff);
  box-shadow: inset 0 0 0 4px rgba(255,255,255,.16);
}

/* ---- diagonal gold glint sweeping across the card ---- */
.cd-glint {
  position: absolute; top: -30%; bottom: -30%; left: -40%; width: 28%;
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--gold-soft) 70%, #fff) 50%, transparent);
  opacity: .0; transform: rotate(12deg) translateX(0);
  mix-blend-mode: screen;
}
.in-view .cd-glint { animation: cdGlint 7.5s var(--ease-soft) infinite; }
@keyframes cdGlint {
  0%   { opacity: 0; transform: rotate(12deg) translateX(-30%); }
  8%   { opacity: .55; }
  22%  { opacity: 0; transform: rotate(12deg) translateX(380%); }
  100% { opacity: 0; transform: rotate(12deg) translateX(380%); }
}

/* ---- corner flourishes ---- */
.cd-corner { position: absolute; width: clamp(30px, 17%, 56px); height: auto; }
.cd-corner--tl { top: clamp(6px, 3%, 13px); left: clamp(6px, 3%, 13px); }
.cd-corner--tr { top: clamp(6px, 3%, 13px); right: clamp(6px, 3%, 13px); transform: scaleX(-1); }
.cd-corner--bl { bottom: clamp(6px, 3%, 13px); left: clamp(6px, 3%, 13px); transform: scaleY(-1); }
.cd-corner--br { bottom: clamp(6px, 3%, 13px); right: clamp(6px, 3%, 13px); transform: scale(-1, -1); }

/* ---- illustrated crest ---- */
.cd-crest {
  position: absolute; left: 50%; top: clamp(8px, 5%, 20px); transform: translateX(-50%);
  width: clamp(64px, 36%, 116px); height: auto; opacity: .92;
  filter: drop-shadow(0 2px 4px rgba(43,38,34,.08));
}

/* ---- draw-on (stroke lines) + fade-in (filled dots/stars) ---- */
.cd-draw { stroke-dasharray: 100; stroke-dashoffset: 100; }
.cd-dot, .cd-twinkle, .cd-crest .cd-gold-f, .cd-crest .cd-ink-f { opacity: 0; }
.card-decor.draw .cd-draw { animation: cdDrawOn 1.15s var(--ease-expo) forwards; }
.card-decor.draw .cd-dot,
.card-decor.draw .cd-twinkle,
.card-decor.draw .cd-crest .cd-gold-f,
.card-decor.draw .cd-crest .cd-ink-f { animation: cdFadeIn .5s var(--ease-soft) .85s forwards; }
@keyframes cdDrawOn { to { stroke-dashoffset: 0; } }
@keyframes cdFadeIn { from { opacity: 0; transform: scale(.5); } to { opacity: 1; transform: none; } }

/* continuous twinkle once revealed + section in view */
.in-view .card-decor.draw .cd-crest .cd-twinkle {
  animation: cdFadeIn .5s var(--ease-soft) .85s forwards, cdTwinkle 3.4s var(--ease-soft) 1.4s infinite;
  transform-box: fill-box; transform-origin: center;
}
.in-view .card-decor.draw .cd-crest .cd-twinkle:nth-of-type(2) { animation-delay: .85s, 2.1s; }
.in-view .card-decor.draw .cd-crest .cd-twinkle:nth-of-type(3) { animation-delay: .85s, 2.8s; }
@keyframes cdTwinkle { 0%,100% { opacity: .35; transform: scale(.8); } 50% { opacity: 1; transform: scale(1.15); } }

/* ============================================================
   MAKER CARD — body layout + long-text typography + extras
   ============================================================ */
.mk-card {
  /* landscape postcard — wider than tall, more room for a line of text.
     aspect-ratio drives the height so auto-fit typography has a target. */
  min-height: 0; height: auto; aspect-ratio: 3 / 2;
}
.mk-body {
  position: relative; z-index: 2;
  flex: 1 1 auto; min-height: 0; overflow: hidden;
  display: flex; flex-direction: column; justify-content: flex-end; gap: var(--sp-3);
}
.mk-msg {
  /* font-size is driven by JS auto-fit (fitText); margin keeps it gracefully spaced */
  margin-block: auto 0; overflow-x: hidden;
}
/* last-resort scroll if even the smallest font can't fit a very long text */
.mk-msg.scroll {
  overflow-y: auto; max-height: 100%; padding-right: 3px;
  scrollbar-width: thin; scrollbar-color: color-mix(in srgb, var(--accent) 40%, transparent) transparent;
}
.mk-msg.scroll::-webkit-scrollbar { width: 5px; }
.mk-msg.scroll::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--accent) 40%, transparent); border-radius: 3px; }

/* ink-writing reveal (played when a curated text is inserted) */
.mk-msg.writing { animation: inkWrite .7s var(--ease-soft); }
@keyframes inkWrite {
  0%   { clip-path: inset(0 100% 0 0); opacity: .35; filter: blur(.6px); }
  100% { clip-path: inset(0 0 0 0);    opacity: 1;   filter: blur(0); }
}

/* mood/occasion colour-wash overlay */
.mk-wash {
  position: absolute; inset: 0; z-index: 5; pointer-events: none; border-radius: inherit;
  opacity: 0; background: radial-gradient(120% 120% at 30% 18%, color-mix(in srgb, var(--accent) 55%, transparent), transparent 65%);
}
.mk-wash.washing { animation: moodWash .7s var(--ease-soft); }
@keyframes moodWash { 0% { opacity: 0; transform: scale(.6); } 35% { opacity: .8; } 100% { opacity: 0; transform: scale(1.25); } }

/* ============================================================
   MAKER CONTROLS — length toggle · shuffle · long-text picks
   ============================================================ */
.mk-text-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--sp-2); }
.mk-len-toggle {
  display: inline-flex; padding: 3px; gap: 2px; border-radius: var(--r-pill);
  background: color-mix(in srgb, var(--paper-2) 80%, transparent); border: 1px solid var(--line);
}
.mk-len-toggle button {
  padding: .32em .9em; border-radius: var(--r-pill); font-size: var(--fs-xs); font-weight: 700;
  letter-spacing: .02em; color: var(--ink-soft); transition: color var(--dur-1), background var(--dur-1), box-shadow var(--dur-1);
}
.mk-len-toggle button[aria-pressed="true"] {
  color: var(--ink); background: var(--surface); box-shadow: var(--sh-1);
}
.mk-shuffle {
  display: inline-flex; align-items: center; gap: .4em;
  padding: .38em .9em; border-radius: var(--r-pill); font-size: var(--fs-xs); font-weight: 700;
  color: var(--rose-deep); background: color-mix(in srgb, var(--rose-soft) 60%, transparent);
  border: 1px solid color-mix(in srgb, var(--rose) 35%, var(--line));
  transition: transform var(--dur-1) var(--ease-back), background var(--dur-1), box-shadow var(--dur-2);
}
.mk-shuffle:hover { background: var(--rose-soft); transform: translateY(-1px); box-shadow: var(--sh-1); }
.mk-shuffle .shuffle-ico { display: inline-block; }
.mk-shuffle:hover .shuffle-ico { animation: shuffleSpin .6s var(--ease-back); }
@keyframes shuffleSpin { from { transform: rotate(0); } to { transform: rotate(180deg); } }

/* short picks reuse .pick; long picks become multi-line cards */
.pick-row.is-long { flex-direction: column; align-items: stretch; }
.pick.pick-long {
  font-family: var(--font-hand); font-size: 1.05rem; line-height: 1.28; text-align: left;
  color: var(--ink); border-radius: var(--r-sm); white-space: normal;
  padding: .55em .8em;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  border: 1px dashed color-mix(in srgb, var(--rose) 40%, var(--line));
  background: color-mix(in srgb, var(--surface) 70%, transparent);
}
.pick.pick-long:hover { transform: translateY(-1px); border-color: var(--rose); background: var(--surface); }
.pick-empty { font-size: var(--fs-xs); color: var(--ink-faint); }

/* longer notes on the pensieri wall (referenced from studio.js) */
.pensiero-note.is-long {
  max-width: 34ch; text-align: left;
  font-size: clamp(1.02rem, 1.8vw, 1.22rem); line-height: 1.32; font-weight: 500;
}

/* ============================================================
   HERO CARD — extra life (glint already via decor; long-text fit)
   ============================================================ */
.card-msg { overflow-x: hidden; }   /* font-size driven by JS auto-fit (fitText) */
.card-msg.scroll { overflow-y: auto; max-height: 100%; scrollbar-width: thin; }

/* floating petals drifting through the hero */
.hero-petals { position: absolute; inset: 0; z-index: 1; pointer-events: none; overflow: hidden; }
.petal {
  position: absolute; top: -6%; left: var(--px, 50%);
  width: var(--pz, 14px); height: var(--pz, 14px);
  color: var(--pc, var(--rose)); opacity: 0; will-change: transform, opacity;
}
.petal svg { width: 100%; height: 100%; display: block; }
.in-view .petal { animation: petalFall var(--pt, 16s) linear var(--pd, 0s) infinite; }
@keyframes petalFall {
  0%   { opacity: 0; transform: translate3d(0, 0, 0) rotate(0deg); }
  8%   { opacity: var(--po, .7); }
  92%  { opacity: var(--po, .7); }
  100% { opacity: 0; transform: translate3d(var(--pdx, 30px), 112vh, 0) rotate(540deg); }
}

/* ============================================================
   OCCASION GALLERY — decorated mini-preview card
   ============================================================ */
.occ-preview {
  position: relative; width: 100%; aspect-ratio: 5 / 3; border-radius: var(--r);
  background-color: color-mix(in srgb, var(--accent) 12%, var(--surface));
  box-shadow: var(--sh-1), inset 0 0 0 1px color-mix(in srgb, var(--accent) 18%, transparent);
  overflow: hidden; display: grid; place-items: center;
  --accent-ink: color-mix(in srgb, var(--accent) 60%, var(--ink));
  transition: box-shadow var(--dur-2) var(--ease-soft);
}
.occ-preview::before { /* tinted top band */
  content: ""; position: absolute; left: 0; right: 0; top: 0; height: 42%; z-index: 1;
  background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 26%, transparent), transparent);
}
.occ-preview-emoji {
  position: relative; z-index: 3; font-size: 2rem; line-height: 1; margin-top: 10px;
  filter: drop-shadow(0 3px 6px rgba(43,38,34,.14));
}
/* scale the decoration down for the compact preview */
.occ-preview .cd-crest { width: clamp(44px, 30%, 70px); top: 5px; opacity: .8; }
.occ-preview .cd-corner { width: clamp(20px, 20%, 32px); }
.occ-preview .cd-frame { inset: 6px; border-radius: 12px; }
.occ-preview .cd-pattern { opacity: .05; }
.in-view .occ-preview-emoji { animation: occFloat 6s var(--ease-soft) infinite; }
@keyframes occFloat { 0%,100% { transform: translateY(0) rotate(-3deg); } 50% { transform: translateY(-5px) rotate(3deg); } }
.occ-link:hover .occ-preview, .occ-link:focus-visible .occ-preview {
  box-shadow: var(--sh-2), inset 0 0 0 1px color-mix(in srgb, var(--accent) 40%, transparent);
}
/* redraw the preview decoration on hover for a decorative reveal */
.occ-link:hover .card-decor .cd-draw, .occ-link:focus-visible .card-decor .cd-draw {
  animation: cdDrawOn 1s var(--ease-expo) forwards;
}

/* ============================================================
   RICHER SCROLL-REVEALS — directional variants (piggyback on .in)
   ============================================================ */
.reveal[data-reveal="left"]  { opacity: 0; }
.reveal[data-reveal="right"] { opacity: 0; }
.reveal[data-reveal="zoom"]  { opacity: 0; }
.reveal[data-reveal="left"].in  { animation: revLeft  var(--dur-3) var(--ease-expo) forwards; }
.reveal[data-reveal="right"].in { animation: revRight var(--dur-3) var(--ease-expo) forwards; }
.reveal[data-reveal="zoom"].in  { animation: revZoom  var(--dur-3) var(--ease-back) forwards; }
.reveal[data-reveal][style*="--d"].in { animation-delay: calc(var(--d, 0) * 90ms); }
@keyframes revLeft  { from { opacity: 0; transform: translateX(-30px); } to { opacity: 1; transform: none; } }
@keyframes revRight { from { opacity: 0; transform: translateX(30px); }  to { opacity: 1; transform: none; } }
@keyframes revZoom  { from { opacity: 0; transform: scale(.9); }          to { opacity: 1; transform: none; } }

/* ============================================================
   SECTION-LEVEL AMBIENT TINT — breathing maker + CTA backgrounds
   ============================================================ */
.maker { position: relative; }
.maker::after {
  content: ""; position: absolute; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(45% 50% at 18% 22%, color-mix(in srgb, var(--rose) 14%, transparent), transparent 70%),
    radial-gradient(42% 48% at 82% 78%, color-mix(in srgb, var(--gold) 14%, transparent), transparent 72%);
}
.maker.in-view::after { animation: heroBreath 16s var(--ease-soft) infinite alternate; }
.maker > * { position: relative; z-index: 1; }

.cta-card { position: relative; }
.cta-card::after {
  content: ""; position: absolute; inset: -20%; z-index: 0; pointer-events: none; border-radius: 50%;
  background: radial-gradient(closest-side, color-mix(in srgb, var(--gold) 16%, transparent), transparent 70%);
}
.cta-band.in-view .cta-card::after { animation: ctaPulse 9s var(--ease-soft) infinite alternate; }
@keyframes ctaPulse { 0% { transform: scale(.9); opacity: .6; } 100% { transform: scale(1.1); opacity: 1; } }
.cta-card > * { position: relative; z-index: 1; }
.cta-motif { display: inline-block; }
.cta-band.in-view .cta-motif { animation: float 5s var(--ease-soft) infinite; }

/* ============================================================
   REDUCED MOTION — full calm fallback for everything new
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  .cd-draw { stroke-dasharray: none; stroke-dashoffset: 0; }
  .cd-dot, .cd-twinkle, .cd-crest .cd-gold-f, .cd-crest .cd-ink-f { opacity: 1; }
  .cd-pattern, .cd-glint, .cd-crest .cd-twinkle, .petal,
  .occ-preview-emoji, .maker::after, .cta-card::after, .cta-motif,
  .mk-shuffle .shuffle-ico {
    animation: none !important;
  }
  .card-decor.draw .cd-draw,
  .card-decor.draw .cd-dot,
  .card-decor.draw .cd-twinkle,
  .card-decor.draw .cd-crest .cd-gold-f,
  .card-decor.draw .cd-crest .cd-ink-f { animation: none !important; opacity: 1; }
  .mk-msg.writing, .mk-wash.washing { animation: none !important; }
  .mk-wash.washing { opacity: 0; }
  .petal { display: none; }
  .reveal[data-reveal].in { animation: fade var(--dur-3) ease forwards; }
}

/* ============================================================
   RESPONSIVE TUNING
   ============================================================ */
@media (max-width: 560px) {
  /* keep landscape on phones, but a touch taller (7:5) so a long verse breathes */
  .mk-card { height: auto; aspect-ratio: 7 / 5; }
  .cd-crest { width: clamp(60px, 40%, 96px); }
}
