/* ============================================================
   Twirl Tales — shared design system
   Warm hand-made storybook aesthetic.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,600;9..144,700&family=Alegreya+Sans:wght@400;500;700&family=Gochi+Hand&display=swap');

:root {
  --paper: #FAF3E6;
  --card: #FFFBF2;
  --ink: #3B4262;
  --ink-soft: #7A7F9A;
  --coral: #E8604C;
  --coral-deep: #C94A38;
  --sun: #F2B441;
  --sky: #7FB3D6;
  --leaf: #82A65D;

  --font-head: "Fraunces", serif;
  --font-body: "Alegreya Sans", sans-serif;
  --font-hand: "Gochi Hand", cursive;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 18px;
  line-height: 1.5;
  overflow-x: hidden;
  min-height: 100vh;
}

/* Paper grain overlay */
.grain-overlay {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 9999;
  pointer-events: none;
  opacity: 0.05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ---------- Layout helpers ---------- */
.page-wrap {
  max-width: 680px;
  margin: 0 auto;
  padding: 0 20px 80px;
}

@media (max-width: 400px) {
  .page-wrap {
    padding: 0 14px 60px;
  }
}

/* ---------- Progress header ---------- */
.progress-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 500;
  background: var(--paper);
  border-bottom: 2px solid rgba(59, 66, 98, 0.12);
  padding: 10px 20px;
}

.progress-header-inner {
  max-width: 680px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.wordmark {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 20px;
  color: var(--ink);
  white-space: nowrap;
}

.wordmark svg {
  flex-shrink: 0;
}

.progress-status {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  min-width: 96px;
}

.progress-label {
  font-family: var(--font-hand);
  font-size: 18px;
  color: var(--ink-soft);
  line-height: 1;
}

.progress-track {
  width: 96px;
  height: 8px;
  border-radius: 6px;
  background: rgba(59, 66, 98, 0.12);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 6px;
  background: var(--coral);
  width: 0%;
  transition: width 0.6s ease;
}

/* push page content below the fixed header */
.header-spacer {
  height: 64px;
}

/* ---------- Starburst ---------- */
.starburst-layer {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 64px;
  pointer-events: none;
  z-index: 600;
  overflow: visible;
}

.starburst-spark {
  position: absolute;
  top: 50%;
  right: 90px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--coral);
  opacity: 1;
  animation: spark-burst 1s ease-out forwards;
}

@keyframes spark-burst {
  to {
    transform: translate(var(--dx), var(--dy)) scale(0.2);
    opacity: 0;
  }
}

/* ---------- Hero ---------- */
.hero {
  padding-top: 48px;
  text-align: left;
}

.kicker {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.2em;
  color: var(--coral-deep);
  text-transform: uppercase;
  margin: 0 0 12px;
}

.hero h1 {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 42px;
  line-height: 1.15;
  margin: 0 0 16px;
  color: var(--ink);
}

.hero .sub {
  font-size: 19px;
  color: var(--ink);
  max-width: 56ch;
  margin: 0 0 14px;
}

.margin-note {
  font-family: var(--font-hand);
  font-size: 22px;
  color: var(--ink-soft);
  transform: rotate(-1deg);
  margin: 0;
}

@media (max-width: 480px) {
  .hero h1 {
    font-size: 32px;
  }
  .hero .sub {
    font-size: 17px;
  }
}

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border: 2px solid rgba(59, 66, 98, 0.18);
  border-radius: 18px;
  padding: 28px 24px;
  margin: 28px 0;
  box-shadow: 0 6px 18px rgba(59, 66, 98, 0.1);
  transform: rotate(-0.5deg);
  transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.6s ease;
}

.card:nth-child(even) {
  transform: rotate(0.4deg);
}

.card:focus-within {
  transform: rotate(0deg);
  box-shadow: 0 8px 22px rgba(59, 66, 98, 0.16);
}

.card.reveal {
  opacity: 0;
  transform: translateY(24px) rotate(-0.5deg);
}

.card.reveal:nth-child(even) {
  transform: translateY(24px) rotate(0.4deg);
}

.card.reveal.in-view {
  opacity: 1;
  transform: translateY(0) rotate(-0.5deg);
}

.card.reveal.in-view:nth-child(even) {
  transform: translateY(0) rotate(0.4deg);
}

.section-label {
  display: inline-block;
  font-family: var(--font-hand);
  font-size: 24px;
  color: var(--coral-deep);
  margin: 0 0 2px;
  transform: rotate(-1deg);
}

.card h2 {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 26px;
  margin: 0 0 18px;
  color: var(--ink);
}

.card-hint {
  font-size: 15px;
  color: var(--ink-soft);
  margin: -10px 0 18px;
}

.fine-print {
  font-size: 13px;
  color: var(--ink-soft);
  margin-top: 10px;
  line-height: 1.4;
}

/* ---------- Form fields ---------- */
.field {
  margin-bottom: 22px;
}

.field label,
.field .field-label {
  display: block;
  font-family: var(--font-hand);
  font-size: 20px;
  color: var(--ink-soft);
  margin-bottom: 4px;
}

.field-note {
  font-family: var(--font-hand);
  font-size: 15px;
  color: var(--ink-soft);
  margin-left: 6px;
}

input[type="text"],
input[type="email"],
input[type="tel"],
input[type="number"],
textarea {
  width: 100%;
  border: none;
  border-bottom: 2px solid rgba(59, 66, 98, 0.3);
  background: transparent;
  font-family: var(--font-body);
  font-size: 18px;
  color: var(--ink);
  padding: 10px 4px;
  min-height: 44px;
  border-radius: 0;
  outline-offset: 2px;
}

textarea {
  min-height: 88px;
  resize: vertical;
  line-height: 1.5;
}

input::placeholder,
textarea::placeholder {
  color: rgba(122, 127, 154, 0.6);
}

input:focus,
textarea:focus {
  outline: 2px solid var(--sky);
  border-bottom-color: var(--sky);
}

/* ---------- Pronoun chips ---------- */
.chip-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.chip {
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 16px;
  padding: 10px 20px;
  border-radius: 999px;
  border: 2px solid rgba(59, 66, 98, 0.3);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  min-height: 44px;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.chip:hover {
  border-color: var(--ink);
}

.chip:focus-visible {
  outline: 2px solid var(--sky);
}

.chip.selected {
  background: var(--coral);
  border-color: var(--coral-deep);
  color: var(--card);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 17px;
  padding: 14px 28px;
  min-height: 48px;
  border-radius: 12px;
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.08s ease, box-shadow 0.08s ease, opacity 0.15s ease;
}

.btn-primary {
  background: var(--coral);
  color: var(--card);
  box-shadow: 0 4px 0 var(--coral-deep);
}

.btn-primary:hover {
  filter: brightness(1.03);
}

.btn-primary:active,
.btn-primary.pressed {
  transform: translateY(2px);
  box-shadow: 0 2px 0 var(--coral-deep);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  box-shadow: 0 4px 0 var(--coral-deep);
  transform: none;
}

.btn-secondary {
  background: transparent;
  color: var(--ink);
  border: 2px solid var(--ink);
  box-shadow: none;
}

.btn-secondary:hover {
  background: rgba(59, 66, 98, 0.06);
}

.btn-secondary:active {
  transform: translateY(1px);
}

.btn-small {
  font-size: 14px;
  padding: 9px 16px;
  min-height: 40px;
  border-radius: 9px;
}

.btn-block {
  width: 100%;
}

/* ---------- Dropzone / photos ---------- */
.dropzone {
  border: 2px dashed rgba(59, 66, 98, 0.35);
  border-radius: 14px;
  padding: 28px 16px;
  text-align: center;
  cursor: pointer;
  color: var(--ink-soft);
  font-size: 16px;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.dropzone:hover,
.dropzone.drag-over {
  border-color: var(--coral);
  background: rgba(232, 96, 76, 0.06);
}

.dropzone strong {
  color: var(--ink);
}

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.photo-thumb {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  overflow: hidden;
  border: 2px solid rgba(59, 66, 98, 0.18);
}

.photo-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.photo-thumb .remove-x {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(59, 66, 98, 0.75);
  color: #fff;
  border: none;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.inline-warning {
  font-size: 14px;
  color: var(--coral-deep);
  margin-top: 10px;
}

/* ---------- Cast rows ---------- */
.cast-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

@media (max-width: 480px) {
  .cast-row {
    grid-template-columns: 1fr;
    gap: 4px;
  }
}

/* ---------- Milestone note ---------- */
.milestone-note {
  font-family: var(--font-hand);
  font-size: 19px;
  color: var(--leaf);
  margin-top: 10px;
}

/* ---------- Validation ---------- */
.field-error {
  font-family: var(--font-hand);
  font-size: 17px;
  color: var(--coral-deep);
  margin-top: 4px;
  display: none;
}

.field-error.show {
  display: block;
}

.card.has-error {
  border-color: var(--coral);
}

/* ---------- Confirmation ---------- */
.confirm-section {
  display: none;
}

.confirm-section.show {
  display: block;
}

.timeline-list {
  list-style: none;
  counter-reset: tl;
  padding: 0;
  margin: 20px 0;
}

.timeline-list li {
  counter-increment: tl;
  position: relative;
  padding: 6px 0 6px 44px;
  font-size: 17px;
  color: var(--ink);
  text-align: left;
}

.timeline-list li::before {
  content: counter(tl);
  position: absolute;
  left: 0;
  top: 4px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--sun);
  color: var(--ink);
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.link-box {
  background: var(--paper);
  border: 2px dashed rgba(59, 66, 98, 0.3);
  border-radius: 12px;
  padding: 16px;
  margin: 18px 0;
}

.link-box .link-label {
  font-family: var(--font-hand);
  font-size: 18px;
  color: var(--ink-soft);
  margin-bottom: 6px;
}

.link-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.link-row input[type="text"] {
  flex: 1;
  min-width: 0;
  border: 2px solid rgba(59, 66, 98, 0.2);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  background: var(--card);
}

/* ---------- Error / status message ---------- */
.status-message {
  font-size: 15px;
  color: var(--coral-deep);
  margin-top: 12px;
  display: none;
}

.status-message.show {
  display: block;
}

/* ---------- Meet page: character cards ---------- */
.char-card {
  background: var(--card);
  border: 2px solid rgba(59, 66, 98, 0.18);
  border-radius: 18px;
  padding: 24px;
  margin: 24px 0;
  box-shadow: 0 6px 18px rgba(59, 66, 98, 0.1);
  text-align: center;
  position: relative;
}

.char-card.enter-fade {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.6s ease, transform 0.6s ease;
}

.char-card.enter-fade.in-view {
  opacity: 1;
  transform: translateY(0);
}

.char-name {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 24px;
  margin: 0 0 16px;
}

.char-sheet-wrap {
  display: inline-block;
  max-width: 100%;
  cursor: zoom-in;
  perspective: 900px;
}

.char-sheet-wrap img {
  max-width: 100%;
  max-height: 360px;
  border-radius: 14px;
  border: 2px solid rgba(59, 66, 98, 0.15);
  display: block;
  margin: 0 auto;
}

.char-sheet-wrap.twirl-in img {
  animation: twirl-entrance 1.4s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes twirl-entrance {
  0% {
    transform: rotateY(0deg) scale(0.6);
  }
  70% {
    transform: rotateY(650deg) scale(1.05);
  }
  100% {
    transform: rotateY(720deg) scale(1);
  }
}

.speech-bubble {
  position: relative;
  display: inline-block;
  background: var(--card);
  border: 2px solid var(--ink);
  border-radius: 16px;
  padding: 10px 18px;
  font-family: var(--font-hand);
  font-size: 22px;
  color: var(--ink);
  margin: 14px auto 18px;
  max-width: 90%;
}

.speech-bubble::after {
  content: "";
  position: absolute;
  bottom: -10px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
  border-top: 10px solid var(--ink);
}

.speech-bubble::before {
  content: "";
  position: absolute;
  bottom: -7px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-top: 8px solid var(--card);
  z-index: 1;
}

.char-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 16px;
}

.changes-form {
  display: none;
  margin-top: 14px;
  text-align: left;
}

.changes-form.show {
  display: block;
}

.changes-form textarea {
  margin-bottom: 12px;
}

.stamp {
  position: absolute;
  top: 16px;
  right: 16px;
  background: var(--coral);
  color: var(--card);
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 14px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 3px solid var(--coral-deep);
  transform: rotate(6deg);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.changes-pending-note {
  font-family: var(--font-hand);
  font-size: 19px;
  color: var(--sky);
  margin-top: 12px;
}

/* ---------- Lightbox ---------- */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(59, 66, 98, 0.9);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  cursor: zoom-out;
  padding: 24px;
}

.lightbox.show {
  display: flex;
}

.lightbox img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 10px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
}

/* ---------- Waiting / error states ---------- */
.wiggle-pencil {
  font-size: 48px;
  display: inline-block;
  animation: wiggle 1.8s ease-in-out infinite;
}

@keyframes wiggle {
  0%, 100% { transform: rotate(-8deg); }
  50% { transform: rotate(8deg); }
}

.center-card {
  text-align: center;
}

.hand-headline {
  font-family: var(--font-hand);
  font-size: 32px;
  color: var(--coral-deep);
  margin: 0 0 12px;
  text-align: center;
}

/* ---------- Confetti ---------- */
.confetti-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1500;
  overflow: hidden;
}

.confetti-star {
  position: absolute;
  top: -20px;
  font-size: 18px;
  animation: confetti-fall 2s ease-in forwards;
}

@keyframes confetti-fall {
  to {
    transform: translateY(110vh) rotate(360deg);
    opacity: 0.2;
  }
}

/* ---------- Loader dots ---------- */
.loading-dots::after {
  content: "";
  animation: dots 1.2s steps(4, end) infinite;
}

@keyframes dots {
  0% { content: ""; }
  25% { content: "."; }
  50% { content: ".."; }
  75% { content: "..."; }
  100% { content: ""; }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
  .card.reveal,
  .char-card.enter-fade {
    opacity: 1;
    transform: none;
  }
  .wiggle-pencil {
    animation: none;
  }
}

/* ---------- Gate page (used by _middleware inline HTML too, kept here for reference) ---------- */
.gate-wrap {
  max-width: 380px;
  margin: 12vh auto 0;
  padding: 0 20px;
  text-align: center;
}
