:root {
  --ink: #15161A;
  --paper: #F7F7F5;
  --muted: #5A5D66;
  --line: #DCDCD6;
  --surface: #FFFFFF;
  --btn-bg: #15161A;
  --btn-ink: #FFFFFF;
  --serif: 'Newsreader', Georgia, serif;
  --sans: 'Inter', system-ui, -apple-system, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, monospace;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --ink: #EDEDEA;
  --paper: #121317;
  --muted: #A3A6AE;
  --line: #33353D;
  --surface: #1C1E24;
  --btn-bg: #EDEDEA;
  --btn-ink: #15161A;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button { font: inherit; color: inherit; }

#app {
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
}

/* ---------- Card shell ---------- */

.card {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: calc(env(safe-area-inset-top) + 16px) 24px calc(env(safe-area-inset-bottom) + 24px);
  overflow-y: auto;
  user-select: none;
  -webkit-user-select: none;
  animation: card-in 0.22s ease-out;
}

@keyframes card-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .card { animation: none; }
}

.card--story { background: var(--paper); color: var(--ink); }
.card--color { background: var(--sec); color: var(--sec-ink); }

.progress { display: flex; gap: 4px; flex-shrink: 0; }
.progress span {
  flex: 1;
  height: 3px;
  border-radius: 2px;
  background: currentColor;
  opacity: 0.25;
}
.progress span.done { opacity: 1; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.topbar__right { display: flex; align-items: center; gap: 8px; }

.brand, .mono-label {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.mono-label { letter-spacing: 0.1em; }

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 22px;
  border: 1px solid currentColor;
  border-color: color-mix(in srgb, currentColor 40%, transparent);
  background: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.icon-btn svg { width: 20px; height: 20px; }

.streak-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 44px;
  padding: 0 14px;
  border-radius: 22px;
  font-family: var(--mono);
  font-size: 13px;
  background: currentColor;
}
.streak-chip > * { color: var(--chip-ink, #15161A); }
.card--story .streak-chip > * { --chip-ink: var(--paper); }
.card--color .streak-chip > * { --chip-ink: var(--sec); }
.streak-chip svg { width: 16px; height: 16px; }

.spacer { flex-grow: 1; }

/* ---------- Type ---------- */

.display {
  margin: 0;
  font-family: var(--serif);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 0.98;
}
.display--xl { font-size: clamp(52px, 16vw, 68px); }
.display--md { font-size: clamp(30px, 9vw, 36px); line-height: 1.08; letter-spacing: -0.01em; }

.lede { margin: 0; font-size: 16px; line-height: 1.45; opacity: 0.9; }
.body { margin: 0; font-size: 17px; line-height: 1.5; }

/* ---------- Cover / section list ---------- */

.rows { display: flex; flex-direction: column; border-top: 1px solid color-mix(in srgb, currentColor 40%, transparent); }
.row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding: 14px 0;
  border-bottom: 1px solid color-mix(in srgb, currentColor 40%, transparent);
  font-size: 17px;
  font-weight: 500;
}
.row__num { font-family: var(--mono); font-size: 13px; font-weight: 500; }
.row--preview { justify-content: flex-start; align-items: flex-start; font-weight: 400; font-size: 16px; line-height: 1.35; }
.row--preview .row__num { padding-top: 2px; }

.pill-btn {
  height: 56px;
  border-radius: 28px;
  border: 0;
  font-weight: 600;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  text-decoration: none;
  width: 100%;
}
.pill-btn svg { width: 18px; height: 18px; }
.card--color .pill-btn--solid { background: #FFFFFF; color: #15161A; }
.card--color .pill-btn--ghost { background: transparent; color: inherit; border: 1px solid color-mix(in srgb, currentColor 60%, transparent); font-weight: 500; height: 52px; }
.text-link {
  align-self: center;
  background: none;
  border: 0;
  padding: 12px;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.center-note { text-align: center; font-family: var(--mono); font-size: 12px; letter-spacing: 0.06em; }

/* ---------- Story card ---------- */

.tagrow { display: flex; align-items: center; gap: 10px; }
.tag {
  background: var(--sec);
  color: var(--sec-ink);
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 6px 10px;
  border-radius: 6px;
}
.count { font-family: var(--mono); font-size: 12px; color: var(--muted); letter-spacing: 0.06em; }

.block { display: flex; flex-direction: column; gap: 8px; }
.card--story .block .mono-label { color: var(--muted); }

.callout {
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--sec-tint);
  border-radius: 14px;
  padding: 16px;
}
.callout .block { gap: 6px; }
.callout .block p { margin: 0; font-size: 16px; line-height: 1.5; }
.callout .mono-label.accent { color: var(--sec-strong); }
.callout hr { border: 0; height: 1px; background: color-mix(in srgb, var(--ink) 15%, transparent); margin: 0; }
:root[data-theme="dark"] .callout { background: var(--surface); }
:root[data-theme="dark"] .callout .mono-label.accent { color: var(--sec-soft); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
  text-decoration: none;
}

.actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-shrink: 0;
  position: sticky;
  bottom: calc(-1 * (env(safe-area-inset-bottom) + 24px));
  margin: 0 -24px calc(-1 * (env(safe-area-inset-bottom) + 24px));
  padding: 12px 24px calc(env(safe-area-inset-bottom) + 24px);
  background: var(--paper);
}
.actions .icon-btn { width: 52px; height: 52px; border-radius: 26px; background: var(--surface); border: 1px solid var(--line); }
.actions .icon-btn[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.actions .read-btn {
  flex: 1;
  height: 52px;
  border-radius: 26px;
  background: var(--btn-bg);
  color: var(--btn-ink);
  text-decoration: none;
  font-weight: 600;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.actions .read-btn svg { width: 16px; height: 16px; }

/* ---------- Images ---------- */

.hero {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}
.hero img {
  width: 100%;
  aspect-ratio: 2 / 1;
  object-fit: cover;
  border-radius: 14px;
  background: var(--line);
  display: block;
}
.hero figcaption { font-family: var(--mono); font-size: 11px; letter-spacing: 0.04em; color: var(--muted); }
.hero--sm img { aspect-ratio: 2 / 1; border-radius: 10px; }

.thumb { margin: 0; flex-shrink: 0; }
.thumb img {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 10px;
  display: block;
  background: color-mix(in srgb, currentColor 20%, transparent);
}

/* ---------- Recap / milestone ---------- */

.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.stat {
  border: 1px solid color-mix(in srgb, currentColor 45%, transparent);
  border-radius: 14px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stat__num { font-family: var(--serif); font-size: 40px; font-weight: 600; line-height: 1; }
.stat .mono-label { font-size: 12px; letter-spacing: 0.06em; }

.build-num { font-family: var(--serif); font-weight: 600; font-size: clamp(96px, 32vw, 132px); line-height: 0.9; letter-spacing: -0.03em; }
.build-title { margin: 6px 0 0; font-family: var(--serif); font-weight: 500; font-size: 30px; line-height: 1.15; }

.week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
.day { display: flex; flex-direction: column; align-items: center; gap: 6px; font-family: var(--mono); font-size: 11px; }
.dot {
  width: 36px;
  height: 36px;
  border-radius: 18px;
  border: 2px solid color-mix(in srgb, currentColor 35%, transparent);
  display: flex;
  align-items: center;
  justify-content: center;
}
.dot--read { background: currentColor; border-color: currentColor; }
.dot--hotfix { border: 2px dashed currentColor; }
.dot svg { width: 16px; height: 16px; }

.bar { height: 8px; border-radius: 4px; background: color-mix(in srgb, currentColor 30%, transparent); overflow: hidden; }
.bar > div { height: 100%; border-radius: 4px; background: currentColor; }
.bar-labels { display: flex; justify-content: space-between; }

/* ---------- Sheet (all stories, saved) ---------- */

.sheet {
  position: absolute;
  inset: 0;
  background: var(--paper);
  color: var(--ink);
  z-index: 10;
  overflow-y: auto;
  padding: calc(env(safe-area-inset-top) + 16px) 24px calc(env(safe-area-inset-bottom) + 32px);
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.sheet h2 { margin: 0; font-family: var(--serif); font-weight: 600; font-size: 40px; letter-spacing: -0.01em; }
.sheet-section { display: flex; flex-direction: column; gap: 4px; }
.sheet-item { padding: 14px 0; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.sheet-item h3 { margin: 0; font-family: var(--serif); font-weight: 600; font-size: 21px; line-height: 1.2; }
.sheet-item p { margin: 0; color: var(--muted); font-size: 15px; line-height: 1.45; }
.sheet-item .chips .chip { min-height: 36px; padding: 6px 12px; font-size: 13px; }
.empty { color: var(--muted); font-size: 16px; }
.toast {
  position: absolute;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 96px);
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--paper);
  padding: 10px 16px;
  border-radius: 20px;
  font-size: 14px;
  z-index: 20;
  pointer-events: none;
}

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

/* Cards with a photo get a slightly smaller headline so more fits on screen. */
.card--has-image { gap: 18px; }
.card--has-image .display--md { font-size: clamp(27px, 8vw, 31px); }
.card--has-image .body { font-size: 16px; }
