:root {
  --bg: #f7f4ee;
  --surface: #fffdf8;
  --surface-2: #f1ece2;
  --ink: #2b2926;
  --ink-soft: #6b6459;
  --ink-faint: #9a9284;
  --line: #e4ddcf;
  --accent: #3f5b74;
  --accent-deep: #2e4557;
  --gold: #a9812f;
  --good: #4a7c59;
  --shadow: 0 1px 2px rgba(43,41,38,.05), 0 8px 24px rgba(43,41,38,.06);
  --radius: 14px;
  --maxw: 720px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1a1917;
    --surface: #232120;
    --surface-2: #2c2a27;
    --ink: #ece7dd;
    --ink-soft: #b3ab9c;
    --ink-faint: #837b6d;
    --line: #35322d;
    --accent: #8fb0cc;
    --accent-deep: #a9c4db;
    --gold: #caa25a;
    --good: #7fb08d;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  min-height: 100vh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#app { min-height: 100vh; }

.loading {
  display: grid;
  place-items: center;
  min-height: 60vh;
  color: var(--ink-faint);
  font-size: 15px;
}

/* ---------- Shared layout ---------- */
.wrap {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 20px;
}

a { color: var(--accent); }

button {
  font-family: inherit;
  cursor: pointer;
}

/* ---------- List header ---------- */
.masthead {
  padding: 28px 0 8px;
  text-align: center;
}
.masthead h1 {
  font-family: 'EB Garamond', Georgia, serif;
  font-weight: 600;
  font-size: 28px;
  letter-spacing: .2px;
  margin: 0 0 2px;
}
.masthead .subtitle {
  color: var(--ink-soft);
  font-size: 14px;
  margin: 0;
}

/* Progress */
.progress-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  margin: 18px 0 14px;
}
.progress-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.progress-count {
  font-family: 'EB Garamond', Georgia, serif;
  font-size: 19px;
  font-weight: 600;
}
.progress-count b { color: var(--accent-deep); }
.progress-pct {
  font-size: 13px;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}
.bar {
  height: 9px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}
.bar > span {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-deep));
  border-radius: 999px;
  transition: width .5s cubic-bezier(.2,.7,.2,1);
}

/* Controls */
.controls {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg);
  padding: 8px 0 12px;
}
.search {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 15px;
  outline: none;
}
.search:focus { border-color: var(--accent); }
.search::placeholder { color: var(--ink-faint); }

.filters {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.chip {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-soft);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 500;
}
.chip[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.count-note {
  margin-left: auto;
  align-self: center;
  font-size: 12px;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
}

/* Talk list */
.list { list-style: none; margin: 4px 0 40px; padding: 0; }
.item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 4px;
  border-bottom: 1px solid var(--line);
}
.item-body {
  flex: 1;
  min-width: 0;
  cursor: pointer;
  border: none;
  background: none;
  text-align: left;
  padding: 0;
  color: inherit;
}
.item-title {
  font-family: 'EB Garamond', Georgia, serif;
  font-size: 18px;
  font-weight: 600;
  line-height: 1.25;
  margin: 0 0 3px;
  color: var(--ink);
}
.item.read .item-title { color: var(--ink-soft); }
.item-meta {
  font-size: 13px;
  color: var(--ink-faint);
}
.tick {
  flex: none;
  width: 30px;
  height: 30px;
  margin-top: 2px;
  border-radius: 50%;
  border: 1.5px solid var(--line);
  background: var(--surface);
  color: transparent;
  display: grid;
  place-items: center;
  transition: all .18s ease;
}
.tick svg { width: 16px; height: 16px; }
.item.read .tick {
  background: var(--good);
  border-color: var(--good);
  color: #fff;
}
.tick:active { transform: scale(.9); }

.empty {
  text-align: center;
  color: var(--ink-faint);
  padding: 48px 20px;
  font-size: 15px;
}

/* ---------- Reader ---------- */
.reader-top {
  position: sticky;
  top: 0;
  z-index: 5;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.2) blur(8px);
  border-bottom: 1px solid var(--line);
}
.reader-top .wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 52px;
}
.back {
  border: none;
  background: none;
  color: var(--accent);
  font-size: 15px;
  font-weight: 500;
  padding: 8px 6px 8px 0;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.reader {
  padding: 10px 0 120px;
}
.reader h2 {
  font-family: 'EB Garamond', Georgia, serif;
  font-weight: 600;
  font-size: 30px;
  line-height: 1.15;
  margin: 18px 0 8px;
}
.reader .byline {
  color: var(--ink-soft);
  font-size: 15px;
  margin: 0 0 4px;
}
.reader .origin {
  font-size: 14px;
  margin: 0 0 20px;
}
.reader hr {
  border: none;
  border-top: 1px solid var(--line);
  margin: 0 0 22px;
}
.prose p {
  font-family: 'EB Garamond', Georgia, serif;
  font-size: 20px;
  line-height: 1.62;
  margin: 0 0 1.05em;
  color: var(--ink);
}

/* Floating mark-as-read */
.mark-dock {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 14px 20px calc(14px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 70%, transparent);
  display: flex;
  justify-content: center;
}
.mark-btn {
  width: 100%;
  max-width: var(--maxw);
  border: 1.5px solid var(--accent);
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  padding: 14px;
  border-radius: 14px;
  box-shadow: var(--shadow);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all .18s ease;
}
.mark-btn.is-read {
  background: var(--surface);
  color: var(--good);
  border-color: var(--good);
}
.mark-btn svg { width: 18px; height: 18px; }
.mark-btn:active { transform: translateY(1px); }

/* Sync status pill */
.sync {
  position: fixed;
  top: calc(10px + env(safe-area-inset-top));
  right: 12px;
  z-index: 30;
  font-size: 12px;
  color: var(--ink-soft);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 11px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity .3s, transform .3s;
  pointer-events: none;
}
.sync.show { opacity: 1; transform: translateY(0); }
.sync.warn { color: var(--gold); }
