/* v3.css — "the journal is the page"
 *
 * Design language: Material 3 Expressive tokens (shape scale, spring motion,
 * emphasized type, tonal color) + Apple HIG chrome (translucent floating
 * top/bottom layers over an opaque content canvas, concentric radii, thumb-zone
 * primary action). Content — the journal pages — stays literal paper: opaque,
 * serif, ruled. Research notes: docs/v3-research.md.
 */

/* ------------------------------------------------------------------ Tokens -- */
:root {
  /* Tonal color (HCT-flavored ramp seeded from the brand rust #e76f51).
     Roles follow M3: primary=T40-ish, container=T90, on-container=T10. */
  --primary: #b3402a;            /* tone ~40 — buttons, key accents */
  --on-primary: #ffffff;
  --primary-container: #ffdbd2;  /* tone ~90 — color-blocked containers */
  --on-primary-container: #3e0e02;
  --secondary-container: #f7e0c1; /* warm gold container */
  --on-secondary-container: #2a1c04;
  --tertiary: #226a5f;           /* teal — success, links */
  --tertiary-container: #cce8e0;
  --on-tertiary-container: #05201b;

  --surface: #fff8f4;            /* warm near-white canvas */
  --surface-dim: #f3e9e3;
  --on-surface: #231a16;
  --on-surface-var: #53433d;
  --outline: #85736c;
  --outline-var: #d8c2ba;

  --paper: #ffffff;              /* journal pages stay paper in both schemes */
  --paper-ink: #1c1917;
  --paper-line: #c9bfb8;
  --paper-accent: #b3402a;

  --scrim: rgba(35, 26, 22, .42);

  /* Chrome translucency (Apple: controls float; keep legible, test reduced
     transparency). Opaque-ish tints + blur, not glass for glass's sake. */
  --chrome-bg: rgba(255, 248, 244, .86);
  --chrome-border: rgba(133, 115, 108, .22);

  /* M3E shape scale */
  --shape-s: 8px;
  --shape-m: 12px;
  --shape-l: 16px;
  --shape-xl: 28px;
  --shape-xxl: 32px;
  --shape-full: 999px;

  /* M3E motion: spatial springs (overshoot) for position/size; effects (no
     bounce) for color/opacity. linear() approximates damping .8 / stiffness 380. */
  --spring-spatial: linear(0, .012 1.1%, .05 2.4%, .193 5.1%, .794 13.3%, 1.045 18%, 1.085 20.5%, 1.081 24.4%, 1.003 36.2%, .987 42.7%, 1.001 62%, 1);
  --ease-effects: cubic-bezier(.2, 0, 0, 1);
  --dur-fast: 200ms;
  --dur-default: 480ms;

  --font-ui: "Google Sans Flex", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-paper: "Literata", Georgia, "Times New Roman", serif;

  --top-h: 148px;      /* approx sticky header height, phone */
  --bottom-h: 92px;    /* bottom bar clearance */
  --maxw: 1060px;
  color-scheme: light; /* print-first product: always the warm paper theme */
}


/* ------------------------------------------------------------------- Base -- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.5;
  background: var(--surface);
  color: var(--on-surface);
}
button { font: inherit; cursor: pointer; }
.hidden { display: none !important; }
:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

/* ------------------------------------------------------------- Top chrome -- */
.chrome { position: fixed; left: 0; right: 0; z-index: 20; }
.chrome-top {
  top: 0;
  background: var(--chrome-bg);
  border-bottom: 1px solid var(--chrome-border);
}
@supports (backdrop-filter: blur(1px)) {
  .chrome-top { backdrop-filter: blur(14px) saturate(1.4); }
}
/* Apple a11y: when the user asks for reduced transparency, go opaque. */
@media (prefers-reduced-transparency: reduce) {
  .chrome-top, .chrome-bottom { background: var(--surface); backdrop-filter: none; }
}
/* Increased contrast: solid chrome, stronger borders (HIG Increase Contrast). */
@media (prefers-contrast: more) {
  .chrome-top, .chrome-bottom { background: var(--surface); backdrop-filter: none; }
  .search-box, .dl-more, .search-results { border-color: var(--outline); }
  .statusline, .controls-hint, .search-trust { color: var(--on-surface); }
}

.chrome-top-inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 10px 16px 12px;
  padding-top: calc(10px + env(safe-area-inset-top));
}
.topline {
  display: flex; align-items: baseline; gap: 10px;
  margin-bottom: 8px;
}
.brand {
  font-weight: 700; font-size: 17px; letter-spacing: -.01em;
  font-variation-settings: "wght" 700;
  white-space: nowrap;
}
.brand-tag { font-size: 12.5px; color: var(--on-surface-var); white-space: nowrap; }
@media (max-width: 480px) {
  .brand { font-size: 16px; }
  .brand-tag { display: none; } /* keep the top line to one calm row */
}

/* The one input. ≥16px font so iOS never zoom-jumps. */
.search { position: relative; max-width: 640px; }
.search-label {
  display: block;
  font-size: 14px; font-weight: 600;
  margin-bottom: 6px;
}
.search-box {
  display: flex; align-items: center; gap: 8px;
  background: var(--paper);
  border: 1.5px solid var(--outline-var);
  border-radius: var(--shape-l);
  padding: 0 8px 0 14px;
  transition: border-color var(--dur-fast) var(--ease-effects),
              box-shadow var(--dur-fast) var(--ease-effects);
}
.search-box:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 22%, transparent);
}
.search-ico { width: 20px; height: 20px; flex: 0 0 auto; color: var(--on-surface-var); }
#book-q {
  flex: 1 1 auto; min-width: 0;
  border: 0; background: none;
  padding: 13px 4px;
  font: inherit; font-size: 16px;
  color: var(--on-surface);
}
#book-q::placeholder { color: var(--outline); }
#book-q:focus { outline: none; }
.search-clear {
  flex: 0 0 auto;
  width: 34px; height: 34px;
  border: 0; border-radius: var(--shape-full);
  background: var(--surface-dim);
  color: var(--on-surface-var);
  font-size: 13px;
}
.search-trust {
  margin: 7px 2px 0;
  font-size: 12.5px;
  color: var(--on-surface-var);
}

/* Search results drop under the input as plain tappable rows (≥44px). */
.search-results {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px);
  z-index: 30;
  margin: 0; padding: 6px; list-style: none;
  background: var(--paper);
  border: 1px solid var(--outline-var);
  border-radius: var(--shape-l);
  box-shadow: 0 12px 40px rgba(35, 26, 22, .18);
  max-height: 46vh; overflow-y: auto;
  animation: pop-in var(--dur-default) var(--spring-spatial);
}
@keyframes pop-in {
  from { opacity: 0; transform: translateY(-4px) scale(.98); }
  to   { opacity: 1; transform: none; }
}
.sr-item {
  display: flex; align-items: center; gap: 12px;
  min-height: 52px;
  padding: 8px 10px;
  border-radius: var(--shape-m);
  cursor: pointer;
}
.sr-item:hover, .sr-item[aria-selected="true"] { background: var(--primary-container); color: var(--on-primary-container); }
.sr-cover {
  flex: 0 0 34px; width: 34px; height: 48px;
  border-radius: 4px;
  background: var(--surface-dim) center/cover no-repeat;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.sr-text { min-width: 0; }
.sr-title { font-weight: 600; font-size: 15px; line-height: 1.25; }
.sr-sub { font-size: 12.5px; color: var(--on-surface-var); }
.sr-item:hover .sr-sub { color: inherit; opacity: .75; }
.sr-badge {
  margin-left: auto; flex: 0 0 auto;
  font-size: 11px; font-weight: 700; letter-spacing: .04em;
  padding: 3px 9px; border-radius: var(--shape-full);
  background: var(--tertiary-container); color: var(--on-tertiary-container);
}
.sr-manual { border-top: 1px solid var(--outline-var); margin-top: 4px; padding-top: 8px; }
.sr-manual .sr-title { color: var(--primary); }

/* ------------------------------------------------------------------ Canvas -- */
.canvas {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: calc(var(--top-h) + 18px) 16px calc(var(--bottom-h) + env(safe-area-inset-bottom) + 24px);
}

.statusline {
  display: flex; align-items: center; gap: 10px;
  min-height: 28px;
  margin: 0 2px 12px;
  font-size: 14px; font-weight: 600;
  color: var(--on-surface-var);
}
/* M3E loading indicator: a small shape-morphing blob (CSS border-radius morph),
   only shown for real async waits (AI questions, PDF build). */
.statusline-loader {
  width: 18px; height: 18px; flex: 0 0 auto;
  background: var(--primary);
  animation: shape-morph 2.4s var(--ease-effects) infinite,
             spin 4.8s linear infinite;
}
@keyframes shape-morph {
  0%, 100% { border-radius: 50%; }
  25%      { border-radius: 38% 62% 55% 45% / 55% 40% 60% 45%; }
  50%      { border-radius: var(--shape-s); }
  75%      { border-radius: 60% 40% 45% 55% / 45% 60% 40% 55%; }
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ----------------------------------------------------------- Journal pages -- */
.journal {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
}
@media (min-width: 640px)  { .journal { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 980px)  { .journal { grid-template-columns: repeat(3, 1fr); } }

.pagecard {
  position: relative;
  background: var(--paper);
  color: var(--paper-ink);
  border-radius: var(--shape-m);
  box-shadow: 0 1px 2px rgba(35,26,22,.08), 0 6px 18px rgba(35,26,22,.10);
  aspect-ratio: 17 / 22;              /* half-letter 5.5×8.5in — faithful shape */
  padding: 7.2% 8%;
  font-family: var(--font-paper);
  font-size: clamp(11px, 2.9vw, 15px);
  line-height: 1.45;
  overflow: hidden;
  animation: page-in var(--dur-default) var(--spring-spatial) backwards;
}
@media (min-width: 640px) { .pagecard { font-size: clamp(10px, 1.75vw, 14px); } }
@media (min-width: 980px) { .pagecard { font-size: 13px; } }
@keyframes page-in {
  from { opacity: 0; transform: translateY(14px) scale(.97); }
  to   { opacity: 1; transform: none; }
}
.pagecard-tag {
  position: absolute; top: 8px; right: 10px;
  font-family: var(--font-ui);
  font-size: 10px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--outline);
}

/* Cover page */
.pc-cover { display: flex; flex-direction: column; text-align: center; }
.pc-cover-rule {
  border: 2px solid var(--paper-ink);
  border-radius: 6px;
  flex: 1;
  display: flex; flex-direction: column;
  padding: 8% 7%;
}
.pc-cover-title {
  font-size: 1.65em; font-weight: 600; letter-spacing: .01em;
  margin: 4% 0 1%;
}
.pc-cover-sub { font-style: italic; font-size: .92em; margin-bottom: 9%; }
.pc-fields { text-align: left; margin-top: auto; }
.pc-field {
  display: flex; gap: 6px; align-items: baseline;
  margin-bottom: 7%;
  font-size: .92em;
}
.pc-field-label { font-weight: 600; white-space: nowrap; }
.pc-field-value {
  flex: 1;
  border-bottom: 1.5px solid var(--paper-line);
  min-height: 1.3em;
  padding: 0 2px 1px;
}
/* Editable cover fields: the journal is the form. */
.pc-field-value[contenteditable] { cursor: text; }
.pc-field-value[contenteditable]:empty::before {
  content: attr(data-ph);
  color: var(--paper-line);
  font-style: italic;
}
.pc-field-value[contenteditable]:focus {
  outline: none;
  background: color-mix(in srgb, var(--paper-accent) 8%, transparent);
  border-bottom-color: var(--paper-accent);
}
.pc-cover-foot { font-style: italic; font-size: .85em; margin-top: 7%; }

/* How-to-answer page */
.pc-guide-head { font-weight: 600; font-size: 1.2em; margin-bottom: 2%; }
.pc-guide-note { font-style: italic; font-size: .88em; margin-bottom: 5%; }
.pc-guide-steps { margin: 0 0 5%; padding-left: 1.2em; font-size: .88em; }
.pc-guide-steps li { margin-bottom: 2%; }
.pc-guide-steps .lbl { font-weight: 600; }
.pc-example-q { font-weight: 600; font-size: .92em; margin-bottom: 2%; }
.pc-example-a { font-size: .86em; }
.pc-example-a .tag { font-weight: 600; font-style: italic; }

/* Chapter page */
.pc-ch-head {
  font-family: var(--font-ui);
  font-weight: 700; font-size: .9em; letter-spacing: .05em; text-transform: uppercase;
  color: var(--paper-accent);
  margin-bottom: 3%;
}
.pc-ch-q {
  font-weight: 600; font-size: 1.06em; line-height: 1.35;
  min-height: 2.6em;
  margin-bottom: 4%;
  border-radius: 6px;
}
/* Tap-to-edit affordance on questions */
button.pc-ch-q, .pc-ch-q[contenteditable] { display: block; width: 100%; text-align: left; }
button.pc-ch-q {
  background: none; border: 0; padding: 0;
  font: inherit; font-weight: 600; color: inherit;
}
button.pc-ch-q:hover { background: color-mix(in srgb, var(--paper-accent) 7%, transparent); }
.pc-ch-q[contenteditable]:focus {
  outline: 2px dashed var(--paper-accent); outline-offset: 3px;
}
/* Chapter question being written by AI: shimmering placeholder lines + a live
   "writing…" tag, so the page visibly shows work in progress (never frozen). */
.pc-ch-q--writing {
  min-height: 2.6em;
  display: flex; flex-direction: column; gap: .5em;
  margin-bottom: 4%;
}
.writing-line {
  height: .8em; border-radius: 4px;
  background: linear-gradient(90deg,
    color-mix(in srgb, var(--paper-line) 70%, transparent) 0%,
    color-mix(in srgb, var(--paper-line) 20%, transparent) 45%,
    color-mix(in srgb, var(--paper-line) 70%, transparent) 90%);
  background-size: 220% 100%;
  animation: writing-shimmer 1.25s var(--ease-effects) infinite;
}
.writing-line.short { width: 62%; }
.writing-tag {
  display: inline-flex; align-items: center; gap: 6px;
  margin-top: .35em;
  font-family: var(--font-ui);
  font-size: .74em; font-weight: 600;
  color: var(--paper-accent);
}
.writing-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--paper-accent);
  animation: writing-pulse 1s var(--ease-effects) infinite;
}
@keyframes writing-shimmer { from { background-position: 220% 0; } to { background-position: -220% 0; } }
@keyframes writing-pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .3; transform: scale(.65); } }
/* Brief accent flash when a question lands in place. */
.pc-ch-q--filled { animation: q-flash var(--dur-default) var(--ease-effects); }
@keyframes q-flash {
  from { background: color-mix(in srgb, var(--paper-accent) 20%, transparent); border-radius: 6px; }
  to { background: transparent; }
}
.pc-lines { display: flex; flex-direction: column; gap: 1.35em; margin-top: 1.6em; }
.pc-line { border-bottom: 1px solid var(--paper-line); height: 0; }
.pc-vocab { margin-top: 6%; font-size: .88em; }
.pc-vocab-label { font-weight: 600; }
.pc-vocab .pc-lines { margin-top: 1.1em; }

/* "+N more pages" stack card */
.pc-more {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px;
  background:
    linear-gradient(var(--paper), var(--paper)) padding-box,
    repeating-linear-gradient(-3deg, var(--paper) 0 8px, var(--surface-dim) 8px 9px) border-box;
  border: 0;
  font-family: var(--font-ui);
  color: var(--on-surface-var);
  text-align: center;
  box-shadow: 0 1px 2px rgba(35,26,22,.08), 3px 3px 0 -1px var(--paper), 4px 4px 0 0 var(--outline-var), 7px 7px 0 -1px var(--paper), 8px 8px 0 0 var(--outline-var);
}
.pc-more strong { font-size: 1.5em; color: var(--on-surface); }
.pc-more span { font-size: .95em; max-width: 20ch; }

/* --------------------------------------------------------- Inline controls -- */
.journal-controls {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 22px;
  margin: 20px 2px 0;
}
.chapters-ctl { display: flex; align-items: center; gap: 12px; }
.chapters-ctl-label { font-weight: 600; font-size: 15px; }
.seg {
  display: inline-flex; align-items: center;
  background: var(--surface-dim);
  border-radius: var(--shape-full);
  padding: 4px;
}
.seg-btn {
  width: 44px; height: 44px;
  border: 0; border-radius: var(--shape-full);
  background: var(--paper);
  color: var(--on-surface);
  font-size: 20px; font-weight: 600;
  box-shadow: 0 1px 2px rgba(35,26,22,.12);
  transition: border-radius var(--dur-default) var(--spring-spatial),
              transform var(--dur-default) var(--spring-spatial);
}
.seg-btn:active { border-radius: var(--shape-m); transform: scale(.92); } /* M3E press morph */
.seg-val {
  min-width: 52px; text-align: center;
  font-size: 17px; font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.controls-hint { margin: 0; font-size: 13.5px; color: var(--on-surface-var); }

/* Regenerate: a quiet pill next to the chapter stepper. Hidden unless AI is on
   and a book-specific journal is loaded. */
.regen-btn {
  display: inline-flex; align-items: center; gap: 7px;
  height: 44px; padding: 0 16px;
  border: 1px solid var(--outline, rgba(35,26,22,.18));
  border-radius: var(--shape-full);
  background: var(--paper);
  color: var(--on-surface);
  font-size: 14.5px; font-weight: 600;
  cursor: pointer;
  transition: border-radius var(--dur-default) var(--spring-spatial),
              transform var(--dur-default) var(--spring-spatial),
              background var(--dur-default) var(--spring-spatial);
}
.regen-btn:hover { background: var(--surface-dim); }
.regen-btn:active { border-radius: var(--shape-m); transform: scale(.96); }
.regen-btn svg { flex: 0 0 auto; }

/* Confirm-chapters sheet: the stepper sits centered above the generate button. */
.confirm-count {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  margin: 18px 0 22px;
}
.confirm-count-label { font-size: 15px; font-weight: 600; color: var(--on-surface-var); }

/* ---------------------------------------------------------------- Support -- */
.support { margin-top: 44px; }
.support-row {
  display: grid; gap: 14px;
  grid-template-columns: 1fr;
}
@media (min-width: 640px) { .support-row { grid-template-columns: repeat(3, 1fr); } }
.support-item {
  background: var(--secondary-container);
  color: var(--on-secondary-container);
  border-radius: var(--shape-xl);
  padding: 18px 20px;
}
.support-item h2 { margin: 0 0 6px; font-size: 17px; font-weight: 700; }
.support-item p { margin: 0; font-size: 14.5px; line-height: 1.5; }

.faq {
  margin-top: 18px;
  background: var(--surface-dim);
  border-radius: var(--shape-l);
  padding: 4px 18px;
}
.faq summary {
  cursor: pointer;
  font-weight: 700; font-size: 15px;
  padding: 12px 0;
  min-height: 44px; display: flex; align-items: center;
}
.faq dl { margin: 0 0 14px; }
.faq dt { font-weight: 700; font-size: 14.5px; margin-top: 12px; }
.faq dd { margin: 3px 0 0; font-size: 14.5px; color: var(--on-surface-var); }
.support-links {
  margin: 20px 2px 0;
  font-size: 13.5px; color: var(--on-surface-var);
}
.support-links a { color: var(--tertiary); }

/* ------------------------------------------------------------ Bottom chrome -- */
.chrome-bottom {
  bottom: 0;
  background: var(--chrome-bg);
  border-top: 1px solid var(--chrome-border);
}
@supports (backdrop-filter: blur(1px)) {
  .chrome-bottom { backdrop-filter: blur(14px) saturate(1.4); }
}
.chrome-bottom-inner {
  max-width: 640px;
  margin: 0 auto;
  display: flex; gap: 8px;
  padding: 10px 16px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
}
/* The one dominant action (M3E: single large filled button per view). */
.dl-main {
  flex: 1 1 auto;
  min-height: 56px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 1px;
  border: 0;
  border-radius: var(--shape-full);
  background: var(--primary);
  color: var(--on-primary);
  box-shadow: 0 4px 16px color-mix(in srgb, var(--primary) 42%, transparent);
  transition: border-radius var(--dur-default) var(--spring-spatial),
              transform var(--dur-default) var(--spring-spatial);
}
.dl-main:active { border-radius: var(--shape-l); transform: scale(.98); } /* press morph */
.dl-main[disabled] { opacity: .6; cursor: progress; }
.dl-main-label { font-size: 16.5px; font-weight: 700; letter-spacing: .01em; }
/* The current book/chapters line lives above the button row, not inside the
   button — one line, ellipsized so long titles never grow the bar. */
.bar-caption {
  max-width: 640px;
  margin: 0 auto;
  padding: 8px 16px 0;
  font-size: 12.5px; font-weight: 600;
  color: var(--on-surface-var);
  text-align: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.dl-more {
  flex: 0 0 auto;
  width: 56px; min-height: 56px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1.5px solid var(--outline-var);
  border-radius: var(--shape-full);
  background: var(--paper);
  color: var(--on-surface);
  padding: 0;
  transition: transform var(--dur-default) var(--spring-spatial),
              border-radius var(--dur-default) var(--spring-spatial);
}
.dl-more svg { display: block; }

/* ------------------------------------------------------- Download-done sheet -- */
.sheet-scrim {
  position: fixed; inset: 0; z-index: 40;
  background: var(--scrim);
  animation: fade-in var(--dur-fast) var(--ease-effects);
}
@keyframes fade-in { from { opacity: 0; } }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41;
  max-width: 560px; margin: 0 auto;
  background: var(--surface);
  border-radius: var(--shape-xxl) var(--shape-xxl) 0 0;
  padding: 10px 22px calc(18px + env(safe-area-inset-bottom));
  box-shadow: 0 -12px 48px rgba(0,0,0,.28);
  animation: sheet-up var(--dur-default) var(--spring-spatial);
  max-height: 86vh; overflow-y: auto;
}
@keyframes sheet-up { from { transform: translateY(60%); opacity: .4; } to { transform: none; opacity: 1; } }
.sheet-handle {
  width: 40px; height: 4px;
  border-radius: var(--shape-full);
  background: var(--outline-var);
  margin: 4px auto 14px;
}
/* Visible close in the corner — sheets must never rely on the scrim alone. */
.sheet-x {
  position: absolute; top: 10px; right: 12px;
  width: 44px; height: 44px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 0; border-radius: var(--shape-full);
  background: var(--surface-dim);
  color: var(--on-surface-var);
  font-size: 16px; font-weight: 700;
  padding: 0;
}
.sheet-x:hover { color: var(--on-surface); }
.done-check {
  width: 52px; height: 52px;
  margin: 2px auto 10px;
  border-radius: var(--shape-full);
  background: var(--tertiary);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; font-weight: 800;
  animation: pop-in var(--dur-default) var(--spring-spatial);
}
.sheet h2 {
  margin: 0 0 12px; text-align: center;
  font-size: 22px; font-weight: 800; letter-spacing: -.01em;
}
.done-steps {
  margin: 0 auto; padding-left: 22px; max-width: 380px;
  font-size: 15px; line-height: 1.7; color: var(--on-surface-var);
}
.done-steps strong, .done-steps em { color: var(--on-surface); }
.done-formats { margin-top: 16px; text-align: center; }
.done-formats-label {
  margin: 0 0 2px;
  font-size: 13.5px; font-weight: 700;
  color: var(--on-surface-var);
}
.done-email {
  margin: 18px auto 0; max-width: 400px;
  background: var(--surface-dim);
  border-radius: var(--shape-l);
  padding: 14px 16px;
}
.done-email label { display: block; font-size: 14px; font-weight: 700; margin-bottom: 8px; }
.done-email-row { display: flex; gap: 8px; }
.done-email-row input {
  flex: 1 1 auto; min-width: 0;
  border: 1.5px solid var(--outline-var); border-radius: var(--shape-m);
  background: var(--paper); color: var(--on-surface);
  padding: 10px 12px; font: inherit; font-size: 16px;
}
.done-email-row button {
  border: 0; border-radius: var(--shape-full);
  background: var(--primary-container); color: var(--on-primary-container);
  font-weight: 700; font-size: 14px;
  padding: 0 16px; min-height: 44px;
}
.done-email-note { margin: 8px 0 0; font-size: 13.5px; font-weight: 600; color: var(--tertiary); }
.sheet-close {
  display: block;
  margin: 16px auto 0;
  min-height: 44px;
  border: 0; border-radius: var(--shape-full);
  background: none;
  color: var(--tertiary);
  font-weight: 700; font-size: 15px;
  padding: 0 18px;
}

/* Desktop: header is roomier; journal grid breathes. */
@media (min-width: 720px) {
  :root { --top-h: 158px; }
  .chrome-top-inner { padding-top: 14px; }
  .topline { margin-bottom: 10px; }
}

/* ------------------------------------------------------------- View toggle -- */
.viewbar {
  display: inline-flex;
  background: var(--surface-dim);
  border-radius: var(--shape-full);
  padding: 4px;
  margin: 0 0 14px;
}
.viewbar-btn {
  min-height: 44px;
  padding: 0 20px;
  border: 0; border-radius: var(--shape-full);
  background: none;
  color: var(--on-surface-var);
  font-weight: 700; font-size: 14.5px;
  transition: border-radius var(--dur-default) var(--spring-spatial);
}
.viewbar-btn.is-active {
  background: var(--primary);
  color: var(--on-primary);
  box-shadow: 0 2px 8px color-mix(in srgb, var(--primary) 35%, transparent);
}

/* ----------------------------------------------------------- Print preview -- */
/* The exact imposed booklet, rendered by the same server code as the PDF. */
.print-preview {
  border: 1px solid var(--outline-var);
  border-radius: var(--shape-l);
  overflow: hidden;
  background: #fff;
  box-shadow: var(--shadow, 0 1px 2px rgba(35,26,22,.08)), 0 6px 18px rgba(35,26,22,.10);
}
#print-frame {
  display: block; width: 100%; border: 0;
  height: min(72vh, 760px);
  background: #fff;
}

/* ------------------------------------------------------------------- Toast -- */
/* Unmissable, floating above the bottom action bar; one at a time. */
.toast {
  position: fixed;
  left: 50%; transform: translateX(-50%);
  bottom: calc(var(--bottom-h) + env(safe-area-inset-bottom) + 12px);
  z-index: 60;
  display: flex; align-items: center; gap: 12px;
  max-width: min(92vw, 480px);
  min-width: min(86vw, 340px);
  background: var(--on-surface);
  color: var(--surface);
  border-radius: var(--shape-l);
  padding: 14px 18px;
  box-shadow: 0 12px 40px rgba(0,0,0,.35);
  animation: toast-in var(--dur-default) var(--spring-spatial);
}
@keyframes toast-in { from { opacity: 0; transform: translateX(-50%) translateY(16px) scale(.96); } to { opacity: 1; transform: translateX(-50%); } }
.toast-loader {
  width: 20px; height: 20px; flex: 0 0 auto;
  background: var(--primary);
  animation: shape-morph 2.4s var(--ease-effects) infinite, spin 4.8s linear infinite;
}
.toast-check {
  width: 22px; height: 22px; flex: 0 0 auto;
  border-radius: 50%;
  background: var(--tertiary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 900;
}
.toast-body { min-width: 0; flex: 1 1 auto; display: flex; flex-direction: column; gap: 7px; }
.toast-text { font-size: 14.5px; font-weight: 600; line-height: 1.35; }
.toast-bar {
  display: block; height: 5px;
  border-radius: var(--shape-full);
  background: color-mix(in srgb, var(--surface) 22%, transparent);
  overflow: hidden;
}
.toast-bar-fill {
  display: block; height: 100%; width: 0%;
  border-radius: var(--shape-full);
  background: var(--primary);
  transition: width .35s var(--ease-effects);
}
.toast-action {
  flex: 0 0 auto;
  border: 0; border-radius: var(--shape-full);
  background: color-mix(in srgb, var(--surface) 16%, transparent);
  color: var(--surface);
  font-weight: 700; font-size: 13.5px;
  padding: 8px 14px; min-height: 38px;
}
.toast.toast--error { background: #5c1a10; color: #ffe1d9; }

.done-sub {
  margin: 0 auto 12px; max-width: 400px; text-align: center;
  font-size: 14.5px; color: var(--on-surface-var); line-height: 1.5;
}

/* ------------------------------------------------------------- Share sheet -- */
.share-stage {
  position: relative;
  margin: 14px auto 0;
  max-width: 250px;
  border-radius: var(--shape-l);
  overflow: hidden;
  background: var(--surface-dim);
  box-shadow: 0 6px 22px rgba(35,26,22,.18);
}
#share-img {
  display: block; width: 100%;
  aspect-ratio: 2 / 3;               /* vertical default; square via class */
  object-fit: cover;
  transition: opacity var(--dur-fast) var(--ease-effects);
}
.share-stage.is-square #share-img { aspect-ratio: 1 / 1; }
.share-stage.is-loading #share-img { opacity: .35; }
.share-stage-loading {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
}
.share-stage-loading::after {
  content: "";
  width: 26px; height: 26px;
  background: var(--primary);
  animation: shape-morph 2.4s var(--ease-effects) infinite, spin 4.8s linear infinite;
}
.share-chips {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 8px;
  margin: 16px 0 0;
}
.share-chip {
  border: 1.5px solid var(--outline-var);
  background: var(--paper);
  color: var(--on-surface);
  font-weight: 600; font-size: 13.5px;
  border-radius: var(--shape-full);
  padding: 0 16px; min-height: 40px;
  transition: border-radius var(--dur-default) var(--spring-spatial);
}
.share-chip.is-active {
  background: var(--primary-container);
  color: var(--on-primary-container);
  border-color: transparent;
}
.btn-share-primary {
  display: block;
  width: min(100%, 340px);
  margin: 18px auto 0;
  min-height: 52px;
  border: 0; border-radius: var(--shape-full);
  background: var(--primary); color: var(--on-primary);
  font-weight: 700; font-size: 16px;
  box-shadow: 0 4px 16px color-mix(in srgb, var(--primary) 40%, transparent);
  transition: border-radius var(--dur-default) var(--spring-spatial), transform var(--dur-default) var(--spring-spatial);
}
.btn-share-primary:active { border-radius: var(--shape-l); transform: scale(.98); }
.btn-share-primary[disabled] { opacity: .6; cursor: progress; }
.share-secondary {
  display: flex; justify-content: center; gap: 24px;
  margin-top: 6px;
}
.v2link-like {
  border: 0; background: none;
  color: var(--tertiary);
  font-weight: 700; font-size: 14px;
  text-decoration: underline; text-underline-offset: 3px;
  min-height: 44px; padding: 0 6px;
}
