:root {
  --bg: #100e0c;
  --bg-raised: #1a1714;
  --bg-sunken: #0a0908;
  --ink: #e9ddc9;
  --ink-soft: #a89880;
  --ink-faint: #6b5f4f;
  --accent: #d9a441;
  --accent-soft: #8a6a2c;
  --line: #2a251f;
  --serif: ui-serif, "Iowan Old Style", "Charter", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --story-size: 21px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
html[data-theme="day"] {
  --bg: #f7f2e7;
  --bg-raised: #fffdf8;
  --bg-sunken: #ece5d6;
  --ink: #241f19;
  --ink-soft: #6b5f4f;
  --ink-faint: #9c8f7c;
  --accent: #9a6b12;
  --accent-soft: #c9a45e;
  --line: #ded4c1;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

#dim {
  position: fixed; inset: 0; z-index: 90; pointer-events: none;
  background: #000; opacity: 0; transition: opacity .25s;
}

/* ---------- layout ---------- */
#app { padding: calc(var(--safe-t) + 20px) 20px 120px; max-width: 720px; margin: 0 auto; }
.view { animation: rise .32s cubic-bezier(.2,.7,.3,1) both; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

.eyebrow {
  font-size: 11px; letter-spacing: .16em; text-transform: uppercase;
  color: var(--ink-faint); font-weight: 600;
}
h1 { font-family: var(--serif); font-size: 30px; line-height: 1.15; margin: 6px 0 0; font-weight: 600; }
.sub { color: var(--ink-soft); font-size: 14px; margin-top: 8px; line-height: 1.5; }

/* ---------- tonight ---------- */
.hero { margin-bottom: 26px; }
.cards { display: flex; flex-direction: column; gap: 14px; }

.card {
  display: block; width: 100%; text-align: left;
  background: var(--bg-raised); border: 1px solid var(--line);
  border-radius: 18px; padding: 16px 18px; position: relative;
  transition: transform .12s, border-color .2s;
}
.card:active { transform: scale(.985); }
.card.done { opacity: .5; }
.card-top { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.card-top svg { width: 15px; height: 15px; color: var(--accent); flex: none; }
.slot {
  font-size: 10.5px; letter-spacing: .14em; text-transform: uppercase;
  color: var(--accent); font-weight: 700;
}
.card h2 {
  font-family: var(--serif); font-size: 21px; line-height: 1.25;
  margin: 0 0 6px; font-weight: 600; padding-right: 34px;
}
.card .meta { font-size: 13px; color: var(--ink-soft); line-height: 1.45; }
.card .mins { font-size: 12px; color: var(--ink-faint); margin-top: 8px; }
.swap {
  position: absolute; top: 12px; right: 10px;
  width: 40px; height: 40px; display: grid; place-items: center;
  color: var(--ink-faint); border-radius: 12px;
}
.swap:active { color: var(--accent); }
.check { position: absolute; bottom: 14px; right: 16px; color: var(--accent); }
.check svg { width: 18px; height: 18px; }

.tonight-foot { margin-top: 22px; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.ghost {
  border: 1px solid var(--line); border-radius: 999px; padding: 9px 16px;
  font-size: 13px; color: var(--ink-soft);
}
.ghost:active { border-color: var(--accent-soft); color: var(--accent); }

.streak {
  margin-top: 26px; padding-top: 18px; border-top: 1px solid var(--line);
  display: flex; gap: 22px; color: var(--ink-faint); font-size: 12px;
}
.streak b { display: block; font-family: var(--serif); font-size: 22px; color: var(--ink); font-weight: 600; }

/* ---------- reader ---------- */
#app.reading { padding-bottom: 150px; }
.progress {
  position: fixed; top: 0; left: 0; height: 2px; background: var(--accent);
  z-index: 60; transition: width .1s linear;
}
.r-head { margin-bottom: 26px; }
.r-head h1 { font-size: 29px; margin-top: 10px; }
.r-source { font-family: var(--serif); font-style: italic; color: var(--ink-soft); font-size: 15px; margin-top: 12px; }
.r-lesson {
  margin-top: 18px; padding: 13px 15px; border-left: 2px solid var(--accent-soft);
  background: var(--bg-raised); border-radius: 0 12px 12px 0;
}
.r-lesson .tag {
  font-size: 10px; letter-spacing: .14em; text-transform: uppercase;
  color: var(--ink-faint); font-weight: 700; display: block; margin-bottom: 5px;
}
.r-lesson p { margin: 0; font-family: var(--serif); font-style: italic; font-size: 15px; line-height: 1.5; color: var(--ink-soft); }

.story { font-family: var(--serif); font-size: var(--story-size); line-height: 1.72; }
.story p { margin: 0 0 1.05em; }
.story .verse { margin: 0 0 1.25em; text-align: center; line-height: 1.62; }
.story .verse span { display: block; }
.story .first::first-line { font-variant-caps: small-caps; letter-spacing: .015em; }
.the-end {
  text-align: center; font-family: var(--serif); font-style: italic;
  color: var(--ink-faint); margin: 34px 0 30px; font-size: 16px;
}

.r-next {
  border-top: 1px solid var(--line); padding-top: 22px;
}
.r-next .label { font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-faint); font-weight: 600; }
.btn {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; margin-top: 12px; padding: 15px 18px;
  background: var(--accent); color: #17120a; border-radius: 15px;
  font-weight: 650; font-size: 15px; text-align: left;
}
html[data-theme="day"] .btn { color: #fffdf8; }
.btn:active { filter: brightness(.92); }
.btn.secondary { background: transparent; border: 1px solid var(--line); color: var(--ink-soft); font-weight: 500; }
.btn svg { flex: none; width: 19px; height: 19px; }
.btn .t { flex: 1; min-width: 0; }
.btn .t small { display: block; font-weight: 500; opacity: .72; font-size: 12px; margin-top: 2px; }

/* ---------- reader toolbar ---------- */
#toolbar {
  position: fixed; z-index: 80; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--safe-b) + 16px);
  display: flex; align-items: center; gap: 4px;
  background: var(--bg-raised); border: 1px solid var(--line);
  border-radius: 999px; padding: 5px; box-shadow: 0 8px 30px rgba(0,0,0,.45);
  transition: opacity .25s, transform .25s;
}
#toolbar.tucked { opacity: 0; transform: translateX(-50%) translateY(28px); pointer-events: none; }
#toolbar button { width: 46px; height: 42px; display: grid; place-items: center; border-radius: 999px; color: var(--ink-soft); }
#toolbar button:active { background: var(--bg-sunken); color: var(--accent); }
#toolbar button.on { color: var(--accent); }
#toolbar .divider { width: 1px; height: 22px; background: var(--line); margin: 0 3px; }
.aa-sm { font-family: var(--serif); font-size: 13px; }
.aa-lg { font-family: var(--serif); font-size: 19px; }

/* ---------- library ---------- */
.search {
  width: 100%; margin: 16px 0 14px; padding: 13px 16px;
  background: var(--bg-raised); border: 1px solid var(--line); border-radius: 14px;
  color: var(--ink); font-size: 16px; font-family: var(--sans);
}
.search::placeholder { color: var(--ink-faint); }
.search:focus { outline: none; border-color: var(--accent-soft); }

.filters { display: flex; gap: 7px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 6px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 7px 14px; border-radius: 999px; font-size: 13px;
  border: 1px solid var(--line); color: var(--ink-soft); white-space: nowrap;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: #17120a; font-weight: 600; }
html[data-theme="day"] .chip.on { color: #fffdf8; }

.rows { margin-top: 4px; }
.row {
  display: flex; align-items: baseline; gap: 12px; width: 100%; text-align: left;
  padding: 14px 2px; border-bottom: 1px solid var(--line);
}
.row .n { font-size: 11px; color: var(--ink-faint); width: 30px; flex: none; font-variant-numeric: tabular-nums; }
.row .body { flex: 1; min-width: 0; }
.row .ttl { display: block; font-family: var(--serif); font-size: 17px; line-height: 1.3; }
.row .src { display: block; font-size: 12.5px; color: var(--ink-soft); margin-top: 3px; line-height: 1.4; }
.row.read .ttl, .row.read .src { color: var(--ink-faint); }
.row .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); flex: none; align-self: center; opacity: 0; }
.row.read .dot { opacity: .55; }
.empty { text-align: center; color: var(--ink-faint); padding: 50px 20px; font-size: 14px; line-height: 1.6; }

/* ---------- goodnight ---------- */
.goodnight { text-align: center; padding: 60px 10px 30px; }
.goodnight svg { width: 46px; height: 46px; color: var(--accent); stroke-width: 1.2; }
.goodnight h1 { font-size: 34px; margin-top: 20px; }
.goodnight .sub { max-width: 340px; margin: 12px auto 0; }
.goodnight .btn { max-width: 300px; margin: 26px auto 0; }

/* ---------- tab bar ---------- */
#tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 70;
  display: flex; justify-content: center; gap: 6px;
  padding: 8px 10px calc(var(--safe-b) + 8px);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
#tabbar.hide { display: none; }
.tab {
  flex: 1; max-width: 130px; display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 6px 4px; color: var(--ink-faint); border-radius: 12px;
}
.tab span { font-size: 10.5px; letter-spacing: .02em; }
.tab.on { color: var(--accent); }
.tab svg { width: 21px; height: 21px; }

.backlink { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-faint); font-size: 13px; margin-bottom: 4px; }
.backlink svg { width: 15px; height: 15px; }

@media (min-width: 640px) { #app { padding-left: 32px; padding-right: 32px; } }
@media (prefers-reduced-motion: reduce) { .view { animation: none; } }
