/* Light (default) */
:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --text: #222222;
  --muted: #8a8a8a;
  --rule: #ececec;
  --hover: #f5f5f5;
  --accent: #2a2a2a;
  --link: #2a6cb0;
  --pill: #f0f0f0;
  --reader-size: 20px;
  --serif: Charter, "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Segoe UI", system-ui, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #1c1c1e;
    --surface: #242426;
    --text: #e6e6e6;
    --muted: #8e8e93;
    --rule: #333336;
    --hover: #2a2a2d;
    --accent: #f2f2f2;
    --link: #7fb2e8;
    --pill: #333336;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1c1c1e;
  --surface: #242426;
  --text: #e6e6e6;
  --muted: #8e8e93;
  --rule: #333336;
  --hover: #2a2a2d;
  --accent: #f2f2f2;
  --link: #7fb2e8;
  --pill: #333336;
  color-scheme: dark;
}
:root[data-theme="sepia"] {
  --bg: #f7f0e3;
  --surface: #fbf6ec;
  --text: #4b3b2a;
  --muted: #9a8670;
  --rule: #e6dac6;
  --hover: #efe5d3;
  --accent: #4b3b2a;
  --link: #8a5a2b;
  --pill: #eadfcb;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 16px/1.5 var(--sans); -webkit-text-size-adjust: 100%; -webkit-font-smoothing: antialiased; }
a { color: inherit; }

svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  text-decoration: none;
  font: inherit;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }

/* ---------- List ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  position: sticky;
  top: 0;
  align-self: flex-start;
  width: 220px;
  height: 100vh;
  padding: 28px 16px;
  border-right: 1px solid var(--rule);
  flex-shrink: 0;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 40px;
  padding: 0 12px;
  margin-bottom: 20px;
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
  text-decoration: none;
}
.brand img { width: 28px; height: 28px; flex-shrink: 0; }
.sections { display: flex; flex-direction: column; gap: 2px; }
.sections a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  font-size: 15px;
  font-weight: 500;
}
.sections a:hover { background: var(--hover); color: var(--text); }
.sections a[aria-current="page"] { color: var(--text); background: var(--pill); }

.list { flex: 1; min-width: 0; max-width: 760px; margin: 0 auto; padding: 28px 40px 80px; }
.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 40px;
  margin-bottom: 0;
  padding-bottom: 20px;
  box-sizing: content-box;
  border-bottom: 1px solid var(--rule);
}
.list-header h1 { margin: 0; font-size: 26px; font-weight: 700; letter-spacing: -0.02em; }
.count { color: var(--muted); font-size: 14px; }

.rows { list-style: none; margin: 0; padding: 0; }
.row { display: flex; gap: 20px; align-items: flex-start; padding: 20px 0; border-bottom: 1px solid var(--rule); }
.row-link { display: block; text-decoration: none; color: inherit; }
.row-text { flex: 1; min-width: 0; }
.row-thumb-link { display: block; flex-shrink: 0; }
.row-title {
  margin: 0 0 4px;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}
.row-link:hover .row-title { text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }
.row-excerpt {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.row-thumb {
  width: 96px;
  height: 96px;
  object-fit: cover;
  border-radius: 6px;
  background: var(--pill);
  flex-shrink: 0;
}
.row-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 20px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}
.row-meta form { margin: 0; }
.row-meta .icon-btn { width: 32px; height: 32px; margin: -6px -6px -6px 0; opacity: 0; transition: opacity 0.15s; }
.row:hover .row-meta .icon-btn, .row-meta .icon-btn:focus-visible { opacity: 1; }
@media (hover: none) { .row-meta .icon-btn { opacity: 1; } }

.empty { padding: 48px 0; color: var(--muted); text-align: center; }

.account {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 24px 0 0;
  padding: 12px 12px 0;
  border-top: 1px solid var(--rule);
  font-size: 14px;
}
.account-name { min-width: 0; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account button { flex-shrink: 0; white-space: nowrap; }
.account button {
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  cursor: pointer;
  padding: 4px 0;
}
.account button:hover { color: var(--text); text-decoration: underline; }

/* Log in / sign up */
.auth { max-width: 360px; margin: 0 auto; padding: 72px 20px; }
.auth-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
  font: 700 26px var(--serif);
  text-decoration: none;
}
.auth-card {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 28px 24px;
  border: 1px solid var(--rule);
  border-radius: 12px;
  background: var(--surface);
}
.auth-card h1 { margin: 0; font-size: 20px; }
.auth-card label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; }
.auth-card input {
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: 16px var(--sans);
}
.auth-card input:focus { outline: 2px solid var(--link); outline-offset: -1px; border-color: transparent; }
.auth-card button {
  height: 44px;
  margin-top: 4px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: var(--bg);
  font: 600 15px var(--sans);
  cursor: pointer;
}
.auth-error { margin: 0; padding: 10px 12px; border-radius: 8px; background: #fdecea; color: #a12a1f; font-size: 14px; }
.auth-forgot { align-self: center; color: var(--muted); font-size: 14px; }
.auth-note { margin: 0; color: var(--muted); font-size: 15px; line-height: 1.5; }
.auth-note a { color: var(--link); }
.auth-switch { margin-top: 20px; text-align: center; color: var(--muted); font-size: 14px; }
.auth-switch a { color: var(--link); }

/* Phone: sidebar becomes a top bar with tabs */
@media (max-width: 760px) {
  .app { display: block; }
  .sidebar {
    position: sticky;
    z-index: 5;
    width: auto;
    height: auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-right: 0;
    border-bottom: 1px solid var(--rule);
    background: var(--bg);
  }
  .brand { height: auto; margin: 0; padding: 0; font-size: 19px; gap: 8px; }
  .brand img { width: 24px; height: 24px; }
  .sections { flex-direction: row; }
  .sections a { padding: 6px 10px; font-size: 14px; gap: 6px; }
  .sections svg { display: none; }
  .sidebar { flex-wrap: wrap; }
  .account { order: 3; width: 100%; margin: 8px 0 0; padding: 8px 0 0; font-size: 13px; }
  .list { padding: 20px 16px 60px; }
  .list-header h1 { font-size: 22px; }
  .row { padding: 16px 0; gap: 14px; }
  .row-title { font-size: 16px; }
  .row-excerpt { font-size: 14px; }
  .row-thumb { width: 72px; height: 72px; }
}

/* ---------- Reader ---------- */
.readerbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 52px;
  padding: 0 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--rule);
}
.readerbar-actions { display: flex; align-items: center; gap: 4px; }
.readerbar-actions form { margin: 0; }
.text-btn { font-family: var(--serif); font-size: 18px; font-weight: 600; letter-spacing: -0.02em; }

.settings {
  position: absolute;
  top: 48px;
  right: 12px;
  width: 260px;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12);
}
.settings[hidden] { display: none; }
.settings-row { display: flex; gap: 6px; padding: 6px; }
.settings-row + .settings-row { border-top: 1px solid var(--rule); }
.settings button {
  flex: 1;
  height: 40px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font: 14px var(--sans);
  cursor: pointer;
}
.settings button:hover { background: var(--hover); }
.settings button[aria-pressed="true"] { border-color: var(--text); }
.size button:first-child { font: 14px var(--serif); }
.size button:last-child { font: 22px var(--serif); }
.font-serif { font-family: var(--serif) !important; }
.swatch-light { background: #ffffff !important; color: #222 !important; }
.swatch-sepia { background: #f7f0e3 !important; color: #4b3b2a !important; }
.swatch-dark { background: #1c1c1e !important; color: #e6e6e6 !important; }

.reader { max-width: 680px; margin: 0 auto; padding: 40px 24px 96px; }
.reader-source { margin: 0 0 12px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; }
.reader-source a { color: var(--muted); text-decoration: none; }
.reader-source a:hover { color: var(--text); }
.reader h1 {
  margin: 0 0 12px;
  font-family: var(--serif);
  font-size: calc(var(--reader-size) * 1.75);
  line-height: 1.15;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}
:root[data-font="sans"] .reader h1 { font-family: var(--sans); letter-spacing: -0.02em; }
.reader-meta { margin: 0; color: var(--muted); font-size: 14px; }

.content {
  margin-top: 32px;
  padding-top: 32px;
  border-top: 1px solid var(--rule);
  font-family: var(--serif);
  font-size: var(--reader-size);
  line-height: 1.65;
  overflow-wrap: break-word;
}
:root[data-font="sans"] .content { font-family: var(--sans); line-height: 1.6; }
.content p { margin: 0 0 1.1em; }
.content a { color: var(--link); text-decoration-thickness: 1px; text-underline-offset: 2px; }
.content h1, .content h2, .content h3 { line-height: 1.25; margin: 1.8em 0 0.6em; }
.content h1, .content h2 { font-size: 1.3em; }
.content h3 { font-size: 1.12em; }
.content img, .content video { display: block; max-width: 100%; height: auto; margin: 1.5em auto; border-radius: 4px; }
.content figure { margin: 1.5em 0; }
.content figcaption { color: var(--muted); font: 14px/1.4 var(--sans); text-align: center; }
.content blockquote { margin: 1.5em 0; padding-left: 1em; border-left: 3px solid var(--rule); font-style: italic; }
.content pre { overflow-x: auto; padding: 12px; background: var(--hover); border-radius: 6px; font-size: 0.75em; }
.content code { font-size: 0.85em; }
.content table { display: block; overflow-x: auto; border-collapse: collapse; font-size: 0.8em; }
.content td, .content th { padding: 6px 10px; border: 1px solid var(--rule); }
.content hr { border: 0; border-top: 1px solid var(--rule); margin: 2em 0; }

.fallback { font-family: var(--sans); font-size: 16px; color: var(--muted); }
.fallback a { color: var(--link); font-weight: 600; }

.reader-end { margin-top: 56px; display: flex; justify-content: center; }

@media (max-width: 760px) {
  .reader { padding: 28px 20px 72px; }
  .content { margin-top: 24px; padding-top: 24px; }
}

/* ---------- Reading progress ---------- */
.readerbar { position: sticky; }
.time-left {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  pointer-events: none;
}
.progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 3px;
  background: transparent;
  pointer-events: none;
}
.progress span {
  display: block;
  height: 100%;
  background: #d9822b;
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.1s linear;
}

/* ---------- Finish ---------- */
.reader-end { flex-direction: column; align-items: center; gap: 16px; }
.reader-secondary {
  padding: 10px 24px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  font: 600 14px var(--sans);
  cursor: pointer;
}
.reader-secondary:hover { background: var(--hover); }
.reader-end form { margin: 0; }

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

/* Account: sidebar on desktop, quietly at the bottom of the list on phones. */
.account-bottom { display: none; }
@media (max-width: 760px) {
  .account-side { display: none; }
  .account-bottom { display: flex; width: auto; margin: 40px 0 0; padding: 16px 0 0; border-top: 0; font-size: 13px; }
}

/* Account links and delete page */
.account-links { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.account-links a { color: var(--muted); text-decoration: none; white-space: nowrap; }
.account-links a:hover { color: var(--text); text-decoration: underline; }
.auth-card button.danger { background: #c0392b; color: #fff; }
.auth-card button.danger:hover { background: #a93226; }
.auth-notice { margin: 0; padding: 10px 12px; border-radius: 8px; background: #e8f3ea; color: #24613a; font-size: 14px; }
.account-side, .account-bottom { flex-direction: column; align-items: flex-start; gap: 6px; }
.account-side .account-name { max-width: 100%; }
