:root {
  --bg: #ffffff;
  --text: #1a1a1a;
  --muted: #8a8a8a;
  --line: #eeeeee;
  --sans: 'Inter', system-ui, -apple-system, sans-serif;
  --serif: 'Literata', Georgia, serif;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #141414; --text: #e8e8e8; --muted: #7a7a7a; --line: #262626; }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; cursor: pointer; background: none; border: 0; padding: 0; }
a { color: inherit; }
[hidden] { display: none !important; }

/* ---------- Library ---------- */
#library { max-width: 640px; margin: 0 auto; padding: 48px 16px 80px; }
.lib-header { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; flex-wrap: wrap; }
.brand { font-weight: 500; }
.tabs { display: flex; gap: 18px; }
.tabs button { color: var(--muted); }
.tabs button:hover, .tabs button.active { color: var(--text); }

#omni { width: 100%; margin: 32px 0 8px; padding: 10px 0; border: 0; border-bottom: 1px solid var(--line); background: none; color: var(--text); font: inherit; outline: none; }
#omni:focus { border-color: var(--text); }
#omni::placeholder { color: var(--muted); }
#omni:disabled { color: var(--muted); }

.list { list-style: none; margin: 0; padding: 0; }
.item { position: relative; padding: 16px 0; }
.item a.cover { position: absolute; inset: 0; }
.item h3 { margin: 0 0 2px; font: 500 15px/1.4 var(--sans); }
.item .meta { color: var(--muted); font-size: 13px; }
.item .meta > * + *::before { content: '·'; margin: 0 6px; color: var(--muted); }
.tag { color: var(--muted); position: relative; z-index: 1; }
.tag:hover { color: var(--text); }
.item .actions { position: absolute; right: 0; bottom: 16px; display: flex; gap: 14px; font-size: 13px; color: var(--muted); background: var(--bg); padding-left: 12px; opacity: 0; transition: opacity .1s; z-index: 1; }
.item:hover .actions, .item:focus-within .actions { opacity: 1; }
.actions button:hover, .actions button.on { color: var(--text); }
@media (hover: none) { .item .actions { opacity: 1; position: static; margin-top: 6px; padding: 0; } }
.item.pending h3 { color: var(--muted); }

.empty { color: var(--muted); padding: 48px 0; }
.lib-footer { margin-top: 64px; color: var(--muted); font-size: 12px; }
.lib-footer a { color: var(--muted); text-decoration: underline; text-underline-offset: 3px; cursor: grab; }

/* ---------- Reader ---------- */
#reader {
  --r-bg: #ffffff; --r-text: #1a1a1a; --r-muted: #8a8a8a; --r-line: #eeeeee;
  /* The reader uses the operating system's own fonts (San Francisco / New York on Apple, Segoe on Windows). */
  --sans: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --serif: ui-serif, 'New York', 'Iowan Old Style', Georgia, serif;
  --r-size: 20px; --r-font: var(--sans); --r-width: 640px;
  background: var(--r-bg); color: var(--r-text); min-height: 100vh;
}
#reader[data-theme="sepia"] { --r-bg: #f6f0e3; --r-text: #3b3024; --r-muted: #93836b; --r-line: #e6dcc8; }
#reader[data-theme="dark"] { --r-bg: #141414; --r-text: #d6d6d6; --r-muted: #777777; --r-line: #2a2a2a; }
#reader[data-font="serif"] { --r-font: var(--serif); }
#reader[data-width="wide"] { --r-width: 800px; }

.progress-bar { position: fixed; top: 0; left: 0; right: 0; height: 2px; z-index: 20; }
#progress-fill { height: 100%; width: 0; background: var(--r-text); opacity: .35; }
.reader-bar { position: sticky; top: 0; z-index: 10; display: flex; justify-content: space-between; align-items: center; padding: 14px 20px; background: var(--r-bg); font: 13px var(--sans); color: var(--r-muted); transition: opacity .2s; }
.reader-bar.hide { opacity: 0; pointer-events: none; }
.reader-bar:hover { opacity: 1; }
.reader-actions { display: flex; gap: 18px; align-items: center; }
.text-btn { color: var(--r-muted); font-size: 13px; }
.text-btn:hover, .text-btn.on { color: var(--r-text); }
#back { font-size: 16px; }

.menu { position: relative; }
.type-menu { position: absolute; right: -8px; top: 28px; width: 200px; background: var(--r-bg); border: 1px solid var(--r-line); border-radius: 8px; padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.type-menu .row { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.type-menu .themes { grid-template-columns: repeat(3, 1fr); }
.type-menu button { border: 1px solid var(--r-line); border-radius: 6px; padding: 6px; color: var(--r-muted); }
.type-menu button.active { border-color: var(--r-text); color: var(--r-text); }
.type-menu .serif { font-family: var(--serif); }
.swatch { height: 28px; }
.swatch.light { background: #ffffff !important; }
.swatch.sepia { background: #f6f0e3 !important; }
.swatch.dark { background: #141414 !important; }

.article { max-width: var(--r-width); margin: 0 auto; padding: 40px 20px 160px; font: var(--r-size)/1.7 var(--r-font); }
.article header { margin-bottom: 48px; font-family: var(--sans); }
.article h1 { font: 600 clamp(28px, 4.5vw, 38px)/1.2 var(--r-font); letter-spacing: -0.015em; margin: 0 0 12px; }
.article .byline { color: var(--r-muted); font-size: 13px; }
.article .byline a { color: var(--r-muted); text-decoration: none; }
.article .byline a:hover { color: var(--r-text); }
.article .content { overflow-wrap: break-word; }
.article .content a { color: inherit; text-decoration-color: var(--r-muted); text-underline-offset: 3px; }
.article .content img, .article .content video, .article .content picture { max-width: 100%; height: auto; display: block; margin: 1.5em auto; }
.article .content figure { margin: 1.8em 0; }
.article .content figcaption { font: 13px/1.5 var(--sans); color: var(--r-muted); text-align: center; margin-top: -.8em; }
.article .content h2, .article .content h3 { line-height: 1.3; margin: 1.8em 0 .6em; }
.article .content blockquote { margin: 1.5em 0; padding-left: 1em; border-left: 2px solid var(--r-line); color: var(--r-muted); }
.article .content pre { background: var(--r-line); padding: 14px 16px; border-radius: 6px; overflow-x: auto; font-size: 14px; line-height: 1.5; }
.article .content code { font-size: .85em; }
.article .content table { display: block; overflow-x: auto; border-collapse: collapse; font-size: .8em; }
.article .content td, .article .content th { border: 1px solid var(--r-line); padding: 6px 10px; }
.article .content hr { border: 0; border-top: 1px solid var(--r-line); margin: 2em 0; }
.article .done { margin-top: 80px; text-align: center; font: 13px var(--sans); color: var(--r-muted); }
.article .done button { color: var(--r-muted); text-decoration: underline; text-underline-offset: 3px; }
.article .done button:hover { color: var(--r-text); }
.fallback { font: 15px var(--sans); color: var(--r-muted); padding: 24px 0; }
.fallback .row { display: flex; gap: 18px; margin-top: 12px; }
.fallback a, .fallback button { color: var(--r-text); text-decoration: underline; text-underline-offset: 3px; }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 8px 16px; border-radius: 6px; font-size: 13px; z-index: 50; max-width: calc(100% - 32px); }
.toast button { margin-left: 12px; text-decoration: underline; text-underline-offset: 3px; }

/* ---------- Sign in ---------- */
#signin, #newpass { max-width: 380px; margin: 0 auto; padding: 18vh 16px 64px; }
.signin-lede { color: var(--muted); margin: 8px 0 28px; }
#signin-form, #newpass-form { display: flex; flex-direction: column; gap: 10px; }
.field { padding: 10px 0; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; background: none; color: var(--text); font: inherit; font-size: 16px; outline: none; }
.field:focus { border-color: var(--text); }
.field[hidden] { display: none; }
.btn { align-self: flex-start; margin-top: 8px; padding: 8px 16px; border: 1px solid var(--text) !important; border-radius: 6px; }
.btn:disabled { opacity: .5; cursor: progress; }
.signin-msg { min-height: 1.5em; font-size: 13px; margin: 16px 0 0; }
.signin-links { display: flex; flex-direction: column; gap: 10px; margin-top: 36px; font-size: 13px; }
.signin-links a { color: var(--muted); text-decoration: none; }
.signin-links a:hover { color: var(--text); }
.lib-footer p { margin: 0 0 6px; }
.lib-footer #signout { cursor: pointer; }

/* ---------- Phone help ---------- */
.help { max-width: 640px; margin: 0 auto; padding: 32px 16px 80px; font-size: 15px; line-height: 1.6; }
.help-back { color: var(--muted); text-decoration: none; font-size: 13px; }
.help-back:hover { color: var(--text); }
.help h1 { font-size: 22px; font-weight: 500; margin: 28px 0 8px; }
.help h2 { font-size: 15px; font-weight: 500; margin: 32px 0 6px; }
.help p { margin: 0 0 10px; }
.help strong { font-weight: 500; }
.help ol { padding-left: 20px; margin: 0 0 10px; }
.help li { margin-bottom: 6px; }
.help code { font-size: 13px; background: var(--line); padding: 2px 6px; border-radius: 4px; word-break: break-all; user-select: all; }
.help-note { color: var(--muted); font-size: 13px; }

/* Phones: a little more room for thumbs. */
@media (max-width: 600px) {
  #library { padding-top: 24px; }
  .lib-header { flex-direction: column; align-items: flex-start; gap: 12px; }
  .tabs { gap: 16px; }
  .item { padding: 14px 0; }
  .reader-bar { padding: 10px 16px; }
  .reader-actions { gap: 16px; }
  .text-btn { padding: 6px 0; }
}
