/* Reading Space — app styles. Mobile-first; sidebar layout ≥ 900px. */

:root {
  --brand: #e4572e;
  --brand-strong: #c9441d;
  --brand-soft: #fde8e1;
  --on-brand: #fff;
  --bg: #faf8f5;
  --bg-elev: #ffffff;
  --bg-sunken: #f2eee8;
  --fg: #1f1b16;
  --fg-muted: #6b645b;
  --fg-faint: #9a9288;
  --border: #e8e2d9;
  --border-strong: #d6cec2;
  --shadow: 0 1px 2px rgba(40, 30, 20, .05), 0 4px 16px rgba(40, 30, 20, .06);
  --shadow-lg: 0 10px 40px rgba(40, 30, 20, .18);
  --success: #2f8f5b;
  --danger: #c43d3d;
  --hl-yellow: #fff1a8;
  --hl-green: #c9f2c7;
  --hl-blue: #c7e3ff;
  --hl-pink: #ffd1e3;
  --hl-purple: #e3d4ff;
  --radius: 16px;
  --radius-sm: 10px;
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, "Times New Roman", serif;
  --tabbar-h: 64px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  color-scheme: light;
}

[data-theme="dark"] {
  --brand: #f0683f;
  --brand-strong: #ff8a62;
  --brand-soft: #3a2119;
  --bg: #141210;
  --bg-elev: #1e1b18;
  --bg-sunken: #0f0d0c;
  --fg: #efe9e1;
  --fg-muted: #a69e94;
  --fg-faint: #776f66;
  --border: #2e2a26;
  --border-strong: #403a34;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  --shadow-lg: 0 10px 40px rgba(0, 0, 0, .6);
  --success: #5cc48b;
  --danger: #ff6b6b;
  --hl-yellow: #6b5d12;
  --hl-green: #245a2c;
  --hl-blue: #1f4870;
  --hl-pink: #6e2846;
  --hl-purple: #4b3577;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
  min-height: 100dvh;
}
img, svg { display: block; max-width: 100%; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { line-height: 1.2; margin: 0; }
p { margin: 0; }
[hidden] { display: none !important; }

:focus-visible { outline: 3px solid color-mix(in srgb, var(--brand) 60%, transparent); outline-offset: 2px; border-radius: 6px; }

.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: 8px; top: -60px; z-index: 1000; background: var(--bg-elev); padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); }
.skip-link:focus { top: calc(8px + var(--safe-top)); }

/* ---------- Layout ---------- */
.layout { min-height: 100vh; }
main {
  outline: none;
  max-width: 760px;
  margin: 0 auto;
  padding: calc(16px + var(--safe-top)) calc(18px + var(--safe-right)) calc(var(--tabbar-h) + 32px + var(--safe-bottom)) calc(18px + var(--safe-left));
}
main.wide { max-width: 1040px; }

.sidebar { display: none; }
.tabbar {
  position: fixed; z-index: 50; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: space-around;
  padding: 6px calc(6px + var(--safe-right)) calc(6px + var(--safe-bottom)) calc(6px + var(--safe-left));
  background: color-mix(in srgb, var(--bg-elev) 88%, transparent);
  -webkit-backdrop-filter: saturate(1.6) blur(16px);
  backdrop-filter: saturate(1.6) blur(16px);
  border-top: 1px solid var(--border);
}
.tabbar a {
  flex: 1; min-height: 52px; min-width: 44px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 11px; font-weight: 500; color: var(--fg-muted); border-radius: 12px; text-decoration: none;
}
.tabbar a svg { width: 24px; height: 24px; }
.tabbar a[aria-current="page"] { color: var(--brand); }
body.no-chrome .tabbar, body.no-chrome .sidebar { display: none !important; }
body.no-chrome main { padding-bottom: calc(40px + var(--safe-bottom)); }

@media (min-width: 900px) {
  .tabbar { display: none; }
  .sidebar {
    display: flex; flex-direction: column; gap: 4px;
    position: fixed; top: 0; bottom: 0; left: 0; width: 240px;
    padding: calc(24px + var(--safe-top)) 16px 24px calc(16px + var(--safe-left));
    border-right: 1px solid var(--border);
    background: var(--bg-elev);
  }
  .sidebar .brand { margin: 0 8px 24px; }
  .sidebar a.nav {
    display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 12px;
    color: var(--fg-muted); border-radius: 10px; font-weight: 500; text-decoration: none;
  }
  .sidebar a.nav svg { width: 20px; height: 20px; }
  .sidebar a.nav:hover { background: var(--bg-sunken); color: var(--fg); }
  .sidebar a.nav[aria-current="page"] { background: var(--brand-soft); color: var(--brand); }
  .sidebar .spacer { flex: 1; }
  .layout { padding-left: 240px; }
  main { padding: 40px 40px 64px; }
  body.no-chrome .layout { padding-left: 0; }
}

/* ---------- Brand ---------- */
.brand { display: flex; align-items: center; gap: 10px; color: var(--fg); text-decoration: none !important; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px; background: var(--brand); color: #fff;
  display: grid; place-items: center; font-family: var(--font-serif); font-weight: 700; font-size: 24px; line-height: 1; padding-bottom: 4px;
}
.brand-name { font-family: var(--font-serif); font-size: 19px; font-weight: 600; letter-spacing: -.01em; }

/* ---------- Offline banner ---------- */
.offline-banner {
  position: sticky; top: 0; z-index: 60;
  padding: calc(8px + var(--safe-top)) 16px 8px; text-align: center; font-size: 14px; font-weight: 500;
  background: var(--fg); color: var(--bg);
}

/* ---------- Typography helpers ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 8px 0 20px; }
.page-title { font-family: var(--font-serif); font-size: 32px; font-weight: 600; letter-spacing: -.02em; }
.page-sub { color: var(--fg-muted); margin-top: 4px; }
.section-title { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--fg-muted); margin: 28px 0 12px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.section-title a { text-transform: none; letter-spacing: 0; font-size: 14px; }
.muted { color: var(--fg-muted); }
.faint { color: var(--fg-faint); }
.small { font-size: 14px; }
.serif { font-family: var(--font-serif); }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 12px; }
.center { text-align: center; }

/* ---------- Cards ---------- */
.card {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow);
}
.card + .card { margin-top: 12px; }
.card-title { font-weight: 600; font-size: 15px; margin-bottom: 6px; }
.grid { display: grid; gap: 12px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 640px) { .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border-radius: 999px; border: 1px solid var(--border-strong);
  background: var(--bg-elev); color: var(--fg); font-weight: 600; font-size: 15px; cursor: pointer;
  text-decoration: none !important; white-space: nowrap; transition: background .15s, transform .1s, border-color .15s;
}
.btn:hover { background: var(--bg-sunken); }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn svg { width: 18px; height: 18px; flex: none; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.btn-primary:hover { background: var(--brand-strong); border-color: var(--brand-strong); }
.btn-danger { color: var(--danger); }
.btn-danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--bg-sunken); }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn-block { width: 100%; }
.icon-btn {
  display: inline-grid; place-items: center; width: 44px; height: 44px; flex: none;
  border: none; background: transparent; border-radius: 12px; color: var(--fg-muted); cursor: pointer;
}
.icon-btn:hover { background: var(--bg-sunken); color: var(--fg); }
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn.active { color: var(--brand); }
.icon-btn.sm { width: 40px; height: 40px; }
.icon-btn.sm svg { width: 19px; height: 19px; }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Forms ---------- */
.input, .select, .textarea {
  width: 100%; min-height: 44px; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--border-strong);
  background: var(--bg-elev); font-size: 16px;
}
.textarea { min-height: 96px; resize: vertical; line-height: 1.5; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 25%, transparent); }
.search { position: relative; }
.search svg { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--fg-faint); pointer-events: none; }
.search .input { padding-left: 40px; border-radius: 999px; }
label.field { display: block; }
label.field > span { display: block; font-size: 14px; font-weight: 500; color: var(--fg-muted); margin-bottom: 6px; }

.switch { position: relative; display: inline-block; width: 50px; height: 30px; flex: none; }
.switch input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--border-strong); transition: background .2s; pointer-events: none; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .2s; }
.switch input:checked + span { background: var(--brand); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:focus-visible + span { outline: 3px solid color-mix(in srgb, var(--brand) 60%, transparent); outline-offset: 2px; }

/* segmented control */
.segmented {
  display: inline-flex; padding: 4px; gap: 2px; border-radius: 999px; background: var(--bg-sunken); border: 1px solid var(--border);
  max-width: 100%; overflow-x: auto; scrollbar-width: none;
}
.segmented::-webkit-scrollbar { display: none; }
.segmented button {
  min-height: 36px; padding: 0 14px; border: none; border-radius: 999px; background: transparent; color: var(--fg-muted);
  font-weight: 600; font-size: 14px; cursor: pointer; white-space: nowrap;
}
.segmented button[aria-pressed="true"], .segmented button[aria-selected="true"] { background: var(--bg-elev); color: var(--fg); box-shadow: var(--shadow); }
.segmented.block { display: flex; }
.segmented.block button { flex: 1; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; scrollbar-width: none; }
.tabs button {
  min-height: 44px; padding: 0 14px; border: none; background: none; cursor: pointer; font-weight: 600; color: var(--fg-muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap;
}
.tabs button[aria-selected="true"] { color: var(--fg); border-bottom-color: var(--brand); }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--bg-elev); font-size: 14px; font-weight: 500; color: var(--fg-muted); cursor: pointer; white-space: nowrap;
}
.chip b { color: var(--fg); font-weight: 700; }
.chip[aria-pressed="true"] { border-color: var(--brand); color: var(--brand); background: var(--brand-soft); }
.chip[aria-pressed="true"] b { color: var(--brand); }
.chip svg { width: 16px; height: 16px; }
.chip.removable { padding-right: 4px; cursor: default; }
.chip.removable button { border: none; background: none; width: 28px; height: 28px; display: grid; place-items: center; color: inherit; cursor: pointer; border-radius: 50%; }

.day-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.day-chips button {
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--border-strong); background: var(--bg-elev);
  font-weight: 600; font-size: 13px; color: var(--fg-muted); cursor: pointer;
}
.day-chips button[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: #fff; }

/* ---------- Issue list ---------- */
.issue-list { display: flex; flex-direction: column; gap: 10px; }
.issue {
  position: relative; display: flex; gap: 12px; padding: 14px 6px 12px 14px;
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  transition: border-color .15s;
}
.issue:hover { border-color: var(--border-strong); }
.issue .avatar { margin-top: 2px; }
.issue-body { flex: 1; min-width: 0; }
.issue-link { color: inherit; text-decoration: none !important; display: block; }
.issue-link::after { content: ""; position: absolute; inset: 0; border-radius: var(--radius); }
.issue-meta { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--fg-muted); min-width: 0; }
.issue-meta .pub { font-weight: 600; color: var(--fg); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.issue-meta .when { flex: none; }
.issue-subject { font-family: var(--font-serif); font-size: 18px; font-weight: 600; line-height: 1.3; margin: 4px 0; letter-spacing: -.005em; overflow-wrap: anywhere; }
.issue.read .issue-subject { color: var(--fg-muted); font-weight: 500; }
.issue-snippet { font-size: 14px; color: var(--fg-muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.issue-foot { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--fg-faint); margin-top: 8px; flex-wrap: wrap; }
.issue-foot svg { width: 14px; height: 14px; }
.issue-actions { position: relative; z-index: 1; display: flex; flex-direction: column; margin: -6px 0; }
.unread-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--brand); flex: none; }
.progress-mini { width: 48px; height: 4px; border-radius: 4px; background: var(--bg-sunken); overflow: hidden; }
.progress-mini i { display: block; height: 100%; background: var(--brand); }
.avatar {
  width: 40px; height: 40px; border-radius: 12px; flex: none; display: grid; place-items: center;
  font-weight: 700; font-size: 17px; color: #fff; font-family: var(--font-serif);
}
.avatar.sm { width: 28px; height: 28px; font-size: 13px; border-radius: 8px; }
.avatar.lg { width: 56px; height: 56px; font-size: 24px; border-radius: 16px; }

.list-row {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; min-height: 60px;
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); color: inherit; text-decoration: none !important;
}
.list-row + .list-row { margin-top: 8px; }
.list-row:hover { border-color: var(--border-strong); }
.list-row .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row .sub { font-size: 13px; color: var(--fg-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row > svg { width: 18px; height: 18px; color: var(--fg-faint); flex: none; }
.badge { display: inline-flex; align-items: center; justify-content: center; min-width: 24px; height: 24px; padding: 0 8px; border-radius: 999px; background: var(--brand); color: #fff; font-size: 12px; font-weight: 700; }
.badge.neutral { background: var(--bg-sunken); color: var(--fg-muted); }

.cat-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 640px) { .cat-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.cat {
  display: flex; flex-direction: column; gap: 8px; padding: 16px; min-height: 112px; border-radius: var(--radius);
  background: var(--bg-elev); border: 1px solid var(--border); color: inherit; text-decoration: none !important;
}
.cat:hover { border-color: var(--border-strong); }
.cat .cat-icon { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; color: #fff; }
.cat .cat-icon svg { width: 20px; height: 20px; }
.cat .name { font-weight: 600; line-height: 1.25; }
.cat .sub { font-size: 13px; color: var(--fg-muted); margin-top: auto; }

.empty { text-align: center; padding: 48px 16px; color: var(--fg-muted); }
.empty svg { width: 44px; height: 44px; margin: 0 auto 12px; color: var(--fg-faint); }
.empty h3 { color: var(--fg); font-family: var(--font-serif); font-size: 20px; margin-bottom: 6px; }
.empty .btn { margin-top: 16px; }

/* skeletons */
.skel { background: linear-gradient(90deg, var(--bg-sunken) 25%, color-mix(in srgb, var(--bg-sunken) 50%, var(--bg-elev)) 37%, var(--bg-sunken) 63%); background-size: 400% 100%; animation: shimmer 1.4s ease infinite; border-radius: 8px; }
.skel-line { height: 14px; margin: 8px 0; }
.skel-card { height: 112px; border-radius: var(--radius); }
.skel-card + .skel-card { margin-top: 10px; }
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* ---------- Home ---------- */
.home-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.home-top .brand-mark { width: 32px; height: 32px; font-size: 21px; }
@media (min-width: 900px) { .home-top .brand { display: none; } }
.greeting { font-family: var(--font-serif); font-size: 30px; font-weight: 600; letter-spacing: -.02em; margin-top: 18px; }
@media (min-width: 640px) { .greeting { font-size: 36px; } }
.stat-hero { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 20px; }
.stat-hero .card { display: flex; align-items: center; gap: 10px; padding: 14px; margin: 0; min-width: 0; }
@media (min-width: 480px) { .stat-hero .card { gap: 14px; padding: 16px; } }
.stat-hero .ring { width: 44px; height: 44px; }
@media (min-width: 480px) { .stat-hero .ring { width: 52px; height: 52px; } }
.stat-hero .big { white-space: nowrap; font-size: 26px; font-weight: 700; line-height: 1; letter-spacing: -.02em; }
.stat-hero .big small { font-size: 14px; font-weight: 600; color: var(--fg-muted); letter-spacing: 0; }
.stat-hero .lbl { font-size: 13px; color: var(--fg-muted); margin-top: 4px; }
.flame { width: 36px; height: 36px; flex: none; color: var(--fg-faint); }
.flame.on { color: var(--brand); }
.ring { width: 52px; height: 52px; flex: none; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 6; }
.ring .track { stroke: var(--bg-sunken); }
.ring .val { stroke: var(--brand); stroke-linecap: round; transition: stroke-dashoffset .6s ease; }
.ring.done .val { stroke: var(--success); }
.counts-row { display: flex; gap: 8px; margin-top: 12px; overflow-x: auto; scrollbar-width: none; }
.counts-row a.chip { text-decoration: none; }

.brief-card { margin-top: 16px; background: linear-gradient(135deg, color-mix(in srgb, var(--brand) 14%, var(--bg-elev)), var(--bg-elev) 70%); }
.brief-card .head { display: flex; align-items: center; gap: 10px; }
.brief-card .head svg { width: 22px; height: 22px; color: var(--brand); flex: none; }
.brief-card .head h2 { font-family: var(--font-serif); font-size: 20px; flex: 1; }
.brief-preview { margin-top: 10px; color: var(--fg-muted); font-size: 15px; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.brief-card .actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.inbox-card { margin-top: 16px; border: 1.5px dashed color-mix(in srgb, var(--brand) 50%, var(--border)); background: var(--brand-soft); box-shadow: none; }
.inbox-card h2 { font-family: var(--font-serif); font-size: 20px; margin-bottom: 4px; }
.inbox-addr { display: flex; align-items: center; gap: 8px; margin-top: 12px; padding: 4px 4px 4px 14px; border-radius: 12px; background: var(--bg-elev); border: 1px solid var(--border); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 15px; }
.inbox-addr span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Markdown (AI output) ---------- */
.md { font-size: 16px; line-height: 1.65; overflow-wrap: anywhere; }
.md > * + * { margin-top: .75em; }
.md h2, .md h3 { font-family: var(--font-serif); font-size: 20px; margin-top: 1.4em; letter-spacing: -.01em; }
.md h4 { font-size: 16px; margin-top: 1.2em; }
.md > :first-child { margin-top: 0; }
.md ul, .md ol { padding-left: 1.3em; margin-bottom: 0; }
.md li + li { margin-top: .35em; }
.md .tldr { padding: 12px 14px; border-radius: 12px; background: var(--brand-soft); font-weight: 500; }
.md .tldr strong { color: var(--brand); }

/* ---------- Reader ---------- */
.reader-progress { position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 70; pointer-events: none; }
.reader-progress i { display: block; height: 100%; width: 0; background: var(--brand); transition: width .2s; }
.reader-bar {
  position: sticky; top: 0; z-index: 40; display: flex; align-items: center; gap: 2px;
  margin: calc(-16px - var(--safe-top)) -18px 0; padding: calc(6px + var(--safe-top)) 10px 6px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: saturate(1.6) blur(14px); backdrop-filter: saturate(1.6) blur(14px);
  border-bottom: 1px solid transparent; transition: border-color .2s;
}
.reader-bar.scrolled { border-bottom-color: var(--border); }
.reader-bar .title { flex: 1; min-width: 0; font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; opacity: 0; transition: opacity .2s; padding: 0 4px; }
.reader-bar.scrolled .title { opacity: 1; }
@media (min-width: 900px) { .reader-bar { margin: -40px -40px 0; padding: 10px 28px; } }
.reader-head { margin: 20px 0 18px; }
.reader-head .pubrow { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.reader-head .pubrow a { color: var(--fg); font-weight: 600; }
.reader-head h1 { font-family: var(--font-serif); font-size: 28px; font-weight: 600; letter-spacing: -.02em; margin: 16px 0 10px; line-height: 1.2; overflow-wrap: anywhere; }
@media (min-width: 640px) { .reader-head h1 { font-size: 34px; } }
.reader-tools { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.summary-card { margin-bottom: 18px; }
.summary-card summary { list-style: none; display: flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 600; min-height: 32px; }
.summary-card summary::-webkit-details-marker { display: none; }
.summary-card summary svg.ic { width: 20px; height: 20px; color: var(--brand); }
.summary-card summary .chev { margin-left: auto; width: 18px; height: 18px; transition: transform .2s; color: var(--fg-faint); }
.summary-card[open] summary .chev { transform: rotate(180deg); }
.summary-card .md { margin-top: 12px; font-size: 15px; }
.summary-card .foot { display: flex; justify-content: flex-end; margin-top: 8px; }
.reader-frame-wrap { overflow: hidden; background: #fff; margin: 0 -18px; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.reader-frame-wrap.comfort { background: var(--bg); border-color: transparent; }
@media (min-width: 640px) { .reader-frame-wrap { margin: 0; border: 1px solid var(--border); border-radius: var(--radius); } }
.reader-frame { display: block; width: 100%; border: 0; min-height: 200px; background: transparent; }
.reader-end { margin: 28px 0; display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

.hl-toolbar {
  position: absolute; z-index: 80; display: flex; align-items: center; gap: 6px; padding: 6px;
  background: #1f1b16; color: #fff; border-radius: 999px; box-shadow: var(--shadow-lg); transform: translateX(-50%);
}
.hl-toolbar button.sw { width: 34px; height: 34px; border-radius: 50%; border: 2px solid rgba(255,255,255,.75); cursor: pointer; }
.hl-toolbar button.note { min-height: 34px; padding: 0 12px; border: none; background: transparent; color: inherit; font-weight: 600; cursor: pointer; display: flex; align-items: center; gap: 6px; }
.hl-toolbar button.note svg { width: 16px; height: 16px; }
.sw-yellow { background: #ffe066; } .sw-green { background: #8ce08a; } .sw-blue { background: #7cc0ff; } .sw-pink { background: #ff9cc3; } .sw-purple { background: #b998ff; }
.color-picker { display: flex; gap: 10px; flex-wrap: wrap; }
.color-picker button { width: 44px; height: 44px; border-radius: 50%; border: 3px solid transparent; cursor: pointer; box-shadow: inset 0 0 0 2px rgba(0,0,0,.06); }
.color-picker button[aria-pressed="true"] { border-color: var(--fg); }

/* ---------- Highlights page ---------- */
.hl-item { position: relative; padding: 16px 16px 12px 22px; }
.hl-item::before { content: ""; position: absolute; left: 0; top: 14px; bottom: 14px; width: 5px; border-radius: 0 4px 4px 0; background: var(--c, var(--hl-yellow)); }
.hl-quote { font-family: var(--font-serif); font-size: 17px; line-height: 1.55; overflow-wrap: anywhere; }
.hl-quote mark { background: var(--c); color: inherit; padding: 1px 0; border-radius: 2px; box-decoration-break: clone; -webkit-box-decoration-break: clone; }
.hl-note { margin-top: 8px; font-size: 14px; color: var(--fg-muted); padding: 8px 10px; background: var(--bg-sunken); border-radius: 8px; white-space: pre-wrap; overflow-wrap: anywhere; }
.hl-src { margin-top: 10px; font-size: 13px; display: flex; align-items: center; gap: 4px; color: var(--fg-muted); }
.hl-src a { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.note-body { white-space: pre-wrap; overflow-wrap: anywhere; }
.c-yellow { --c: var(--hl-yellow); } .c-green { --c: var(--hl-green); } .c-blue { --c: var(--hl-blue); } .c-pink { --c: var(--hl-pink); } .c-purple { --c: var(--hl-purple); }
.color-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--c); border: 1px solid var(--border-strong); display: inline-block; flex: none; }

/* ---------- Analytics ---------- */
.stat { padding: 16px; margin: 0 !important; }
.stat .v { font-size: 26px; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; }
.stat .l { font-size: 13px; color: var(--fg-muted); margin-top: 4px; }
.chart { width: 100%; height: auto; overflow: visible; }
.chart .bar { fill: var(--brand); }
.chart .bar.zero { fill: var(--border); }
.chart text { fill: var(--fg-faint); font-size: 10px; font-family: var(--font-sans); }
.chart .grid-line { stroke: var(--border); stroke-dasharray: 3 3; }
.hbar { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; align-items: center; }
.hbar + .hbar { margin-top: 14px; }
.hbar .name { font-size: 14px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar .val { font-size: 13px; color: var(--fg-muted); }
.hbar .track { grid-column: 1 / -1; height: 8px; border-radius: 8px; background: var(--bg-sunken); overflow: hidden; }
.hbar .track i { display: block; height: 100%; border-radius: 8px; background: var(--brand); }

/* ---------- Settings ---------- */
.settings-section { margin-top: 28px; }
.settings-section > h2 { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--fg-muted); margin: 0 0 10px 4px; }
.settings-group { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.setting { display: flex; align-items: center; gap: 12px; padding: 14px 16px; min-height: 60px; }
.setting + .setting, .setting + .schedule, .schedule + .setting { border-top: 1px solid var(--border); }
.setting .txt { flex: 1; min-width: 0; }
.setting .txt .t { font-weight: 500; }
.setting .txt .d { font-size: 13px; color: var(--fg-muted); margin-top: 2px; }
.setting.col { flex-direction: column; align-items: stretch; }
.setting .select, .setting .input { width: auto; max-width: 55%; }
.notice { padding: 12px 14px; border-radius: 12px; background: var(--bg-sunken); font-size: 14px; color: var(--fg-muted); display: flex; gap: 10px; }
.notice svg { width: 18px; height: 18px; flex: none; margin-top: 2px; }
.notice.warn { background: color-mix(in srgb, #f5b100 16%, var(--bg-elev)); color: var(--fg); }
.status-pill { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; padding: 4px 10px; border-radius: 999px; background: var(--bg-sunken); color: var(--fg-muted); white-space: nowrap; }
.status-pill.ok { background: color-mix(in srgb, var(--success) 18%, var(--bg-elev)); color: var(--success); }
.status-pill.bad { background: color-mix(in srgb, var(--danger) 14%, var(--bg-elev)); color: var(--danger); }
.status-pill i { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.schedule { padding: 14px 16px; }
.schedule + .schedule { border-top: 1px solid var(--border); }
.schedule .top { display: flex; align-items: center; gap: 12px; }
.schedule .input[type="time"] { width: 150px; flex: none; }
.schedule .label-input { flex: 1; min-width: 0; }
.schedule .bottom { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.schedule .bottom .select { width: auto; flex: 1; min-width: 0; }
.schedule.disabled .label-input, .schedule.disabled .day-chips, .schedule.disabled .bottom { opacity: .55; }
.pub-setting { flex-wrap: wrap; }
.pub-setting .select { order: 5; flex: 1 1 100%; max-width: none; }
@media (min-width: 640px) { .pub-setting { flex-wrap: nowrap; } .pub-setting .select { order: 0; flex: 0 1 220px; } }

/* ---------- Login ---------- */
.login { min-height: calc(100vh - 80px); min-height: calc(100dvh - 80px); display: grid; place-items: center; }
.login-card { width: 100%; max-width: 380px; text-align: center; }
.login-card .brand-mark { width: 76px; height: 76px; font-size: 50px; border-radius: 22px; margin: 0 auto 18px; padding-bottom: 8px; box-shadow: var(--shadow-lg); }
.login-card h1 { font-family: var(--font-serif); font-size: 30px; margin-bottom: 6px; }
.login-card form { margin-top: 28px; text-align: left; display: grid; gap: 12px; }
.form-error { color: var(--danger); font-size: 14px; min-height: 20px; }

/* ---------- Toasts ---------- */
.toasts {
  position: fixed; z-index: 200; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + 16px + var(--safe-bottom)); display: flex; flex-direction: column; gap: 8px; align-items: center;
  width: min(92vw, 420px); pointer-events: none;
}
body.no-chrome .toasts { bottom: calc(20px + var(--safe-bottom)); }
@media (min-width: 900px) { .toasts { bottom: 28px; left: calc(50% + 120px); } body.no-chrome .toasts { left: 50%; } }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 12px; padding: 10px 10px 10px 16px; min-height: 48px; width: 100%;
  border-radius: 14px; background: var(--fg); color: var(--bg); box-shadow: var(--shadow-lg); font-size: 15px; font-weight: 500;
  animation: toast-in .25s ease;
}
.toast.error { background: var(--danger); color: #fff; }
.toast .msg { flex: 1; }
.toast button { border: none; background: transparent; color: var(--brand); font-weight: 700; cursor: pointer; min-height: 36px; padding: 0 10px; border-radius: 8px; }
.toast.error button { color: #fff; text-decoration: underline; }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px); } }

/* ---------- Modal / sheet ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 150; background: rgba(15, 10, 5, .45); display: flex; align-items: flex-end; justify-content: center;
  animation: fade-in .2s ease;
}
.sheet {
  width: 100%; max-width: 560px; max-height: 88vh; max-height: 88dvh; overflow: auto; overscroll-behavior: contain;
  background: var(--bg-elev); border-radius: 22px 22px 0 0; padding: 8px 20px calc(20px + var(--safe-bottom));
  box-shadow: var(--shadow-lg); animation: sheet-in .28s cubic-bezier(.2, .8, .2, 1);
}
.sheet::before { content: ""; display: block; width: 40px; height: 5px; border-radius: 5px; background: var(--border-strong); margin: 4px auto 10px; }
.sheet-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.sheet-head h2 { flex: 1; font-family: var(--font-serif); font-size: 21px; }
.sheet-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
.sheet-actions .left { margin-right: auto; }
.menu-list { display: flex; flex-direction: column; }
.menu-list button { display: flex; align-items: center; gap: 14px; min-height: 52px; padding: 0 8px; border: none; background: none; text-align: left; font-size: 16px; cursor: pointer; border-radius: 10px; }
.menu-list button:hover { background: var(--bg-sunken); }
.menu-list button svg { width: 20px; height: 20px; color: var(--fg-muted); }
.menu-list button.danger, .menu-list button.danger svg { color: var(--danger); }
@media (min-width: 640px) {
  .overlay { align-items: center; padding: 20px; }
  .sheet { border-radius: 22px; padding: 20px; }
  .sheet::before { display: none; }
}
@keyframes fade-in { from { opacity: 0; } }
@keyframes sheet-in { from { transform: translateY(40px); opacity: 0; } }

.panel-list > * + * { margin-top: 10px; }
.panel-item { padding: 12px 14px; border-radius: 12px; background: var(--bg-sunken); }
.panel-item .actions { display: flex; justify-content: flex-end; gap: 2px; margin-top: 4px; }
.panel-item .hl-quote { font-size: 15px; }
.panel-item .hl-quote mark { background: var(--c); color: inherit; }

.load-more { display: flex; justify-content: center; padding: 20px; color: var(--fg-muted); min-height: 60px; }

.fade-in { animation: fade-in .25s ease; }

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