/*
 * The buy page (books/<book>/buy/): the buyer's choices, the live preview of the pages they make, Continue to
 * payment. Same tokens and components as site.css (.field, .choice-card, .order-alert, .button); loaded on the buy
 * pages only.
 */
@font-face {
  font-family: 'Caveat';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/caveat-latin-400-normal.woff2') format('woff2');
}

/* The handwriting a typed note can be printed in (all SIL OFL) */
@font-face {
  font-family: 'Dancing Script';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/dancing-script-latin-400-normal.woff2') format('woff2');
}

@font-face {
  font-family: 'Great Vibes';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/great-vibes-latin-400-normal.woff2') format('woff2');
}

/* ---------- Head: the book, small, beside the heading ---------- */
.buy-head {
  padding-bottom: 0;
}

.buy-book {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 16px;
  align-items: center;
}

.buy-book img {
  width: 72px;
  height: auto;
  border-radius: 4px;
  box-shadow: var(--shadow-soft);
}

.buy-book h1 {
  font-size: 30px;
}

.buy-book-line {
  margin-top: 4px;
  color: var(--color-ink-muted);
  font-size: var(--text-ui);
}

.buy-price {
  color: var(--color-ink);
  font-weight: 600;
  white-space: nowrap;
}

@media (min-width: 768px) {
  .buy-book {
    grid-template-columns: 96px minmax(0, 1fr);
    gap: 22px;
  }
  .buy-book img {
    width: 96px;
  }
  .buy-book h1 {
    font-size: var(--text-h1);
  }
  .buy-book-line {
    font-size: 18px;
  }
}

.buy-section {
  padding-top: 24px;
}

/* ---------- Layout: phone stacks form, preview, pay; desktop puts the preview beside the form ---------- */
.buy {
  display: grid;
  gap: 32px;
  grid-template-areas: 'form' 'preview' 'pay';
}

.buy-form {
  grid-area: form;
  display: grid;
  gap: 28px;
}

.buy-preview {
  grid-area: preview;
}

.buy-pay {
  grid-area: pay;
  display: grid;
  gap: 12px;
}

@media (min-width: 900px) {
  .buy {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas: 'form preview' 'pay preview';
    grid-template-rows: auto 1fr;
    column-gap: 56px;
    align-items: start;
  }
  .buy-preview {
    position: sticky;
    top: 24px;
  }
}

/* ---------- Steps ---------- */
.buy-step {
  display: grid;
  gap: 14px;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.buy-step legend {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0;
  margin-bottom: 14px;
  font-family: var(--font-display);
  font-size: var(--text-title);
  line-height: 1.25;
}

.buy-step legend .optional {
  font-family: var(--font-sans);
  font-size: var(--text-ui);
}

.step-no {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--color-brand);
  color: var(--color-brand-ink);
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 600;
}

.buy:not(.is-gift) .gift-only {
  display: none;
}

.note-mode {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.note-mode label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px 16px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--color-line-strong);
  background: var(--color-bg-elev);
  font-size: var(--text-ui);
  cursor: pointer;
}

.note-mode label:has(input:checked) {
  border: 2px solid var(--color-brand);
  padding: 7px 15px;
  background: var(--color-surface);
  font-weight: 600;
}

.note-mode label:has(input:focus-visible) {
  outline: 3px solid var(--color-accent-text);
  outline-offset: 2px;
}

.note-mode input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--color-brand);
}

/* Handwriting for a typed note: each choice shown in its own hand */
.font-pick {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 4px 0 0;
  padding: 0;
  border: 0;
  min-width: 0;
}

.font-pick legend {
  width: 100%;
  margin-bottom: 8px;
  padding: 0;
  font-size: var(--text-ui);
  font-weight: 600;
}

.font-pick label {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 6px 16px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--color-line-strong);
  background: var(--color-bg-elev);
  cursor: pointer;
}

.font-pick label:has(input:checked) {
  border: 2px solid var(--color-brand);
  padding: 5px 15px;
  background: var(--color-surface);
}

.font-pick label:has(input:focus-visible) {
  outline: 3px solid var(--color-accent-text);
  outline-offset: 2px;
}

.font-pick input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--color-brand);
}

.font-sample {
  color: #24304a;
  line-height: 1;
}

.font-caveat {
  font-family: 'Caveat', var(--font-lu);
  font-size: 24px;
}

.font-dancing {
  font-family: 'Dancing Script', var(--font-lu);
  font-size: 22px;
}

.font-vibes {
  font-family: 'Great Vibes', var(--font-lu);
  font-size: 26px;
}

.field input[type='file'] {
  padding: 10px 12px;
  font-size: var(--text-ui);
}

.field input[type='file']::file-selector-button {
  margin-right: 12px;
  padding: 8px 14px;
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--color-brand);
  color: var(--color-brand-ink);
  font: 500 var(--text-ui) var(--font-sans);
  cursor: pointer;
}

.field.has-error textarea {
  border: 2px solid var(--color-accent-text);
}

.buy-alert[hidden] {
  display: none;
}

/* ---------- Pay ---------- */
.buy-total {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding-top: 16px;
  border-top: 1px solid var(--color-line-strong);
  font-weight: 600;
}

.buy-total strong {
  font-size: var(--text-title);
  font-variant-numeric: tabular-nums;
}

.buy-pay .button-block {
  width: 100%;
  max-width: none;
}

/* ---------- The preview: two A5 pages, drawn to scale (type in container units) ---------- */
.book-pages {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 12px;
}

.book-page {
  margin: 0;
  min-width: 0;
}

.book-page figcaption {
  margin-top: 8px;
  font-size: var(--text-caption);
  color: var(--color-ink-muted);
}

.page {
  container-type: inline-size;
  position: relative;
  aspect-ratio: 148 / 210;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  /* % of the page width: cqw here would read the viewport, since a container can’t size its own padding */
  padding: 9% 9% 7%;
  background: #fffdf8;
  border: 1px solid var(--color-line);
  border-radius: 4px;
  box-shadow: var(--shadow-soft);
  color: #1f2a26;
}

.page p {
  margin: 0;
}

/* Inside the cover: the photo on top, the note under it */
.inside-cover .page {
  justify-content: center;
  gap: 4%;
}

.inside-cover.has-photo .page {
  justify-content: flex-start;
}

.page-photo {
  /* The whole photo, never cropped: at its own shape across the page, shrinking (and scaled to fit) when the note
     needs the room, down to a third of the page (buy.js sets that floor) */
  flex: 0 1 auto;
  width: 100%;
  height: auto;
  min-height: 0;
  object-fit: contain;
}

.page-note-photo {
  flex: 0 1 auto;
  width: 100%;
  min-height: 0;
  max-height: 50%;
  object-fit: contain;
  mix-blend-mode: multiply;
}

.inside-cover:not(.has-photo) .page-note-photo {
  max-height: 80%;
}

.page-note {
  flex: none;
  font-family: 'Caveat', var(--font-lu);
  /* --note-scale: set by buy.js so a long note still fits the page */
  font-size: calc(7.4cqw * var(--note-scale, 1));
  line-height: 1.2;
  color: #24304a;
  white-space: pre-line;
  overflow-wrap: anywhere;
}

.inside-cover[data-font='dancing'] .page-note {
  font-family: 'Dancing Script', var(--font-lu);
  font-size: calc(6.6cqw * var(--note-scale, 1));
}

.inside-cover[data-font='vibes'] .page-note {
  font-family: 'Great Vibes', var(--font-lu);
  font-size: calc(8cqw * var(--note-scale, 1));
  line-height: 1.15;
}

.page-empty {
  margin: auto 0;
  padding: 6cqw;
  border: 1px dashed var(--color-line-strong);
  border-radius: 4px;
  text-align: center;
  font-size: 6cqw;
  line-height: 1.4;
  color: var(--color-ink-muted);
}

/* The title page, like the book's */
.page-portrait {
  width: 13cqw;
  height: 13cqw;
  border-radius: 50%;
  object-fit: cover;
}

.page-title {
  margin-top: 5cqw !important;
  font-family: var(--font-display);
  font-size: 11cqw;
  line-height: 1.05;
}

.page-sub {
  margin-top: 3cqw !important;
  font-size: 3.6cqw;
  line-height: 1.35;
  color: #5c6761;
}

.page-chef {
  margin-top: 3cqw !important;
  font-size: 3cqw;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #5c6761;
}

.page-hand {
  margin-top: 7cqw;
  /* As the book signs it: the whole note tilted up to the right about its top-left corner, 2-4 degrees by copy
     (AIM_dev store/dedication/layout.ts SIGNING_TILT_DEG); the preview shows the middle of that range */
  transform: rotate(-3deg);
  transform-origin: top left;
  font-family: 'Caveat', var(--font-lu);
  font-size: 6.6cqw;
  line-height: 1.22;
  color: #24304a;
}

.page-hand > p {
  transform-origin: left center;
}

.page-hand p + p {
  margin-top: 2.4cqw;
}

.hand-word {
  display: inline-block;
  transform-origin: left bottom;
}

.hand-greeting[hidden] {
  display: none;
}

.hand-signature {
  display: block;
  width: 17cqw;
  height: auto;
  margin-top: 2cqw;
}

.hand-date {
  margin-top: 1cqw !important;
  font-size: 5cqw;
}

.preview-note {
  margin-top: 14px;
  font-size: var(--text-ui);
  color: var(--color-ink-muted);
}

/* site.css gives imgs, fields and alerts a display; the hidden attribute must still win on these pages */
[hidden] {
  display: none !important;
}

/* The names and "Tell Lu about", shown only when Lu writes the dedication */
.lu-writes {
  display: grid;
  gap: 14px;
}

.send-email {
  display: grid;
  gap: 14px;
}

/* ---------- Thank you (books/<book>/thanks/) ---------- */
.thanks {
  display: grid;
  gap: 24px;
  max-width: 640px;
}

.thanks-lead {
  font-size: 20px;
  line-height: 1.5;
}

.thanks-ready {
  display: grid;
  gap: 24px;
  justify-items: start;
}

.thanks-line {
  margin: 0;
  padding: 20px 24px;
  border-radius: 8px;
  background: #fffdf8;
  border: 1px solid var(--color-line);
}

.thanks-line figcaption {
  font-size: var(--text-ui);
  color: var(--color-ink-muted);
}

.thanks-line blockquote {
  margin: 8px 0 0;
  font-family: 'Caveat', var(--font-lu);
  font-size: 26px;
  line-height: 1.3;
  color: #24304a;
}

.thanks-line blockquote p {
  margin: 0;
}

.thanks-more {
  color: var(--color-ink-muted);
  font-size: var(--text-ui);
}
