/* Book Thrifting — phone-first, dark by default because the camera is the
   primary surface and a bright chrome around a live viewfinder is unusable. */

:root {
  --ink: #14110f;
  --ink-2: #1d1917;
  --ink-3: #2a2421;
  --line: #372f2a;
  --paper: #f4efe6;
  --paper-dim: #b7ada0;
  --paper-faint: #7d746a;
  --brass: #d9a441;
  --brass-dim: #8a6a2c;
  --hit: #6fce8f;
  --hit-dim: #1f3a29;
  --maybe: #d9a441;
  --danger: #e2725b;
  --radius: 14px;
  --tab-h: 58px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, system-ui, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--font);
  font-size: 16px;
  overscroll-behavior: none;
}
body { position: fixed; inset: 0; }

#app { position: absolute; inset: 0; display: flex; flex-direction: column; }

.view {
  position: absolute;
  inset: 0 0 calc(var(--tab-h) + var(--safe-b)) 0;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.view[hidden] { display: none; }

.scroll {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 0 16px calc(28px + var(--safe-b));
}

/* ── top bar ─────────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(var(--safe-t) + 14px) 16px 10px;
  flex: none;
}
.topbar h1 {
  font: 600 27px/1.1 var(--serif);
  letter-spacing: -0.01em; margin: 0;
}
.icon-btn {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--ink-3); border: 1px solid var(--line);
  color: var(--paper); display: grid; place-items: center; cursor: pointer;
  padding: 0; appearance: none; -webkit-appearance: none;
}
.icon-btn svg { width: 19px; height: 19px; }
.icon-btn:active { transform: scale(0.93); }

/* ── camera ──────────────────────────────────────────── */
.camera-stage {
  position: relative; flex: 1; overflow: hidden;
  background: #000; display: flex;
}
#video, .freeze {
  position: absolute; inset: 0;
  width: 100%; height: 100%; object-fit: cover;
}
/* The review frame shows the whole capture, which is wider than the live crop,
   so a highlighted book can never sit off the edge of the screen. */
.freeze { z-index: 2; object-fit: contain; background: #000; }
.freeze[hidden] { display: none; }
.overlay { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 3; pointer-events: none; }

.cam-idle {
  position: absolute; inset: 0; z-index: 5;
  display: grid; place-items: center;
  background: radial-gradient(120% 90% at 50% 40%, #221d1a, #100d0c);
  padding: 24px;
}
.cam-idle[hidden] { display: none; }
.cam-idle-inner { text-align: center; max-width: 300px; }
.cam-icon { color: var(--brass); margin-bottom: 18px; }
.cam-icon svg { width: 52px; height: 52px; }
.cam-idle h2 { font: 600 24px/1.2 var(--serif); margin: 0 0 8px; }
.cam-idle p { color: var(--paper-dim); font-size: 14.5px; line-height: 1.5; margin: 0 0 22px; }

.scan-status {
  position: absolute; z-index: 4; left: 50%; transform: translateX(-50%);
  top: calc(var(--safe-t) + 16px);
  display: flex; align-items: center; gap: 9px;
  background: rgba(20,17,15,.86); backdrop-filter: blur(12px);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 8px 16px 8px 12px; font-size: 13.5px; font-weight: 500;
}
.scan-status[hidden] { display: none; }
.spinner {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--brass-dim); border-top-color: var(--brass);
  animation: spin .7s linear infinite; flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

.sweep-pill {
  position: absolute; z-index: 4; left: 16px;
  top: calc(var(--safe-t) + 16px);
  display: flex; align-items: center; gap: 7px;
  background: rgba(20,17,15,.8); backdrop-filter: blur(12px);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 13px; font-size: 12.5px; color: var(--paper-dim);
}
.sweep-pill[hidden] { display: none; }
.sweep-pill .dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--brass);
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .25; } }

/* Three columns with equal 1fr sides, so the shutter is centred on the screen
   no matter what is in the side cells — a hidden torch button, a spacer, or
   nothing. A flex row with space-between centres it only while both sides
   happen to be the same width, which is a promise the markup cannot keep. */
.cam-controls {
  flex: none; display: grid; grid-template-columns: 1fr auto 1fr;
  align-items: center; padding: 14px 22px 16px; gap: 14px; background: var(--ink);
}
.cam-controls > .ghost-btn:first-child { justify-self: start; }
.cam-controls > .ghost-btn:last-of-type,
.cam-controls > .ghost-btn-spacer { justify-self: end; }
.cam-controls[hidden] { display: none; }
/* padding:0 and appearance:none matter here. A <button> carries a user-agent
   padding of 1px 6px, which leaves a 54px content box inside a 72px circle —
   too narrow for the 58px dot, which then sits 2px right of centre. Any
   fixed-size round button needs the same two resets. */
.shutter {
  width: 72px; height: 72px; border-radius: 50%;
  border: 3px solid var(--paper); background: transparent;
  padding: 0; appearance: none; -webkit-appearance: none;
  display: grid; place-items: center; cursor: pointer; flex: none;
  transition: transform .12s ease;
}
.shutter span {
  width: 58px; height: 58px; border-radius: 50%;
  background: var(--paper); display: block; transition: background .15s;
}
.shutter:active { transform: scale(0.93); }
.shutter:disabled { opacity: .45; }
.shutter:disabled span { background: var(--paper-faint); }

.ghost-btn, .ghost-btn-spacer {
  min-width: 76px; border: 0; background: transparent; color: var(--paper-dim);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  cursor: pointer; padding: 8px 4px; border-radius: 12px;
}
/* Both need this: the display rule above outranks the user-agent [hidden]
   rule, so without it a "hidden" spacer still occupies its column. */
.ghost-btn[hidden], .ghost-btn-spacer[hidden] { display: none; }
.ghost-btn-spacer { pointer-events: none; }
.ghost-btn-label { font-size: 13.5px; font-weight: 600; }
.ghost-btn-sub { font-size: 11px; letter-spacing: .04em; text-transform: uppercase; color: var(--paper-faint); }
.ghost-btn[aria-pressed="true"] { color: var(--brass); }
.ghost-btn[aria-pressed="true"] .ghost-btn-sub { color: var(--brass-dim); }

/* ── tab bar ─────────────────────────────────────────── */
.tabbar {
  position: absolute; bottom: 0; left: 0; right: 0; z-index: 20;
  height: calc(var(--tab-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: rgba(20,17,15,.94); backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
}
.tab {
  background: none; border: 0; color: var(--paper-faint); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 10.5px; letter-spacing: .02em; font-weight: 500; padding: 0;
}
.tab svg { width: 21px; height: 21px; }
.tab[aria-current="true"] { color: var(--brass); }
.tab:active { opacity: .6; }

/* ── forms ───────────────────────────────────────────── */
.field {
  width: 100%; background: var(--ink-3); border: 1px solid var(--line);
  color: var(--paper); border-radius: 11px; padding: 11px 14px;
  font-size: 16px; font-family: inherit; outline: none;
}
.field::placeholder { color: var(--paper-faint); }
.field:focus { border-color: var(--brass-dim); }
.field-lg { padding: 13px 15px; }
.list-tools { padding: 4px 0 14px; }

.btn {
  border: 0; border-radius: 11px; padding: 12px 18px;
  font-size: 15px; font-weight: 600; font-family: inherit; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--brass); color: #1b1408; }
.btn-quiet { background: var(--ink-3); color: var(--paper); border: 1px solid var(--line); }
.btn-block { width: 100%; }
.btn-stack { display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px; }
.text-btn { background: none; border: 0; color: var(--brass); font: 600 15px inherit; font-family: inherit; cursor: pointer; padding: 8px 4px; }

/* ── book rows ───────────────────────────────────────── */
.book-rows { display: flex; flex-direction: column; gap: 2px; padding-bottom: 12px; }
.book-row {
  display: flex; gap: 13px; align-items: flex-start;
  padding: 11px 0; border-bottom: 1px solid var(--line);
}
/* One size for both the artwork and the text stand-in. They cannot share a
   display value: `display: grid` on an <img> turns it into a grid container and
   the image itself is never painted. */
.cover, .cover-fallback {
  width: 46px; height: 68px; flex: none; border-radius: 4px;
  background: var(--ink-3);
  box-shadow: 0 2px 8px rgba(0,0,0,.4); overflow: hidden;
}
.cover { display: block; object-fit: cover; }
.cover-fallback {
  display: grid; place-items: center; padding: 4px;
  font: 600 9px/1.2 var(--font); color: var(--paper-faint); text-align: center;
}
.cover-lg { width: 62px; height: 92px; }
.book-meta { flex: 1; min-width: 0; }
.book-title { font: 600 15.5px/1.3 var(--font); margin: 1px 0 3px; }
.book-author { font-size: 13.5px; color: var(--paper-dim); line-height: 1.35; }
.book-sub { font-size: 12px; color: var(--paper-faint); margin-top: 4px; }
.row-action {
  flex: none; align-self: center; border: 1px solid var(--line);
  background: var(--ink-3); color: var(--paper-dim);
  width: 34px; height: 34px; border-radius: 50%;
  padding: 0; appearance: none; -webkit-appearance: none;
  display: grid; place-items: center; cursor: pointer;
}
.row-action svg { width: 16px; height: 16px; }
.row-action:active { transform: scale(0.9); }
.row-action.is-added { background: var(--hit-dim); border-color: transparent; color: var(--hit); }
.row-action.is-danger:active { color: var(--danger); }

.badge {
  display: inline-block; font-size: 10.5px; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; padding: 3px 7px; border-radius: 5px; margin-top: 6px;
}
.badge-got { background: var(--hit-dim); color: var(--hit); }
.badge-maybe { background: #3a2f14; color: var(--maybe); }

/* ── empty & misc ────────────────────────────────────── */
.empty { text-align: center; padding: 52px 22px; }
.empty[hidden] { display: none; }
.empty h3 { font: 600 20px/1.2 var(--serif); margin: 0 0 8px; }
.empty p { color: var(--paper-dim); font-size: 14.5px; line-height: 1.55; margin: 0 0 20px; }
.empty .btn { margin: 0 4px 8px; }

.section-label {
  font: 600 11.5px/1 var(--font); letter-spacing: .1em; text-transform: uppercase;
  color: var(--paper-faint); margin: 26px 0 10px;
}
.row-toggle, .row-slider {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 13px 0; border-bottom: 1px solid var(--line);
}
.row-toggle span, .row-slider span { display: flex; flex-direction: column; gap: 3px; }
.row-toggle strong, .row-slider strong { font-size: 15px; font-weight: 600; }
.row-toggle small, .row-slider small { font-size: 12.5px; color: var(--paper-dim); line-height: 1.4; }
.row-toggle input[type=checkbox] { width: 50px; height: 30px; flex: none; accent-color: var(--brass); }
.row-slider { flex-direction: column; align-items: stretch; }
.row-slider input[type=range] { width: 100%; accent-color: var(--brass); margin-top: 4px; }
.note { font-size: 13px; color: var(--paper-dim); line-height: 1.55; margin: 0 0 16px; }
.version { font-size: 11.5px; color: var(--paper-faint); text-align: center; padding: 8px 0 0; }
.stats {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
  margin: 6px 0 4px;
}
.stat { background: var(--ink-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 13px 10px; text-align: center; }
.stat b { display: block; font: 600 22px/1 var(--serif); color: var(--brass); }
.stat span { font-size: 11.5px; color: var(--paper-dim); }

/* ── sheets ──────────────────────────────────────────── */
.sheet-scrim {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,.55); backdrop-filter: blur(3px);
  display: flex; align-items: flex-end;
  animation: fade .18s ease;
}
.sheet-scrim[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } }
.sheet {
  background: var(--ink-2); width: 100%;
  border-radius: 20px 20px 0 0; border-top: 1px solid var(--line);
  max-height: 88vh; display: flex; flex-direction: column;
  padding-bottom: var(--safe-b);
  animation: rise .26s cubic-bezier(.22,1,.36,1);
}
@keyframes rise { from { transform: translateY(100%); } }
.sheet-grip {
  width: 38px; height: 4px; border-radius: 2px; background: var(--line);
  margin: 9px auto 4px; flex: none;
}
.sheet-head { display: flex; gap: 10px; align-items: center; padding: 8px 16px 12px; flex: none; }
.sheet-body { overflow-y: auto; padding: 0 16px 20px; -webkit-overflow-scrolling: touch; }
.sheet-result .sheet-body { padding-top: 6px; }

.hint { color: var(--paper-faint); font-size: 13.5px; text-align: center; padding: 34px 20px; line-height: 1.55; }

/* ── result sheet ────────────────────────────────────── */
.result-head { text-align: center; padding: 8px 8px 18px; }
.result-head .eyebrow {
  font-size: 11.5px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase;
  color: var(--brass); margin-bottom: 7px;
}
.result-head h2 { font: 600 26px/1.15 var(--serif); margin: 0 0 6px; }
.result-head p { color: var(--paper-dim); font-size: 14px; margin: 0; line-height: 1.5; }
.result-head.is-hit .eyebrow { color: var(--hit); }

.hit-card {
  display: block;
  background: var(--ink-3); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 13px; margin-bottom: 10px;
}
.hit-main { display: flex; gap: 14px; align-items: flex-start; }

.hit-card.is-hit { border-color: var(--hit); box-shadow: 0 0 0 1px var(--hit) inset; }
.hit-actions { display: flex; gap: 8px; margin-top: 10px; }
.hit-actions .btn { padding: 8px 14px; font-size: 13.5px; border-radius: 9px; }
.detected-line { font-size: 12px; color: var(--paper-faint); margin-top: 6px; }

.spine-list { margin-top: 8px; }
.spine-list summary {
  font-size: 13px; color: var(--paper-dim); cursor: pointer; padding: 10px 0;
  border-top: 1px solid var(--line); list-style: none;
}
.spine-list summary::-webkit-details-marker { display: none; }
.spine-list summary::after { content: ' ›'; }
.spine-list[open] summary::after { content: ' ⌄'; }
.spine-chips { display: flex; flex-wrap: wrap; gap: 6px; padding-bottom: 12px; }
.spine-chip {
  font-size: 12px; background: var(--ink-3); border: 1px solid var(--line);
  color: var(--paper-dim); padding: 5px 9px; border-radius: 7px;
}

/* ── toasts ──────────────────────────────────────────── */
.toast-wrap {
  position: fixed; left: 0; right: 0; z-index: 90;
  bottom: calc(var(--tab-h) + var(--safe-b) + 14px);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none; padding: 0 16px;
}
.toast {
  background: var(--paper); color: var(--ink); font-size: 14px; font-weight: 500;
  padding: 11px 17px; border-radius: 11px; box-shadow: 0 8px 26px rgba(0,0,0,.45);
  animation: toast-in .22s cubic-bezier(.22,1,.36,1); max-width: 100%;
}
.toast.is-bad { background: var(--danger); color: #fff; }
@keyframes toast-in { from { transform: translateY(14px); opacity: 0; } }

@media (min-width: 720px) {
  #app { max-width: 480px; margin: 0 auto; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
  .sheet { max-width: 480px; margin: 0 auto; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* Development only: ?mock=1 shows the fixture shelf where the viewfinder goes. */
.camera-stage.is-mock { background: #17130f url('/dev/mock-shelf.png') center/cover no-repeat; }
