/* My books — neutral cream base, dark olive text, deep olive accent. Flat: no shadows, no gradients. */
:root {
  --bg: #F5F1E6;         /* neutral warm cream page background (no yellow tint) */
  --surface: #E9E3D3;    /* cards, tiles, inputs — a slightly deeper cream */
  --surface-dark: #F5F1E6; /* tab bar (same as page, separated by a thin line) */
  --line: #D3CCB8;       /* thin dividers only */
  --text: #33321F;       /* body text: near-black olive, high contrast */
  --icon-inactive: #6E6B5A; /* inactive tab icons and labels */
  --accent: #545333;     /* deep olive: headings, the single primary action, active states */
  --on-accent: #FBF8EF;  /* text on deep olive */

  --radius: 14px;
  --radius-small: 10px;
  --gutter: 20px;
  --tabbar-height: 64px;
  color-scheme: light;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Manrope, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 17px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

main {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 28px) var(--gutter)
           calc(env(safe-area-inset-bottom) + var(--tabbar-height) + 32px);
}

h1, h2, h3 { color: var(--accent); margin: 0; font-weight: 700; letter-spacing: -0.01em; }
h1 { font-size: 32px; line-height: 1.15; }
h2 { font-size: 20px; line-height: 1.3; }
h3 { font-size: 17px; }
p { margin: 0; }

.eyebrow {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.muted { opacity: 0.8; }

.stack > * + * { margin-top: 16px; }
.section { margin-top: 36px; }
.section > h2 { margin-bottom: 12px; }

/* Cards: separated by tint, never boxed inside each other */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 18px 20px;
}
.card p + p { margin-top: 6px; }

.list { background: var(--surface); border-radius: var(--radius); }
.list-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 56px; padding: 14px 20px;
}
.list-row + .list-row { border-top: 1px solid var(--line); }
.list-row .value { font-weight: 600; text-align: right; }

/* Buttons */
button, .button {
  font: inherit;
  border: 0;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 52px;
  padding: 0 22px;
  border-radius: var(--radius);
  text-decoration: none;
}
.button-primary { background: var(--accent); color: var(--on-accent); font-weight: 700; }
.button-secondary { background: var(--surface); color: var(--accent); font-weight: 600; }
.button-block { width: 100%; }
.button-hero { min-height: 72px; font-size: 19px; }
button:disabled { opacity: 0.6; cursor: default; }
button:active:not(:disabled), .button:active { transform: scale(0.985); }
button:focus-visible, a:focus-visible, input:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

/* Inputs */
label { display: block; font-weight: 600; margin-bottom: 8px; }
input[type="text"], input[type="password"], input[type="search"] {
  width: 100%;
  font: inherit;
  font-size: 18px; /* ≥16px stops iOS zooming in */
  color: var(--accent);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-small);
  min-height: 52px;
  padding: 0 16px;
  -webkit-appearance: none;
  appearance: none;
}
input::placeholder { color: var(--text); opacity: 0.55; }

.error { color: var(--accent); font-weight: 600; min-height: 1.5em; }

/* Login */
.login {
  min-height: calc(100vh - 120px);
  display: flex; flex-direction: column; justify-content: center;
}
.login-mark { color: var(--accent); width: 64px; height: 64px; margin-bottom: 28px; }
.login h1 { margin-bottom: 8px; }
.login form { margin-top: 32px; }
.login form > * + * { margin-top: 14px; }

/* Empty / placeholder states */
.empty {
  text-align: center;
  padding: 36px 20px;
}
.empty svg { width: 40px; height: 40px; margin-bottom: 12px; }
.empty p + p { margin-top: 6px; }

.coming-list { margin: 0; padding: 0; list-style: none; }
.coming-list li {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 14px 0;
}
.coming-list li + li { border-top: 1px solid var(--line); }
.coming-list .stage { white-space: nowrap; font-size: 15px; }

.banner { display: flex; gap: 14px; align-items: flex-start; }
.banner .banner-text { flex: 1; }
.banner button { min-height: 40px; padding: 0 14px; font-size: 15px; background: var(--accent); color: var(--on-accent); font-weight: 600; }

/* Line icons */
svg { fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

/* Bottom tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: space-around;
  background: var(--surface-dark);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
}
.tabbar[hidden] { display: none; }
.tabbar a {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  height: var(--tabbar-height);
  color: var(--icon-inactive);
  text-decoration: none;
  font-size: 12px; font-weight: 600;
}
.tabbar a svg { width: 26px; height: 26px; }
.tabbar a.active { color: var(--accent); }

/* Toast */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom) + var(--tabbar-height) + 16px);
  max-width: calc(100% - 2 * var(--gutter));
  background: var(--accent); color: var(--on-accent);
  padding: 12px 18px; border-radius: var(--radius-small);
  font-weight: 600; font-size: 15px; text-align: center;
  z-index: 20;
}
.toast[hidden] { display: none; }

.spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2s; } }

/* ───────────── Stage 2: adding books ───────────── */

.small { font-size: 14px; }
.hint { margin-top: 8px; font-size: 15px; }
.label { display: block; font-weight: 600; margin-bottom: 8px; }

/* Book rows: cover on the left, text on the right */
.list { overflow: hidden; }
.book-row { justify-content: flex-start; align-items: flex-start; gap: 14px; }
.book-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.book-text h3, .book-title { font-size: 17px; font-weight: 700; color: var(--accent); overflow-wrap: anywhere; }
.cover {
  flex: none; width: 48px; height: 72px; border-radius: 4px;
  object-fit: cover; background: var(--line);
}
.cover-empty { display: block; }
.tag {
  align-self: flex-start; margin-top: 6px;
  font-size: 13px; font-weight: 600;
  padding: 2px 10px; border-radius: 999px;
  background: var(--bg); color: var(--accent);
}

/* Rows that are buttons (pick a match) */
button.list-row {
  width: 100%; min-height: 0; border-radius: 0;
  padding: 14px 20px; background: transparent; color: inherit;
  text-align: left; font-weight: 400; display: flex;
}
button.list-row:active:not(:disabled) { transform: none; background: var(--line); }

.back-link {
  min-height: 44px; padding: 0; margin: -8px 0 8px;
  background: none; color: var(--accent); font-weight: 600;
  display: inline-flex; align-items: center; text-decoration: none;
}
.series-link { text-decoration: none; }

.busy { margin-top: 30vh; }
.busy .spinner { margin: 0 auto 14px; }

/* Typed title */
.input-row { display: flex; gap: 10px; }
.input-row input { flex: 1; min-width: 0; }

/* Camera button beside the search box */
.icon-button { flex: none; width: 52px; padding: 0; }
.icon-button svg { width: 26px; height: 26px; }

/* Forms */
.form > * + * { margin-top: 18px; }
.field-row { display: flex; gap: 12px; }
.field.grow { flex: 1; min-width: 0; }
.field.narrow { width: 96px; flex: none; }
.confirm-head { display: flex; gap: 14px; align-items: flex-end; }
.confirm-head .cover { width: 64px; height: 96px; }

select, input[type="date"] {
  width: 100%; font: inherit; font-size: 18px;
  color: var(--accent); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius-small);
  min-height: 52px; padding: 0 14px;
  -webkit-appearance: none; appearance: none;
}
select {
  background-image: linear-gradient(45deg, transparent 50%, var(--accent) 50%), linear-gradient(135deg, var(--accent) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%;
  background-size: 6px 6px; background-repeat: no-repeat;
  padding-right: 36px;
}
[hidden] { display: none !important; }

.pills { display: flex; flex-wrap: wrap; gap: 8px; }
.pill input { position: absolute; opacity: 0; pointer-events: none; }
.pill span {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 16px;
  border-radius: 999px; background: var(--surface); color: var(--text);
  font-weight: 600; cursor: pointer;
}
.pill input:checked + span { background: var(--accent); color: var(--on-accent); }
.pill input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Screenshot review */
.bulk .bulk-fields { display: flex; gap: 10px; }
.review-grid { display: grid; gap: 10px; }
.review-item {
  display: flex; align-items: flex-start; gap: 4px;
  background: var(--surface); border-radius: var(--radius);
  padding: 12px 14px 12px 6px;
}
.review-item.excluded { opacity: 0.55; }
.tick { display: flex; align-items: center; justify-content: center; width: 44px; height: 72px; margin: 0; flex: none; }
.tick input { width: 24px; height: 24px; accent-color: var(--accent); }
.review-item details { flex: 1; min-width: 0; }
.review-item summary { display: flex; gap: 12px; cursor: pointer; list-style: none; }
.review-item summary::-webkit-details-marker { display: none; }
.edit-fields { margin-top: 14px; }
.edit-fields > * + * { margin-top: 12px; }
.edit-fields label { font-size: 15px; margin-bottom: 4px; }
.edit-fields input, .edit-fields select { min-height: 46px; font-size: 17px; }

.save-bar {
  position: sticky;
  bottom: calc(env(safe-area-inset-bottom) + var(--tabbar-height) + 12px);
  margin-top: 24px;
}

/* Wider layout on a computer for the adding screens */
@media (min-width: 900px) {
  main.wide { max-width: 1000px; }
  main.wide .review-grid { grid-template-columns: 1fr 1fr; align-items: start; }
  main.wide #title-form, main.wide #book-form { max-width: 620px; }
  main.wide .save-bar { max-width: 420px; margin-left: auto; }
}

/* ───────────── Stage 3: library ───────────── */

a.row-link { color: inherit; text-decoration: none; }
a.row-link:active { background: var(--line); }
.button-block { display: flex; }
a.button { font-weight: 600; }

/* Books / Rankings switch */
.segmented {
  display: flex; background: var(--surface); border-radius: var(--radius); padding: 4px; gap: 4px;
}
.segmented a {
  flex: 1; text-align: center; min-height: 44px; display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-small); color: var(--text); text-decoration: none; font-weight: 600;
}
.segmented a.on { background: var(--accent); color: var(--on-accent); }

/* Filters */
.filters > * + * { margin-top: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 40px; padding: 0 14px; border-radius: 999px;
  background: var(--surface); color: var(--text); font-weight: 600; font-size: 15px;
}
.chip[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }

/* Series groups */
.library-grid { display: grid; gap: 16px; }
.series-group { background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.series-head {
  display: flex; flex-direction: column; gap: 2px; padding: 16px 20px 14px;
  color: inherit; text-decoration: none; border-bottom: 1px solid var(--line);
}
a.series-head:active { background: var(--line); }
.series-name { font-size: 19px; font-weight: 700; color: var(--accent); }
.series-head .progress { margin-top: 8px; }
.progress {
  display: block; height: 6px; border-radius: 999px; background: var(--line); overflow: hidden; margin-top: 8px;
}
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.series-books .list-row + .list-row { border-top: 1px solid var(--line); }
.tag-quiet { background: transparent; border: 1px solid var(--line); }

/* Book and series pages */
.book-hero { display: flex; gap: 18px; align-items: flex-end; margin-top: 8px; }
.book-hero .cover { width: 96px; height: 144px; border-radius: 6px; }
.book-hero-text { min-width: 0; }
.book-hero-text h1 { font-size: 26px; overflow-wrap: anywhere; }
.book-hero-text p { margin-top: 4px; }
.series-link { display: inline-block; margin-top: 6px; color: var(--accent); font-weight: 600; }
textarea {
  width: 100%; font: inherit; font-size: 17px; color: var(--accent);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-small);
  padding: 12px 14px; resize: vertical; -webkit-appearance: none; appearance: none;
}
.more-fields summary { cursor: pointer; font-weight: 600; color: var(--accent); min-height: 44px; display: flex; align-items: center; }
.more-fields > .field { margin-top: 12px; }
.danger { color: #8A2E1F; }

/* Rankings */
.rank-num { flex: none; width: 28px; align-self: center; text-align: center; font-weight: 700; color: var(--accent); font-size: 18px; }
.banner-button {
  flex: none; min-height: 40px; padding: 0 16px; font-size: 15px;
  background: var(--accent); color: var(--on-accent); text-decoration: none;
}

/* This or that? */
.versus { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: stretch; }
.vs-card {
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 6px;
  padding: 18px 12px; min-height: 220px; text-align: center;
  background: var(--surface); color: var(--text); font-weight: 400;
}
.vs-card .cover { width: 84px; height: 126px; margin-bottom: 6px; }
.vs-card strong { color: var(--accent); font-size: 16px; overflow-wrap: anywhere; }
.vs-card:active:not(:disabled) { background: var(--line); }
.vs-or { align-self: center; font-weight: 700; color: var(--icon-inactive); }

@media (min-width: 900px) {
  main.wide .library-grid { grid-template-columns: 1fr 1fr; align-items: start; }
  main.wide .rank-list { max-width: 680px; }
}

/* Home: the three main actions */
.home-actions > * + * { margin-top: 12px; }
.action-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.action-card {
  display: flex; flex-direction: column; align-items: flex-start; justify-content: flex-start; gap: 2px;
  min-height: 116px; padding: 16px; text-align: left;
  background: var(--surface); color: var(--text); font-weight: 400;
}
.action-card svg { width: 26px; height: 26px; color: var(--accent); margin-bottom: 8px; }
.action-card strong { color: var(--accent); font-size: 17px; line-height: 1.25; }

/* ───────────── Stage 4: debriefs ───────────── */

.debrief-book { display: flex; gap: 14px; align-items: center; }
.debrief-book .cover { width: 44px; height: 66px; }

.choice-button {
  display: flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: 2px;
  width: 100%; min-height: 60px; padding: 14px 18px; text-align: left;
  background: var(--surface); color: var(--text); font-weight: 400;
}
.choice-button strong { color: var(--accent); font-size: 18px; }
.choice-button span { font-size: 15px; }
.choice-button.primary { background: var(--accent); color: var(--on-accent); }
.choice-button.primary strong { color: var(--on-accent); }
.choice-button.quiet { background: transparent; border: 1px solid var(--line); }
.tier-buttons > * + * { margin-top: 10px; }
.stack > .choice-button + .choice-button { margin-top: 12px; }

h1.question { font-size: 26px; line-height: 1.25; }
.section-tight { margin-top: 12px; }

.scale { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.scale-btn {
  min-height: 60px; padding: 0; font-size: 22px; font-weight: 700;
  background: var(--surface); color: var(--accent);
}
.scale-btn:active { background: var(--accent); color: var(--on-accent); }
.scale-anchors { display: flex; justify-content: space-between; gap: 16px; margin-top: 8px; }
.scale-anchors span:last-child { text-align: right; }

.debrief-links { display: flex; justify-content: space-between; gap: 12px; }
.link-button {
  min-height: 44px; padding: 0; background: none; color: var(--accent);
  font-weight: 600; font-size: 15px; text-decoration: underline; text-underline-offset: 3px;
}

.tag-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.tag-row .tag { margin-top: 0; }
.card .tag { background: var(--bg); }

.button-pair { display: flex; gap: 10px; margin-top: 12px; }
.button-pair > * { flex: 1; }

/* Taste profile */
.profile-grid { display: grid; gap: 14px; }
.profile-grid textarea { min-height: 64px; }
textarea.plain { background: transparent; border: 0; padding: 0; font-size: 17px; line-height: 1.55; color: var(--text); }
textarea.plain:focus { outline: 2px solid var(--accent); outline-offset: 6px; border-radius: 4px; }

@media (min-width: 900px) {
  main.wide .profile-grid { grid-template-columns: 1fr 1fr; }
}

/* ───────────── Stage 5: recaps ───────────── */

.spoiler-note { margin-top: 10px; font-weight: 600; color: #8A2E1F; }
.recap h2 { margin-bottom: 8px; }
.recap p + p { margin-top: 10px; }
@media (min-width: 900px) {
  main.wide .recap { max-width: 680px; }
}

/* ───────────── Stage 6: recommendations ───────────── */

.card h2 { font-size: 19px; }
.pick-grid { display: grid; gap: 14px; }
.pick-head { display: flex; gap: 14px; align-items: flex-start; }
.pick-head .cover { width: 64px; height: 96px; }
.pick p + p { margin-top: 4px; }
.pick .chip { background: var(--bg); }
.pick .chip[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }
.pick .want-btn { background: var(--bg); }

.verdict-tier { font-size: 26px; font-weight: 700; color: var(--accent); margin: 2px 0 6px; }
.plain-list { margin: 6px 0 0; padding-left: 20px; }
.plain-list li + li { margin-top: 4px; }
.next-up { color: var(--accent); font-weight: 600; }

.past-recs summary { cursor: pointer; font-weight: 700; color: var(--accent); min-height: 44px; display: flex; align-items: center; font-size: 18px; }

/* Ask my library */
.chat { display: flex; flex-direction: column; gap: 10px; }
.bubble { max-width: 88%; padding: 12px 16px; border-radius: var(--radius); }
.bubble.user { align-self: flex-end; background: var(--accent); color: var(--on-accent); }
.bubble.assistant { align-self: flex-start; background: var(--surface); }
.bubble p + p, .bubble p + ul, .bubble ul + p { margin-top: 8px; }
.chat-form { display: flex; gap: 10px; align-items: flex-end; }
.chat-form textarea { flex: 1; min-height: 52px; }
.chat .spinner { display: block; }

@media (min-width: 900px) {
  main.wide .pick-grid { grid-template-columns: 1fr 1fr; align-items: start; }
  main.wide .chat, main.wide .chat-form { max-width: 720px; }
}

/* Controls sitting on a card use the page colour so they stand out from it */
.card .pill span, .card input[type="text"], .card input[type="search"], .card select, .card textarea:not(.plain),
.card .icon-button { background-color: var(--bg); }
.card .pill input:checked + span { background: var(--accent); color: var(--on-accent); }
