/* =========================================================================
   Omahaindia Library — application shell
   Light, warm and calm. The books themselves are loud and colourful, so the
   chrome around them stays quiet: white cards, generous spacing, one accent.
   ========================================================================= */

:root {
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --ink: #0f172a;
  --ink-2: #475569;
  --ink-3: #94a3b8;
  --line: #e2e8f0;

  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --brand-soft: #eff6ff;
  --accent: #f97316;
  --accent-soft: #fff7ed;
  --good: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;

  --r-sm: 10px;
  --r: 16px;
  --r-lg: 22px;
  --shadow-1: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .04);
  --shadow-2: 0 4px 12px rgba(15, 23, 42, .07), 0 2px 4px rgba(15, 23, 42, .04);
  --shadow-3: 0 12px 32px rgba(15, 23, 42, .12);

  /* Literata was commissioned specifically for reading books on screen, so it
     carries the body text; Fraunces gives headings warmth and character without
     tipping into novelty. Both are variable fonts, self-hosted, 149 KB total. */
  --font: "Literata", Georgia, "Iowan Old Style", serif;
  --font-display: "Fraunces", var(--font);
  /* A companion sans for dense UI — tables, tags, metadata — where a serif at
     11-13px turns muddy. */
  --font-ui: system-ui, -apple-system, "Segoe UI", sans-serif;

  --topbar-h: 64px;
  --tabbar-h: 62px;
  --wrap: 1240px;
}

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

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-weight: 400;
  line-height: 1.5;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

img { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }

:focus-visible {
  outline: 3px solid var(--brand);
  outline-offset: 2px;
  border-radius: 6px;
}

/* Respect a user's motion preference — animation here is decoration, never
   the only signal that something changed. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- typography ----------
   One scale, used everywhere. Before this pass, components set their own sizes
   inline (12.5px here, 13px there) and nothing lined up; every size below is
   now a named step and inline overrides have been removed. */
:root {
  --t-xs: 12px;    /* metadata, table headers  */
  --t-sm: 13.5px;  /* secondary UI text        */
  --t-md: 15px;    /* default UI text          */
  --t-lg: 17px;    /* body copy                */
}

h1 { font-family: var(--font-display); font-size: clamp(26px, 4vw, 36px); font-weight: 700; letter-spacing: -.015em; line-height: 1.15; }
h2 { font-family: var(--font-display); font-size: clamp(19px, 2.6vw, 23px); font-weight: 700; letter-spacing: -.01em; line-height: 1.25; }
h3 { font-family: var(--font-display); font-size: var(--t-lg); font-weight: 700; }
.sub { color: var(--ink-2); font-weight: 400; font-size: var(--t-md); }
.muted { color: var(--ink-3); }

/* Dense UI keeps a sans: a serif below ~14px turns muddy on a phone, and these
   are scan targets rather than reading text. */
.tag, .chip, .card-meta, .series-count, .note-date, .note-at,
.stat-tile .label, .metric span, .rewards-stat span,
table, .log-row, .spark-labels, .badge small, .hint,
.tabbar, .btn, .card-badge, .banner-eyebrow {
  font-family: var(--font-ui);
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 18px; border-radius: 999px; border: 1px solid transparent;
  font-weight: 800; font-size: var(--t-md); cursor: pointer; background: none;
  transition: transform .12s ease, background .15s ease, box-shadow .15s ease;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px) scale(.99); }
.btn-primary { background: var(--brand); color: #fff; box-shadow: var(--shadow-2); }
.btn-primary:hover { background: var(--brand-dark); }
.btn-accent { background: var(--accent); color: #fff; box-shadow: var(--shadow-2); }
.btn-ghost { color: var(--ink-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn-outline { border-color: var(--line); background: var(--surface); }
.btn-outline:hover { border-color: var(--brand); color: var(--brand); }
.btn-danger { background: var(--bad); color: #fff; }
.btn-block { width: 100%; }
.btn-sm { padding: 7px 13px; font-size: var(--t-sm); }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

.iconbtn {
  display: grid; place-items: center; width: 40px; height: 40px;
  border-radius: 12px; border: none; background: none; cursor: pointer; color: var(--ink-2);
  transition: background .15s ease, color .15s ease;
}
.iconbtn:hover { background: var(--surface-2); color: var(--ink); }
.iconbtn.on { color: var(--accent); background: var(--accent-soft); }

/* ---------- topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 16px;
  padding: 0 clamp(14px, 3vw, 28px);
  background: rgba(255, 255, 255, .86);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.logo { display: flex; align-items: center; gap: 9px; flex-shrink: 0; }
.logo-text { font-family: var(--font-display); font-weight: 700; font-size: var(--t-lg); letter-spacing: -.01em; }
.logo-text b { font-weight: 800; color: var(--brand); }
@media (max-width: 640px) { .logo-text { display: none; } }

.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.badge-admin {
  background: var(--ink); color: #fff; font-size: var(--t-xs); font-weight: 800;
  padding: 3px 9px; border-radius: 999px; letter-spacing: .04em; text-transform: uppercase;
}

/* ---------- search ---------- */
.search { position: relative; flex: 1; max-width: 480px; }
.search input {
  width: 100%; padding: 10px 14px 10px 40px;
  border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface-2); font-weight: 600; font-size: var(--t-md);
  transition: background .15s, border-color .15s, box-shadow .15s;
}
.search input:focus {
  background: var(--surface); border-color: var(--brand);
  box-shadow: 0 0 0 4px var(--brand-soft); outline: none;
}
.search-icon { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--ink-3); pointer-events: none; }

/* ---------- streak chip ---------- */
.streak-chip {
  display: inline-flex; align-items: center; gap: 5px;
  background: linear-gradient(135deg, #fff7ed, #ffedd5);
  border: 1px solid #fed7aa; color: #c2410c;
  padding: 6px 13px; border-radius: 999px; font-weight: 800; font-size: var(--t-md);
}
.streak-chip .flame { font-size: var(--t-md); }
.streak-chip.cold { background: var(--surface-2); border-color: var(--line); color: var(--ink-3); }

/* ---------- avatars ---------- */
.avatar-btn { border: none; background: none; cursor: pointer; padding: 0; border-radius: 50%; }
.avatar {
  display: grid; place-items: center;
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--brand-soft); color: var(--brand);
  font-family: var(--font-display); font-weight: 800; font-size: var(--t-lg);
  border: 2px solid var(--surface); box-shadow: var(--shadow-1);
}
.avatar.lg { width: 96px; height: 96px; font-size: 38px; }

/* ---------- layout ---------- */
main { max-width: var(--wrap); margin: 0 auto; padding: clamp(18px, 3vw, 34px) clamp(14px, 3vw, 28px) 60px; }
section + section { margin-top: 34px; }

/* ---------- shelves ---------- */
.shelf { margin-bottom: 34px; }
.shelf-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 13px; }
.shelf-head h2 { display: flex; align-items: center; gap: 9px; }
.shelf-head a { font-size: var(--t-md); font-weight: 800; color: var(--brand); }

/* Horizontal scroller with snap — the Netflix row, but touch-first. */
.shelf-row {
  display: grid; grid-auto-flow: column; grid-auto-columns: 158px;
  gap: 15px; overflow-x: auto; overscroll-behavior-x: contain;
  scroll-snap-type: x mandatory; padding: 4px 4px 14px;
  scrollbar-width: thin; scrollbar-color: var(--line) transparent;
}
.shelf-row::-webkit-scrollbar { height: 7px; }
.shelf-row::-webkit-scrollbar-thumb { background: var(--line); border-radius: 999px; }
.shelf-row > * { scroll-snap-align: start; }
@media (min-width: 700px) { .shelf-row { grid-auto-columns: 178px; } }

.grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
@media (min-width: 700px) { .grid { grid-template-columns: repeat(auto-fill, minmax(172px, 1fr)); } }

/* ---------- engagement nudges ----------
   An invitation, never a countdown. One line of state, one line of action,
   and the whole thing is a link so there is nothing to decide. */
.nudge {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 18px; border-radius: var(--r);
  margin-bottom: 18px; box-shadow: var(--shadow-1);
  transition: transform .15s ease, box-shadow .15s ease;
}
.nudge:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); }
.nudge b { display: block; font-size: var(--t-lg); }
.nudge span:not(.nudge-icon) { font-size: var(--t-sm); font-weight: 600; opacity: .85; }
.nudge-icon {
  width: 42px; height: 42px; border-radius: 50%; flex-shrink: 0;
  display: grid; place-items: center;
}
.nudge-streak {
  background: linear-gradient(135deg, #fff7ed, #ffedd5);
  border: 1px solid #fed7aa; color: #9a3412;
}
.nudge-streak .nudge-icon { background: rgba(234, 88, 12, .14); color: #c2410c; }

/* ---------- series banner ----------
   The front door of the library. One per series: artwork, blurb and progress,
   the whole thing a single link into the book. --accent is set per series. */
.series-block { margin-bottom: 40px; }

/* All series sit in one horizontal scroller of vertical cards, so however many
   series exist they stay on one screen and are swiped through rather than
   scrolled past. */
.banner-row {
  display: grid; grid-auto-flow: column; grid-auto-columns: 268px;
  gap: 18px; overflow-x: auto; overscroll-behavior-x: contain;
  scroll-snap-type: x mandatory; padding: 4px 4px 18px;
  scrollbar-width: thin; scrollbar-color: var(--line) transparent;
}
.banner-row::-webkit-scrollbar { height: 8px; }
.banner-row::-webkit-scrollbar-thumb { background: var(--line); border-radius: 999px; }
.banner-row > * { scroll-snap-align: start; }
@media (min-width: 700px) { .banner-row { grid-auto-columns: 300px; } }

.banner {
  display: flex; flex-direction: column;
  padding: 18px;
  border-radius: var(--r-lg);
  background:
    linear-gradient(160deg, color-mix(in srgb, var(--accent) 10%, #fff) 0%,
                            color-mix(in srgb, var(--accent) 3%, #fff) 100%);
  border: 1px solid color-mix(in srgb, var(--accent) 22%, var(--line));
  box-shadow: var(--shadow-1);
  transition: transform .18s cubic-bezier(.2,.8,.3,1), box-shadow .18s ease;
  height: 100%;
}
/* Fallback for engines without color-mix. */
@supports not (color: color-mix(in srgb, red 50%, blue)) {
  .banner { background: var(--surface); border-color: var(--line); }
}
.banner:hover { transform: translateY(-4px); box-shadow: var(--shadow-3); }
.banner:active { transform: translateY(-1px); }

.banner-cover {
  width: 100%; aspect-ratio: 3/4; border-radius: var(--r);
  overflow: hidden; box-shadow: var(--shadow-2);
  margin-bottom: 14px; transition: transform .2s ease;
}
.banner:hover .banner-cover { transform: scale(1.02); }
.banner-cover { background: var(--surface-2); display: grid; place-items: center; }
.banner-cover img { width: 100%; height: 100%; object-fit: cover; }

.banner-eyebrow {
  font-size: var(--t-xs); font-weight: 800; letter-spacing: .06em; text-transform: uppercase;
  color: var(--accent); margin-bottom: 5px;
}
.banner-title {
  font-family: var(--font-display); font-size: 20px;
  font-weight: 800; line-height: 1.15; margin-bottom: 4px;
}
.banner-tagline {
  font-size: var(--t-sm); font-weight: 700; color: var(--ink-2); margin-bottom: 8px;
  line-height: 1.4;
}
/* The blurb is clamped so every card is the same height regardless of how
   long its copy is; the full text is on the book itself. */
.banner-writeup {
  font-size: var(--t-sm); font-weight: 600; color: var(--ink-2); line-height: 1.55;
  margin-bottom: 12px;
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical;
  overflow: hidden;
}
.banner-progress {
  height: 6px; border-radius: 999px; background: rgba(255,255,255,.8);
  overflow: hidden; margin-bottom: 12px;
}
.banner-progress i {
  display: block; height: 100%; border-radius: 999px; background: var(--accent);
  transition: width .5s ease;
}
/* Pinned to the bottom so the CTA lines up across cards of differing text. */
.banner-cta { margin-top: auto; display: flex; flex-direction: column; gap: 7px; }
.banner-cta .btn { background: var(--accent); pointer-events: none; width: 100%; }
.banner-next {
  font-size: var(--t-sm); font-weight: 700; color: var(--ink-3);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ---------- series shelves ---------- */
/* The home screen is organised series-first: each series gets its own shelf
   with a completion bar, so a child sees "the country books" as a collection
   rather than a flat list of titles. */
.section-divider {
  display: flex; align-items: center; gap: 14px;
  margin: 34px 0 22px; color: var(--ink-3);
  font-size: var(--t-sm); font-weight: 800; text-transform: uppercase; letter-spacing: .08em;
}
.section-divider::before, .section-divider::after {
  content: ""; flex: 1; height: 1px; background: var(--line);
}

.series-shelf { margin-bottom: 30px; }
.series-title { display: flex; align-items: baseline; gap: 11px; flex-wrap: wrap; }
.series-count {
  font-size: var(--t-sm); font-weight: 800; color: var(--ink-3);
  background: var(--surface-2); border-radius: 999px; padding: 3px 11px;
}
.series-bar {
  height: 6px; border-radius: 999px; background: var(--surface-2);
  overflow: hidden; margin: 4px 0 12px; max-width: 340px;
}
.series-bar i {
  display: block; height: 100%; border-radius: 999px;
  background: linear-gradient(90deg, var(--brand), var(--accent));
  transition: width .5s ease;
}

/* ---------- book card ---------- */
.card {
  position: relative; display: flex; flex-direction: column; gap: 9px;
  border-radius: var(--r); cursor: pointer;
  transition: transform .16s cubic-bezier(.2, .8, .3, 1);
}
.card:hover { transform: translateY(-4px); }
.card:hover .card-cover { box-shadow: var(--shadow-3); }

/* Every cover is generated at exactly 600x800, so the card fills edge to edge
   with no letterboxing. See services/covers.js for how mixed-shape sources are
   normalised onto that canvas. */
.card-cover {
  position: relative; aspect-ratio: 3 / 4; border-radius: var(--r);
  overflow: hidden; background: var(--surface-2);
  box-shadow: var(--shadow-2); transition: box-shadow .16s ease;
  display: grid; place-items: center;
}
.card-cover img { width: 100%; height: 100%; object-fit: cover; }

.card-title { font-size: var(--t-md); font-weight: 800; line-height: 1.3; }
.card-meta { font-size: var(--t-sm); color: var(--ink-3); font-weight: 700; }

/* Progress ribbon along the bottom of the cover. */
.card-progress {
  position: absolute; left: 0; right: 0; bottom: 0; height: 5px;
  background: rgba(255, 255, 255, .45);
}
.card-progress i { display: block; height: 100%; background: var(--accent); }

.card-badge {
  position: absolute; top: 9px; left: 9px;
  background: rgba(15, 23, 42, .78); color: #fff;
  font-size: var(--t-xs); font-weight: 800; padding: 4px 9px; border-radius: 999px;
  backdrop-filter: blur(4px);
}
.card-badge.done { background: rgba(22, 163, 74, .92); }
.card-fav {
  position: absolute; top: 7px; right: 7px;
  width: 32px; height: 32px; border-radius: 50%; border: none; cursor: pointer;
  display: grid; place-items: center;
  background: rgba(255, 255, 255, .82); backdrop-filter: blur(4px);
  color: var(--ink-3); transition: transform .15s, color .15s;
}
.card-fav.on { color: var(--bad); }
.card-fav:active { transform: scale(.88); }
.card-reason { font-size: var(--t-xs); color: var(--brand); font-weight: 800; }

/* ---------- hero / continue reading ---------- */
.hero {
  display: grid; gap: 20px; align-items: center;
  grid-template-columns: 1fr; margin-bottom: 30px;
  background: linear-gradient(135deg, #eff6ff 0%, #fff7ed 100%);
  border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: clamp(18px, 3vw, 28px);
}
@media (min-width: 760px) { .hero { grid-template-columns: 150px 1fr auto; } }
.hero-cover { width: 130px; aspect-ratio: 3/4; border-radius: var(--r); overflow: hidden; box-shadow: var(--shadow-3); }
.hero-cover img { width: 100%; height: 100%; object-fit: cover; }
.hero h1 { margin-bottom: 5px; }
.hero-eyebrow { font-size: var(--t-sm); font-weight: 800; color: var(--brand); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 6px; }
.hero-bar { height: 9px; border-radius: 999px; background: rgba(255, 255, 255, .7); overflow: hidden; margin: 12px 0 7px; max-width: 420px; }
.hero-bar i { display: block; height: 100%; background: var(--accent); border-radius: 999px; transition: width .5s ease; }
.hero-skeleton { height: 190px; border-radius: var(--r-lg); }

/* ---------- greeting strip ---------- */
.greet { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 22px; }
.greet h1 { flex: 1; min-width: 200px; }
.stat-pills { display: flex; gap: 9px; flex-wrap: wrap; }
.pill {
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  padding: 7px 15px; font-size: var(--t-sm); font-weight: 800; box-shadow: var(--shadow-1);
}
.pill b { color: var(--brand); }

/* ---------- goal ring ---------- */
.goal-ring { display: flex; align-items: center; gap: 12px; }
.ring { --pct: 0; width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(var(--accent) calc(var(--pct) * 1%), var(--surface-2) 0);
  position: relative; flex-shrink: 0; }
.ring::after { content: ""; position: absolute; inset: 6px; background: var(--surface); border-radius: 50%; }
.ring span { position: relative; z-index: 1; font-size: var(--t-sm); font-weight: 800; }

/* ---------- categories ---------- */
.filter-bar { display: flex; gap: 9px; overflow-x: auto; padding: 4px 4px 16px; scrollbar-width: none; }
.filter-bar::-webkit-scrollbar { display: none; }
.chip {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-2);
  padding: 8px 16px; border-radius: 999px; font-weight: 800; font-size: var(--t-md);
  cursor: pointer; white-space: nowrap; transition: all .15s;
}
.chip:hover { border-color: var(--brand); color: var(--brand); }
.chip.active { background: var(--ink); border-color: var(--ink); color: #fff; }

/* ---------- tabbar ----------
   Sits directly under the header on every screen size. A top bar keeps the
   tabs in view next to the page title, and leaves the bottom of the screen
   free — which matters most in the reader, where thumbs rest. */
.tabbar {
  position: sticky; top: var(--topbar-h); z-index: 39;
  display: flex; gap: 3px; align-items: center;
  padding: 7px clamp(10px, 3vw, 28px);
  background: rgba(255, 255, 255, .94); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  overflow-x: auto; scrollbar-width: none;
}
.tabbar::-webkit-scrollbar { display: none; }
.tabbar a {
  display: flex; flex-direction: row; align-items: center; gap: 7px;
  padding: 8px 15px; border-radius: 999px; white-space: nowrap;
  font-size: var(--t-sm); font-weight: 800; color: var(--ink-3);
  transition: background .15s, color .15s;
}
.tabbar a:hover { background: var(--surface-2); color: var(--ink-2); }
.tabbar a.active { color: var(--brand); background: var(--brand-soft); }
.tabbar .ico { width: 18px; height: 18px; }
.tabbar .ico { width: 22px; height: 22px; background: currentColor;
  -webkit-mask-size: contain; mask-size: contain; -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat; }
.ico[data-ico="home"]   { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 10l9-7 9 7v10a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 10l9-7 9 7v10a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z'/%3E%3C/svg%3E"); }
.ico[data-ico="grid"]   { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.2' stroke-linejoin='round'%3E%3Crect x='3' y='3' width='7' height='7' rx='1.5'/%3E%3Crect x='14' y='3' width='7' height='7' rx='1.5'/%3E%3Crect x='3' y='14' width='7' height='7' rx='1.5'/%3E%3Crect x='14' y='14' width='7' height='7' rx='1.5'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.2' stroke-linejoin='round'%3E%3Crect x='3' y='3' width='7' height='7' rx='1.5'/%3E%3Crect x='14' y='3' width='7' height='7' rx='1.5'/%3E%3Crect x='3' y='14' width='7' height='7' rx='1.5'/%3E%3Crect x='14' y='14' width='7' height='7' rx='1.5'/%3E%3C/svg%3E"); }
.ico[data-ico="heart"]  { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.2' stroke-linejoin='round'%3E%3Cpath d='M12 21s-7-4.6-9.3-8.4C.6 9.3 2.4 5 6.2 5c2 0 3.4 1.1 4.3 2.3H13c.9-1.2 2.3-2.3 4.3-2.3 3.8 0 5.6 4.3 3.5 7.6C19 16.4 12 21 12 21z'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.2' stroke-linejoin='round'%3E%3Cpath d='M12 21s-7-4.6-9.3-8.4C.6 9.3 2.4 5 6.2 5c2 0 3.4 1.1 4.3 2.3H13c.9-1.2 2.3-2.3 4.3-2.3 3.8 0 5.6 4.3 3.5 7.6C19 16.4 12 21 12 21z'/%3E%3C/svg%3E"); }
.ico[data-ico="trophy"] { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M7 4h10v5a5 5 0 0 1-10 0z'/%3E%3Cpath d='M7 6H4v2a3 3 0 0 0 3 3M17 6h3v2a3 3 0 0 1-3 3M9 20h6M12 14v6'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M7 4h10v5a5 5 0 0 1-10 0z'/%3E%3Cpath d='M7 6H4v2a3 3 0 0 0 3 3M17 6h3v2a3 3 0 0 1-3 3M9 20h6M12 14v6'/%3E%3C/svg%3E"); }
.ico[data-ico="sparkle"] { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.2' stroke-linejoin='round'%3E%3Cpath d='M12 3l2.2 5.6L20 11l-5.8 2.4L12 19l-2.2-5.6L4 11l5.8-2.4z'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.2' stroke-linejoin='round'%3E%3Cpath d='M12 3l2.2 5.6L20 11l-5.8 2.4L12 19l-2.2-5.6L4 11l5.8-2.4z'/%3E%3C/svg%3E"); }
.ico[data-ico="chart"]   { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.2' stroke-linecap='round'%3E%3Cpath d='M4 20V10M10 20V4M16 20v-7M22 20H2'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.2' stroke-linecap='round'%3E%3Cpath d='M4 20V10M10 20V4M16 20v-7M22 20H2'/%3E%3C/svg%3E"); }
.ico[data-ico="note"]    { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 4h14v16l-7-3-7 3z'/%3E%3Cpath d='M9 8h6M9 12h4'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 4h14v16l-7-3-7 3z'/%3E%3Cpath d='M9 8h6M9 12h4'/%3E%3C/svg%3E"); }

}

/* ---------- forms ---------- */
.form { display: flex; flex-direction: column; gap: 15px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: var(--t-sm); font-weight: 800; color: var(--ink-2); }
.field input, .field select, .field textarea {
  padding: 12px 14px; border-radius: var(--r-sm); border: 1px solid var(--line);
  background: var(--surface); font-weight: 600; font-size: var(--t-md); width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); outline: none;
}
.hint { font-size: var(--t-sm); color: var(--ink-3); font-weight: 600; }
.form-error {
  background: #fef2f2; border: 1px solid #fecaca; color: #b91c1c;
  padding: 11px 14px; border-radius: var(--r-sm); font-size: var(--t-md); font-weight: 700;
}
.form-ok { background: #f0fdf4; border: 1px solid #bbf7d0; color: #15803d;
  padding: 11px 14px; border-radius: var(--r-sm); font-size: var(--t-md); font-weight: 700; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 150px; }

/* ---------- auth pages ---------- */
.page-auth { background: var(--surface); }
.auth-page { display: grid; grid-template-columns: 1fr; min-height: 100dvh; max-width: none; padding: 0; }
@media (min-width: 900px) { .auth-page { grid-template-columns: 1.05fr 1fr; } }
.auth-art {
  display: none; padding: 48px; color: #fff;
  background: linear-gradient(150deg, #1e3a8a 0%, #2563eb 55%, #f97316 190%);
  align-items: center;
}
@media (min-width: 900px) { .auth-art { display: flex; } }
.auth-art-inner { max-width: 440px; }
.auth-art h2 { font-size: 38px; line-height: 1.15; margin-bottom: 16px; }
.auth-art p { opacity: .9; font-size: 16.5px; }
.auth-points { list-style: none; margin-top: 28px; display: flex; flex-direction: column; gap: 12px; }
.auth-points li { padding-left: 30px; position: relative; font-weight: 700; opacity: .95; }
.auth-points li::before {
  content: ""; position: absolute; left: 0; top: 6px; width: 18px; height: 18px;
  border-radius: 50%; background: rgba(255, 255, 255, .25);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .8);
}
.auth-form-wrap { display: flex; flex-direction: column; justify-content: center; padding: 32px clamp(20px, 6vw, 64px); gap: 28px; }
.auth-card { max-width: 420px; width: 100%; }
.auth-tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 999px; margin-bottom: 24px; }
.auth-tabs a { flex: 1; text-align: center; padding: 9px; border-radius: 999px; font-weight: 800; font-size: var(--t-md); color: var(--ink-2); }
.auth-tabs a.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1); }
.auth-foot { margin-top: 20px; font-size: var(--t-md); color: var(--ink-2); }
.auth-foot a { color: var(--brand); font-weight: 800; }

/* ---------- profiles ---------- */
.page-profiles { background: linear-gradient(170deg, #f8fafc, #eff6ff); }
.profiles-page { text-align: center; padding-top: clamp(40px, 8vh, 90px); }
.profiles-page h1 { margin-bottom: 6px; }
.profiles-grid { display: flex; flex-wrap: wrap; gap: 26px; justify-content: center; margin-top: 40px; }
.profile-card {
  display: flex; flex-direction: column; align-items: center; gap: 11px;
  border: none; background: none; cursor: pointer; width: 130px;
  transition: transform .16s ease;
}
.profile-card:hover { transform: translateY(-5px); }
.profile-card .avatar { width: 96px; height: 96px; font-size: 38px; }
.profile-card:hover .avatar { box-shadow: 0 0 0 4px var(--brand-soft), var(--shadow-2); }
.profile-card b { font-size: var(--t-lg); }
.profile-card small { color: var(--ink-3); font-weight: 700; }
.profile-card.add .avatar { background: var(--surface-2); color: var(--ink-3); border-style: dashed; }

.pin-input {
  font-size: 30px; letter-spacing: 14px; text-align: center; padding: 14px;
  border-radius: var(--r); border: 1px solid var(--line); width: 100%; font-weight: 800;
}

/* ---------- dialog ---------- */
.dialog {
  border: none; border-radius: var(--r-lg); padding: 26px;
  box-shadow: var(--shadow-3); max-width: 480px; width: calc(100vw - 32px);
  color: var(--ink); background: var(--surface);
}
.dialog::backdrop { background: rgba(15, 23, 42, .5); backdrop-filter: blur(3px); }
.dialog h2 { margin-bottom: 16px; }
.dialog-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }

/* ---------- rewards ---------- */
.rewards-hero {
  background: linear-gradient(135deg, #fff7ed, #ffedd5);
  border: 1px solid #fed7aa; border-radius: var(--r-lg); padding: 26px;
  display: flex; gap: 26px; flex-wrap: wrap; align-items: center;
}
.rewards-stat { text-align: center; }
.rewards-stat b { display: block; font-family: var(--font-display); font-size: 34px; color: #c2410c; line-height: 1; }
.rewards-stat span { font-size: var(--t-sm); font-weight: 800; color: #9a3412; text-transform: uppercase; letter-spacing: .05em; }

.badge-grid { display: grid; gap: 15px; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); }
.badge {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  padding: 18px 12px; text-align: center; box-shadow: var(--shadow-1);
}
.badge.locked { opacity: .5; filter: grayscale(1); }
.badge .glyph {
  width: 52px; height: 52px; margin: 0 auto 10px; border-radius: 50%;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #fde68a, #fbbf24); color: #78350f;
  box-shadow: inset 0 -2px 6px rgba(120, 53, 15, .12);
}
.badge.locked .glyph { background: var(--surface-2); color: var(--ink-3); box-shadow: none; }
.badge b { display: block; font-size: var(--t-sm); line-height: 1.25; }
.badge small { color: var(--ink-3); font-size: var(--t-xs); font-weight: 700; }

/* ---------- celebration ---------- */
.celebration {
  position: fixed; inset: 0; z-index: 200; display: grid; place-items: center;
  background: rgba(15, 23, 42, .55); backdrop-filter: blur(4px);
  animation: fade .3s ease;
}
.celebration-card {
  background: var(--surface); border-radius: var(--r-lg); padding: 34px 30px;
  text-align: center; max-width: 380px; box-shadow: var(--shadow-3);
  animation: pop .45s cubic-bezier(.2, 1.4, .4, 1);
}
.celebration-icon {
  width: 86px; height: 86px; margin: 0 auto 16px;
  display: grid; place-items: center; border-radius: 50%;
  background: linear-gradient(135deg, #fde68a, #fbbf24); color: #78350f;
  box-shadow: 0 8px 22px rgba(251, 191, 36, .35);
}
.celebration-card h2 { margin-bottom: 8px; }
.celebration-card p { color: var(--ink-2); margin-bottom: 20px; }
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 201; overflow: hidden; }
.confetti i {
  position: absolute; width: 9px; height: 15px; top: -20px;
  animation: fall linear forwards;
}
@keyframes fall { to { transform: translateY(105vh) rotate(720deg); opacity: .2; } }
@keyframes pop { from { transform: scale(.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes fade { from { opacity: 0; } }

/* ---------- subscribe ---------- */
.subscribe { max-width: 880px; text-align: center; }
.subscribe > h1 { margin-bottom: 8px; }
.plans { display: grid; gap: 18px; margin: 34px 0 20px; grid-template-columns: 1fr; text-align: left; }
@media (min-width: 660px) { .plans { grid-template-columns: 1fr 1fr; } }
.plan {
  background: var(--surface); border: 2px solid var(--line); border-radius: var(--r-lg);
  padding: 26px; position: relative; box-shadow: var(--shadow-1);
}
.plan.best { border-color: var(--brand); box-shadow: var(--shadow-2); }
.plan-tag {
  position: absolute; top: -12px; right: 20px; background: var(--brand); color: #fff;
  font-size: var(--t-xs); font-weight: 800; padding: 4px 12px; border-radius: 999px;
}
.plan h3 { font-size: 19px; margin-bottom: 4px; }
.plan .price { font-family: var(--font-display); font-size: 40px; font-weight: 800; line-height: 1.1; }
.plan .price small { font-size: var(--t-md); color: var(--ink-3); font-weight: 700; }
.plan .save { color: var(--good); font-weight: 800; font-size: var(--t-sm); margin-top: 4px; }
.plan .btn { margin-top: 18px; }
.subscribe-notes { color: var(--ink-2); font-size: var(--t-md); display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }

/* ---------- error page ---------- */
.error-page { text-align: center; padding-top: 14vh; max-width: 520px; }
.error-code { font-family: var(--font-display); font-size: 76px; font-weight: 800; color: var(--line); line-height: 1; }
.error-page h1 { margin: 4px 0 10px; }
.error-page p { color: var(--ink-2); margin-bottom: 24px; }

/* ---------- icons ---------- */
.star-row { display: inline-flex; gap: 2px; vertical-align: middle; }
.star-row .star-on { color: #f59e0b; }
.star-row .star-off { color: var(--line); }

/* ---------- empty state ---------- */
.empty { text-align: center; padding: 46px 20px; color: var(--ink-2); }
.empty-icon {
  width: 68px; height: 68px; margin: 0 auto 14px;
  display: grid; place-items: center; border-radius: 50%;
  background: var(--surface-2); color: var(--ink-3);
}
.empty h3 { margin-bottom: 6px; }

/* ---------- notes ----------
   Shared by the reader drawer and the child's "Me" tab. Dark-theme variants
   live in reader.css, scoped to .reader. */
.note-list { display: flex; flex-direction: column; gap: 10px; }
.note {
  background: var(--surface-2); border-radius: var(--r-sm);
  padding: 11px 13px; border-left: 3px solid var(--accent);
  color: inherit;
}
a.note:hover { background: #e8edf3; }
.note-head { display: flex; align-items: center; gap: 9px; margin-bottom: 6px; }
.note-at {
  border: none; background: var(--accent-soft); color: #c2410c;
  font-size: var(--t-xs); font-weight: 800; padding: 2px 8px; border-radius: 999px; cursor: pointer;
}
.note-at:hover { background: #fed7aa; }
.note-date { font-size: var(--t-xs); color: var(--ink-3); font-weight: 700; }
.note-del {
  margin-left: auto; border: none; background: none; cursor: pointer;
  color: var(--ink-3); padding: 2px; display: grid; place-items: center;
}
.note-del:hover { color: var(--bad); }
.note-body {
  font-size: var(--t-md); font-weight: 600; line-height: 1.5;
  white-space: pre-wrap; word-break: break-word;
}

/* ---------- installed-app mode ----------
   In standalone there is no browser chrome, so the header must take over the
   status-bar inset itself or it sits under the notch/clock. */
.standalone .topbar {
  height: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding-top: env(safe-area-inset-top);
}
.standalone .tabbar { top: calc(var(--topbar-h) + env(safe-area-inset-top)); }
.standalone main { padding-bottom: calc(60px + env(safe-area-inset-bottom)); }
/* The reader is full-bleed, so it handles both insets itself. */
.standalone .reader-bar {
  height: calc(58px + env(safe-area-inset-top));
  padding-top: env(safe-area-inset-top);
}

/* ---------- install invitation ---------- */
.install-banner {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 160; width: min(460px, calc(100vw - 24px));
  display: flex; align-items: center; gap: 13px;
  padding: 13px 15px; border-radius: var(--r);
  background: var(--surface); border: 1px solid var(--line);
  box-shadow: var(--shadow-3);
  animation: installIn .3s cubic-bezier(.2, .8, .3, 1);
}
@keyframes installIn { from { opacity: 0; transform: translate(-50%, 14px); } }
.install-icon {
  width: 38px; height: 38px; border-radius: 11px; flex-shrink: 0;
  display: grid; place-items: center;
  background: var(--brand-soft); color: var(--brand);
}
.install-text { flex: 1; min-width: 0; }
.install-text b { display: block; font-size: var(--t-sm); line-height: 1.3; }
.install-text span { font-size: var(--t-xs); color: var(--ink-3); font-weight: 600; }
.install-close {
  border: none; background: none; cursor: pointer; color: var(--ink-3);
  padding: 4px; display: grid; place-items: center; flex-shrink: 0;
}
.install-close:hover { color: var(--ink); }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 20px); transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 11px 20px; border-radius: 999px;
  font-weight: 700; font-size: var(--t-md); z-index: 150; box-shadow: var(--shadow-3);
  animation: toastIn .25s ease;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 12px); } }

/* ---------- skeleton ---------- */
.skeleton {
  background: linear-gradient(100deg, var(--surface-2) 30%, #e8edf3 50%, var(--surface-2) 70%);
  background-size: 220% 100%; animation: shimmer 1.3s infinite linear;
  border-radius: var(--r); min-height: 190px;
}
.card.skeleton { aspect-ratio: 3/4; min-height: 0; }
.profile-card.skeleton { width: 96px; height: 96px; border-radius: 50%; min-height: 0; }
@keyframes shimmer { to { background-position: -220% 0; } }

/* ---------- utilities ---------- */
[hidden] { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
