/* Shared by local development and the Cloudflare production deployment. */
:root {
  --cream: #f8f4eb;
  --paper: #fffdf8;
  --ink: #26332e;
  --muted: #6c746f;
  --forest: #315b4c;
  --forest-dark: #24483c;
  --sage: #dce7df;
  --terracotta: #c86d4d;
  --peach: #f3ddd2;
  --line: #e5dfd4;
  --shadow: 0 14px 34px rgba(44, 58, 50, 0.1);
  --sans: "DM Sans", system-ui, sans-serif;
  --serif: "Newsreader", Georgia, serif;
  --base-size: 16px;
}

* { box-sizing: border-box; }

html { background: #eee9df; scroll-behavior: smooth; }

body {
  margin: 0;
  color: var(--ink);
  background: #eee9df;
  font-family: var(--sans);
  font-size: var(--base-size);
  -webkit-font-smoothing: antialiased;
}

button, textarea { font: inherit; }
button { color: inherit; }
button:focus-visible, textarea:focus-visible { outline: 3px solid #e4a04a; outline-offset: 3px; }

[hidden] { display: none !important; }

.login-screen {
  display: grid;
  min-height: 100dvh;
  padding: 16px;
  place-items: center;
  background: radial-gradient(circle at 50% 0, #fffdf7 0, var(--cream) 42%, #e6eee8 100%);
}
.login-card { width: min(430px, calc(100vw - 32px)); min-width: 0; padding: 38px 30px; border: 1px solid rgba(49, 91, 76, 0.13); border-radius: 30px; background: rgba(255, 253, 248, 0.92); box-shadow: 0 24px 70px rgba(43, 64, 54, 0.14); text-align: center; }
.login-mark { display: grid; width: 68px; height: 68px; margin: 0 auto 22px; place-items: center; border-radius: 50%; background: var(--forest); box-shadow: 0 10px 24px rgba(49, 91, 76, 0.22); }
.login-mark svg { width: 39px; fill: none; stroke: white; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.7; }
.login-card h1 { margin: 9px 0 14px; font-family: var(--serif); font-size: clamp(2.3rem, 10vw, 3.2rem); font-weight: 600; line-height: 0.98; letter-spacing: -0.035em; }
.login-card > p { margin: 0; color: var(--muted); line-height: 1.55; }
.login-benefits { display: grid; gap: 12px; margin: 27px 0; text-align: left; }
.login-benefits div { display: grid; min-height: 65px; grid-template-columns: 42px 1fr; gap: 2px 10px; align-content: center; padding: 10px 13px; border-radius: 16px; background: #f2f5ef; }
.login-benefits span { grid-row: 1 / 3; align-self: center; font-size: 1.55rem; }
.login-benefits strong { font-size: 0.92rem; }
.login-benefits small { color: var(--muted); font-size: 0.76rem; }
.google-button-wrap { display: flex; min-width: 0; min-height: 44px; overflow: hidden; align-items: center; justify-content: center; color: var(--muted); font-size: 0.8rem; }
.login-error { min-height: 22px; margin-top: 12px !important; color: #9c3f35 !important; font-size: 0.82rem; }
.login-note { display: block; margin-top: 8px; color: #878e8a; font-size: 0.7rem; line-height: 1.45; }

.app-shell {
  position: relative;
  width: 100%;
  max-width: 520px;
  min-height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
  background: var(--cream);
  box-shadow: 0 0 50px rgba(39, 51, 46, 0.12);
}

.topbar {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 74px;
  padding: max(12px, env(safe-area-inset-top)) 22px 0;
  background: var(--cream);
}

.account-actions { position: relative; display: flex; gap: 8px; align-items: center; }
.profile-button { display: grid; width: 44px; height: 44px; padding: 0; place-items: center; overflow: hidden; border: 2px solid white; border-radius: 50%; background: var(--forest); color: white; box-shadow: 0 2px 8px rgba(40, 55, 48, 0.15); font-weight: 700; cursor: pointer; }
.profile-button img { width: 100%; height: 100%; object-fit: cover; }
.profile-menu { position: absolute; z-index: 50; top: 52px; right: 0; display: grid; width: 230px; gap: 4px; padding: 16px; border: 1px solid var(--line); border-radius: 17px; background: var(--paper); box-shadow: var(--shadow); }
.profile-menu strong, .profile-menu small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-menu small { color: var(--muted); font-size: 0.72rem; }
.profile-menu button { min-height: 43px; margin-top: 10px; border: 1px solid #e0c9c1; border-radius: 12px; background: #fff5f1; color: #944b39; font-weight: 700; cursor: pointer; }

.brand {
  display: flex;
  gap: 9px;
  align-items: center;
  padding: 0;
  border: 0;
  background: none;
  color: var(--forest-dark);
  font-size: 1.08rem;
  font-weight: 700;
  cursor: pointer;
}

.brand-mark {
  display: grid;
  width: 31px;
  height: 31px;
  place-items: center;
  border-radius: 50%;
  background: var(--forest);
}

.brand-mark svg { width: 20px; fill: none; stroke: white; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.8; }

.icon-button, .back-button, .more-button {
  display: grid;
  min-width: 44px;
  height: 44px;
  padding: 0;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.55);
  font-weight: 600;
  cursor: pointer;
}

.large-a { margin-left: 1px; font-size: 1.3em; }

main { min-height: calc(100dvh - 74px); }
.screen { display: none; padding: 20px 22px 112px; animation: fade-in 250ms ease; }
.screen.active { display: block; }

@keyframes fade-in { from { opacity: 0; transform: translateY(5px); } }

.eyebrow, .card-label, .page-chapter {
  color: var(--terracotta);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.home-intro { padding: 22px 2px 28px; }
.home-intro h1 {
  margin: 8px 0 13px;
  font-family: var(--serif);
  font-size: clamp(2.6rem, 11vw, 3.6rem);
  font-weight: 600;
  line-height: 0.98;
  letter-spacing: -0.035em;
}
.home-intro p { max-width: 420px; margin: 0; color: var(--muted); font-size: 1.02rem; line-height: 1.55; }

.library-heading { margin-top: 1px !important; }
.library-heading > div { display: grid; gap: 3px; }
.add-book-button {
  display: flex;
  min-height: 44px;
  gap: 5px;
  align-items: center;
  padding: 0 13px;
  border: 1px solid #c7d4cd;
  border-radius: 13px;
  background: #edf3ef;
  color: var(--forest);
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
}
.add-book-button span { font-size: 1.2rem; font-weight: 400; }
.book-shelf {
  display: flex;
  gap: 10px;
  margin: 0 -22px 18px;
  padding: 2px 22px 8px;
  overflow-x: auto;
  scroll-snap-type: x proximity;
  scrollbar-width: none;
}
.book-shelf::-webkit-scrollbar { display: none; }
.book-selector {
  display: grid;
  min-width: 170px;
  min-height: 108px;
  grid-template-columns: 38px 1fr;
  grid-template-rows: 1fr auto;
  gap: 4px 10px;
  padding: 13px;
  scroll-snap-align: start;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: var(--paper);
  text-align: left;
  cursor: pointer;
}
.book-selector.active { border: 2px solid var(--forest); padding: 12px; background: #f0f5f1; }
.book-selector-cover {
  display: grid;
  width: 38px;
  height: 48px;
  grid-row: 1 / 3;
  place-items: center;
  border-radius: 3px 7px 7px 3px;
  background: var(--book-color, var(--terracotta));
  color: white;
  box-shadow: inset 4px 0 rgba(45, 43, 35, 0.12);
  font-family: var(--serif);
  font-size: 0.8rem;
}
.book-selector-copy { display: grid; align-content: start; gap: 3px; min-width: 0; }
.book-selector-copy strong { display: -webkit-box; overflow: hidden; font-size: 0.84rem; line-height: 1.2; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.book-selector-copy small { color: var(--muted); font-size: 0.68rem; }
.book-selector-status { color: var(--forest); font-size: 0.68rem; font-weight: 700; }
.load-error { min-width: calc(100% - 44px); margin: 10px 0; color: var(--muted); line-height: 1.5; }
.empty-library { padding: 30px 24px; border: 1px dashed #bdc9c2; border-radius: 24px; background: #f1f5f2; text-align: center; }
.empty-library[hidden] { display: none; }
.empty-library .empty-book { display: grid; width: 58px; height: 72px; margin: 0 auto 16px; place-items: center; border-radius: 4px 10px 10px 4px; background: var(--forest); color: white; box-shadow: inset 7px 0 rgba(255, 255, 255, 0.1); font-size: 1.5rem; }
.empty-library h2 { margin: 0; font-family: var(--serif); font-size: 1.8rem; }
.empty-library p { margin: 8px auto 20px; color: var(--muted); line-height: 1.5; }
.empty-library .primary-button { margin: 0 auto; }

.story-card {
  padding: 21px;
  border-radius: 24px;
  background: var(--forest);
  color: white;
  box-shadow: var(--shadow);
}
.story-card-top { display: flex; justify-content: space-between; align-items: flex-start; }
.story-card .card-label { color: #d9e6df; }
.story-card h2 { margin: 7px 0 0; font-family: var(--serif); font-size: 1.72rem; font-weight: 600; }
.book-card-actions { display: flex; justify-content: center; gap: 8px; margin: 10px 0 -8px; }
.book-card-actions button { min-height: 44px; padding: 0 12px; border: 0; background: transparent; color: #d9e6df; font-weight: 600; cursor: pointer; }
.book-card-actions .delete-book-button { color: #f3c7bb; }
.mini-cover {
  display: grid;
  width: 54px;
  height: 68px;
  place-items: center;
  border: 2px solid rgba(255, 255, 255, 0.45);
  border-radius: 5px 9px 9px 5px;
  background: #bc684c;
  box-shadow: inset 5px 0 rgba(61, 52, 40, 0.12);
  font-family: var(--serif);
  font-size: 1.15rem;
}
.progress-row { margin: 22px 0 18px; }
.progress-copy { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; color: #dbe5df; font-size: 0.82rem; }
.progress-copy strong { color: white; font-size: 0.95rem; }
.progress-track, .chapter-progress { height: 6px; overflow: hidden; border-radius: 99px; background: rgba(255, 255, 255, 0.18); }
.progress-track span, .chapter-progress span { display: block; height: 100%; border-radius: inherit; background: #e8b394; }

.primary-button {
  display: flex;
  width: 100%;
  min-height: 56px;
  gap: 10px;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 16px;
  background: white;
  color: var(--forest-dark);
  font-weight: 700;
  cursor: pointer;
}
.button-icon { display: grid; width: 31px; height: 31px; place-items: center; border-radius: 50%; background: var(--peach); }
.button-icon svg { width: 18px; fill: none; stroke: var(--terracotta); stroke-linecap: round; stroke-width: 1.8; }

.section-heading { display: flex; align-items: center; justify-content: space-between; margin: 33px 2px 13px; }
.section-heading h2 { margin: 0; font-family: var(--serif); font-size: 1.55rem; }
.section-heading > div { display: grid; gap: 3px; }
.section-heading span { color: var(--muted); font-size: 0.8rem; }
.add-chapter-button { min-height: 44px; padding: 0 12px; border: 1px solid #c7d4cd; border-radius: 13px; background: #edf3ef; color: var(--forest); font-size: 0.76rem; font-weight: 700; cursor: pointer; }
.chapter-list { display: grid; gap: 10px; }
.chapter-row {
  display: flex;
  width: 100%;
  min-height: 76px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: var(--paper);
  overflow: hidden;
}
.chapter-select {
  display: flex;
  min-width: 0;
  flex: 1;
  gap: 14px;
  align-items: center;
  align-self: stretch;
  padding: 12px 8px 12px 14px;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.chapter-row.current { border-color: #bdcfc5; background: #f1f6f2; }
.chapter-number { display: grid; width: 42px; height: 42px; flex: 0 0 42px; place-items: center; border-radius: 13px; background: #eee9df; color: var(--muted); font-family: var(--serif); font-size: 1.05rem; }
.chapter-row.current .chapter-number { background: var(--forest); color: white; }
.chapter-copy { display: grid; min-width: 0; flex: 1; gap: 3px; }
.chapter-copy strong { overflow: hidden; font-size: 0.95rem; text-overflow: ellipsis; white-space: nowrap; }
.chapter-copy small { color: var(--muted); font-size: 0.76rem; }
.chapter-actions { display: grid; flex: 0 0 58px; align-self: stretch; border-left: 1px solid var(--line); }
.chapter-actions button { min-height: 38px; padding: 0 6px; border: 0; background: transparent; color: var(--forest); font-size: 0.7rem; font-weight: 700; cursor: pointer; }
.chapter-actions button + button { border-top: 1px solid var(--line); color: #9a4d42; }

.conversation-screen { padding: 7px 0 200px; }
.conversation-heading, .preview-heading { display: grid; grid-template-columns: 46px 1fr 46px; gap: 11px; align-items: center; padding: 12px 22px 17px; }
.conversation-heading h1, .preview-heading h1 { margin: 2px 0 0; font-family: var(--serif); font-size: 1.48rem; font-weight: 600; line-height: 1.1; }
.back-button { font-size: 1.35rem; }
.more-button { letter-spacing: 0.08em; }
.chapter-progress { height: 4px; border-radius: 0; background: var(--line); }
.chapter-progress span { background: var(--terracotta); }
.conversation { padding: 21px 22px 5px; }
.date-divider { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; color: #8b918e; font-size: 0.75rem; }
.date-divider::before, .date-divider::after { height: 1px; flex: 1; background: var(--line); content: ""; }
.message-row { display: grid; grid-template-columns: 39px 1fr; gap: 10px; }
.ai-avatar { display: grid; width: 39px; height: 39px; place-items: center; border-radius: 50% 50% 50% 14px; background: var(--forest); color: white; font-family: var(--serif); font-size: 1.25rem; }
.speaker { display: block; margin: 1px 0 7px; color: var(--forest); font-size: 0.77rem; font-weight: 700; }
.bubble { padding: 16px 17px; border-radius: 4px 20px 20px 20px; background: white; box-shadow: 0 5px 20px rgba(54, 64, 58, 0.065); font-size: 0.96rem; line-height: 1.56; }
.bubble p { margin: 0; }
.bubble p + p { margin-top: 10px; }
.listen-button { display: flex; min-height: 44px; gap: 7px; align-items: center; margin-top: 7px; padding: 0 12px; border: 0; background: transparent; color: var(--forest); font-size: 0.78rem; font-weight: 600; cursor: pointer; }
.listen-button svg { width: 19px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.7; }
.prompt-label { margin: 24px 0 10px 49px; color: var(--muted); font-size: 0.78rem; }
.choice-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-left: 49px; }
.choice { display: flex; min-height: 66px; gap: 7px; align-items: center; padding: 10px; border: 1px solid var(--line); border-radius: 14px; background: var(--paper); font-size: 0.78rem; font-weight: 600; line-height: 1.25; text-align: left; cursor: pointer; }
.choice span { font-size: 1.25rem; }
.user-message { display: flex; justify-content: flex-end; margin: 20px 0 18px 49px; }
.user-message .bubble { max-width: 90%; border-radius: 20px 4px 20px 20px; background: var(--forest); color: white; }
.typing { display: flex; gap: 5px; align-items: center; min-height: 48px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: #98aaa1; animation: blink 1s infinite alternate; }
.typing i:nth-child(2) { animation-delay: 180ms; }
.typing i:nth-child(3) { animation-delay: 360ms; }
@keyframes blink { to { opacity: 0.25; transform: translateY(-2px); } }

.composer { position: fixed; z-index: 20; right: max(0px, calc((100vw - 520px) / 2)); bottom: 75px; left: max(0px, calc((100vw - 520px) / 2)); padding: 12px 17px 9px; border-top: 1px solid var(--line); background: rgba(248, 244, 235, 0.97); backdrop-filter: blur(12px); }
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
.text-input-wrap { min-height: 52px; flex: 1; padding: 13px 14px; border: 1px solid #d7d0c5; border-radius: 18px; background: white; }
textarea { display: block; width: 100%; max-height: 96px; resize: none; border: 0; outline: 0; background: transparent; color: var(--ink); line-height: 1.45; }
textarea::placeholder { color: #989d9a; }
.mic-button, .send-button { display: grid; width: 54px; height: 54px; flex: 0 0 54px; place-items: center; border: 0; border-radius: 50%; background: var(--terracotta); color: white; box-shadow: 0 6px 14px rgba(186, 91, 60, 0.26); cursor: pointer; }
.mic-button svg { width: 25px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-width: 1.8; }
.send-button { display: none; background: var(--forest); font-size: 1.35rem; }
.composer.has-text .send-button { display: grid; }
.composer.has-text .mic-button { display: none; }
.composer-help { margin: 7px 0 0; color: var(--muted); font-size: 0.69rem; text-align: center; }
.recording-panel { padding: 4px 3px 8px; text-align: center; }
.recording-panel[hidden] { display: none; }
.recording-status { display: flex; align-items: center; justify-content: center; gap: 8px; }
.recording-status time { margin-left: 8px; color: var(--muted); font-variant-numeric: tabular-nums; }
.recording-dot { width: 9px; height: 9px; border-radius: 50%; background: #d9534f; animation: pulse 1s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(217, 83, 79, 0.14); } }
.waveform { display: flex; height: 35px; gap: 4px; align-items: center; justify-content: center; margin: 7px 0 0; }
.waveform i { width: 3px; height: 12px; border-radius: 4px; background: var(--terracotta); animation: wave 800ms ease-in-out infinite alternate; }
.waveform i:nth-child(3n) { animation-delay: -400ms; height: 24px; }
.waveform i:nth-child(2n) { animation-delay: -200ms; height: 18px; }
@keyframes wave { to { transform: scaleY(0.4); opacity: 0.55; } }
.recording-panel p { margin: 0 0 9px; color: var(--muted); font-size: 0.76rem; }
.stop-button { min-height: 45px; padding: 0 22px; border: 0; border-radius: 14px; background: var(--forest); color: white; font-weight: 700; cursor: pointer; }

.preview-screen { padding: 7px 0 112px; }
.share-button svg { width: 22px; fill: none; stroke: var(--ink); stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.7; }
.view-toggle { display: grid; grid-template-columns: 1fr 1fr; margin: 3px 22px 20px; padding: 4px; border-radius: 14px; background: #e9e4da; }
.view-toggle button { min-height: 42px; border: 0; border-radius: 11px; background: transparent; color: var(--muted); font-size: 0.78rem; font-weight: 600; cursor: pointer; }
.view-toggle button.active { background: white; color: var(--forest); box-shadow: 0 2px 8px rgba(36, 56, 47, 0.08); }
.book-readiness { margin: -9px 22px 18px; color: var(--muted); font-size: 0.76rem; line-height: 1.4; text-align: center; }
.book-readiness.ready { color: var(--forest); font-weight: 700; }
.book-stage { padding: 0 22px; }
.pages { scrollbar-width: none; }
.pages::-webkit-scrollbar { display: none; }
.flip-view .pages { display: flex; gap: 18px; overflow-x: auto; scroll-snap-type: x mandatory; overscroll-behavior-x: contain; }
.flip-view .book-page { min-width: 100%; scroll-snap-align: center; }
.book-page { position: relative; aspect-ratio: 0.72; overflow: hidden; border-radius: 4px 13px 13px 4px; background: #fffdf8; box-shadow: 0 16px 36px rgba(49, 52, 47, 0.16), inset 9px 0 15px rgba(44, 39, 28, 0.035); }
.cover-page { display: flex; flex-direction: column; justify-content: space-between; padding: 11% 10%; background: #31584a; color: #f8f0de; text-align: center; }
.cover-page::after { position: absolute; inset: 15px; border: 1px solid rgba(255, 246, 222, 0.35); border-radius: 2px 8px 8px 2px; content: ""; pointer-events: none; }
.cover-page span { font-size: 0.66rem; letter-spacing: 0.18em; }
.cover-page h2 { margin: 10px 0 15px; overflow-wrap: anywhere; font-family: var(--serif); font-size: clamp(2.2rem, 12vw, 4rem); font-weight: 500; line-height: 0.88; letter-spacing: -0.04em; }
.cover-rule { width: 42px; height: 1px; margin: 0 auto 14px; background: #d9a27f; }
.cover-page p { margin: 0; color: #dbe3dd; font-family: var(--serif); font-size: 0.95rem; line-height: 1.3; }
.cover-page small { position: relative; z-index: 1; font-size: 0.68rem; font-weight: 600; letter-spacing: 0.15em; }
.cover-flower { position: relative; width: 54px; height: 54px; margin: 6px auto 4px; }
.cover-flower i { position: absolute; top: 7px; left: 20px; width: 15px; height: 25px; transform-origin: 7px 20px; border-radius: 90% 10% 90% 10%; background: #d99977; }
.cover-flower i:nth-child(2) { transform: rotate(72deg); }.cover-flower i:nth-child(3) { transform: rotate(144deg); }.cover-flower i:nth-child(4) { transform: rotate(216deg); }.cover-flower i:nth-child(5) { transform: rotate(288deg); }
.cover-flower b { position: absolute; z-index: 2; top: 20px; left: 20px; width: 14px; height: 14px; border-radius: 50%; background: #e9c887; }
.text-page { padding: 13% 11% 10%; color: #3c3932; }
.text-page .page-chapter { text-align: center; }
.text-page h2 { margin: 5px 0 7px; font-family: var(--serif); font-size: clamp(2rem, 9vw, 3.1rem); font-weight: 600; line-height: 1; text-align: center; }
.ornament { margin-bottom: 9%; color: #bd7459; text-align: center; }
.text-page p { font-family: var(--serif); font-size: clamp(0.92rem, 3.8vw, 1.25rem); line-height: 1.52; }
.text-page p { -webkit-user-select: text; user-select: text; }
.continuation-page { padding-top: 9%; }
.continuation-heading { display: flex; min-width: 0; gap: 6px; align-items: baseline; margin-bottom: 7%; padding-bottom: 4%; border-bottom: 1px solid #ded5c7; white-space: nowrap; }
.continuation-heading span { flex: 0 0 auto; color: var(--terracotta); font-size: 0.66rem; font-weight: 700; letter-spacing: 0.12em; }
.continuation-heading strong { min-width: 0; overflow: hidden; color: #5e584e; font-family: var(--serif); font-size: 0.94rem; font-weight: 600; line-height: 1.15; text-overflow: ellipsis; white-space: nowrap; }
.continuation-page p { overflow-wrap: anywhere; }
.dropcap::first-letter { float: left; margin: 5px 6px 0 0; color: var(--terracotta); font-size: 3.2em; line-height: 0.7; }
.text-page blockquote { margin: 9% 3%; padding-left: 11px; border-left: 2px solid #d7a48a; color: #766b60; font-family: var(--serif); font-size: clamp(0.85rem, 3.5vw, 1.1rem); font-style: italic; line-height: 1.4; }
.page-number { position: absolute; right: 0; bottom: 5%; left: 0; font-family: var(--serif); font-size: 0.78rem; text-align: center; }
.page-controls { display: flex; align-items: center; justify-content: center; gap: 28px; margin-top: 18px; }
.page-controls button { display: grid; width: 46px; height: 46px; place-items: center; border: 1px solid var(--line); border-radius: 50%; background: white; font-size: 1.25rem; cursor: pointer; }
.page-controls span { min-width: 45px; color: var(--muted); font-size: 0.82rem; text-align: center; }
.page-controls strong { color: var(--ink); }
.swipe-hint { margin: 9px 0 0; color: var(--muted); font-size: 0.72rem; text-align: center; }
.selection-hint { margin: 5px 22px 0; color: var(--forest); font-size: 0.7rem; text-align: center; }
.draft-review { margin: 22px; padding: 18px; border: 1px solid var(--line); border-radius: 18px; background: white; }
.draft-review[hidden] { display: none; }
.draft-review h2 { margin: 5px 0 4px; font-family: var(--serif); font-size: 1.4rem; }
.draft-review p { margin: 0; color: var(--muted); font-size: 0.8rem; line-height: 1.45; }
.draft-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 15px; }
.draft-actions button { min-height: 46px; padding: 0 10px; border: 1px solid var(--line); border-radius: 12px; background: #f5f1e9; color: var(--forest); font-size: 0.75rem; font-weight: 700; cursor: pointer; }
.draft-actions .approve-draft-button { grid-column: 1 / -1; border: 0; background: var(--forest); color: white; }
.draft-actions button:disabled { opacity: 0.6; cursor: default; }
.scroll-view .pages { display: grid; gap: 20px; overflow: visible; }
.scroll-view .book-page { width: 100%; min-width: 0; }
.scroll-view + .page-controls { display: none; }

.bottom-nav {
  position: fixed;
  z-index: 30;
  right: max(0px, calc((100vw - 520px) / 2));
  bottom: 0;
  left: max(0px, calc((100vw - 520px) / 2));
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  height: calc(75px + env(safe-area-inset-bottom));
  padding: 7px 14px env(safe-area-inset-bottom);
  border-top: 1px solid rgba(211, 204, 191, 0.8);
  background: rgba(255, 253, 248, 0.96);
  backdrop-filter: blur(14px);
}
.bottom-nav button { display: flex; flex-direction: column; gap: 3px; align-items: center; justify-content: center; border: 0; background: transparent; color: #858b87; font-size: 0.7rem; font-weight: 600; cursor: pointer; }
.bottom-nav svg { width: 23px; height: 23px; fill: none; stroke: currentColor; stroke-linejoin: round; stroke-width: 1.7; }
.bottom-nav button.active { color: var(--forest); }
.bottom-nav button.active svg { fill: var(--sage); }

.toast { position: fixed; z-index: 100; right: 50%; bottom: 95px; width: max-content; max-width: calc(100vw - 40px); padding: 11px 18px; transform: translate(50%, 20px); border-radius: 99px; background: var(--ink); color: white; box-shadow: var(--shadow); font-size: 0.82rem; opacity: 0; pointer-events: none; transition: 220ms ease; }
.toast.show { transform: translate(50%, 0); opacity: 1; }
.selection-ai-button { position: fixed; z-index: 45; right: 50%; bottom: calc(91px + env(safe-area-inset-bottom)); min-height: 48px; padding: 0 18px; transform: translateX(50%); border: 0; border-radius: 99px; background: var(--forest); color: white; box-shadow: 0 8px 24px rgba(30, 56, 46, 0.3); font-weight: 700; cursor: pointer; }
.selection-ai-button[hidden] { display: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }

.book-dialog {
  width: min(440px, calc(100vw - 32px));
  padding: 0;
  border: 0;
  border-radius: 24px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 26px 70px rgba(29, 39, 34, 0.28);
}
.book-dialog::backdrop { background: rgba(30, 39, 35, 0.54); backdrop-filter: blur(3px); }
.book-dialog form { padding: 24px; }
.dialog-heading { display: grid; grid-template-columns: 1fr 44px; gap: 12px; align-items: start; }
.dialog-heading h2 { margin: 6px 0 22px; font-family: var(--serif); font-size: 1.8rem; line-height: 1.08; }
.dialog-close { display: grid; width: 44px; height: 44px; place-items: center; border: 1px solid var(--line); border-radius: 50%; background: white; font-size: 1.5rem; cursor: pointer; }
.book-title-field { display: grid; gap: 8px; font-size: 0.82rem; font-weight: 700; }
.book-title-field input { width: 100%; height: 56px; padding: 0 15px; border: 1px solid #d2cbc0; border-radius: 14px; background: white; color: var(--ink); font: inherit; font-size: 1rem; }
.book-title-field input:focus { outline: 3px solid #e4a04a; outline-offset: 2px; }
.title-suggestions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.title-suggestions button { min-height: 40px; padding: 0 11px; border: 1px solid var(--line); border-radius: 99px; background: #f4f0e8; color: var(--muted); font-size: 0.72rem; cursor: pointer; }
.dialog-actions { display: grid; grid-template-columns: 1fr 1.3fr; gap: 10px; margin-top: 24px; }
.dialog-actions button { min-height: 52px; border-radius: 14px; font-weight: 700; cursor: pointer; }
.secondary-button { border: 1px solid var(--line); background: white; }
.dialog-primary { border: 0; background: var(--forest); color: white; }

body.large-text { --base-size: 18px; }
body.large-text .choice-grid { grid-template-columns: 1fr; }

@media (min-width: 700px) {
  body { padding: 18px 0; }
  .app-shell { min-height: calc(100dvh - 36px); border-radius: 28px; }
  .topbar { border-radius: 28px 28px 0 0; }
  .bottom-nav { bottom: 18px; border-radius: 0 0 28px 28px; }
  .composer { bottom: 93px; }
}

@media (max-width: 360px) {
  .screen { padding-right: 16px; padding-left: 16px; }
  .conversation { padding-right: 16px; padding-left: 16px; }
  .conversation-heading, .preview-heading { padding-right: 16px; padding-left: 16px; }
  .choice-grid, .prompt-label { margin-left: 0; }
}

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