/* PR Cards: app-only pieces. Everything else comes from PRKit (public/kit). Colors, type, spacing,
   radius, motion and shadows are kit tokens; the only new values are the card art (themes, sizes in card units). */

/* The card has no color of its own: n5 paper, n160 ink. Color only comes from the foil and pens. */
:root { --ground: var(--n5); --ink: var(--n160); --env: var(--n15); --env-dark: var(--n25); }

body { min-height: 100dvh; }
@layer base { a { color: inherit; } }

/* ---------- Top bar ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-16);
  padding: var(--space-12) var(--space-16);
  padding-top: max(var(--space-12), env(safe-area-inset-top));
  background: rgb(from var(--n10) r g b / 88%);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.brand { display: inline-flex; align-items: center; gap: var(--space-8); text-decoration: none; color: var(--n160); }
.brand .pr-mark { display: block; }
.who { color: var(--n90); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }

.banner { margin: 0 var(--space-16) var(--space-16); padding: var(--space-12) var(--space-16); border-radius: var(--radius-8); background: var(--redTint10); color: var(--red120); font: var(--title-s); letter-spacing: var(--title-s-ls); display: flex; gap: var(--space-12); align-items: center; justify-content: space-between; }
.banner[hidden] { display: none; }

/* ---------- Home ---------- */
.home { max-width: 1040px; margin: 0 auto; padding: var(--space-16) var(--space-16) var(--space-56); display: flex; flex-direction: column; gap: var(--space-40); }
.hero { position: relative; overflow: hidden; background: var(--n5); display: flex; flex-direction: column; align-items: flex-start; gap: var(--space-16); }
.hero > :not(.foil) { position: relative; }
.hero h1 { margin: 0; font: var(--title-xxl); letter-spacing: var(--title-xxl-ls); color: var(--n160); max-width: 14ch; }
.hero p { margin: 0; font: var(--body-l); letter-spacing: var(--body-l-ls); color: var(--n110); max-width: 44ch; }
@media (max-width: 560px) { .hero h1 { font: var(--title-xl); letter-spacing: var(--title-xl-ls); } }

.section { display: flex; flex-direction: column; gap: var(--space-16); }
.section h2 { margin: 0; font: var(--title-m); letter-spacing: var(--title-m-ls); color: var(--n160); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: var(--space-16); }
.empty { margin: 0; color: var(--n90); font: var(--body-m); }

.tile { overflow: hidden; color: var(--n150); }
.tile-art { position: relative; aspect-ratio: 5 / 3; background: var(--ground); padding: var(--space-16); display: flex; flex-direction: column; justify-content: flex-end; gap: var(--space-4); color: var(--ink); }
.tile-art > :not(svg) { position: relative; }
.tile-name { font: var(--title-l); letter-spacing: var(--title-l-ls); overflow-wrap: anywhere; }
.tile-meta { padding: var(--space-12) var(--space-16) var(--space-16); display: flex; flex-direction: column; gap: var(--space-6); }
.tile-date { font: var(--title-s); letter-spacing: var(--title-s-ls); display: flex; gap: var(--space-8); align-items: center; flex-wrap: wrap; }
.tile-sub { font: var(--body-s); letter-spacing: var(--body-s-ls); color: var(--n110); }

/* ---------- Dialog (kit Dialog look on a native <dialog>) ---------- */
dialog.dialog { padding: 0; border: 0; color: var(--n150); }
dialog.dialog::backdrop { background: rgb(from var(--n160) r g b / 40%); }
dialog.dialog[open] { animation: dialog-in var(--dur-240) var(--ease-out); }
@keyframes dialog-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
.dialog-head { padding: var(--panel-pad) var(--panel-pad) 0; margin: 0; font: var(--title-l); letter-spacing: var(--title-l-ls); }
.form-stack { display: flex; flex-direction: column; gap: var(--space-16); padding-top: var(--space-16); }

/* ---------- Card page ---------- */
.cardpage { display: flex; flex-direction: column; align-items: safe center; gap: var(--space-24); padding: 0 var(--space-16) var(--space-56); }
.cardbar { width: 100%; max-width: 1040px; display: flex; align-items: center; justify-content: space-between; gap: var(--space-8); flex-wrap: wrap; min-height: 32px; }
.cardbar-right { display: flex; align-items: center; gap: var(--space-16); }
.status { font: var(--body-s); letter-spacing: var(--body-s-ls); color: var(--n90); }
.status.warn { color: var(--red100); }

/* The birthday card. Everything inside is sized in card units: 1 unit = var(--s) px (card is 1000 units wide). */
.bcard {
  --s: 0.6; --tilt: -0.6deg;
  position: relative;
  width: var(--card-w, 600px);
  height: calc(var(--card-h, 1300) * var(--s) * 1px);
  border-radius: calc(40px * var(--s)); /* 24px at the usual size, and it scales with the card */
  background: var(--ground);
  box-shadow: var(--shadow-2), var(--sx, 0px) calc(30px * var(--s) + var(--sy, 0px)) calc(60px * var(--s)) -20px rgb(0 0 0 / 22%);
  will-change: transform;
  rotate: var(--tilt);
  transition: height var(--dur-320) var(--ease-out);
  overflow: hidden;
  touch-action: pan-y;
}
.bcard.is-hidden { visibility: hidden; }
.bcard-head { position: absolute; inset: 0; color: var(--ink); pointer-events: none; }
.hel { position: absolute; display: block; }
.hel-mark .pr-mark { display: block; width: 100%; height: 100%; }
.hel-photo .bcard-photo { width: 100%; height: 100%; }
.bcard-title { margin: 0; font-family: var(--font-sans); font-weight: 700; line-height: 1.05; letter-spacing: -0.03em; white-space: nowrap; }
.bcard-hint { position: absolute; left: 0; right: 0; top: calc(50% + 190px * var(--s)); text-align: center; color: var(--ink); opacity: 0.6; font-family: var(--font-sans); font-weight: 500; font-size: calc(30px * var(--s)); pointer-events: none; }

/* One person's message + signature, placed on the card */
.entry {
  position: absolute; left: 0; top: 0;
  width: calc(300px * var(--s));
  padding: calc(14px * var(--s)) calc(16px * var(--s));
  border-radius: calc(12px * var(--s));
  transform-origin: 50% 50%;
  color: var(--n150);
  animation: entry-in var(--dur-320) var(--ease-pop) both;
}
@keyframes entry-in { from { opacity: 0; scale: 0.9; } }
.entry-text { margin: 0; font-family: var(--font-sans); font-weight: 480; font-size: calc(24px * var(--s)); line-height: 1.3; white-space: pre-wrap; overflow-wrap: anywhere; text-wrap: pretty; }
.entry-sig { display: block; margin-top: calc(10px * var(--s)); color: var(--pen); }
.entry-sig svg { display: block; height: calc(78px * var(--s)); width: auto; max-width: 100%; overflow: visible; }
.entry-typed { font-family: var(--font-sans); font-style: italic; font-weight: 620; font-size: calc(40px * var(--s)); line-height: 1.1; letter-spacing: -0.02em; overflow-wrap: anywhere; }
.entry-name { margin-top: calc(4px * var(--s)); font-family: var(--font-sans); font-weight: 500; font-size: calc(20px * var(--s)); color: var(--n90); }
.entry.mine { cursor: grab; touch-action: none; }
.entry.mine:active { cursor: grabbing; }
.entry.mine.is-selected { box-shadow: inset 0 0 0 1.5px rgb(from var(--blue100) r g b / 60%); background: rgb(from var(--n0) r g b / 45%); }
@media (hover: hover) { .entry.mine:hover { box-shadow: inset 0 0 0 1.5px rgb(from var(--blue100) r g b / 35%); } }
.entry-turn {
  display: none; position: absolute; left: 50%; top: -30px; translate: -50% 0;
  width: 20px; height: 20px; border-radius: 50%; border: 0; padding: 0;
  background: var(--n0); box-shadow: var(--shadow-1), inset 0 0 0 1.5px var(--blue100);
  cursor: grab; touch-action: none;
}
.entry-turn::before { content: ""; position: absolute; left: 50%; top: 100%; width: 1.5px; height: 10px; translate: -50% 0; background: rgb(from var(--blue100) r g b / 60%); }
.entry-turn::after { content: ""; position: absolute; inset: -10px; } /* bigger tap area */
.entry.mine.is-selected .entry-turn { display: block; }
.entry-del { display: none; position: absolute; right: 0; top: -40px; }
.is-designing .entry.is-selected .entry-del { display: inline-flex; }

/* The form: a sheet over the card. Closed, only its peek bar shows at the bottom; open, the form slides up. */
.sheet-wrap { position: fixed; inset: 0; z-index: 25; pointer-events: none; }
.sheet-scrim { position: absolute; inset: 0; background: rgb(from var(--n160) r g b / 18%); opacity: 0; transition: opacity var(--dur-240) var(--ease-out); }
.sheet-wrap.is-open .sheet-scrim { opacity: 1; pointer-events: auto; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; margin-inline: auto; width: min(100%, 640px);
  background: var(--n0); border-radius: var(--radius-24) var(--radius-24) 0 0; box-shadow: var(--shadow-3, var(--shadow-2));
  pointer-events: auto; padding-bottom: env(safe-area-inset-bottom);
}
.sheet-peek { padding: var(--space-16) var(--space-24); }
.sheet-cta { width: 100%; }
.sheet-wrap.is-open .sheet-peek { display: none; }
.sheet-fold { display: grid; grid-template-rows: 0fr; transition: grid-template-rows var(--dur-320) var(--ease-out); }
.sheet-wrap.is-open .sheet-fold { grid-template-rows: 1fr; }
.sheet-inner { overflow: hidden; min-height: 0; }
.sheet-wrap.is-open .sheet-inner { overflow-y: auto; max-height: calc(100dvh - var(--space-40)); overscroll-behavior: contain; }
.sheet-grabber { display: block; width: var(--space-40); height: var(--space-4); margin: 0 auto var(--space-16); border-radius: var(--radius-2); background: var(--n35); }
.composer { padding: var(--space-8) var(--space-24) var(--space-24); }
.cardpage { padding-bottom: 120px; }
.composer-head { margin: 0 0 var(--space-16); font: var(--title-m); letter-spacing: var(--title-m-ls); color: var(--n160); }
.composer .field + .field { margin-top: var(--space-24); }
.field-row { display: flex; align-items: center; justify-content: space-between; gap: var(--space-8); }
.count { font: var(--body-s); letter-spacing: var(--body-s-ls); color: var(--n90); }
.count.over { color: var(--red120); }
.composer-actions { display: flex; justify-content: flex-end; gap: var(--space-8); margin-top: var(--space-24); }
.mine-summary { display: flex; align-items: center; justify-content: space-between; gap: var(--space-16); flex-wrap: wrap; }
.mine-summary p { margin: 0; font: var(--body-m); letter-spacing: var(--body-m-ls); color: var(--n110); }
.inline-actions { display: flex; gap: var(--space-16); align-items: center; }

.pens { display: flex; gap: var(--space-8); flex-wrap: wrap; }
.pen { width: 28px; height: 28px; border-radius: 50%; border: 0; padding: 0; cursor: pointer; background: var(--sw); transition: scale var(--dur-160) var(--ease-out); }
.pen[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--n0), 0 0 0 4px var(--sw); scale: 0.86; }
.pen:focus-visible { outline: 2px solid var(--blue100); outline-offset: 4px; }

/* Signature pad (after bencho.dev's Signature pad) */
.sigpad { position: relative; aspect-ratio: 5 / 2; border-radius: var(--radius-12); background: var(--n0); box-shadow: inset 0 0 0 var(--control-edge-width) var(--control-edge-ink), var(--shadow-0); overflow: hidden; touch-action: none; cursor: crosshair; }
.sigpad canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.sigpad-line { position: absolute; left: 6%; right: 6%; top: 72%; height: 1px; background: var(--n25); pointer-events: none; }
.sigpad-label { position: absolute; left: 0; right: 0; top: calc(72% + var(--space-8)); text-align: center; font: var(--body-s); letter-spacing: var(--body-s-ls); color: var(--n80); pointer-events: none; transition: opacity var(--dur-160) var(--ease-fade); }
.sigpad.has-ink .sigpad-label { opacity: 0.5; }
.sigpad-clear { position: absolute; top: var(--space-8); right: var(--space-8); opacity: 0; pointer-events: none; transition: opacity var(--dur-160) var(--ease-fade); }
.sigpad.has-ink .sigpad-clear { opacity: 1; pointer-events: auto; }
.sig-typed-preview { min-height: 1.4em; margin: var(--space-8) 0 0; padding: var(--space-8) var(--space-4); font-family: var(--font-sans); font-style: italic; font-weight: 620; font-size: 30px; line-height: 1.1; letter-spacing: -0.02em; color: var(--pen); overflow-wrap: anywhere; }

.signers { max-width: 600px; text-align: center; color: var(--n110); font: var(--body-m); letter-spacing: var(--body-m-ls); margin: 0; }
.signers b { color: var(--n150); font-weight: 600; }

.notice { max-width: 480px; margin: 80px auto; text-align: center; display: flex; flex-direction: column; gap: var(--space-16); align-items: center; padding: 0 var(--space-16); }
.notice h1 { margin: 0; font: var(--title-xl); letter-spacing: var(--title-xl-ls); }
.notice p { margin: 0; color: var(--n110); font: var(--body-l); }

/* ---------- Envelope intro ---------- */
.intro { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; background: var(--n10); cursor: pointer; }
/* A portrait envelope sized to the card inside (sizes set in app.js): pocket diagonals from the top corners, flap fills the V */
.env { position: relative; width: var(--ew); height: var(--eh); perspective: calc(var(--ew) * 3); }
.env-back, .env-front, .env-flap { position: absolute; left: 0; right: 0; }
.env-back { top: 0; bottom: 0; border-radius: calc(var(--ew) * 0.06); background: var(--env-dark); box-shadow: var(--shadow-2); }
.env-card { position: absolute; z-index: 1; left: calc((var(--ew) - var(--cw)) / 2); bottom: calc(var(--ew) * 0.05); width: var(--cw); height: var(--ch); transform-origin: 50% 50%; }
.env-card > .bcard { position: absolute; inset: 0; rotate: 0deg; box-shadow: var(--shadow-1); }
.env-front { z-index: 2; top: 0; bottom: 0; border-radius: calc(var(--ew) * 0.06); background: var(--env); clip-path: polygon(0 0, 50% var(--v), 100% 0, 100% 100%, 0 100%); }
.env-front::after { content: ""; position: absolute; inset: 0; border-radius: inherit; background: linear-gradient(to top, rgb(0 0 0 / 3%), transparent 40%); }
.env-flap { z-index: 3; top: 0; height: var(--v); transform-origin: 50% 0; background: var(--env-dark); clip-path: polygon(0 0, 100% 0, 50% 100%); backface-visibility: visible; }
.env-flap::after { content: ""; position: absolute; inset: 0; background: linear-gradient(to bottom, rgb(255 255 255 / 12%), transparent); }
.intro-skip { position: absolute; bottom: max(var(--space-24), env(safe-area-inset-bottom)); left: 50%; translate: -50% 0; color: var(--n90); font: var(--body-s); }

@media (prefers-reduced-motion: reduce) { .intro { display: none; } }

.cardpage.is-intro > :not(.bcard) { visibility: hidden; }

/* Held message: swells + stretches (set in JS), springs back on drop */
.entry-body { transition: transform var(--dur-640) var(--ease-spring); will-change: transform; border-radius: inherit; }
.entry-body.is-held { transition: none; }
.entry.mine.is-selected .entry-body:not(.is-held) { }
.entry.mine:has(.is-held) { filter: drop-shadow(0 8px 14px rgb(0 0 0 / 14%)); z-index: 2; }

/* Logos set to draw in later hold their first frame until released (app.js releaseMarks) */
.pr-mark.is-waiting .pr-bar { animation-play-state: paused !important; }

/* Foil (foil.js): dot grid that lights up in confetti colors */
.foil { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; border-radius: inherit; }

/* The birthday person's photo */
.bcard-photo, .tile-photo, .photo-preview { display: block; flex: none; border-radius: 50%; object-fit: cover; background: var(--n15) center / cover no-repeat; }
.bcard-photo { box-shadow: 0 0 0 calc(8px * var(--s)) var(--n0), var(--shadow-1); }
.tile-photo { width: 40px; height: 40px; box-shadow: 0 0 0 3px var(--n0), var(--shadow-0); margin-bottom: var(--space-4); }
.is-letter { display: grid; place-items: center; color: var(--n90); font-family: var(--font-sans); font-weight: 600; }
.bcard-photo.is-letter { font-size: calc(80px * var(--s)); }
.tile-photo.is-letter { font: var(--title-m); }
.photo-pick { display: flex; align-items: center; gap: var(--space-12); }
.photo-preview { width: 48px; height: 48px; box-shadow: var(--shadow-0); }
.env-to { position: absolute; left: 0; right: 0; bottom: 18%; text-align: center; font: var(--title-m); letter-spacing: var(--title-m-ls); color: var(--n130); }

/* Slide to open (from the Tutor rewards exploration, after bencho's slide-confirm) */
.intro-stack { display: flex; flex-direction: column; align-items: center; gap: var(--space-40); width: min(420px, 84vw); }
.slide {
  --knob: 64px;
  position: relative; width: 100%; height: calc(var(--knob) + var(--space-16));
  border-radius: calc(var(--knob) / 2 + var(--space-8)); background: var(--n0); box-shadow: inset 0 0 0 1px var(--n35), var(--shadow-2);
  touch-action: none; user-select: none; -webkit-user-select: none; overflow: hidden;
  animation: slide-up var(--dur-640) var(--ease-out) .5s both;
}
@keyframes slide-up { from { opacity: 0; translate: 0 12px; } }
.slide-fill { position: absolute; left: 0; top: 0; bottom: 0; width: calc(var(--knob) + var(--space-16)); border-radius: inherit; background: var(--greenTint25); transition: width 420ms var(--ease-spring); }
.slide-label { position: absolute; inset: 0; display: grid; place-items: center; padding-left: calc(var(--knob) + var(--space-16)); font: var(--title-m); letter-spacing: var(--title-m-ls); color: var(--n130); opacity: calc(1 - var(--k) * 1.6); }
.slide-knob {
  position: absolute; left: var(--space-8); top: var(--space-8); width: var(--knob); height: var(--knob); border: 0; border-radius: 50%; padding: 0;
  display: grid; place-items: center; background: var(--green100); color: var(--n0); cursor: grab; box-shadow: var(--shadow-2);
  transition: translate 420ms var(--ease-spring); touch-action: none;
}
.slide[data-drag] .slide-knob, .slide[data-drag] .slide-fill { transition: none; }
.slide[data-drag] .slide-knob { cursor: grabbing; }
.slide-knob:focus-visible { outline: 3px solid var(--blue100); outline-offset: 3px; }

/* Recipient: "Slide to open" at the bottom; the card rises as you slide */
.intro-slide { position: fixed; left: 50%; bottom: max(var(--space-32), env(safe-area-inset-bottom)); translate: -50% 0; z-index: 30; width: min(420px, calc(100vw - 32px)); display: flex; flex-direction: column; align-items: center; gap: var(--space-16); }
.intro-for { margin: 0; font: var(--title-m); letter-spacing: var(--title-m-ls); color: var(--n130); }
.bcard { touch-action: pan-x pan-y; } /* two-finger pinch zooms the card, not the page */
.bcard-stage { transform-origin: 0 0; position: relative; z-index: 1; will-change: transform; }
.cardpage { overflow-x: clip; }

/* Edit card (admins): the panel sits on the right (bottom on phones); the card stops tilting; pieces show a frame on hover */
.is-designing .bcard { --tilt: 0deg; }
.is-designing .sheet-wrap, .is-hidden-btn { display: none !important; }
.is-designing .hel { pointer-events: auto; cursor: move; touch-action: none; }
@media (hover: hover) { .is-designing .hel:hover:not(.is-on) { outline: 1.5px dashed rgb(from var(--coral100) r g b / 70%); outline-offset: 2px; } }
.is-designing .hel[hidden] { display: none; }
.card-moveable { --moveable-color: var(--coral100); }
.card-moveable .moveable-line { background: var(--coral100) !important; }
.card-moveable .moveable-control { background: var(--n0) !important; border: 1.5px solid var(--coral100) !important; width: 12px !important; height: 12px !important; margin-top: -6px !important; margin-left: -6px !important; }
.card-moveable .moveable-guideline, .card-moveable .moveable-gap { background: var(--coral100) !important; }
/* Edit card: the Studio's panel (kit-tuner-panel, 360 wide on the right, n5; a bottom sheet on phones) */
.design.kit-tuner-panel { position: fixed; z-index: 30; top: 0; right: 0; bottom: 0; width: 360px; background: var(--n5); border-left: 1px solid var(--n15); overscroll-behavior: contain; gap: var(--space-16); }
.design[hidden] { display: none; }
.is-designing .cardpage { padding-right: 376px; }
.design-top { display: flex; align-items: center; justify-content: space-between; gap: var(--space-16); }
.design .seg { align-self: flex-start; }
.seg[style*="--seg-off"] .seg-hl { opacity: 0; }
.design .studio-theme-row > .icon { flex: none; color: var(--n110); }
.design .control-label { cursor: pointer; }
/* the slider's thumb, placed the way Radix places it (inside the track at both ends) */
.ui-slider-thumb-wrap { position: absolute; top: 50%; transform: translate(-50%, -50%); }
.ui-slider:focus-visible { outline: none; }
.ui-slider:focus-visible .ui-slider-thumb { box-shadow: 0 0 0 2px var(--n0), 0 0 0 4px var(--blue100); }
.photo-row { display: flex; align-items: center; gap: var(--space-16); }
.photo-row .photo-preview { width: 48px; height: 48px; }
.drawer-layer.card-opts .drawer { z-index: 41; }
@media (max-width: 800px) {
  .design.kit-tuner-panel { top: auto; left: 0; width: auto; max-height: 52dvh; border-left: 0; border-radius: var(--radius-24) var(--radius-24) 0 0; box-shadow: var(--shadow-2); padding-bottom: calc(var(--space-24) + env(safe-area-inset-bottom)); }
  .is-designing .cardpage { padding-right: var(--space-16); padding-bottom: 54dvh; }
}
/* rich title: bold, underline, color, marker highlight (strokes drawn by rich.js behind the words) */
.bcard-title { isolation: isolate; }
.bcard-title b { font-weight: 800; }
.bcard-title u { text-decoration-thickness: 0.06em; text-underline-offset: 0.12em; }
.bcard-title .r-acc { color: var(--green100); }
mark.r-hl { background: none; color: inherit; }
.hl-sample-text { position: relative; isolation: isolate; }
.drawer:focus { outline: none; }
.r-ink { position: absolute; inset: 0; z-index: -1; pointer-events: none; }
/* the formatting box in Edit card */
.rich-b, .rich-u { min-width: 32px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.swatches { display: flex; gap: var(--space-8); flex-wrap: wrap; }
.swatch { width: 28px; height: 28px; border-radius: 50%; border: 0; padding: 0; background: var(--sw); cursor: pointer; }
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--n0), 0 0 0 4px var(--n160); }
