/* HomeLibrary — warm, book-ish, mobile-first */
:root {
  --bg: #f7f2e8;
  --card: #fffdf8;
  --ink: #2b2620;
  --muted: #8a7f6f;
  --line: #e7ddcc;
  --green: #2f5747;
  --green-dark: #234236;
  --terra: #c26d4f;
  --gold: #b98a2e;
  --danger: #b0442f;
  --radius: 16px;
  --shadow: 0 2px 10px rgba(60, 45, 20, .08);
  --serif: "Iowan Old Style", "Palatino", Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.45;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); font-size: .9rem; margin-top: .5rem; }

h1, h2, h3, .topbar-name, .wiz-title { font-family: var(--serif); }

/* ---------- buttons & inputs ---------- */
.btn {
  font: inherit; border: 0; border-radius: 12px; padding: .8rem 1.1rem;
  cursor: pointer; font-weight: 600; transition: transform .06s ease;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--green); color: #fff; }
.btn.primary:disabled { background: #9fb0a8; }
.btn.ghost { background: transparent; color: var(--green); border: 1.5px solid var(--green); }
.btn.terra { background: var(--terra); color: #fff; }
.btn.subtle { background: #efe7d7; color: var(--ink); }
.btn.wide { width: 100%; display: block; }
.btn.small { padding: .45rem .75rem; font-size: .88rem; border-radius: 10px; }
.icon-btn {
  font: inherit; background: transparent; border: 0; font-size: 1.25rem;
  padding: .5rem .6rem; cursor: pointer; border-radius: 12px; color: var(--ink);
}
input[type=text], input[type=search], input[type=password], input[type=number],
input[type=email], textarea, select {
  font: inherit; width: 100%; padding: .8rem .9rem; border: 1.5px solid var(--line);
  border-radius: 12px; background: var(--card); color: var(--ink); outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--green); }

.chip-row { display: flex; flex-wrap: wrap; gap: .5rem; margin: .8rem 0; }
.chip {
  font: inherit; border: 1.5px solid var(--line); background: var(--card);
  border-radius: 999px; padding: .5rem .95rem; cursor: pointer; font-size: .92rem;
}
.chip.selected, .chip:active { border-color: var(--green); background: #e9f0ec; }

.row-2 { display: flex; gap: .6rem; margin-top: .8rem; }
.row-2 .btn { flex: 1; }

/* ---------- gate & onboarding ---------- */
.screen { min-height: 100dvh; }
#gate, #onboard { display: flex; align-items: center; justify-content: center; padding: 1.5rem; }
#gate.hidden, #onboard.hidden { display: none; }
.gate-card, .onboard-card {
  width: 100%; max-width: 380px; background: var(--card); border-radius: 20px;
  box-shadow: var(--shadow); padding: 2rem 1.5rem; text-align: center;
}
.logo-mark {
  width: 64px; height: 64px; margin: 0 auto 1rem; border-radius: 18px;
  background: var(--green); color: #f7f2e8; font-size: 2rem; line-height: 64px;
}
.gate-card h1 { margin-bottom: .25rem; }
.gate-card { text-align: left; }
.gate-card .logo-mark, .gate-card h1, .gate-card #gateSub { text-align: center; }
.gate-card h1, .gate-card #gateSub { display: block; }
.gate-card input { margin-bottom: .6rem; }
.gate-field { margin-bottom: .9rem; }
.gate-field label { display: block; font-size: .8rem; color: var(--muted); margin-bottom: .25rem; }
.gate-field .hint { font-size: .74rem; color: var(--muted); margin-top: .2rem; }
.at-wrap { position: relative; }
.at-wrap .at { position: absolute; left: .8rem; top: 50%; transform: translateY(-50%);
               color: var(--muted); pointer-events: none; }
.at-wrap input { padding-left: 1.7rem; }
/* Consent: shown once, at sign-up. Plain and quiet, but the one clause a
   reasonable person would not expect is stated on the line itself rather than
   left for them to find inside the notice. */
.consent { display: flex; gap: .55rem; align-items: flex-start; margin: 1rem 0 .2rem;
           font-size: .78rem; color: var(--muted); line-height: 1.45; }
.consent input { width: 17px; height: 17px; margin: .12rem 0 0; flex: 0 0 auto; }
.consent a { color: var(--muted); }
.gate-switch { text-align: center; margin-top: 1.1rem; font-size: .84rem; }
.gate-switch button { background: none; border: 0; color: var(--green);
                      font: inherit; font-weight: 600; cursor: pointer; padding: 0; }
.librarian-avatar {
  width: 40px; height: 40px; border-radius: 50%; background: var(--green);
  display: flex; align-items: center; justify-content: center; font-size: 1.15rem;
  color: #fff; flex: 0 0 auto;
}
.librarian-avatar.big { width: 72px; height: 72px; font-size: 2rem; margin: 0 auto 1rem; }
.bubble {
  background: #eef2ee; border-radius: 16px; padding: 1rem 1.1rem; text-align: left;
  margin-bottom: 1.1rem;
}
.bubble p + p { margin-top: .6rem; }
.onboard-card input { margin-bottom: .3rem; }

/* ---------- first-run room picker ---------- */
/* A pill that reads as ticked or not at a glance, because the gesture here is
   pruning a list someone else wrote, not filling in a form. */
.room-grid { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: .9rem; }
.room-item {
  font: inherit; font-size: .92rem; display: inline-flex; align-items: center; gap: .45rem;
  border: 1.5px solid var(--line); background: var(--card); color: var(--muted);
  border-radius: 999px; padding: .5rem .95rem; cursor: pointer; user-select: none;
}
.room-item .tick { font-size: .82rem; opacity: .35; }
.room-item.on {
  border-color: var(--green); background: #eef2ee; color: var(--ink); font-weight: 600;
}
.room-item.on .tick { opacity: 1; color: var(--green); }
.room-add { display: flex; gap: .5rem; align-items: stretch; }
.room-add input { margin-bottom: 0; }
.room-add .btn { flex: 0 0 auto; }
.scan-lead { font-size: .84rem; margin: .9rem 0 .5rem; }

/* ---------- the sign-up wizard ---------- */
/* Three dots, not "Step 2 of 3": the count matters, the arithmetic doesn't. */
.step-dots { display: flex; gap: .4rem; justify-content: center; margin-bottom: 1.1rem; }
.step-dots .dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--line);
}
.step-dots .dot.on { background: var(--green); transform: scale(1.25); }
.step-dots .dot.done { background: #9fb0a8; }
.gate-lead { font-size: .86rem; line-height: 1.55; margin-bottom: 1.1rem; text-align: left; }
.share-block {
  border: 1.5px solid var(--line); border-radius: 14px; padding: .85rem .9rem;
  margin: 1rem 0 .2rem; background: var(--card);
}
.share-ask { margin: 0; }
.share-ask span { font-size: .82rem; line-height: 1.55; }
.share-ask em { color: var(--muted); font-style: normal; font-weight: 600; }

/* ---------- third-party sign-in ---------- */
/* Google's own guidance: white surface, their mark, no recolouring. */
.btn.google {
  background: #fff; color: #1f1f1f; border: 1.5px solid #dadce0;
  display: inline-flex; align-items: center; justify-content: center; gap: .6rem;
  font-weight: 500;
}
.btn.google:hover { background: #f8f9fa; }
.g-mark {
  font-family: var(--serif); font-weight: 700; font-size: 1.05rem; line-height: 1;
  background: conic-gradient(from -45deg, #ea4335 0 25%, #fbbc05 0 50%, #34a853 0 75%, #4285f4 0);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
/* A labelled rule, so the two routes read as alternatives rather than steps. */
.or-rule {
  display: flex; align-items: center; gap: .7rem; margin: 1rem 0;
  color: var(--muted); font-size: .78rem;
}
.or-rule::before, .or-rule::after {
  content: ""; flex: 1; height: 1px; background: var(--line);
}

/* ---------- main layout ---------- */
#main { display: flex; flex-direction: column; min-height: 100dvh; }
#topbar {
  display: flex; align-items: center; gap: .7rem; padding: .8rem 1rem;
  padding-top: calc(.8rem + env(safe-area-inset-top));
  background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.topbar-text { flex: 1; min-width: 0; }
.topbar-name { font-size: 1.15rem; font-weight: 700; }
.topbar-sub { font-size: .78rem; color: var(--muted); }
#content { flex: 1; padding: 1rem; padding-bottom: calc(76px + env(safe-area-inset-bottom)); max-width: 640px; width: 100%; margin: 0 auto; }
#bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; display: flex; z-index: 30;
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-btn {
  flex: 1; font: inherit; background: none; border: 0; padding: .55rem 0 .5rem;
  color: var(--muted); font-size: .78rem; cursor: pointer; display: flex;
  flex-direction: column; align-items: center; gap: .1rem;
}
.nav-btn span { font-size: 1.3rem; }
.nav-btn.active { color: var(--green); font-weight: 700; }

/* ---------- find ---------- */
.search-row { margin-bottom: .7rem; }
#scanCoverBtn { margin-bottom: 1rem; }
.cards { display: flex; flex-direction: column; gap: .7rem; }
.book-row {
  display: flex; gap: .8rem; background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: .7rem; cursor: pointer; align-items: center;
}
.book-cover {
  width: 48px; height: 68px; border-radius: 6px; object-fit: cover; flex: 0 0 auto;
  background: linear-gradient(160deg, #3c6b58, #234236); color: #f7f2e8;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--serif); font-size: 1.2rem;
}
.book-main { flex: 1; min-width: 0; }
.book-title { font-weight: 700; font-family: var(--serif); }
.book-author { font-size: .86rem; color: var(--muted); }
.book-loc { font-size: .8rem; color: var(--green); margin-top: .2rem; }
.status-chip {
  display: inline-block; font-size: .72rem; border-radius: 999px; padding: .1rem .55rem;
  background: #f3e3c3; color: #7a5b17; margin-left: .4rem; vertical-align: middle;
}
.status-chip.lent { background: #e8dff3; color: #5a4585; }
.find-hint { text-align: center; color: var(--muted); padding: 2rem 1rem; }
.find-hint .big { font-size: 2rem; margin-bottom: .4rem; }

/* ---------- ask / chat ---------- */
#tab-ask { display: flex; flex-direction: column; min-height: calc(100dvh - 190px); }
.chat { flex: 1; display: flex; flex-direction: column; gap: .7rem; padding-bottom: .8rem; }
.msg { max-width: 88%; padding: .7rem .95rem; border-radius: 16px; }
.msg.user { align-self: flex-end; background: var(--green); color: #fff; border-bottom-right-radius: 5px; }
.msg.bot { align-self: flex-start; background: var(--card); box-shadow: var(--shadow); border-bottom-left-radius: 5px; }
.msg.bot .followup { margin-top: .5rem; color: var(--muted); font-size: .9rem; }
.msg .speak-again { background: none; border: 0; cursor: pointer; font-size: .95rem; padding: 0; margin-left: .4rem; }
.chat-picks { display: flex; flex-direction: column; gap: .5rem; margin-top: .6rem; }
.ask-row {
  position: sticky; bottom: calc(64px + env(safe-area-inset-bottom));
  display: flex; gap: .4rem; align-items: center; background: var(--bg); padding: .4rem 0;
}
.ask-row input { flex: 1; }
.icon-btn.mic, .icon-btn.send { background: var(--card); border: 1.5px solid var(--line); }
.icon-btn.mic.listening { background: var(--terra); color: #fff; border-color: var(--terra); animation: pulse 1.2s infinite; }
.icon-btn.mic.thinking { background: var(--gold); color: #fff; border-color: var(--gold); }
.icon-btn.mic.speaking { background: var(--green); color: #fff; border-color: var(--green); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(194,109,79,.5);} 70% { box-shadow: 0 0 0 12px rgba(194,109,79,0);} 100% { box-shadow: 0 0 0 0 rgba(194,109,79,0);} }
.voice-state { text-align: center; font-size: .85rem; color: var(--muted); padding: .3rem 0; }
.typing { display: inline-block; }
.typing i { display: inline-block; width: 6px; height: 6px; margin: 0 2px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; font-style: normal; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25;} 40% { opacity: 1;} }

/* ---------- library map ---------- */
.space-block { margin-bottom: 1.2rem; }
.space-block h3 { margin-bottom: .5rem; font-size: 1.05rem; }
.shelf-card {
  display: flex; gap: .8rem; background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: .7rem; margin-bottom: .6rem; cursor: pointer;
  align-items: center;
}
.shelf-thumb {
  width: 62px; height: 62px; border-radius: 10px; object-fit: cover; flex: 0 0 auto;
  background: #e7ddcc; display: flex; align-items: center; justify-content: center; font-size: 1.5rem;
}
.shelf-main { flex: 1; min-width: 0; }
.shelf-name { font-weight: 700; font-family: var(--serif); }
.shelf-sub { font-size: .82rem; color: var(--muted); }
.badge {
  display: inline-block; font-size: .72rem; font-weight: 700; border-radius: 999px;
  padding: .15rem .6rem; background: var(--terra); color: #fff; margin-top: .25rem;
}
.empty-map { text-align: center; color: var(--muted); padding: 2.2rem 1rem; }
.empty-map .big { font-size: 2.2rem; margin-bottom: .5rem; }

/* shelf detail */
#shelfDetail { position: fixed; inset: 0; z-index: 40; background: var(--bg); overflow-y: auto; }
.detail-header {
  display: flex; align-items: center; gap: .5rem; padding: .8rem 1rem;
  padding-top: calc(.8rem + env(safe-area-inset-top));
  background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0;
}
.detail-header .wiz-title { flex: 1; }
.detail-body { padding: 1rem; max-width: 640px; margin: 0 auto; padding-bottom: 3rem; }
.context-photo { width: 100%; border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 1rem; }
.row-block { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: .8rem; margin-bottom: .8rem; }
.row-block-head { display: flex; align-items: center; gap: .6rem; }
.row-thumb { width: 54px; height: 40px; object-fit: cover; border-radius: 8px; background: #e7ddcc; }
.row-block-head .grow { flex: 1; min-width: 0; }
.row-books { margin-top: .6rem; border-top: 1px dashed var(--line); padding-top: .6rem; display: flex; flex-direction: column; gap: .35rem; }
.row-book-line { display: flex; gap: .5rem; font-size: .9rem; cursor: pointer; }
.row-book-line .pos { color: var(--muted); min-width: 1.6em; text-align: right; }

/* ---------- wizard ---------- */
#wizard { position: fixed; inset: 0; z-index: 50; background: var(--bg); overflow-y: auto; }
.wiz-header {
  display: flex; align-items: center; gap: .5rem; padding: .8rem 1rem;
  padding-top: calc(.8rem + env(safe-area-inset-top));
  background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5;
}
.wiz-title { flex: 1; font-size: 1.05rem; font-weight: 700; text-align: center; }
.wiz-body { padding: 1.1rem; max-width: 560px; margin: 0 auto; padding-bottom: 3rem; }
.wiz-step-label { font-size: .78rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-bottom: .4rem; }
.wiz-body .bubble { margin-bottom: 1rem; }
.camera-cta {
  width: 100%; border: 2px dashed var(--green); background: #eef2ee; color: var(--green);
  border-radius: var(--radius); padding: 2rem 1rem; font: inherit; font-weight: 700;
  cursor: pointer; text-align: center; font-size: 1.05rem;
}
.camera-cta .cam-icon { display: block; font-size: 2.2rem; margin-bottom: .4rem; }
.preview-img { width: 100%; border-radius: var(--radius); box-shadow: var(--shadow); margin: .8rem 0; }
.stepper { display: flex; align-items: center; gap: 1rem; justify-content: center; margin: .6rem 0 1rem; }
.stepper button {
  width: 46px; height: 46px; border-radius: 50%; border: 1.5px solid var(--line);
  background: var(--card); font-size: 1.4rem; cursor: pointer;
}
.stepper .stepper-val { font-size: 1.6rem; font-family: var(--serif); min-width: 2ch; text-align: center; }
.stepper-label { text-align: center; color: var(--muted); font-size: .85rem; margin-bottom: .2rem; }
.book-edit-list { display: flex; flex-direction: column; gap: .45rem; margin: .8rem 0; }
.book-edit {
  display: flex; gap: .4rem; align-items: center; background: var(--card);
  border-radius: 10px; padding: .35rem .45rem; box-shadow: var(--shadow);
}
.book-edit .num { color: var(--muted); font-size: .8rem; min-width: 1.6em; text-align: right; }
.book-edit input { border: 0; padding: .35rem .4rem; background: transparent; border-radius: 6px; min-width: 0; }
.book-edit input:focus { background: #f2ecdf; }
.book-edit input.bt { flex: 1.5 1 0; font-weight: 600; }
.book-edit input.ba { flex: 1 1 0; color: var(--muted); font-size: .88rem; }
.book-edit .del { background: none; border: 0; color: var(--danger); font-size: 1.05rem; cursor: pointer; padding: .2rem .35rem; }
.warn-box { background: #fdeeda; border: 1px solid #eccb96; color: #7a5b17; border-radius: 12px; padding: .7rem .9rem; margin: .7rem 0; font-size: .92rem; }
.ok-box { background: #e6efe9; border: 1px solid #bcd4c6; color: var(--green-dark); border-radius: 12px; padding: .7rem .9rem; margin: .7rem 0; font-size: .92rem; }
.diff-box { background: var(--card); border-radius: 12px; box-shadow: var(--shadow); padding: .7rem .9rem; margin: .7rem 0; font-size: .92rem; }
.progress-line { text-align: center; color: var(--muted); margin: 1rem 0; }
.spinner {
  width: 34px; height: 34px; margin: 1.4rem auto .8rem; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--green); animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.wiz-context-strip { position: relative; margin-bottom: .8rem; }
.wiz-context-strip img { width: 100%; border-radius: var(--radius); opacity: .92; }
.wiz-row-callout {
  position: absolute; left: .6rem; bottom: .6rem; background: rgba(43,38,32,.82); color: #fff;
  border-radius: 10px; padding: .3rem .7rem; font-size: .85rem;
}

/* ---------- modals ---------- */
.modal {
  position: fixed; inset: 0; z-index: 60; background: rgba(30, 24, 15, .5);
  display: flex; align-items: flex-end; justify-content: center;
}
.modal-card {
  width: 100%; max-width: 560px; max-height: 92dvh; overflow-y: auto;
  background: var(--bg); border-radius: 22px 22px 0 0; padding: 1.1rem;
  padding-bottom: calc(1.4rem + env(safe-area-inset-bottom));
}
@media (min-width: 600px) {
  .modal { align-items: center; }
  .modal-card { border-radius: 22px; }
}
.modal-grab { width: 44px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto .9rem; }
.bc-top { display: flex; gap: 1rem; }
.bc-cover { width: 108px; height: 156px; border-radius: 10px; object-fit: cover; flex: 0 0 auto;
  background: linear-gradient(160deg, #3c6b58, #234236); color: #f7f2e8; display: flex;
  align-items: center; justify-content: center; font-family: var(--serif); font-size: 2rem; }
.bc-main { flex: 1; min-width: 0; }
.bc-title { font-family: var(--serif); font-size: 1.25rem; font-weight: 700; line-height: 1.25; }
.bc-author { color: var(--muted); margin-top: .15rem; }
.bc-year { color: var(--muted); font-size: .85rem; }
.bc-section { margin-top: 1rem; }
.bc-section h4 { font-size: .8rem; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); margin-bottom: .4rem; }
.loc-box { background: var(--card); border-radius: 12px; box-shadow: var(--shadow); padding: .7rem .8rem; }
.loc-box .loc-line { color: var(--green-dark); font-weight: 600; }
.loc-box .neighbors { font-size: .86rem; color: var(--muted); margin-top: .3rem; }
.loc-box img { width: 100%; border-radius: 10px; margin-top: .6rem; cursor: zoom-in; }
.blurb { background: var(--card); border-radius: 12px; box-shadow: var(--shadow); padding: .8rem .9rem; font-size: .95rem; }
.bc-notes textarea { min-height: 74px; resize: vertical; }
.bc-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1rem; }
#modalPhoto { align-items: center; }
#zoomImg { max-width: 96vw; max-height: 90dvh; border-radius: 12px; }

/* settings */
.set-row { margin-bottom: 1rem; }
.set-row label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .3rem; }
.toggle-row { display: flex; align-items: center; justify-content: space-between; background: var(--card); border-radius: 12px; padding: .8rem .9rem; box-shadow: var(--shadow); }

/* toast */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 80;
  background: var(--ink); color: #fff; border-radius: 12px; padding: .6rem 1rem;
  font-size: .92rem; max-width: 90vw; text-align: center; box-shadow: var(--shadow);
}

/* household members in Settings */
.member-row { display: flex; align-items: center; gap: .6rem; background: var(--card);
              border-radius: 10px; padding: .55rem .7rem; box-shadow: var(--shadow); }
.member-row .grow { flex: 1; min-width: 0; }

/* Sweep coaching. Three lines, because a video that pans too fast is the one
   failure the user can't diagnose from the result. */
.wiz-tips { margin: .6rem 0 .5rem 1.1rem; padding: 0; }
.wiz-tips li { font-size: .9rem; margin-bottom: .35rem; }
p.small, .muted.small { font-size: .82rem; }
