/* Tokens first: every color below is a role, swapped whole for dark mode.
   The calendar ramp is one hue in four ordinal steps, validated against the
   surface it sits on (light end >= 2:1) — an empty day must never be
   mistaken for a short one. */
:root {
  color-scheme: light;
  --page: #f7f5f0;
  --surface: #fdfcf9;
  --ink: #1b1a17;
  --ink-2: #55534d;
  --muted: #84817a;
  --hair: #e6e3da;
  --base: #c9c6bc;
  --ring: rgba(11, 11, 11, 0.08);
  --c0: #ecebe6;
  --c1: #6cc07c;
  --c2: #3a9d55;
  --c3: #1f7a3d;
  --c4: #0f5228;
  --accent: #2f8a4a;
  --track: #d7eedb;
  --rest: #d3d0c6;
  --good: #0a7d0a;
  --shelf: #b8a58a;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0f0f0e;
    --surface: #1a1a19;
    --ink: #f4f3ee;
    --ink-2: #c3c2b7;
    --muted: #8f8c84;
    --hair: #2c2c2a;
    --base: #3d3d39;
    --ring: rgba(255, 255, 255, 0.08);
    --c0: #262624;
    --c1: #23793f;
    --c2: #2f9a52;
    --c3: #4cbf6b;
    --c4: #86e396;
    --accent: #4cbf6b;
    --track: #1f3a26;
    --rest: #46453f;
    --good: #3fc23f;
    --shelf: #5a4c3a;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0f0f0e;
  --surface: #1a1a19;
  --ink: #f4f3ee;
  --ink-2: #c3c2b7;
  --muted: #8f8c84;
  --hair: #2c2c2a;
  --base: #3d3d39;
  --ring: rgba(255, 255, 255, 0.08);
  --c0: #262624;
  --c1: #23793f;
  --c2: #2f9a52;
  --c3: #4cbf6b;
  --c4: #86e396;
  --accent: #4cbf6b;
  --track: #1f3a26;
  --rest: #46453f;
  --good: #3fc23f;
  --shelf: #5a4c3a;
}

*, *::before, *::after { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 16px/1.5 var(--sans);
}

a { color: inherit; text-underline-offset: 3px; text-decoration-color: var(--base); }
a:hover { text-decoration-color: currentColor; }

h1, h2, h3, p { margin: 0; }

.page {
  max-width: 1000px;
  margin: 0 auto;
  padding: 40px 16px 56px;
  display: grid;
  gap: 16px;
}

.masthead { padding: 8px 4px 16px; }
.masthead h1 {
  font: 600 clamp(36px, 7vw, 52px)/1.05 var(--serif);
  letter-spacing: -0.01em;
}
.masthead p { color: var(--ink-2); margin-top: 8px; }

.status { color: var(--muted); padding: 0 4px; }
.status:empty { display: none; }

.card {
  background: var(--surface);
  border-radius: 16px;
  box-shadow: 0 0 0 1px var(--ring);
  padding: 20px;
  min-width: 0;
}

.card h2, .eyebrow {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-2);
}

.caption { color: var(--muted); font-size: 14px; margin: 2px 0 16px; }

.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

/* --- hero ---------------------------------------------------------------- */

.hero { display: grid; gap: 16px; }
@media (min-width: 760px) { .hero { grid-template-columns: 5fr 7fr; } }

.streak { display: flex; flex-direction: column; justify-content: center; gap: 4px; padding: 28px 24px; }
.hero-num {
  font-size: clamp(72px, 16vw, 112px);
  font-weight: 650;
  line-height: 0.95;
  letter-spacing: -0.04em;
}
.hero-label { font-size: 18px; color: var(--ink-2); }
.today { margin-top: 16px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.today.ok { color: var(--good); }
.today.wait { color: var(--ink-2); }
.today svg { flex: none; }
.sub { color: var(--muted); font-size: 14px; }

.now { display: grid; gap: 16px; align-content: start; }
.book { display: grid; grid-template-columns: 96px 1fr; gap: 20px; align-items: start; }
@media (min-width: 480px) { .book { grid-template-columns: 112px 1fr; } }

.cover {
  aspect-ratio: 2 / 3;
  border-radius: 3px 6px 6px 3px;
  overflow: hidden;
  background: var(--cloth, #6b5b45);
  box-shadow: inset 4px 0 0 rgba(0, 0, 0, 0.18), 0 6px 16px -6px rgba(0, 0, 0, 0.35);
  color: #fbf8f0;
  display: flex;
  align-items: flex-end;
  font: 600 14px/1.2 var(--serif);
}
.cover span { padding: 12px 10px 12px 14px; }
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; }

.book .title { font: 600 clamp(22px, 4vw, 28px)/1.15 var(--serif); }
.book .author { color: var(--ink-2); margin-top: 4px; }

.meter {
  height: 8px;
  border-radius: 4px;
  background: var(--track);
  margin: 16px 0 8px;
  overflow: hidden;
}
.meter span { display: block; height: 100%; width: var(--p); background: var(--accent); border-radius: 4px; }

.meta { color: var(--ink-2); font-size: 14px; }
.next { color: var(--ink-2); font-size: 14px; border-top: 1px solid var(--hair); padding-top: 12px; }
.next i { font-family: var(--serif); color: var(--ink); }
.empty { color: var(--muted); }

/* --- tiles --------------------------------------------------------------- */

.tiles { display: grid; gap: 16px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 640px) { .tiles { grid-template-columns: repeat(var(--n, 5), minmax(0, 1fr)); } }
.tile .label { font-size: 14px; color: var(--ink-2); }
.tile .value { font-size: 28px; font-weight: 600; letter-spacing: -0.01em; margin-top: 2px; }
.tile .unit { font-size: 15px; font-weight: 500; color: var(--muted); margin-left: 2px; }

/* --- calendar ------------------------------------------------------------ */

.years { display: flex; gap: 4px; }
.years button {
  font: 500 13px var(--sans);
  color: var(--ink-2);
  background: none;
  border: 0;
  border-radius: 8px;
  padding: 4px 10px;
  cursor: pointer;
}
.years button:hover { background: var(--c0); }
.years button[aria-pressed="true"] { background: var(--ink); color: var(--surface); }

.calendar { overflow-x: auto; padding-bottom: 4px; border-radius: 8px; outline-offset: 4px; }
.calendar svg { display: block; }
.calendar text, .chart text { font: 11px var(--sans); fill: var(--muted); }
.calendar rect { stroke: transparent; stroke-width: 2; }
.calendar rect.today { stroke: var(--ink-2); stroke-width: 1.5; }
.calendar rect.hot { stroke: var(--ink); stroke-width: 1.5; }

.c0 { fill: var(--c0); background: var(--c0); }
.c1 { fill: var(--c1); background: var(--c1); }
.c2 { fill: var(--c2); background: var(--c2); }
.c3 { fill: var(--c3); background: var(--c3); }
.c4 { fill: var(--c4); background: var(--c4); }

.legend { display: flex; justify-content: flex-end; align-items: center; gap: 3px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.legend i { width: 11px; height: 11px; border-radius: 2px; display: inline-block; }
.legend i:first-child { margin-left: 4px; }
.legend i:last-child { margin-right: 4px; }

/* --- weeks & streaks ----------------------------------------------------- */

.pair { display: grid; gap: 16px; }
@media (min-width: 860px) { .pair { grid-template-columns: 3fr 2fr; } }

.chart { position: relative; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .grid { stroke: var(--hair); stroke-width: 1; }
.chart .axis { stroke: var(--base); stroke-width: 1; }
.chart .bar { fill: var(--accent); }
.chart .bar.hot { opacity: 0.75; }
.chart .hit { fill: transparent; cursor: default; }

.runs { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.runs li { display: grid; grid-template-columns: minmax(0, 9.5em) 1fr; gap: 4px 12px; align-items: center; font-size: 14px; }
.runs .when { color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.runs .track { display: flex; align-items: center; gap: 8px; min-width: 0; }
.runs .fill { height: 12px; min-width: 4px; border-radius: 0 4px 4px 0; background: var(--rest); width: var(--w); }
.runs .live .fill { background: var(--accent); }
.runs .days { font-variant-numeric: tabular-nums; color: var(--ink-2); white-space: nowrap; }
.runs .live .days { color: var(--ink); font-weight: 600; }

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

.shelf {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  min-height: 236px;
  padding: 16px 12px 0;
  overflow-x: auto;
  border-bottom: 10px solid var(--shelf);
  border-radius: 8px 8px 2px 2px;
  background: linear-gradient(to top, var(--c0), transparent 70%);
}

.spine {
  flex: none;
  width: var(--w);
  height: var(--h);
  background: var(--cloth);
  color: #fbf8f0;
  border: 0;
  border-radius: 3px 3px 1px 1px;
  padding: 10px 0;
  cursor: pointer;
  writing-mode: vertical-rl;
  font: 600 13px/1 var(--serif);
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: inset 3px 0 0 rgba(255, 255, 255, 0.12), inset -3px 0 0 rgba(0, 0, 0, 0.18);
  transform-origin: bottom left;
  transition: transform 160ms ease;
}
.spine:hover, .spine:focus-visible { transform: translateY(-6px); }
.spine[aria-pressed="true"] { transform: translateY(-12px); outline: 2px solid var(--ink); outline-offset: 2px; }
.spine.dropped { transform: rotate(-5deg); opacity: 0.7; margin: 0 6px; }
.spine.dropped:hover, .spine.dropped:focus-visible { transform: rotate(-5deg) translateY(-6px); }
.spine.dropped[aria-pressed="true"] { transform: rotate(-5deg) translateY(-12px); }

.detail { display: grid; gap: 6px; padding-top: 20px; }
.detail .title { font: 600 24px/1.2 var(--serif); }
.detail .meta { color: var(--ink-2); }
.detail .stars { letter-spacing: 2px; color: var(--ink); }
.detail blockquote {
  margin: 6px 0 0;
  padding-left: 14px;
  border-left: 3px solid var(--accent);
  font: italic 18px/1.45 var(--serif);
}

.foot { color: var(--muted); font-size: 14px; padding: 8px 4px; }

/* --- tooltip ------------------------------------------------------------- */

.tip {
  position: fixed;
  z-index: 10;
  max-width: 260px;
  pointer-events: none;
  background: var(--ink);
  color: var(--surface);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  line-height: 1.4;
  box-shadow: 0 8px 24px -8px rgba(0, 0, 0, 0.4);
}
.tip strong { display: block; font-size: 15px; }
.tip .muted { opacity: 0.72; }
.tip .book { font-family: var(--serif); }

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
  .spine { transition: none; }
}
