:root {
  --paper: #fbf7ef;
  --paper-deep: #f3ecdf;
  --card: #fffdf8;
  --ink: #2a2f3a;
  --ink-soft: #5d6370;
  --line: #e4dccb;
  --sky: #2f7fb3;
  --sky-wash: #dcebf3;
  --coral: #d9603f;
  --sage: #5d8a5a;
  --sail: #b98a4e;
  --serif: "Fraunces", Georgia, serif;
  --sans: "Figtree", system-ui, sans-serif;
  --hand: "Patrick Hand", "Comic Sans MS", cursive;
  --story: "Mali", "Patrick Hand", cursive;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

img { display: block; max-width: 100%; }

a { color: inherit; }

.wrap {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 32px;
}

/* Header */

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 72px;
}

.wordmark {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 28px;
  letter-spacing: -0.01em;
  text-decoration: none;
}

.top nav a {
  text-decoration: none;
  color: var(--ink-soft);
  font-weight: 500;
  padding: 8px 0;
}

.top nav a:hover { color: var(--ink); }

/* Editor */

.editor-head {
  padding: 40px 0 36px;
  max-width: 720px;
}

h1 {
  text-wrap: balance;
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(34px, 4.4vw, 56px);
  line-height: 1.08;
  letter-spacing: -0.02em;
  margin: 0;
}

.editor {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 64px;
  align-items: start;
  padding-bottom: 72px;
}

.photo {
  position: relative;
  display: block;
  cursor: pointer;
}

.photo img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 20px;
  background: var(--paper-deep);
  box-shadow: 0 1px 2px rgba(60, 45, 20, 0.08), 0 18px 40px -18px rgba(60, 45, 20, 0.28);
}

.photo input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.photo-change {
  position: absolute;
  left: 16px;
  bottom: 16px;
  background: rgba(255, 253, 248, 0.94);
  border-radius: 999px;
  padding: 9px 18px;
  font-weight: 600;
  font-size: 15px;
  box-shadow: 0 2px 10px rgba(40, 30, 10, 0.16);
}

.photo:hover .photo-change,
.photo input:focus-visible ~ .photo-change {
  background: #fff;
  outline: 2px solid var(--ink);
}

.fields {
  display: grid;
  gap: 28px;
  border: 0;
  margin: 0;
  padding: 0;
  min-width: 0;
}

.field { display: grid; gap: 10px; border: 0; margin: 0; padding: 0; min-width: 0; }

.field > label,
.field > legend {
  font-weight: 600;
  font-size: 17px;
  padding: 0;
}

.field > legend { margin-bottom: 10px; }

textarea,
select {
  font: inherit;
  color: inherit;
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  width: 100%;
}

textarea {
  font-family: var(--serif);
  font-size: 22px;
  line-height: 1.35;
  resize: none;
  height: 96px;
}

select {
  width: 140px;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%232a2f3a' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 16px center;
  padding-right: 40px;
}

textarea:focus,
select:focus { outline: none; border-color: var(--ink); }

.styles {
  display: grid;
  grid-template-columns: repeat(2, 168px);
  gap: 16px;
}

.style-card { cursor: pointer; display: block; }

.style-card input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.style-card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 14px;
  outline: 1.5px solid var(--line);
  outline-offset: 0;
}

.style-card span {
  display: block;
  margin-top: 10px;
  font-weight: 500;
  color: var(--ink-soft);
}

.style-card input:checked + img {
  outline: 3px solid var(--ink);
  outline-offset: 3px;
}

.style-card input:checked ~ span { color: var(--ink); font-weight: 600; }

.style-card input:focus-visible + img { outline: 3px solid var(--sky); outline-offset: 3px; }

/* Action row: progress space is always reserved, so nothing jumps */

.action {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 28px;
  min-height: 60px;
  margin-top: 4px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font: inherit;
  font-weight: 600;
  font-size: 18px;
  color: #fff;
  background: #d9622b;
  border: 0;
  border-radius: 999px;
  height: 60px;
  min-width: 232px;
  padding: 0 34px;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.15s ease, background 0.15s ease;
}

.btn:hover { background: #c4541f; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:focus-visible { outline: 3px solid var(--sky); outline-offset: 3px; }
.btn[disabled] { background: var(--ink-soft); cursor: default; transform: none; }

.progress {
  visibility: hidden;
  opacity: 0;
  transition: opacity 0.3s ease;
  min-width: 0;
}

.is-making .progress { visibility: visible; opacity: 1; }

.progress-step {
  font-family: var(--hand);
  font-size: 22px;
  line-height: 1.2;
  height: 27px;
  white-space: nowrap;
}

.progress-bar {
  margin-top: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--paper-deep);
  overflow: hidden;
}

.progress-bar i {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--sky), var(--coral));
}

.is-making .progress-bar i {
  width: 100%;
  transition: width 3.2s cubic-bezier(0.3, 0.1, 0.3, 1);
}

/* My books */

.shelf {
  border-top: 1.5px solid var(--line);
  padding: 44px 0 80px;
}

h2 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 28px;
  letter-spacing: -0.01em;
  margin: 0 0 24px;
}

.book-card {
  display: inline-grid;
  grid-template-columns: 240px auto;
  gap: 24px;
  align-items: center;
  text-decoration: none;
}

.book-card img {
  width: 240px;
  aspect-ratio: 3 / 2;
  object-fit: cover;
  border-radius: 8px;
  box-shadow: 0 1px 2px rgba(60, 45, 20, 0.1), 0 14px 28px -14px rgba(60, 45, 20, 0.35);
  transition: transform 0.2s ease;
}

.book-card:hover img { transform: translateY(-3px) rotate(-0.6deg); }

.book-card b {
  display: block;
  font-family: var(--serif);
  font-weight: 500;
  font-size: 24px;
  line-height: 1.2;
}

.book-card span { color: var(--ink-soft); }

/* Book */

.book { padding-bottom: 40px; }

.cover {
  text-align: center;
  padding: 56px 24px 64px;
}

.cover img {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  object-fit: cover;
  margin: 0 auto 28px;
  box-shadow: 0 0 0 5px var(--card), 0 10px 24px -8px rgba(60, 45, 20, 0.4);
}

.cover h1 { font-size: clamp(40px, 6vw, 84px); }

.starring {
  font-family: var(--hand);
  font-size: clamp(26px, 2.6vw, 38px);
  margin: 14px 0 0;
}

.name { color: var(--coral); }

.pages {
  display: grid;
  gap: 48px;
  justify-items: center;
  padding: 0 24px;
}

.page {
  width: min(100%, calc((100vh - 48px) * 1.4906));
  margin: 0;
  position: relative;
  container-type: inline-size;
}

.spread {
  position: relative;
  aspect-ratio: 1264 / 848;
  border-radius: 6px;
  overflow: hidden;
  background: var(--paper-deep);
  box-shadow: 0 1px 2px rgba(60, 45, 20, 0.1), 0 30px 60px -30px rgba(60, 45, 20, 0.4);
}

.spread > img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.page-text {
  position: absolute;
  left: calc(var(--l) * 1%);
  top: calc(var(--t) * 1%);
  width: calc(var(--w) * 1%);
  font-family: var(--hand);
  font-size: calc(var(--fs, 1.95) * 1cqw);
  line-height: 1.26;
  color: #262b38;
  text-shadow:
    0 0 0.12em var(--paper), 0 0 0.25em var(--paper), 0 0 0.45em var(--paper),
    0 0 0.7em var(--paper), 0 0 1em var(--paper), 0 0 1.4em var(--paper);
}

.page-text p { margin: 0 0 0.62em; }
.page-text p:last-child { margin-bottom: 0; }

.key {
  font-style: normal;
  font-size: 1.5em;
  line-height: 0;
  letter-spacing: 0.01em;
}

.key.k0 { color: var(--coral); }
.key.k1 { color: var(--sky); }
.key.k2 { color: var(--sage); }

.page-text .ask {
  margin-top: 1em;
  font-size: 1.1em;
  color: #3d5878;
}

.sail-name {
  position: absolute;
  left: calc(var(--l) * 1%);
  top: calc(var(--t) * 1%);
  transform: translate(-50%, -50%) rotate(calc(var(--r) * 1deg));
  font-family: var(--hand);
  font-size: calc(var(--s) * 1cqw);
  line-height: 1;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--sail);
  mix-blend-mode: multiply;
  opacity: 0.85;
  white-space: nowrap;
  pointer-events: none;
}

.ending {
  text-align: center;
  padding: 88px 24px 96px;
}

.ending p {
  font-family: var(--hand);
  font-size: 48px;
  line-height: 1;
  margin: 0 0 32px;
}

/* Phone */

@media (max-width: 900px) {
  .editor { grid-template-columns: 300px 1fr; gap: 36px; }
}

@media (max-width: 720px) {
  .wrap { padding: 0 20px; }
  .top { height: 60px; }
  .wordmark { font-size: 24px; }
  .editor-head { padding: 20px 0 24px; }
  .editor { grid-template-columns: 1fr; gap: 28px; padding-bottom: 48px; }
  .photo { max-width: 220px; }
  .photo-change { left: 10px; bottom: 10px; padding: 7px 14px; font-size: 14px; }
  .fields { gap: 24px; }
  textarea { font-size: 20px; }
  .styles { grid-template-columns: repeat(2, minmax(0, 168px)); }
  .action { grid-template-columns: 1fr; gap: 14px; }
  .btn { width: 100%; }
  .action .progress { height: 43px; }
  .shelf { padding: 32px 0 56px; }
  .book-card { grid-template-columns: 132px 1fr; gap: 16px; }
  .book-card img { width: 132px; }
  .book-card b { font-size: 20px; }
}

@media (max-width: 639px) {
  .cover { padding: 28px 20px 36px; }
  .cover-title h1 { font-size: 7cqw; }
  .pages { padding: 0; gap: 36px; }
  .page { width: 100%; }
  .spread { border-radius: 0; box-shadow: none; }
  .page-text {
    position: static;
    width: auto;
    padding: 20px 22px 0;
    font-size: 21px;
    line-height: 1.32;
    text-shadow: none;
  }
  .key { font-size: 1.3em; }
  .ending { padding: 56px 20px 72px; }
  .ending .btn { width: 100%; max-width: 340px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .btn, .book-card img { transition: none; }
}

/* Cover: the cover painting with the title laid over its sky */
.cover { padding: 28px 24px 56px; }
.cover-art {
  position: relative;
  container-type: inline-size;
  width: min(100%, calc((100vh - 48px) * 1.4906));
  margin: 0 auto;
}
.cover .cover-ill {
  display: block;
  width: 100%;
  height: auto;
  margin: 0;
  border-radius: 14px;
  box-shadow: 0 2px 6px rgba(60, 45, 20, 0.08), 0 24px 60px -24px rgba(60, 45, 20, 0.35);
}
.cover-title {
  position: absolute;
  top: 3.5%;
  left: 0;
  right: 0;
  text-shadow: 0 0 .5cqw #fdfbf6, 0 0 1.2cqw #fdfbf6, 0 0 2cqw rgba(253, 251, 246, .9);
}
.cover .cover-title h1 { font-size: 6.2cqw; line-height: 1.05; margin: 0; }
.cover .cover-title .starring { font-size: 3cqw; margin-top: .3em; display: inline-flex; align-items: center; gap: .35em; }
.cover .cover-title #cover-photo {
  width: 1.5em;
  height: 1.5em;
  margin: 0;
  border-radius: 50%;
  box-shadow: 0 0 0 .12em #fdfbf6;
}

/* Chapters: heading, the picture with the opening on it, the rest of the text below on paper */
.chapter { width: 100%; margin: 0 auto 72px; }
.chapter-head {
  width: min(100%, calc((100vh - 48px) * 1.4906));
  margin: 0 auto 18px;
  padding: 0 4px;
  display: flex;
  align-items: baseline;
  gap: 14px;
}
.chapter-num { font-family: var(--hand); font-size: 26px; color: var(--coral); }
.chapter-head h2 { margin: 0; font-size: clamp(26px, 3vw, 38px); }
.chapter-rest {
  max-width: 680px;
  margin: 40px auto 0;
  padding: 0 24px;
  font-family: var(--hand);
  font-size: 25px;
  line-height: 1.42;
  color: #262b38;
}
.chapter-rest p { margin: 0 0 0.8em; }
.ask-together {
  margin-top: 1.4em;
  padding: 18px 22px;
  border-radius: 14px;
  background: var(--paper-deep);
}
.ask-together .ask-label { display: block; font-family: var(--hand); font-size: 18px; color: #7a6a5a; margin-bottom: 4px; }
.ask-together p { margin: 0; color: #3d5878; }
.memory { margin: 0 auto 56px; max-width: 560px; font-family: var(--hand); }
.memory .memory-label { display: block; font-size: 18px; color: #7a6a5a; }
.memory p { font-size: 34px !important; margin: 6px 0 4px !important; color: var(--sky); }
.memory cite { font-style: normal; font-size: 18px; color: #7a6a5a; }
@media (max-width: 639px) {
  .chapter { margin-bottom: 48px; }
  .chapter-head { padding: 0 20px; }
  .chapter-rest { margin-top: 20px; padding: 0 22px; font-size: 21px; }
}
