/* Early Readers: shared design tokens and components for every page except read.html.
   Shape rule: buttons, chips and badges are full pill. Cards and panels are 16px. Inputs are 10px.
   One accent (violet). Status colours (green, amber, red, blue) are only for state, never decoration. */

:root {
  /* Surfaces */
  --bg: #f7f7f9;            /* page */
  --surface: #ffffff;       /* cards, inputs, header */
  --tint: #efedfb;          /* soft accent wash for feature blocks */
  --subtle: #f1f1f4;        /* table heads, skeletons, quiet fills */

  /* Text */
  --ink: #15151c;
  --muted: #565766;         /* 7:1 on --bg */
  --faint: #6e6f7d;         /* helper text, 4.8:1 on --surface */

  /* Lines */
  --line: #e3e3ea;
  --line-strong: #c9c9d4;

  /* Accent */
  --accent: #5a3fd6;
  --accent-hover: #4a30c2;
  --accent-ink: #ffffff;
  --accent-soft: #e9e4fc;
  --accent-text: #4b32c0;   /* accent used as text on light surfaces */

  /* Status: bg + text pairs */
  --ok-bg: #e5f5ec;   --ok: #146c3c;
  --warn-bg: #fdf1dc; --warn: #8a5300;
  --bad-bg: #fde8e7;  --bad: #b3261e;
  --info-bg: #e6effc; --info: #1f5bb8;

  /* Depth: tinted to the ink hue, never pure black */
  --shadow-sm: 0 1px 2px rgba(21, 21, 40, .06);
  --shadow: 0 1px 2px rgba(21, 21, 40, .05), 0 8px 24px -12px rgba(21, 21, 40, .16);
  --shadow-lg: 0 2px 4px rgba(21, 21, 40, .04), 0 24px 56px -20px rgba(21, 21, 40, .28);

  /* Shape */
  --r-panel: 16px;
  --r-card: 16px;
  --r-input: 10px;
  --r-sm: 8px;
  --r-pill: 999px;

  /* Type */
  --font: "Geist", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "Geist Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --book: Literata, Georgia, serif; /* book titles on the claim page only */
  --fs-xs: 13px;
  --fs-sm: 14px;
  --fs-base: 16px;
  --fs-md: 17px;
  --fs-lg: 20px;

  /* Space (4px base) */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 20px; --s6: 24px;
  --s8: 32px; --s10: 40px; --s12: 48px; --s16: 64px; --s20: 80px; --s24: 96px;

  /* Layout */
  --wrap: 1160px;
  --gutter: 16px;
  --head-h: 64px;

  color-scheme: light;
}

@media (min-width: 768px) { :root { --gutter: 32px; } }

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0f14;
    --surface: #17171e;
    --tint: #1d1a2e;
    --subtle: #1d1d25;
    --ink: #ececf1;
    --muted: #a6a7b4;
    --faint: #8d8e9b;
    --line: #2a2a34;
    --line-strong: #3a3a47;
    --accent: #9a86ff;
    --accent-hover: #ae9eff;
    --accent-ink: #120d2b;
    --accent-soft: #2a2350;
    --accent-text: #b3a5ff;
    --ok-bg: #13301f;   --ok: #7fd6a2;
    --warn-bg: #352610; --warn: #f2bd6b;
    --bad-bg: #3a1716;  --bad: #ff9a8f;
    --info-bg: #142540; --info: #8db6f5;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 12px 32px -14px rgba(0, 0, 0, .7);
    --shadow-lg: 0 2px 4px rgba(0, 0, 0, .3), 0 28px 64px -24px rgba(0, 0, 0, .8);
    color-scheme: dark;
  }
}

/* Base */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; scroll-padding-top: calc(var(--head-h) + 16px); }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--fs-md);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}
img { max-width: 100%; display: block; }
a { color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip { position: absolute; left: 12px; top: -60px; z-index: 50; padding: 10px 16px; border-radius: var(--r-sm); background: var(--ink); color: var(--bg); font-size: var(--fs-sm); font-weight: 600; text-decoration: none; }
.skip:focus { top: 12px; }

.wrap { width: 100%; max-width: var(--wrap); margin: 0 auto; padding: 0 var(--gutter); }
.wrap-narrow { width: 100%; max-width: 720px; margin: 0 auto; padding: 0 var(--gutter); }

/* Type */
h1, h2, h3, h4 { font-weight: 600; letter-spacing: -0.022em; margin: 0; text-wrap: balance; color: var(--ink); }
h1 { font-size: clamp(34px, 6.4vw, 56px); line-height: 1.05; letter-spacing: -0.03em; }
h2 { font-size: clamp(26px, 4vw, 38px); line-height: 1.12; }
h3 { font-size: 19px; line-height: 1.3; letter-spacing: -0.012em; }
h4 { font-size: var(--fs-base); line-height: 1.4; letter-spacing: -0.006em; }
p { margin: 0; }
.lede { font-size: clamp(17px, 2vw, 20px); line-height: 1.5; color: var(--muted); max-width: 46ch; }
.body { color: var(--muted); max-width: 62ch; }
.small { font-size: var(--fs-sm); color: var(--muted); }
.eyebrow { font-size: var(--fs-xs); font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--accent-text); }
.num { font-variant-numeric: tabular-nums; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 24px; border-radius: var(--r-pill); border: 1px solid transparent;
  font: inherit; font-size: var(--fs-base); font-weight: 600; line-height: 1; text-decoration: none; white-space: nowrap; cursor: pointer;
  transition: transform .16s cubic-bezier(.16, 1, .3, 1), background-color .16s, border-color .16s, color .16s, box-shadow .16s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--accent); color: var(--accent-ink); box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary, .btn-ghost { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
.btn-secondary:hover, .btn-ghost:hover { border-color: var(--ink); }
.btn-quiet { background: transparent; color: var(--ink); }
.btn-quiet:hover { background: var(--subtle); }
.btn-danger { background: var(--surface); color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }
.btn-danger:hover { background: var(--bad-bg); }
.btn-sm { min-height: 44px; padding: 0 18px; font-size: var(--fs-sm); }
.btn-lg { min-height: 56px; padding: 0 30px; font-size: var(--fs-md); }
.btn-block { width: 100%; }
.arrow { display: inline-block; width: 8px; height: 8px; border-top: 2px solid currentColor; border-right: 2px solid currentColor; transform: rotate(45deg); margin-left: 2px; }
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }
.link { color: var(--accent-text); font-weight: 500; text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }
.link:hover { text-decoration-thickness: 2px; }

/* Brand mark */
.mark { display: inline-flex; align-items: center; gap: 10px; font-weight: 650; font-size: 17px; letter-spacing: -0.02em; text-decoration: none; color: var(--ink); white-space: nowrap; }
.site-head .mark, .app-top .mark { flex: none; }
.mark i { width: 22px; height: 26px; border-radius: 3px 7px 7px 3px; background: var(--accent); position: relative; flex: none; }
.mark i::after { content: ""; position: absolute; left: 5px; top: 0; bottom: 0; width: 2px; background: var(--accent-ink); opacity: .5; }

/* Public header */
.site-head { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--surface) 86%, transparent); backdrop-filter: saturate(160%) blur(14px); -webkit-backdrop-filter: saturate(160%) blur(14px); border-bottom: 1px solid var(--line); }
.site-head .wrap { display: flex; align-items: center; justify-content: space-between; gap: 16px; height: var(--head-h); }
.head-links { display: flex; align-items: center; gap: 8px; }
.head-links a.text { display: inline-flex; align-items: center; min-height: 44px; padding: 0 12px; border-radius: var(--r-pill); font-size: 15px; font-weight: 500; text-decoration: none; color: var(--muted); }
.head-links a.text:hover { color: var(--ink); background: var(--subtle); }
@media (max-width: 560px) { .head-links a.text.hide-sm, .hide-sm-btn { display: none; } }

/* Footer */
.site-foot { border-top: 1px solid var(--line); background: var(--surface); padding: 48px 0 32px; font-size: var(--fs-sm); color: var(--muted); }
.foot-grid { display: grid; gap: 28px 16px; grid-template-columns: 1fr 1fr; }
.foot-grid > :first-child { grid-column: 1 / -1; }
.foot-grid .about { max-width: 34ch; margin-top: 12px; }
.foot-col h4 { font-size: var(--fs-sm); margin-bottom: 8px; }
.foot-col a { display: flex; align-items: center; min-height: 44px; text-decoration: none; color: var(--muted); }
.foot-col a:hover { color: var(--ink); text-decoration: underline; text-underline-offset: 3px; }
.foot-base { margin-top: 40px; padding-top: 20px; border-top: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: 8px 24px; justify-content: space-between; font-size: var(--fs-xs); color: var(--faint); }
@media (min-width: 768px) { .foot-grid { grid-template-columns: 2fr 1fr 1fr 1fr; } .foot-grid > :first-child { grid-column: auto; } }

/* Cards and panels */
.panel, .card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card); }
.card { padding: 24px; box-shadow: var(--shadow-sm); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.card-head h3 { font-size: 17px; }
.divider { height: 1px; background: var(--line); border: 0; margin: 20px 0; }

/* Badges (book states and other status) */
.badge { display: inline-flex; align-items: center; gap: 6px; min-height: 24px; padding: 0 10px; border-radius: var(--r-pill); font-size: 12.5px; font-weight: 600; line-height: 1; white-space: nowrap; background: var(--subtle); color: var(--muted); }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-bad { background: var(--bad-bg); color: var(--bad); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-accent { background: var(--accent-soft); color: var(--accent-text); }
/* Book state map: submitted=neutral, checking=info, accepted=accent, declined=bad, paid=warn, live=ok, done=neutral */

/* Forms */
.field { display: grid; gap: 6px; margin-bottom: 18px; }
.label { font-size: var(--fs-sm); font-weight: 600; color: var(--ink); }
.help { font-size: 13.5px; color: var(--faint); }
.error-text { font-size: 13.5px; color: var(--bad); }
.input, .select, .textarea {
  width: 100%; min-height: 48px; padding: 0 14px; font: inherit; font-size: var(--fs-base);
  color: var(--ink); background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--r-input);
  transition: border-color .15s, box-shadow .15s;
}
.textarea { min-height: 120px; padding: 12px 14px; line-height: 1.5; resize: vertical; }
.input::placeholder, .textarea::placeholder { color: var(--faint); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--muted); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.input[aria-invalid="true"] { border-color: var(--bad); }
.check { display: flex; gap: 12px; align-items: flex-start; min-height: 44px; font-size: var(--fs-sm); line-height: 1.45; color: var(--muted); cursor: pointer; }
.check input { margin: 1px 0 0; width: 20px; height: 20px; accent-color: var(--accent); flex: none; }

/* Inline messages */
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--r-input); font-size: var(--fs-sm); line-height: 1.45; background: var(--subtle); color: var(--ink); }
.alert-ok { background: var(--ok-bg); color: var(--ok); }
.alert-warn { background: var(--warn-bg); color: var(--warn); }
.alert-bad { background: var(--bad-bg); color: var(--bad); }
.alert-info { background: var(--info-bg); color: var(--info); }

/* Tables */
.table-wrap { position: relative; width: 100%; overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r-card); background: var(--surface); }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.table th { text-align: left; font-weight: 600; font-size: 12.5px; color: var(--muted); background: var(--subtle); padding: 10px 14px; white-space: nowrap; }
.table td { padding: 12px 14px; border-top: 1px solid var(--line); vertical-align: top; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table tbody tr:hover { background: color-mix(in srgb, var(--subtle) 60%, transparent); }

/* Stats */
.stat { display: grid; gap: 4px; }
.stat .k { font-size: 13px; color: var(--muted); }
.stat .v { font-size: 26px; font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }

/* Empty, loading */
.empty { display: grid; justify-items: center; gap: 8px; text-align: center; padding: 40px 24px; border: 1px dashed var(--line-strong); border-radius: var(--r-card); color: var(--muted); }
.empty h3 { color: var(--ink); }
.empty p { max-width: 40ch; }
.empty .btn { margin-top: 8px; }
.skeleton { display: block; border-radius: var(--r-sm); background: var(--subtle); min-height: 14px; }
@media (prefers-reduced-motion: no-preference) {
  .skeleton { background: linear-gradient(90deg, var(--subtle) 30%, color-mix(in srgb, var(--subtle) 50%, var(--surface)) 50%, var(--subtle) 70%); background-size: 300% 100%; animation: shimmer 1.4s ease-in-out infinite; }
  @keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }
}

/* App shell: top bar + side nav (author dashboard, admin) */
.app-top { position: sticky; top: 0; z-index: 20; height: var(--head-h); background: var(--surface); border-bottom: 1px solid var(--line); }
.app-top .bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; height: 100%; padding: 0 var(--gutter); }
.app-user { display: flex; align-items: center; gap: 10px; font-size: var(--fs-sm); color: var(--muted); min-width: 0; }
.app-user .email { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 22ch; }
.app-shell { display: grid; min-height: calc(100dvh - var(--head-h)); }
.app-nav { display: flex; gap: 4px; min-width: 0; overflow-x: auto; padding: 8px var(--gutter); border-bottom: 1px solid var(--line); background: var(--surface); }
.app-nav a { display: inline-flex; align-items: center; gap: 10px; min-height: 44px; padding: 0 14px; border-radius: var(--r-sm); font-size: 15px; font-weight: 500; color: var(--muted); text-decoration: none; white-space: nowrap; }
.app-nav a:hover { background: var(--subtle); color: var(--ink); }
.app-nav a[aria-current="page"], .app-nav a.active { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
.app-nav .group { display: none; }
.app-main { padding: 24px var(--gutter) 64px; min-width: 0; }
.app-main .page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 16px; margin-bottom: 24px; }
.app-main .page-head h1 { font-size: clamp(24px, 3vw, 30px); letter-spacing: -0.02em; }
@media (min-width: 960px) {
  .app-shell { grid-template-columns: 240px 1fr; background: linear-gradient(90deg, var(--surface) 0 239px, var(--line) 239px 240px, transparent 240px); }
  .app-nav { flex-direction: column; overflow: visible; padding: 20px 12px; border-bottom: 0; border-right: 1px solid var(--line); position: sticky; top: var(--head-h); height: calc(100dvh - var(--head-h)); }
  .app-nav .group { display: block; margin: 16px 14px 6px; font-size: 12px; font-weight: 600; color: var(--faint); }
  .app-main { padding: 32px 40px 80px; max-width: 1120px; }
}

/* Phone frame around a real screenshot */
.phone { position: relative; width: min(100%, 320px); aspect-ratio: 390 / 800; border-radius: 44px; padding: 10px; background: #111118; box-shadow: var(--shadow-lg); }
.phone img { width: 100%; height: 100%; object-fit: cover; object-position: top; border-radius: 34px; }

/* Sections */
.section { padding: 64px 0; }
@media (min-width: 900px) { .section { padding: 96px 0; } }

/* Entry and scroll reveal, transform and opacity only */
@media (prefers-reduced-motion: no-preference) {
  .rise { animation: rise .7s cubic-bezier(.16, 1, .3, 1) both; animation-delay: calc(var(--i, 0) * 80ms); }
  @keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
  @supports (animation-timeline: view()) {
    .reveal { animation: rise linear both; animation-timeline: view(); animation-range: entry 0% entry 35%; }
  }
}
