/* Designed for older eyes and fingers: large type, high contrast,
   big tap targets (60px+), and nothing that only works on hover. */
:root {
  color-scheme: light;
  --bg: #fbf7f0;
  --card: #ffffff;
  --ink: #1d1b18;
  --muted: #5a554d;
  --line: #e2dacb;
  --brand: #2f5d50;
  --brand-ink: #ffffff;
  --brand-soft: #e3eee9;
  --danger: #a3261b;
  --tab-h: 88px;
  font-size: 21px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.4;
  padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 24px);
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg);
  border-bottom: 2px solid var(--line);
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  display: flex; align-items: center; gap: 12px; min-height: 72px;
}
.topbar h1 { margin: 0; font-size: 1.5rem; flex: 1; line-height: 1.2; overflow-wrap: anywhere; }
.back {
  border: 2px solid var(--brand); background: var(--card); color: var(--brand);
  border-radius: 14px; padding: 8px 16px; font-weight: 700; min-height: 52px;
}

main { padding: 16px; max-width: 720px; margin: 0 auto; }

/* ---------- Bottom tabs ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: grid; grid-template-columns: 1fr 1fr 1fr;
  background: var(--card); border-top: 2px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: var(--tab-h); text-decoration: none; color: var(--muted);
  font-weight: 700; font-size: 0.85rem; gap: 2px;
}
.tabs .ico { font-size: 1.7rem; line-height: 1; }
.tabs a.active { color: var(--brand); background: var(--brand-soft); }
.tabs a.add .ico {
  background: var(--brand); color: var(--brand-ink); border-radius: 50%;
  width: 44px; height: 44px; display: grid; place-items: center; font-weight: 800;
}

/* ---------- Common bits ---------- */
.lead { font-size: 1.15rem; margin: 4px 0 16px; }
.muted { color: var(--muted); }
.count { font-size: 1.05rem; color: var(--muted); margin: 0 0 12px; }

.btn {
  display: block; width: 100%; min-height: 64px; border-radius: 16px;
  border: 2px solid var(--brand); background: var(--brand); color: var(--brand-ink);
  font-weight: 700; font-size: 1.1rem; padding: 12px 18px; text-align: center; text-decoration: none;
}
.btn.secondary { background: var(--card); color: var(--brand); }
.btn.danger { background: var(--card); color: var(--danger); border-color: var(--danger); }
.btn + .btn { margin-top: 12px; }

.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 16px; }
.segmented button {
  min-height: 56px; border-radius: 14px; border: 2px solid var(--brand);
  background: var(--card); color: var(--brand); font-weight: 700; font-size: 0.95rem;
}
.segmented button[aria-pressed="true"] { background: var(--brand); color: var(--brand-ink); }

.chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 0 0 12px; }
.chips button {
  min-height: 48px; padding: 6px 18px; border-radius: 999px; border: 2px solid var(--line);
  background: var(--card); font-weight: 700;
}
.chips button[aria-pressed="true"] { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); }

/* ---------- Book rows ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.letter {
  font-size: 1.3rem; font-weight: 800; color: var(--brand);
  margin: 20px 4px 8px; border-bottom: 2px solid var(--line);
}
.row {
  display: flex; align-items: center; gap: 14px; width: 100%;
  background: var(--card); border: 2px solid var(--line); border-radius: 16px;
  padding: 12px; margin-bottom: 10px; text-align: left; min-height: 76px;
}
.row:active { background: var(--brand-soft); }
.cover {
  flex: none; width: 52px; height: 76px; border-radius: 6px; object-fit: cover;
  background: var(--brand-soft); display: grid; place-items: center; font-size: 1.6rem;
}
.row .text { flex: 1; min-width: 0; }
.row .t { font-weight: 700; font-size: 1.05rem; display: block; }
.row .a { color: var(--muted); display: block; }
.row .chev { color: var(--muted); font-size: 1.6rem; flex: none; }
.row .num {
  flex: none; min-width: 44px; height: 44px; border-radius: 22px; padding: 0 10px;
  background: var(--brand-soft); color: var(--brand); font-weight: 800; display: grid; place-items: center;
}

/* ---------- Search ---------- */
label.big { display: block; font-weight: 700; font-size: 1.15rem; margin-bottom: 8px; }
.search {
  width: 100%; min-height: 68px; font-size: 1.25rem; padding: 12px 16px;
  border: 3px solid var(--brand); border-radius: 16px; background: var(--card);
}
.search:focus { outline: 4px solid var(--brand-soft); }
.status { margin: 14px 4px; font-size: 1.05rem; color: var(--muted); }
.field { margin-bottom: 18px; }

.empty { text-align: center; padding: 32px 8px; }
.empty .big-ico { font-size: 3.5rem; }

/* ---------- Bottom sheet (confirmations) ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.45);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet-backdrop[hidden] { display: none; }
.sheet {
  background: var(--bg); width: 100%; max-width: 720px; border-radius: 24px 24px 0 0;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom)); max-height: 92vh; overflow-y: auto;
  text-align: center;
}
.sheet img.big-cover { width: 130px; height: 190px; object-fit: cover; border-radius: 8px; box-shadow: 0 4px 14px rgba(0,0,0,.2); }
.sheet .big-cover.placeholder { width: 130px; height: 190px; margin: 0 auto; border-radius: 8px; background: var(--brand-soft); display: grid; place-items: center; font-size: 3rem; }
.sheet h2 { font-size: 1.4rem; margin: 14px 0 4px; }
.sheet .by { font-size: 1.1rem; color: var(--muted); margin: 0 0 20px; }
.sheet .q { font-size: 1.2rem; font-weight: 700; margin: 0 0 16px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 16px; right: 16px; z-index: 30;
  bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 16px);
  background: var(--ink); color: #fff; border-radius: 16px; padding: 18px;
  font-size: 1.15rem; font-weight: 700; text-align: center; max-width: 560px; margin: 0 auto;
}
.toast[hidden] { display: none; }

/* ---------- My Books: search + three sort buttons ---------- */
.searchbox { margin-bottom: 16px; }
.search-wrap { display: flex; gap: 8px; }
.search-wrap .search { flex: 1; min-width: 0; }
.clear {
  flex: none; min-height: 68px; padding: 0 14px; border-radius: 16px;
  border: 2px solid var(--brand); background: var(--card); color: var(--brand); font-weight: 700;
}
.clear[hidden] { display: none; }
.segmented.three { grid-template-columns: 1fr 1fr 1fr; }
.segmented.three button { line-height: 1.2; padding: 6px 4px; min-height: 64px; }
/* One big "Clear" button is enough; hide the browser's tiny built-in one. */
input[type=search]::-webkit-search-cancel-button { -webkit-appearance: none; display: none; }
