/* Personalised Story Book — playful but premium children's book UI */

:root {
  --cream: #fdf8f1;
  --cream-2: #f6ecdf;
  --ink: #33283b;
  --ink-soft: #6c6076;
  --plum: #6b4a8f;
  --plum-dark: #533872;
  --coral: #ff7a6b;
  --gold: #f5b544;
  --mint: #7fd1b9;
  --paper: #fffdf9;
  --border: #e6d9c8;
  --shadow-sm: 0 2px 8px rgba(70, 50, 90, .08);
  --shadow-md: 0 12px 32px rgba(70, 50, 90, .13);
  --shadow-lg: 0 28px 70px rgba(60, 40, 80, .26);
  --radius: 18px;
  --display: "Fraunces", Georgia, serif;
  --body: "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--body);
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 12% -8%, #ffe9d6 0%, transparent 60%),
    radial-gradient(900px 480px at 92% 4%, #e6dcff 0%, transparent 62%),
    var(--cream);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

body.admin-area {
  background:
    radial-gradient(1200px 500px at 12% -8%, #d5e3f4 0%, transparent 58%),
    radial-gradient(900px 480px at 92% 4%, #c9d4e8 0%, transparent 62%),
    #e4ebf3;
}

.container { max-width: 1080px; margin: 0 auto; padding: 0 20px 80px; }

/* ---------------------------------------------------------------- hero */
.hero { padding: 64px 20px 36px; text-align: center; }
.hero-inner { max-width: 760px; margin: 0 auto; }
.eyebrow {
  display: inline-block; margin: 0 0 14px;
  background: rgba(107, 74, 143, .1); color: var(--plum);
  border-radius: 999px; padding: 7px 16px;
  font-weight: 700; font-size: 13px; letter-spacing: .04em;
}
.hero h1 {
  font-family: var(--display); font-weight: 700;
  font-size: clamp(30px, 5.2vw, 52px); line-height: 1.1;
  margin: 0 0 16px; letter-spacing: -.02em;
}
.hero-sub { margin: 0; font-size: clamp(15px, 2vw, 18px); color: var(--ink-soft); line-height: 1.65; }

/* ---------------------------------------------------------------- card */
.card {
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 26px;
  box-shadow: var(--shadow-md);
  padding: clamp(20px, 3.4vw, 38px);
  margin-bottom: 28px;
}

.step { padding: 22px 0; border-bottom: 1px dashed var(--border); }
.step:first-child { padding-top: 0; }
.step:last-of-type { border-bottom: 0; }
.step-head { display: flex; gap: 14px; align-items: flex-start; margin-bottom: 18px; }
.step-num {
  flex: none; width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(140deg, var(--plum), #8d63b8);
  color: #fff; font-weight: 700; font-size: 15px;
  display: grid; place-items: center; box-shadow: var(--shadow-sm);
}
.step h2 { font-family: var(--display); font-size: 21px; margin: 3px 0 4px; font-weight: 700; }
.step-hint { margin: 0; color: var(--ink-soft); font-size: 14px; line-height: 1.5; }

/* ------------------------------------------------------------ dropzone */
.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 34px 20px; text-align: center; cursor: pointer;
  border: 2px dashed #d9c4ad; border-radius: var(--radius);
  background: linear-gradient(180deg, #fffaf3, #fdf3e6);
  transition: border-color .18s, background .18s, transform .18s;
}
.dropzone:hover, .dropzone:focus-visible { border-color: var(--plum); background: #fbf5ff; outline: none; }
.dropzone.drag { border-color: var(--coral); background: #fff2ef; transform: scale(1.01); }
.dropzone-icon { font-size: 34px; }
.dropzone-title { font-weight: 700; font-size: 16px; }
.dropzone-sub { font-size: 13px; color: var(--ink-soft); }

.thumbs { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 16px; }
.thumb {
  position: relative; width: 92px; height: 92px; border-radius: 14px;
  overflow: hidden; border: 2px solid #fff; box-shadow: var(--shadow-sm);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-heic {
  width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(180deg, #f3e8da, #efe1d0);
  color: var(--ink-soft); font-size: 12px; font-weight: 700; text-align: center;
}
.thumb button {
  position: absolute; top: 4px; right: 4px; width: 22px; height: 22px;
  border: 0; border-radius: 50%; cursor: pointer; font-size: 14px; line-height: 1;
  background: rgba(30, 20, 40, .68); color: #fff;
}
.thumb button:hover { background: var(--coral); }

/* --------------------------------------------------------------- fields */
.field-grid { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 7px; position: relative; }
.field-label { font-weight: 700; font-size: 14px; }
.field-label em { font-style: normal; font-weight: 400; color: var(--ink-soft); }
.field input, .field select, .field textarea {
  font: inherit; color: inherit; padding: 12px 14px;
  border: 1.5px solid var(--border); border-radius: 12px; background: #fffdfa;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--plum); box-shadow: 0 0 0 4px rgba(107, 74, 143, .12);
}
.field textarea { resize: vertical; line-height: 1.6; }
.field-note { align-self: flex-end; font-size: 12px; color: var(--ink-soft); }

.credit-estimate {
  margin: 10px 0 0; font-size: 14px; font-weight: 700; color: var(--ink-soft);
  display: flex; align-items: center; gap: 6px;
}
.credit-warning {
  display: none; margin: 10px 0 0; padding: 12px 16px; border-radius: 12px;
  background: #ffecea; border: 1px solid #ffc9c1; color: #a33124;
  font-size: 13.5px; font-weight: 600; line-height: 1.5;
}
.credit-warning.show { display: block; }
.credit-warning a { color: inherit; text-decoration: underline; font-weight: 800; }

/* ----------------------------------------------------------- image mode */
/* Three picture styles; auto-fit so the row stays even if one is added or
   removed, and collapses to a single column on a phone. */
.image-mode-toggle {
  display: grid; gap: 12px; margin-top: 8px;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
}
.image-mode-option {
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 4px;
  padding: 16px 12px; border-radius: var(--radius); cursor: pointer;
  border: 1.5px solid var(--border); background: #fff; transition: all .16s;
}
.image-mode-option:hover { border-color: var(--plum); }
.image-mode-option.selected {
  border-color: var(--plum); background: linear-gradient(180deg, #faf5ff, #fff);
  box-shadow: 0 0 0 3px rgba(107, 74, 143, .14);
}
.image-mode-option input { position: absolute; opacity: 0; pointer-events: none; }
.image-mode-icon { font-size: 26px; }
.image-mode-title { font-family: var(--display); font-weight: 700; font-size: 15px; }
.image-mode-sub { font-size: 12px; color: var(--ink-soft); line-height: 1.4; }

/* ----------------------------------------------------------------- tabs */
.tabs { display: flex; gap: 8px; margin-bottom: 18px; flex-wrap: wrap; }
.tab {
  font: inherit; font-weight: 700; font-size: 14px; cursor: pointer;
  padding: 10px 18px; border-radius: 999px;
  border: 1.5px solid var(--border); background: #fff; color: var(--ink-soft);
  transition: all .16s;
}
.tab:hover { border-color: var(--plum); color: var(--plum); }
.tab.active { background: var(--plum); border-color: var(--plum); color: #fff; }

.story-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(228px, 1fr)); gap: 14px; }
.story-loading { color: var(--ink-soft); font-size: 14px; padding: 10px; }
.story-card {
  border: 1.5px solid var(--border); border-radius: var(--radius);
  background: #fff; transition: all .16s; overflow: hidden;
  display: flex; flex-direction: column;
}
.story-card:hover { border-color: var(--plum); box-shadow: var(--shadow-sm); }
.story-card.selected {
  border-color: var(--plum); background: linear-gradient(180deg, #faf5ff, #fff);
  box-shadow: 0 0 0 3px rgba(107, 74, 143, .14);
}
.story-pick {
  text-align: left; font: inherit; cursor: pointer; color: inherit;
  background: none; border: 0; padding: 16px 16px 12px;
  display: flex; flex-direction: column; gap: 6px; flex: 1;
}
.story-expand {
  font: inherit; font-size: 13px; font-weight: 700; cursor: pointer;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 16px; background: none; border: 0; border-top: 1px solid var(--border);
  color: var(--plum);
}
.story-expand:hover { background: #faf5ff; }
.story-chevron { transition: transform .16s; }
.story-card.expanded .story-chevron { transform: rotate(180deg); }
.story-summary { padding: 0 16px 16px; border-top: 1px dashed var(--border); }
.story-summary p { margin: 12px 0 12px; font-size: 13px; line-height: 1.6; color: var(--ink-soft); }
.story-view { font-size: 13px; font-weight: 800; color: var(--plum); text-decoration: none; }
.story-view:hover { text-decoration: underline; }
.story-emoji { font-size: 26px; }
.story-title { font-family: var(--display); font-weight: 700; font-size: 16px; }
.story-tagline { font-size: 13px; color: var(--ink-soft); line-height: 1.45; }

/* --------------------------------------------------------------- submit */
.error-box {
  display: none; margin: 16px 0 0; padding: 13px 16px; border-radius: 12px;
  background: #ffecea; border: 1px solid #ffc9c1; color: #a33124;
  font-size: 14px; font-weight: 600;
}
.error-box.show { display: block; }

.submit-row { margin-top: 26px; text-align: center; }
.btn-primary {
  font: inherit; font-weight: 700; font-size: 17px; cursor: pointer;
  color: #fff; border: 0; border-radius: 999px; padding: 16px 40px;
  background: linear-gradient(135deg, var(--coral), #ff9a5b);
  box-shadow: 0 10px 26px rgba(255, 122, 107, .38);
  transition: transform .16s, box-shadow .16s, filter .16s;
  display: inline-flex; align-items: center; gap: 10px;
}
.btn-primary:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 14px 32px rgba(255, 122, 107, .45); }
.btn-primary:disabled { filter: grayscale(.5) opacity(.6); cursor: not-allowed; }
.btn-sparkle { font-size: 18px; }
.submit-note { margin: 12px 0 0; font-size: 13px; color: var(--ink-soft); }

.btn-ghost {
  font: inherit; font-weight: 700; font-size: 14px; cursor: pointer;
  background: #fff; color: var(--plum);
  border: 1.5px solid var(--border); border-radius: 999px; padding: 11px 24px;
  transition: all .16s;
}
.btn-ghost:hover { border-color: var(--plum); background: #faf5ff; }

/* ------------------------------------------------------------- progress */
.progress-card { text-align: left; }
.progress-head { display: flex; align-items: center; gap: 16px; margin-bottom: 18px; }
.progress-head h2 { font-family: var(--display); font-size: 20px; margin: 0 0 4px; }
.progress-message { margin: 0; color: var(--ink-soft); font-size: 14px; }
.spinner {
  flex: none; width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid rgba(107, 74, 143, .18); border-top-color: var(--plum);
  animation: spin 850ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.progress-track { height: 10px; border-radius: 999px; background: var(--cream-2); overflow: hidden; }
.progress-fill {
  height: 100%; width: 0;
  background: linear-gradient(90deg, var(--gold), var(--coral), var(--plum));
  border-radius: 999px; transition: width .5s ease;
}
.page-dots { display: flex; flex-wrap: wrap; gap: 8px; margin: 18px 0 20px; }
.dot {
  width: 30px; height: 38px; border-radius: 5px; background: var(--cream-2);
  border: 1px solid var(--border); position: relative; overflow: hidden;
}
.dot.ready { background: linear-gradient(160deg, var(--mint), #a8e3d1); border-color: #86cdb8; }
.dot.failed { background: #ffd9d4; border-color: #ffb3a8; }
.dot.active::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.85), transparent);
  animation: sweep 1.1s infinite;
}
@keyframes sweep { from { transform: translateX(-100%); } to { transform: translateX(100%); } }

/* ---------------------------------------------------------- book preview */
.preview { margin-top: 8px; }
.preview-head { text-align: center; margin-bottom: 26px; }
.preview-head h2 { font-family: var(--display); font-size: clamp(24px, 3.6vw, 34px); margin: 0 0 6px; }
.preview-sub { margin: 0; color: var(--ink-soft); font-style: italic; }

.book-stage { display: flex; justify-content: center; padding: 10px 0 6px; }

.book {
  position: relative;
  width: min(940px, 100%);
  aspect-ratio: 2 / 1.32;
  perspective: 2400px;
}
.book-shadow {
  position: absolute; left: 4%; right: 4%; bottom: -18px; height: 34px;
  background: radial-gradient(ellipse at center, rgba(60,40,80,.32), transparent 72%);
  filter: blur(9px);
}
.sheets { position: absolute; inset: 0; transform-style: preserve-3d; }

/* Each sheet is the right-hand half of the spread and swings on the spine. */
.sheet {
  position: absolute; top: 0; left: 50%; width: 50%; height: 100%;
  transform-origin: left center;
  transform-style: preserve-3d;
  transition: transform .95s cubic-bezier(.42, .04, .24, .98);
}
.sheet.flipped { transform: rotateY(-180deg); }

.face {
  position: absolute; inset: 0;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  overflow: hidden;
  background: var(--paper);
  display: flex; flex-direction: column;
}
.face.front { border-radius: 0 12px 12px 0; box-shadow: inset 14px 0 26px -18px rgba(60,40,80,.5); }
.face.back  { transform: rotateY(180deg); border-radius: 12px 0 0 12px; box-shadow: inset -14px 0 26px -18px rgba(60,40,80,.5); }

/* page contents */
.page-inner { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.page-art { flex: 1 1 auto; min-height: 0; background: var(--cream-2); position: relative; }
.page-art img { width: 100%; height: 100%; object-fit: contain; display: block; background: var(--cream-2); }
.page-art.loading::after {
  content: "Illustrating…"; position: absolute; inset: 0;
  display: grid; place-items: center; color: var(--ink-soft); font-size: 13px;
  background: repeating-linear-gradient(45deg, #f3e8da, #f3e8da 10px, #efe1d0 10px, #efe1d0 20px);
}
/* The striped background is a plain ::after (no text — content is per-page,
   so it comes from JS into .page-art-message instead of being baked in
   here); the message itself may be the generic "unavailable" line, or, for
   a page blocked by the AI provider's own content policy, the specific
   reason so the reader isn't left guessing why one page is missing. */
.page-art.unavailable::after {
  content: ""; position: absolute; inset: 0;
  background: repeating-linear-gradient(45deg, #f1e7e5, #f1e7e5 10px, #e9dcda 10px, #e9dcda 20px);
}
.page-art-message {
  position: absolute; inset: 0; z-index: 1;
  display: flex; align-items: center; justify-content: center;
  text-align: center; padding: 18px;
  color: var(--ink-soft); font-size: 13px; line-height: 1.5;
}
.image-notice {
  margin: 12px auto 0; max-width: 620px; padding: 10px 14px;
  border-radius: 12px; background: #fff4e5; border: 1px solid #ffd9a8;
  color: #8a5a12; font-size: 13px; font-weight: 600;
}
/* The page text is composited into the illustration itself, so it is exposed
   to assistive tech here rather than rendered a second time. */
.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px;
  padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* cover + end pages */
.face.cover, .face.end {
  background: linear-gradient(150deg, var(--plum), #4a3168 60%, #3a2553);
  color: #fff; align-items: center; justify-content: center; text-align: center;
  padding: 28px; gap: 12px;
}
.cover-badge { font-size: 34px; }
.cover-title { font-family: var(--display); font-size: clamp(20px, 2.9vw, 32px); line-height: 1.15; margin: 0; }
.cover-line { width: 54px; height: 3px; border-radius: 2px; background: var(--gold); }
.cover-sub { margin: 0; font-size: 14px; opacity: .84; font-style: italic; }
.face.cover.has-photo,
.face.story-cover.has-photo { padding: 0; background: #1e1528; }
.face.cover.has-photo .page-inner,
.face.story-cover.has-photo .page-inner { padding: 0; }
.cover-art { position: relative; width: 100%; height: 100%; overflow: hidden; }
.cover-art > img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover-overlay {
  position: absolute; inset: auto 0 0; padding: 28px 22px 24px;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end;
  gap: 10px; text-align: center; color: #fff;
  background: linear-gradient(180deg, transparent, rgba(20, 12, 32, .78) 55%);
}
.cover-overlay .cover-title { text-shadow: 0 2px 10px rgba(0, 0, 0, .45); }
.face.blank { background: linear-gradient(180deg, #f7efe3, #f2e6d5); }

/* The phone spread: the same two faces, stacked and flat. Hidden until the
   phone breakpoint switches it on and hides the flip book. */
.book-mobile { display: none; flex-direction: column; gap: 14px; width: 100%; }
.face.mpage {
  position: relative; inset: auto;
  width: 100%; aspect-ratio: 1 / 1.28;
  border-radius: 14px; box-shadow: var(--shadow-sm);
  backface-visibility: visible; -webkit-backface-visibility: visible;
  transform: none;
}

.book-controls {
  display: flex; align-items: center; justify-content: center; gap: 20px;
  margin-top: 34px;
}
.nav-btn {
  width: 52px; height: 52px; border-radius: 50%; cursor: pointer;
  font-size: 26px; line-height: 1; font-weight: 700;
  border: 1.5px solid var(--border); background: #fff; color: var(--plum);
  box-shadow: var(--shadow-sm); transition: all .16s;
}
.nav-btn:hover:not(:disabled) { background: var(--plum); color: #fff; border-color: var(--plum); transform: scale(1.06); }
.nav-btn:disabled { opacity: .35; cursor: not-allowed; }
.page-indicator { font-weight: 700; font-size: 14px; color: var(--ink-soft); min-width: 130px; text-align: center; }

.preview-actions {
  margin-top: 26px; display: flex; flex-wrap: wrap; gap: 12px;
  align-items: center; justify-content: center;
}
.preview-actions .btn-primary { text-decoration: none; }
.preview-actions .hidden { display: none; }

.site-foot { text-align: center; padding: 30px 20px 44px; color: var(--ink-soft); font-size: 13px; }

.hidden { display: none !important; }

/* -------------------------------------------------------------- responsive */
@media (max-width: 860px) {
  .field-grid { grid-template-columns: 1fr 1fr; }
  .field:first-child { grid-column: 1 / -1; }
}

@media (max-width: 720px) {
  .hero { padding: 40px 18px 26px; }
  .field-grid { grid-template-columns: 1fr; }

  /* The flip book is two half-width pages side by side, which no phone has
     room for. Shrinking the sheet to full width used to hide the left-hand
     page of every spread; the spread is stacked instead, both pages visible. */
  .image-mode-toggle { grid-template-columns: 1fr; }
  .book { display: none; }
  .book-mobile { display: flex; }
  .book-controls { gap: 14px; margin-top: 26px; }
  .nav-btn { width: 46px; height: 46px; font-size: 22px; }
}

@media (prefers-reduced-motion: reduce) {
  .sheet { transition: none; }
  .dot.active::after { animation: none; }
  .spinner { animation-duration: 2s; }
}

/* ------------------------------------------------ chosen reader's story */

/* Shown on book/new when the visitor arrived from a published reader story.
   It has to read as a choice already made -- with a way out -- rather than as
   a notice, because the ready-made grid right below it looks selectable. */
.chosen-user-story {
  display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
  padding: 12px 14px; margin-bottom: 14px;
  border: 1px solid var(--mint); border-radius: 14px; background: #f3fbf7;
}
.chosen-user-story-icon { font-size: 20px; }
.chosen-user-story-text { flex: 1; min-width: 180px; font-size: 14px; }
.chosen-user-story-text a { font-weight: 700; color: var(--plum-dark); }
.custom-publish-hint { margin: 12px 0 0; font-size: 14px; color: var(--ink-soft); }
.custom-publish-hint a { color: var(--plum-dark); font-weight: 600; }

/* ------------------------------------- story pickers on the book form */

/* "Save this to my stories", ticked by default. A row rather than a bare
   checkbox because the sub-line is what makes the offer make sense. */
.save-story-toggle {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px; margin-top: 12px;
  border: 1px solid var(--border); border-radius: 12px; background: var(--cream);
  cursor: pointer; font-size: 14px;
}
.save-story-toggle input { margin-top: 3px; flex: 0 0 auto; }
.save-story-toggle .field-note { display: block; margin-top: 2px; }

.user-story-subhead {
  font-family: var(--display); font-size: 17px; margin: 22px 0 8px;
}
.my-stories-block { margin-top: 4px; }

/* Selectable cards. Buttons, not links: choosing one changes the form's state
   rather than navigating, and a keyboard reader should get button semantics. */
.user-story-picker {
  display: grid; gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}
.user-story-pick {
  display: grid; gap: 5px; justify-items: start; text-align: left;
  padding: 13px; font: inherit; color: inherit; cursor: pointer;
  border: 2px solid var(--border); border-radius: 13px; background: var(--paper);
  transition: border-color .15s ease, transform .15s ease;
}
.user-story-pick:hover { transform: translateY(-1px); }
.user-story-pick.selected { border-color: var(--plum); background: #faf6ff; }
.user-story-pick-title { font-family: var(--display); font-size: 16px; font-weight: 700; }
.user-story-pick-meta { font-size: 12px; color: var(--ink-soft); }
.user-story-pick-excerpt { font-size: 13px; color: var(--ink-soft); }
