@font-face {
  font-family: "Fraunces";
  src: url("../fonts/fraunces.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --paper: #efece5;        /* the same cream as Reed's paper, so his edges disappear */
  --card: #f8f6f1;
  --ink: #2e2925;
  --ink-2: #6e655c;
  --line: #ddd6ca;
  --green: #4a7330;        /* buttons */
  --green-dark: #3a5c25;
  --bar: #567f38;          /* chart bars (checked against the paper) */
  --green-soft: #e3e9da;
  --tan: #c9a073;
  --blue: #7d93a5;         /* Reed's book */
  --blue-dark: #566b7c;
  --serif: "Fraunces", Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --radius: 20px;
  --tabs-h: 64px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 17px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
img { display: block; max-width: 100%; height: auto; }
button, input, select { font: inherit; color: inherit; }
a { color: inherit; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.15; margin: 0; letter-spacing: -.01em; }
h1 { font-size: 30px; }
h2 { font-size: 22px; }
h3 { font-size: 18px; }
p { margin: 0; }

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: calc(env(safe-area-inset-top) + 14px) 20px calc(var(--tabs-h) + env(safe-area-inset-bottom) + 28px);
}
body.no-tabs #app { padding-bottom: calc(env(safe-area-inset-bottom) + 28px); }

/* ---------- tab bar ---------- */
#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: center;
  padding: 6px 8px calc(env(safe-area-inset-bottom) + 6px);
  background: rgba(239, 236, 229, .92);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
body.no-tabs #tabs { display: none; }
#tabs a {
  flex: 1; max-width: 120px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 0 2px; text-decoration: none; color: var(--ink-2);
  font-size: 12px; font-weight: 600;
}
#tabs svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#tabs a.on { color: var(--green-dark); }
#tabs a.on svg { fill: var(--green-soft); }

/* ---------- Reed ---------- */
.reed {
  transform-origin: 50% 100%;
  animation: reed-in .55s cubic-bezier(.34, 1.56, .64, 1) both, reed-sway 7s ease-in-out .6s infinite;
  /* soften the painted bottom edge of his jumper */
  -webkit-mask-image: linear-gradient(to bottom, #000 84%, transparent 100%);
  mask-image: linear-gradient(to bottom, #000 84%, transparent 100%);
  user-select: none; -webkit-user-drag: none; pointer-events: none;
}
.reed.cheer { animation: reed-in .55s cubic-bezier(.34, 1.56, .64, 1) both, reed-hop .9s ease-in-out .5s 3; }
@keyframes reed-in { from { opacity: 0; transform: translateY(18px) scale(.92); } to { opacity: 1; transform: none; } }
@keyframes reed-sway { 0%, 100% { transform: rotate(0); } 30% { transform: rotate(-1.2deg); } 70% { transform: rotate(1.2deg); } }
@keyframes reed-hop { 0%, 100% { transform: translateY(0); } 40% { transform: translateY(-14px); } 60% { transform: translateY(-14px); } }

.bubble {
  position: relative;
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: 22px;
  padding: 14px 16px;
  font: 500 19px/1.3 var(--serif);
  animation: bubble-in .45s .25s cubic-bezier(.34, 1.56, .64, 1) both;
}
@keyframes bubble-in { from { opacity: 0; transform: scale(.85); } to { opacity: 1; transform: none; } }
.bubble::before, .bubble::after { content: ""; position: absolute; width: 0; height: 0; border-style: solid; }

/* Reed on the left, bubble on the right */
.hero { display: grid; grid-template-columns: 52% 1fr; align-items: center; gap: 6px; margin-top: 4px; }
.hero .reed { width: 100%; }
.hero .bubble { transform-origin: 0 60%; margin-bottom: 26px; }
.hero .bubble::before { left: -13px; top: 42%; border-width: 9px 13px 9px 0; border-color: transparent var(--line) transparent transparent; }
.hero .bubble::after { left: -10px; top: calc(42% + 1px); border-width: 8px 11px 8px 0; border-color: transparent var(--card) transparent transparent; }

/* Reed in the middle, bubble underneath */
.stage { display: flex; flex-direction: column; align-items: center; text-align: center; }
.stage .reed { width: 62%; max-width: 230px; }
.stage .bubble { margin-top: 10px; transform-origin: 50% 0; }
.stage .bubble::before { top: -13px; left: calc(50% - 9px); border-width: 0 9px 13px 9px; border-color: transparent transparent var(--line) transparent; }
.stage .bubble::after { top: -10px; left: calc(50% - 8px); border-width: 0 8px 11px 8px; border-color: transparent transparent var(--card) transparent; }

/* small Reed beside a page title */
.title-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 6px 0 18px; }
.title-row .reed { width: 92px; flex: none; animation: reed-in .55s cubic-bezier(.34, 1.56, .64, 1) both; }
.title-row h1 { padding-bottom: 8px; }

/* ---------- cards ---------- */
.card {
  position: relative; z-index: 1;
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}
.card + .card, .card + .section, .section + .card { margin-top: 16px; }
.hero + .card { margin-top: -20px; } /* tucks the bottom of Reed's jumper behind the card */
.section { margin-top: 26px; }
.section > h2 { margin-bottom: 12px; }
.muted { color: var(--ink-2); }
.small { font-size: 14px; }
.eyebrow { font-size: 13px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-2); }

/* the book you're reading */
.now { display: grid; grid-template-columns: 74px 1fr; gap: 16px; align-items: start; }
.now .eyebrow { margin-bottom: 4px; }
.now h2 { font-size: 21px; }
.now .by { color: var(--ink-2); margin-top: 2px; font-size: 15px; }
.progress { margin-top: 12px; }
.bar-track { height: 10px; border-radius: 6px; background: #e4ded2; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 6px; background: var(--green); transition: width .6s ease; }
.progress-text { display: flex; justify-content: space-between; margin-top: 6px; font-size: 14px; color: var(--ink-2); }
.progress-text b { color: var(--ink); font-weight: 600; }

/* covers */
.cover {
  width: 100%; aspect-ratio: 2 / 3; border-radius: 4px 8px 8px 4px; overflow: hidden;
  background: var(--blue); box-shadow: 0 1px 0 rgba(0,0,0,.08), 2px 3px 8px rgba(60, 45, 30, .16);
  position: relative;
}
.cover img { width: 100%; height: 100%; object-fit: cover; }
.cover.blank { display: flex; align-items: center; justify-content: center; padding: 8px; color: #f6f3ec; text-align: center; font: 600 13px/1.15 var(--serif); }
.cover.blank::before { content: ""; position: absolute; left: 5px; top: 0; bottom: 0; width: 2px; background: rgba(255,255,255,.25); }

/* ---------- buttons ---------- */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: 54px; padding: 12px 20px;
  border: 0; border-radius: 16px; cursor: pointer;
  background: var(--green); color: #fff; font-weight: 650; font-size: 17px; text-decoration: none;
  box-shadow: 0 2px 0 var(--green-dark);
  transition: transform .08s ease, box-shadow .08s ease;
}
.btn:active { transform: translateY(2px); box-shadow: 0 0 0 var(--green-dark); }
.btn.soft { background: var(--green-soft); color: var(--green-dark); box-shadow: none; }
.btn.plain { background: transparent; color: var(--ink); border: 1.5px solid var(--line); box-shadow: none; }
.btn.danger { background: transparent; color: #a3402e; border: 1.5px solid #e3c4bb; box-shadow: none; }
.btn + .btn { margin-top: 10px; }
.card .btn { margin-top: 16px; }
.link { background: none; border: 0; padding: 8px 0; color: var(--green-dark); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.back { display: inline-flex; align-items: center; gap: 4px; background: none; border: 0; padding: 6px 8px 6px 0; color: var(--ink-2); font-weight: 600; cursor: pointer; text-decoration: none; }
.back svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- forms ---------- */
label.field { display: block; margin-top: 16px; }
label.field > span { display: block; font-weight: 600; margin-bottom: 6px; }
label.field > small { display: block; color: var(--ink-2); font-size: 14px; margin-top: 6px; }
.input {
  width: 100%; min-height: 52px; padding: 12px 14px;
  background: #fff; border: 1.5px solid var(--line); border-radius: 14px;
  font-size: 17px; outline: none;
}
.input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(74, 115, 48, .18); }
.big-number {
  width: 100%; text-align: center; padding: 10px;
  font: 600 52px/1.1 var(--serif); letter-spacing: -.02em;
  background: #fff; border: 1.5px solid var(--line); border-radius: 18px; outline: none;
}
.big-number:focus { border-color: var(--green); box-shadow: 0 0 0 4px rgba(74, 115, 48, .18); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.seg { display: flex; background: #e6e1d7; border-radius: 14px; padding: 4px; gap: 4px; }
.seg button { flex: 1; min-height: 44px; border: 0; border-radius: 11px; background: transparent; font-weight: 600; cursor: pointer; color: var(--ink-2); }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.1); }

/* ---------- search results ---------- */
.results { margin-top: 14px; display: flex; flex-direction: column; gap: 10px; }
.result {
  display: grid; grid-template-columns: 52px 1fr; gap: 14px; align-items: center; text-align: left;
  width: 100%; padding: 10px; background: var(--card); border: 1.5px solid var(--line); border-radius: 16px; cursor: pointer;
}
.result:active { background: var(--green-soft); }
.result b { display: block; font: 600 17px/1.2 var(--serif); }
.result span { display: block; font-size: 14px; color: var(--ink-2); margin-top: 2px; }
.searching { display: flex; align-items: center; gap: 10px; padding: 14px 4px; color: var(--ink-2); }
.dots span { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--tan); margin-right: 3px; animation: dot 1s infinite ease-in-out; }
.dots span:nth-child(2) { animation-delay: .15s; } .dots span:nth-child(3) { animation-delay: .3s; }
@keyframes dot { 0%, 100% { transform: translateY(0); opacity: .5; } 50% { transform: translateY(-5px); opacity: 1; } }

/* ---------- tiles + stats ---------- */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile { background: var(--card); border: 1.5px solid var(--line); border-radius: 18px; padding: 14px 16px; }
.tile .num { font: 600 34px/1 var(--serif); letter-spacing: -.02em; margin-top: 6px; }
.tile .unit { font-size: 14px; color: var(--ink-2); margin-top: 4px; }
.period { display: flex; align-items: center; justify-content: space-between; margin: 16px 0 14px; }
.period h2 { font-size: 22px; }
.arrow { width: 44px; height: 44px; border-radius: 50%; border: 1.5px solid var(--line); background: var(--card); display: grid; place-items: center; cursor: pointer; }
.arrow svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.arrow:disabled { opacity: .3; cursor: default; }

.chart { position: relative; margin-top: 8px; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid line { stroke: #e2dcd0; stroke-width: 1; }
.chart .grid text, .chart .xlab { fill: var(--ink-2); font: 500 11px var(--sans); }
.chart .bar { fill: var(--bar); }
.chart .bar.dim { opacity: .35; }
.chart .hit { fill: transparent; cursor: pointer; }
.tip {
  position: absolute; pointer-events: none; transform: translate(-50%, calc(-100% - 10px));
  background: var(--ink); color: #fff; padding: 6px 10px; border-radius: 10px; font-size: 13px; white-space: nowrap;
  opacity: 0; transition: opacity .12s;
}
.tip.on { opacity: 1; }
.tip b { font-weight: 700; }
details.numbers { margin-top: 12px; }
details.numbers summary { cursor: pointer; color: var(--green-dark); font-weight: 600; font-size: 15px; padding: 6px 0; }
details.numbers table { width: 100%; border-collapse: collapse; font-size: 15px; margin-top: 6px; }
details.numbers td { padding: 6px 0; border-bottom: 1px solid var(--line); }
details.numbers td:last-child { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- shelf ---------- */
.list { display: flex; flex-direction: column; gap: 10px; }
.row {
  display: grid; grid-template-columns: 48px 1fr auto; gap: 14px; align-items: center;
  padding: 10px 12px 10px 10px; background: var(--card); border: 1.5px solid var(--line); border-radius: 16px; text-decoration: none;
}
.row b { display: block; font: 600 17px/1.2 var(--serif); }
.row span { display: block; font-size: 14px; color: var(--ink-2); margin-top: 2px; }
.row .chev { width: 18px; height: 18px; fill: none; stroke: var(--ink-2); stroke-width: 2; stroke-linecap: round; }
.shelf { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px 14px; }
.shelf a { text-decoration: none; }
.shelf .t { font: 600 14px/1.2 var(--serif); margin-top: 8px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.shelf .d { font-size: 12px; color: var(--ink-2); margin-top: 2px; }

/* book page */
.book-top { display: grid; grid-template-columns: 110px 1fr; gap: 18px; align-items: end; margin: 10px 0 18px; }
.book-top h1 { font-size: 26px; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 10px 16px; font-size: 16px; }
.facts dt { color: var(--ink-2); }
.facts dd { margin: 0; font-weight: 600; text-align: right; }
.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; background: var(--green-soft); color: var(--green-dark); font-size: 13px; font-weight: 700; }
.pill.grey { background: #e6e1d7; color: var(--ink-2); }

/* ---------- sheets (Reed's reactions and questions) ---------- */
.sheet-wrap {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(46, 41, 37, .35);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .2s ease both;
}
.sheet-wrap.full { background: var(--paper); align-items: center; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.sheet {
  width: 100%; max-width: 480px; max-height: 92dvh; overflow: auto;
  background: var(--paper); border-radius: 26px 26px 0 0;
  padding: 22px 20px calc(env(safe-area-inset-bottom) + 22px);
  animation: up .32s cubic-bezier(.2, .9, .3, 1.1) both;
}
.sheet-wrap.full .sheet { border-radius: 0; max-height: 100dvh; animation: none; padding-top: calc(env(safe-area-inset-top) + 22px); }
@keyframes up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet .stage .reed { width: 54%; max-width: 210px; }
.sheet h1 { margin-top: 14px; }
.sheet .sub { margin-top: 8px; color: var(--ink-2); font-size: 17px; }
.sheet .actions { margin-top: 22px; }

/* confetti */
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 60; overflow: hidden; }
.confetti i { position: absolute; top: -20px; width: 9px; height: 14px; border-radius: 2px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(var(--spin)); } }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 18px); z-index: 70;
  transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 14px; font-size: 15px;
  animation: up .25s ease both;
}

.center { text-align: center; }
.mt8 { margin-top: 8px; } .mt16 { margin-top: 16px; } .mt24 { margin-top: 24px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}

body.sheet-open { overflow: hidden; }
.row .cover.blank, .result .cover.blank { font-size: 0; }
.input::placeholder { color: #a39a8f; }
.big-number::placeholder { color: #d3cbbf; }
