:root {
  --bg: #faf8f4;
  --surface: #ffffff;
  --surface-2: #f2eee7;
  --text: #1f1d1a;
  --muted: #6b665e;
  --line: #e4ded3;
  --accent: #2f5d50;
  --accent-text: #ffffff;
  --accent-soft: #dfeae5;
  --danger: #a3362b;
  --focus: #1b6fd1;
  --radius: 10px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151617;
    --surface: #1e2022;
    --surface-2: #26292b;
    --text: #e9e6e0;
    --muted: #9a958c;
    --line: #34373a;
    --accent: #7fb8a4;
    --accent-text: #0f1a16;
    --accent-soft: #223731;
    --danger: #ee7d70;
    --focus: #6aa8f0;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--sans);
}
.wrap { width: 100%; max-width: 780px; margin: 0 auto; padding: 0 16px; }
main { padding-top: 20px; padding-bottom: 64px; outline: none; }
a { color: var(--accent); text-underline-offset: 2px; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
h1 { font: 600 1.7rem/1.2 var(--serif); }
h2 { font-size: 1.05rem; margin-top: 1.8em; letter-spacing: .01em; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* header */
.top { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding-top: 10px; padding-bottom: 10px; }
.brand { font: 700 1.25rem var(--serif); color: var(--text); text-decoration: none; letter-spacing: .01em; }
nav { display: flex; gap: 4px; }
nav a { padding: 6px 10px; border-radius: 8px; color: var(--muted); text-decoration: none; font-size: .95rem; }
nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.search { flex: 1 1 160px; min-width: 130px; }
.search input { width: 100%; }
.bar .ghost { margin-left: auto; }

/* controls */
input, select, button, textarea { font: inherit; color: inherit; }
input, select, textarea {
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; min-height: 40px; max-width: 100%;
}
input[readonly] { background: var(--surface-2); }
button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 14px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); text-decoration: none; color: var(--text);
}
button:hover, .btn:hover { background: var(--surface-2); }
button.primary, .btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.primary:hover, .btn.primary:hover { filter: brightness(1.08); }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); }
button.danger { color: var(--danger); }
button:disabled { opacity: .55; cursor: default; }
label { display: block; font-size: .9rem; color: var(--muted); margin-bottom: 12px; }
label input, label select { display: block; width: 100%; margin-top: 4px; color: var(--text); }

/* lists */
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.row {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; align-items: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; color: inherit; text-decoration: none;
}
a.row:hover { border-color: var(--accent); }
.row .title { font: 600 1.05rem/1.3 var(--serif); overflow-wrap: anywhere; }
.row .meta { grid-column: 1; color: var(--muted); font-size: .875rem; overflow-wrap: anywhere; }
.row .chip { grid-row: 1 / span 2; grid-column: 2; }
.row.folder .title { font-family: var(--sans); font-size: 1rem; }
.chip {
  display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .78rem; font-weight: 600;
  background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.chip.reading { background: var(--accent-soft); color: var(--accent); }
.chip.queued { background: #f6e9c8; color: #6d5410; }
.chip.finished { background: var(--surface-2); color: var(--muted); }
@media (prefers-color-scheme: dark) { .chip.queued { background: #3b3320; color: #e6cd80; } }
.crumbs { display: flex; flex-wrap: wrap; gap: 4px 8px; margin-bottom: 14px; font-size: .95rem; color: var(--muted); }
.crumbs span[aria-hidden] { opacity: .6; }
.empty { text-align: center; padding: 36px 12px; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; }
.error-box { border: 1px solid var(--danger); color: var(--danger); border-radius: var(--radius); padding: 12px 14px; }

/* book page */
.book h1 { margin-bottom: .15em; }
.authors { font: italic 1.05rem var(--serif); color: var(--muted); margin: 0 0 .4em; }
.facts { display: flex; flex-wrap: wrap; gap: 4px 14px; color: var(--muted); font-size: .875rem; margin-bottom: 4px; overflow-wrap: anywhere; }
.segmented { display: flex; flex-wrap: wrap; gap: 6px; }
.segmented button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
@media (max-width: 520px) { .grid2 { grid-template-columns: 1fr; } }
.pw-row { display: flex; gap: 8px; align-items: flex-end; }
.pw-row label { flex: 1; margin-bottom: 12px; }
.pw-row button { margin-bottom: 12px; }
.copy-row { display: flex; gap: 8px; margin: 6px 0 10px; }
.copy-row input { flex: 1; min-width: 0; }
.result { margin-top: 14px; border-color: var(--accent); }

.notes { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.note { border-left: 3px solid var(--accent); padding: 4px 0 4px 12px; }
.note .head { color: var(--muted); font-size: .8rem; display: flex; flex-wrap: wrap; gap: 2px 10px; }
.note blockquote { margin: 4px 0; font: 1rem/1.5 var(--serif); white-space: pre-wrap; overflow-wrap: anywhere; }
.note .mine { white-space: pre-wrap; overflow-wrap: anywhere; font-size: .95rem; }
.note .kind { font-weight: 600; color: var(--accent); text-transform: uppercase; letter-spacing: .04em; }

/* login */
body.login { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card { width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 28px 24px; }
.login-card .brand { display: block; font-size: 1.9rem; margin-bottom: 4px; }
.login-card form { margin-top: 20px; }
.login-card button { width: 100%; margin-top: 4px; }
.error { color: var(--danger); margin: 0 0 10px; font-size: .95rem; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; max-width: calc(100% - 32px);
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }

.gap { height: 12px; }
.row-actions { grid-row: 1 / span 2; grid-column: 2; display: flex; gap: 6px; }
.offscreen { position: fixed; opacity: 0; pointer-events: none; }
@media (max-width: 520px) { .row-actions { grid-row: 3; grid-column: 1; } }
