:root {
  --bg: #faf7f2;
  --card: #ffffff;
  --ink: #2b2420;
  --ink-soft: #7a6f66;
  --line: #eae3da;
  --accent: #c25e40;
  --accent-soft: #f6e4dd;
  --gold: #e8a33d;
  --green: #4f8a5b;
  --radius: 16px;
  --shadow: 0 1px 3px rgba(43, 36, 32, .07), 0 4px 14px rgba(43, 36, 32, .05);
  --tabbar-h: calc(60px + env(safe-area-inset-bottom));
}

* { box-sizing: border-box; margin: 0; padding: 0; }

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100dvh;
}

.hidden { display: none !important; }

button { font: inherit; border: none; background: none; cursor: pointer; color: inherit; -webkit-tap-highlight-color: transparent; }
input { font: inherit; }

/* ---------- auth ---------- */

.auth-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(160deg, #f6ede3, #faf7f2 55%);
  overflow-y: auto;
}
.auth-card { width: 100%; max-width: 380px; text-align: center; margin: auto; }
.auth-logo { font-size: 52px; margin-bottom: 8px; }
.auth-card h1 { font-size: 34px; letter-spacing: -0.5px; }
.auth-sub { color: var(--ink-soft); margin: 6px 0 26px; }
.auth-card form { display: flex; flex-direction: column; gap: 12px; }
.auth-card input {
  padding: 14px 16px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  font-size: 16px;
}
.auth-card input:focus { outline: none; border-color: var(--accent); }
.auth-error { color: #b3402a; font-size: 14px; }

.landing { margin-top: 34px; text-align: left; }
.landing h2 { font-size: 17px; margin-bottom: 12px; text-align: center; }
.landing ul { list-style: none; display: flex; flex-direction: column; gap: 9px; }
.landing li { font-size: 14px; line-height: 1.45; color: var(--ink-soft); }
.landing li b { color: var(--ink); }
.landing p { font-size: 13px; color: var(--ink-soft); margin-top: 14px; text-align: center; }

.btn-primary {
  background: var(--accent);
  color: #fff;
  padding: 14px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 16px;
}
.btn-primary:active { transform: scale(.98); }
.btn-link { color: var(--accent); margin-top: 18px; font-size: 14.5px; }

/* ---------- layout ---------- */

.app main {
  max-width: 560px;
  margin: 0 auto;
  padding: 20px 16px calc(var(--tabbar-h) + 24px);
}

.view-title { font-size: 26px; letter-spacing: -0.4px; margin-bottom: 4px; }
.view-sub { color: var(--ink-soft); font-size: 14.5px; margin-bottom: 18px; }

.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--tabbar-h);
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  display: flex;
  z-index: 40;
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 11px;
  color: var(--ink-soft);
  font-weight: 500;
}
.tab-icon { font-size: 20px; filter: grayscale(1) opacity(.55); }
.tab.active { color: var(--accent); }
.tab.active .tab-icon { filter: none; }

/* ---------- book cards ---------- */

.book-list { display: flex; flex-direction: column; gap: 12px; }

.book-card {
  display: flex;
  gap: 14px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow);
  text-align: left;
  width: 100%;
  align-items: stretch;
}

.cover {
  width: 58px;
  min-width: 58px;
  height: 86px;
  border-radius: 8px;
  object-fit: cover;
  background: linear-gradient(150deg, #e8ddd0, #d8cabb);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  box-shadow: 0 2px 6px rgba(43, 36, 32, .18);
}

.book-main { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; gap: 3px; }
.book-title { font-weight: 600; font-size: 15.5px; line-height: 1.25; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.book-author { color: var(--ink-soft); font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.book-meta { color: var(--ink-soft); font-size: 12.5px; }

.progress-track {
  height: 6px;
  border-radius: 3px;
  background: var(--line);
  margin-top: 7px;
  overflow: hidden;
}
.progress-fill { height: 100%; border-radius: 3px; background: var(--accent); transition: width .3s ease; }
.progress-label { font-size: 12.5px; color: var(--ink-soft); margin-top: 5px; }
.progress-label b { color: var(--accent); }

.stars { display: inline-flex; gap: 2px; font-size: 16px; }
.stars.lg { font-size: 30px; gap: 10px; }
.star { filter: grayscale(1) opacity(.35); transition: transform .1s; }
.star.on { filter: none; }
.stars.lg .star:active { transform: scale(1.25); }

.badge {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 20px;
  background: var(--accent-soft);
  color: var(--accent);
  width: fit-content;
}
.badge.green { background: #e2efe5; color: var(--green); }

/* ---------- segmented control ---------- */

.segments {
  display: flex;
  background: #efe8df;
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 16px;
}
.segment {
  flex: 1;
  padding: 8px 4px;
  border-radius: 9px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink-soft);
}
.segment.active { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }

/* ---------- search ---------- */

.searchbar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  position: sticky;
  top: 12px;
  z-index: 10;
}
.searchbar input {
  flex: 1;
  padding: 13px 16px;
  border-radius: 12px;
  border: 1.5px solid var(--line);
  background: var(--card);
  font-size: 16px;
  box-shadow: var(--shadow);
}
.searchbar input:focus { outline: none; border-color: var(--accent); }

.add-btn {
  align-self: center;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
  font-size: 22px;
  width: 40px;
  height: 40px;
  min-width: 40px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.add-btn.added { background: #e2efe5; color: var(--green); font-size: 17px; }

.reason { font-size: 12.5px; color: var(--accent); font-weight: 500; }

/* ---------- empty states ---------- */

.empty {
  text-align: center;
  padding: 56px 24px;
  color: var(--ink-soft);
}
.empty .big { font-size: 44px; margin-bottom: 12px; }
.empty p { font-size: 14.5px; line-height: 1.5; }
.empty .btn-primary { margin-top: 18px; display: inline-block; width: auto; padding: 12px 22px; }

.spinner {
  margin: 48px auto;
  width: 28px; height: 28px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- bottom sheet ---------- */

.sheet-backdrop {
  position: fixed; inset: 0;
  background: rgba(30, 24, 20, .45);
  z-index: 50;
  animation: fade .2s ease;
}
@keyframes fade { from { opacity: 0; } }

.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 51;
  background: var(--card);
  border-radius: 22px 22px 0 0;
  padding: 10px 20px calc(20px + env(safe-area-inset-bottom));
  max-width: 560px;
  margin: 0 auto;
  animation: slideup .25s cubic-bezier(.2, .9, .3, 1);
  max-height: 85dvh;
  overflow-y: auto;
}
@keyframes slideup { from { transform: translateY(100%); } }

.sheet-grip { width: 40px; height: 4.5px; border-radius: 3px; background: var(--line); margin: 4px auto 14px; }

.sheet-x {
  position: sticky;
  top: 2px;
  z-index: 2;
  margin-left: auto;
  margin-bottom: -32px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #f2ece4;
  color: var(--ink-soft);
  font-size: 14px;
}

.sheet-head { display: flex; gap: 14px; margin-bottom: 18px; }
.sheet-title { font-size: 18px; font-weight: 700; line-height: 1.25; }
.sheet-author { color: var(--ink-soft); font-size: 14px; margin-top: 3px; }

.sheet h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .6px; color: var(--ink-soft); margin: 20px 0 10px; }

.big-progress { text-align: center; margin: 6px 0 2px; }
.big-progress .pct { font-size: 40px; font-weight: 700; color: var(--accent); letter-spacing: -1px; }
.big-progress .pages { color: var(--ink-soft); font-size: 14px; margin-top: 2px; }

input[type=range] {
  width: 100%;
  margin: 18px 0 6px;
  accent-color: var(--accent);
  height: 34px;
}

.quick-row { display: flex; gap: 8px; margin-top: 6px; }
.quick-btn {
  flex: 1;
  padding: 11px 0;
  border-radius: 11px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  font-size: 14.5px;
}
.quick-btn:active { transform: scale(.96); }

.page-input-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  font-size: 14.5px;
  color: var(--ink-soft);
}
.page-input-row input {
  width: 84px;
  padding: 10px 12px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  text-align: center;
  font-size: 16px;
}
.page-input-row input:focus { outline: none; border-color: var(--accent); }

.sheet-actions { display: flex; flex-direction: column; gap: 9px; margin-top: 22px; }
.sheet-btn {
  padding: 13px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 15px;
  background: #f2ece4;
  text-align: center;
}
.sheet-btn.primary { background: var(--accent); color: #fff; }
.sheet-btn.danger { color: #b3402a; background: #f8e8e4; }
a.sheet-btn { display: block; text-decoration: none; }
.sheet-btn.coffee { background: #ffdd00; color: #3b3222; }
a.coffee-card { display: flex; text-decoration: none; color: inherit; background: linear-gradient(135deg, #fff7d6, #ffedb8); }

.rate-center { text-align: center; padding: 6px 0; }

/* ---------- profile ---------- */

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 22px; }
.stat {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px 14px;
  text-align: center;
  box-shadow: var(--shadow);
}
.stat .n { font-size: 30px; font-weight: 700; color: var(--accent); letter-spacing: -1px; }
.stat .l { font-size: 12.5px; color: var(--ink-soft); margin-top: 3px; }

/* ---------- barcode scanner ---------- */

.scan-btn {
  width: 48px;
  min-width: 48px;
  border-radius: 12px;
  background: var(--card);
  border: 1.5px solid var(--line);
  box-shadow: var(--shadow);
  font-size: 20px;
}

.scanner {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.scanner video { width: 100%; height: 100%; object-fit: cover; }
.scanner-frame {
  position: absolute;
  width: min(78vw, 340px);
  height: 150px;
  border: 3px solid rgba(255, 255, 255, .9);
  border-radius: 16px;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .45);
}
.scanner-hint {
  position: absolute;
  bottom: calc(90px + env(safe-area-inset-bottom));
  color: #fff;
  font-size: 15px;
  text-align: center;
  width: 100%;
  padding: 0 20px;
  text-shadow: 0 1px 4px rgba(0, 0, 0, .7);
}
.scanner-close {
  position: absolute;
  top: calc(16px + env(safe-area-inset-top));
  right: 16px;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(0, 0, 0, .5);
  color: #fff;
  font-size: 18px;
}

/* ---------- goals ---------- */

.section-title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--ink-soft);
  margin: 22px 0 10px;
}
.goal-list { display: flex; flex-direction: column; gap: 10px; }
.goal-row {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  width: 100%;
  text-align: left;
  font-size: 14.5px;
}
.goal-row.add {
  color: var(--accent);
  font-weight: 600;
  text-align: center;
  background: var(--accent-soft);
  box-shadow: none;
}
.goal-top { display: flex; justify-content: space-between; font-weight: 600; margin-bottom: 8px; }
.goal-nums { color: var(--accent); }
.goal-nums.done { color: var(--green); }
.progress-fill.green { background: var(--green); }
.goal-window { font-size: 12px; color: var(--ink-soft); margin-top: 6px; }

/* ---------- multi-dimension ratings ---------- */

.rate-rows { display: flex; flex-direction: column; gap: 4px; }
.rate-row { display: flex; align-items: center; justify-content: space-between; padding: 6px 0; }
.rate-row .rate-label { font-size: 14.5px; font-weight: 600; }
.rate-row .stars { font-size: 24px; gap: 7px; }
.mini-rates { font-size: 12.5px; color: var(--ink-soft); }

/* ---------- premium / plan ---------- */

.plan-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: linear-gradient(135deg, #fdf3e3, #f6e4dd);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  font-size: 15px;
}
.plan-sub { display: block; font-size: 12.5px; color: var(--ink-soft); margin-top: 3px; font-weight: 400; }

.premium-features { display: flex; flex-direction: column; gap: 11px; margin: 14px 4px 6px; font-size: 14.5px; line-height: 1.4; }
.premium-note { text-align: center; font-size: 12.5px; color: var(--ink-soft); margin-top: 12px; line-height: 1.45; }

.rate-row.locked { opacity: .55; }
.goal-row.add.locked { opacity: .6; }

/* ---------- shelf chips ---------- */

.shelf-chips { display: flex; flex-wrap: wrap; gap: 8px; margin: -4px 0 16px; }
.chip {
  padding: 7px 13px;
  border-radius: 20px;
  background: var(--card);
  border: 1.5px solid var(--line);
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
}
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip.new { border-style: dashed; color: var(--accent); background: none; }

/* ---------- reading stats ---------- */

.year-picker { display: flex; align-items: center; justify-content: center; gap: 16px; margin-bottom: 16px; }
.year-picker .quick-btn { flex: 0 0 auto; padding: 8px 16px; }
.year-label { font-weight: 700; font-size: 17px; min-width: 52px; text-align: center; }

.chart-card { background: var(--card); border-radius: var(--radius); padding: 14px 12px 10px; box-shadow: var(--shadow); }
.bars { display: flex; align-items: flex-end; gap: 4px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 3px; }
.bar { width: 100%; max-width: 22px; border-radius: 4px 4px 0 0; background: var(--accent); }
.bar.alt { background: var(--gold); }
.bar-val, .bar-lab { font-size: 10px; color: var(--ink-soft); }

.top-row { display: flex; justify-content: space-between; gap: 12px; padding: 8px 4px; font-size: 14.5px; }
.top-row b { color: var(--accent); white-space: nowrap; }

/* locked stats preview for free accounts */
.stats-teaser { position: relative; width: 100%; overflow: hidden; }
.teaser-bars { filter: blur(3px) grayscale(.4) opacity(.45); pointer-events: none; }
.teaser-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  text-align: center;
  padding: 12px;
}
.teaser-lock { font-size: 26px; }

/* ---------- admin ---------- */

.admin-card { background: var(--card); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.admin-input {
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  font-size: 15px;
  margin-bottom: 10px;
}
.admin-input:focus { outline: none; border-color: var(--accent); }
.admin-card .quick-row { margin: 0 0 6px; }
.admin-user {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 10px 2px;
  border-top: 1px solid var(--line);
  font-size: 13.5px;
}
.admin-user:first-of-type { margin-top: 8px; }
.admin-user .sub { color: var(--ink-soft); font-size: 12px; white-space: nowrap; }

/* ---------- home dashboard ---------- */

.goal-hero {
  display: block;
  width: 100%;
  text-align: left;
  background: linear-gradient(135deg, var(--accent), #d97a5a);
  color: #fff;
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}
.goal-hero-top { display: flex; justify-content: space-between; gap: 10px; font-weight: 600; font-size: 14.5px; margin-bottom: 10px; }
.goal-hero .progress-track { background: rgba(255, 255, 255, .28); margin-top: 0; }
.goal-hero .progress-fill { background: #fff; }
.goal-hero-sub { font-size: 12.5px; opacity: .9; margin-top: 8px; }

.chip-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.chip-stat {
  background: var(--card);
  border-radius: var(--radius);
  padding: 12px 6px;
  text-align: center;
  box-shadow: var(--shadow);
}
.chip-stat .n { font-size: 21px; font-weight: 700; color: var(--accent); letter-spacing: -0.5px; }
.chip-stat .l { font-size: 11px; color: var(--ink-soft); margin-top: 2px; }

/* ---------- cookie note & privacy ---------- */

.cookie-note {
  position: fixed;
  bottom: calc(var(--tabbar-h) + 10px);
  left: 12px;
  right: 12px;
  max-width: 536px;
  margin: 0 auto;
  z-index: 45;
  background: var(--ink);
  color: #fff;
  border-radius: 14px;
  padding: 12px 14px;
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  line-height: 1.4;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .28);
}
.cookie-note .btn-primary { padding: 8px 14px; font-size: 13px; flex: 0 0 auto; border-radius: 10px; }
.cookie-link { color: #f3b992; text-decoration: underline; font-size: 13px; padding: 0; }

.privacy-text p { font-size: 14px; line-height: 1.55; color: var(--ink-soft); margin-bottom: 4px; }
.privacy-text b, .privacy-text code { color: var(--ink); }
.privacy-text a { color: var(--accent); }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  bottom: calc(var(--tabbar-h) + 14px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 11px 20px;
  border-radius: 24px;
  font-size: 14px;
  z-index: 60;
  white-space: nowrap;
  animation: fade .2s ease;
}
