/* ---------- Pastel Design System (BookLantern) ---------- */
:root {
  /* LIGHT (pastel) */
  --bg: #F9FAFE;            /* soft near-white */
  --surface: #FFFFFF;       /* cards, nav */
  --ink: #0F141B;           /* primary text (ink) */
  --ink-muted: #5C6470;

  --brand: #9AB0FF;         /* pastel periwinkle */
  --brand-ink: #0B1020;

  --accent: #FBE4D4;        /* peach wash */
  --accent-ink: #3A2A22;

  --ring: rgba(154,176,255,.55);
  --border: rgba(15,20,27,.10);
  --card-shadow: 0 6px 18px rgba(11,16,32,.06);

  /* --surface-2 was USED in four stylesheets and DEFINED in none, so every
     reference silently fell back to a hardcoded light literal — including
     `.bl-hero__title .hl { background: var(--surface-2, #eef) }`. In dark mode
     that painted a light-lavender pill under near-white text: the hero words
     "books" and "inspire" measured 1.03:1, effectively invisible. Defining the
     token in BOTH themes is the actual fix; the pill also gets its own
     foreground token so it can never inherit the wrong ink again. */
  --surface-2: #EEF1FB;
  --hl-bg: #DDE4FF;
  --hl-ink: #16204A;

  /* Muted/secondary ink that is legible on --surface in both themes. Card
     authors were hardcoded #666, which is 3.04:1 on the dark surface. */
  --ink-2: #45505F;

  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 10px;

  --container: 1200px;

  --btn-pad: 10px 14px;
  --btn-tiny: 6px 10px;

  /* Typography */
  --font-serif: "Soria", ui-serif, Georgia, Cambria, "Times New Roman", serif;
  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif;
  --h1: clamp(1.9rem, 2.3vw + 1.2rem, 2.6rem);
  --h2: clamp(1.3rem, 1.4vw + 0.9rem, 1.7rem);
}

[data-theme="dark"] {
  /* DARK (pastel-friendly, not pitch black) */
  --bg: #0E1219;            /* soft charcoal */
  --surface: #151A22;       /* cards, nav */
  --ink: #E8ECF5;           /* text */
  --ink-muted: #A7B0C2;

  --brand: #9AB0FF;         /* same brand, reads well on dark */
  --brand-ink: #0B1020;

  --accent: #2A2430;        /* muted plum wash for dark */
  --accent-ink: #EADCF2;

  --ring: rgba(154,176,255,.45);
  --border: rgba(232,236,245,.08);
  --card-shadow: 0 8px 22px rgba(0,0,0,.28);

  /* Dark counterparts. The highlight pill becomes a deep periwinkle wash with
     LIGHT ink on it, rather than a light pill the text disappears into. */
  --surface-2: #1D2430;
  --hl-bg: #2B3663;
  --hl-ink: #E9EDFF;

  --ink-2: #B9C2D4;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html { font-size: 16px; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-serif);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

img { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; }
a:hover { text-decoration: underline; }

/* Focus ring */
:where(button, a, input, textarea, select):focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
  border-radius: 8px;
}

/* ---------- Layout ---------- */
.container {
  width: min(100%, var(--container));
  margin-inline: auto;
  padding-inline: 16px;
}

.row { display: flex; gap: 10px; align-items: center; }
.stack { display: flex; flex-direction: column; gap: var(--gap, 12px); }

.grid {
  display: grid;
  grid-template-columns: repeat(var(--cols, 5), minmax(0, 1fr));
  gap: 14px;
}

/* ---------- Navbar ---------- */
.site-nav {
  position: sticky; top: 0; z-index: 50;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 rgba(0,0,0,.02);
}
.site-nav .inner {
  display: flex; align-items: center; gap: 14px;
  justify-content: space-between;
  height: 64px;
  width: min(100%, var(--container));
  margin-inline: auto;
  padding-inline: 16px;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700;
  letter-spacing: .2px;
}
.brand img { width: 36px; height: 36px; border-radius: 9px; }
.brand .word { font-size: 1.05rem; }
@media (max-width: 680px) { .brand .word { display: none; } }

.nav-links {
  display: flex; align-items: center; gap: 12px;
  margin-left: 10px;
}
.nav-actions {
  display: flex; align-items: center; gap: 10px;
}

/* Search */
.nav-search {
  display: flex; gap: 8px; align-items: center;
  margin-inline: 12px;
}
.nav-search input[type="search"] {
  width: clamp(180px, 28vw, 480px);
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  padding: 6px 10px;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: var(--btn-pad);
  font-family: var(--font-serif);
  font-weight: 600;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--card-shadow);
  cursor: pointer;
  transition: transform .02s ease, box-shadow .2s ease, background .2s ease, color .2s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn.primary {
  background: linear-gradient(180deg, var(--brand), #7C95FF);
  color: white;
  border: 0;
}
.btn.secondary {
  background: var(--accent);
  color: var(--accent-ink);
  border: 0;
}
.btn.ghost {
  background: transparent;
  border: 1px solid var(--border);
  box-shadow: none;
}
.btn.tiny { padding: var(--btn-tiny); border-radius: 10px; }

/* Theme toggle pill */
#themeToggle {
  width: 40px; height: 36px;
  border-radius: 12px;
}

/* ---------- Hero ---------- */
.hero {
  background:
    radial-gradient(180px 120px at 20% 0%, color-mix(in oklab, var(--brand) 18%, transparent) 0%, transparent 100%),
    radial-gradient(200px 140px at 90% 0%, color-mix(in oklab, var(--accent) 26%, transparent) 0%, transparent 100%),
    transparent;
  padding: 26px 0 16px;
  border-bottom: 1px solid var(--border);
}
.hero .hero-sub { color: var(--ink-muted); }
.hero .hero-points { color: var(--ink); line-height: 1.6; }
.hero .search { display: flex; gap: 8px; margin-top: 12px; }
.hero .search input[type="text"]{
  flex: 1;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  padding: 8px 12px;
}

/* ---------- Cards & Lists ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--card-shadow);
  overflow: hidden;
}
.row-head { display:flex; align-items:center; justify-content:space-between; }
.carousel {
  display: grid; grid-auto-flow: column; gap: 14px;
  overflow-x: auto; padding: 6px 2px 10px 2px;
  scroll-snap-type: x mandatory;
}
.carousel > * { scroll-snap-align: start; }

/* Book card */
.card .cover { display: block; background: var(--accent); color: var(--accent-ink); }
.card .cover img { width: 100%; height: auto; display: block; }
.card .cover.ph {
  width: 100%; height: 220px;
  display: grid; place-items: center;
  font-size: 1.4rem;
}
.card .meta { padding: 10px 12px; }
.card .title { margin: 0 0 4px; line-height: 1.25; font-size: 1rem; }
.card .author { font-size: .92rem; color: var(--ink-muted); }

/* ---------- Page sections ---------- */
main.container { padding: 16px 0 40px; }
.page-pad { padding: 24px 0 40px; }
.page-title {
  font-size: var(--h1);
  line-height: 1.1;
  margin: 0 0 6px;
}
.page-sub { color: var(--ink-muted); margin: 0; }

/* ---------- Footer ---------- */
.site-footer {
  margin-top: 40px;
  border-top: 1px solid var(--border);
  padding: 16px 0;
  background: var(--surface);
}

/* ---------- Utilities ---------- */
.muted { color: var(--ink-muted); }
.inline { display: inline; }
.row-wrap { display:flex; flex-wrap:wrap; gap:10px; }

/* Forms inside cards */
.card label { display: grid; gap: 6px; }
.card input[type="email"],
.card input[type="password"],
.card input[type="text"],
.card textarea {
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  padding: 10px 12px;
}
.alert { padding: 10px 12px; border-radius: 10px; }
.alert.error { background: #FFEBEE; color: #8A1C20; border: 1px solid #F8C6CC; }
.alert.success { background: #E7F7EE; color: #1B6B3E; border: 1px solid #B7E7CA; }

/* Headlines */
h1 { font-size: var(--h1); margin: 14px 0; }
h2 { font-size: var(--h2); margin: 14px 0; }

/* ---------- Carousels: touch affordance ----------
   These are horizontal scrollers. On a phone there is no scrollbar and no hover
   arrows, so nothing tells the reader more books exist to the side. A fade at
   the trailing edge is the standard hint, and scroll-padding keeps the first
   card clear of the container edge when snapping. */
.carousel {
  -webkit-overflow-scrolling: touch;   /* momentum scrolling on iOS */
  overscroll-behavior-x: contain;      /* don't trigger back-swipe navigation */
  scroll-padding-inline: 2px;
}
/* The trailing-edge fade is applied as a MASK on the scroller itself, not as an
   overlay on the shelf. An absolutely-positioned overlay would also sit on top
   of the shelf heading and dim the "See more" link; a mask affects only the
   cards the scroller paints, and never intercepts clicks. */
@supports (mask-image: linear-gradient(#000, #000)) or (-webkit-mask-image: linear-gradient(#000, #000)) {
  @media (max-width: 768px) {
    .carousel, .shelf-scroll {
      -webkit-mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 26px), transparent 100%);
      mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 26px), transparent 100%);
    }
  }
}

/* Smaller screens: tighten columns */
@media (max-width: 1200px) {
  .grid { grid-template-columns: repeat(var(--cols, 4), minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .grid { grid-template-columns: repeat(var(--cols, 3), minmax(0, 1fr)); }
}
@media (max-width: 680px) {
  .grid { grid-template-columns: repeat(var(--cols, 2), minmax(0, 1fr)); }
}

/* ---------- Mobile guards ----------
   Three whole-site defects the layout audit measured at 390px, fixed once here
   rather than per page. */
@media (max-width: 768px) {
  /* 1) HORIZONTAL OVERFLOW. Every page scrolled 39px sideways. The nav fix
        removes the cause; this is a backstop against a future wide child (a
        stray table, an over-wide embed, a long unbroken URL).
        `clip` NOT `hidden`: overflow:hidden on html/body creates a scroll
        container, which silently breaks `position: sticky` on the topbar.
        overflow:clip clips without creating one, so the sticky header survives.
        Where clip is unsupported the declaration is simply ignored — and the
        actual overflow causes are fixed, so nothing regresses. */
  html, body { max-width: 100%; overflow-x: clip; }

  /* 2) SUB-16px INPUTS. iOS Safari zooms the whole page when focusing an input
        whose font-size is under 16px, which then leaves the layout zoomed and
        scrolled sideways. Measured at 13.33px on every form in the app. */
  input, select, textarea {
    font-size: 16px;
    min-height: 44px;
  }
  textarea { min-height: 88px; }

  /* Long titles and identifiers must wrap rather than widen the page. */
  .card .title, .card .author, .page-title { overflow-wrap: anywhere; }

  /* Tighten page padding so cards get the width instead of the gutters. */
  main.container { padding: 12px 0 32px; }
}

/* ---------- Touch ergonomics ----------
   Keyed on the INPUT DEVICE, not the width. An iPad in portrait is 834px wide —
   wider than any phone breakpoint — but it is still a finger, and it measured
   29px-tall nav links and 13.3px inputs just like the phone did. `hover: none`
   + `pointer: coarse` matches touch devices at any size and never matches a
   mouse-driven desktop, so the desktop layout is untouched by design. */
/* The width clause is not redundant: it is the part that can be VERIFIED. The
   pointer/hover clause is the semantically correct test and catches touch
   laptops, but headless Chromium does not emulate those features reliably, so a
   rule relying on it alone could rot unnoticed. 1024px covers phones and both
   iPad orientations while leaving a 1440px desktop exactly as it was. */
@media (max-width: 1024px), (hover: none) and (pointer: coarse) {
  /* Apple's floor is 44×44pt. min-height alone does nothing to an inline <a>,
     hence inline-flex — the reason an earlier pass measured .shelf__more at
     60×17 despite a min-height rule. */
  .btn, button, input[type="submit"] { min-height: 44px; }
  /* Standalone navigation links, as distinct from links inside prose: an inline
     link in a sentence should stay text-sized, but a "← Back" control on its own
     line is a button in all but name and needs a real target. */
  .topbar .brand, .shelf__more, .site-footer a, a.back, a.link-underline[aria-label="Go back"] {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
  }
  /* inline-flex, not just min-height: these are inline <a>s, and min-height has
     no effect on an inline box. This is why an earlier pass still measured them
     at 29px on the iPad despite the rule being present. */
  .topbar .nav-links a {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
  }

  /* iOS zooms the page when focusing an input under 16px and leaves it zoomed. */
  input, select, textarea { font-size: 16px; }
  input:not([type="checkbox"]):not([type="radio"]),
  select { min-height: 44px; }
}
