:root {
  --bg: #f6f1e8; --fg: #241f19; --muted: #7a6f63; --card: #fffdf9; --line: #e4dccd;
  --accent: #b5542a; --accent-fg: #fff; --ok: #3f7d4e; --warn: #b58a2a; --err: #b03a2e;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #1f1b16; --fg: #efe8dc; --muted: #a2978a; --card: #2a251f; --line: #3b352d; --accent: #e07b4a; --accent-fg: #1f1b16; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--fg); font: 17px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { min-height: 100dvh; display: flex; flex-direction: column; }
header#top { display: flex; gap: 8px; align-items: center; padding: calc(env(safe-area-inset-top) + 10px) 14px 8px; }
main#view { flex: 1; padding: 6px 14px 90px; max-width: 720px; width: 100%; margin: 0 auto; }
nav#nav { position: fixed; bottom: 0; left: 0; right: 0; display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); }
nav#nav a { flex: 1; text-align: center; padding: 14px 4px; color: var(--muted); text-decoration: none; font-weight: 600; font-size: 14px; }
nav#nav a.active { color: var(--accent); }
.chip { background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
#book-chip { flex: 1; cursor: pointer; }
#book-chip.set { border-color: var(--accent); }
.hidden { display: none !important; }
h1 { font-size: 22px; margin: 10px 0; }
h2 { font-size: 17px; margin: 18px 0 8px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
button, .btn { font: inherit; border: 1px solid var(--line); background: var(--card); color: var(--fg); border-radius: var(--radius);
  padding: 12px 16px; cursor: pointer; }
button.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); font-weight: 700; }
button.big { font-size: 20px; padding: 22px 16px; flex: 1; }
button.small { padding: 6px 10px; font-size: 14px; border-radius: 10px; }
button.danger { color: var(--err); }
button:disabled { opacity: .5; }
.row { display: flex; gap: 10px; align-items: center; }
.row > * { min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 10px; }
textarea, input[type=text], input[type=search], input[type=password], select {
  font: inherit; width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); color: var(--fg); }
textarea { min-height: 84px; resize: vertical; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin: 8px 0; }
.card.tap { cursor: pointer; }
.card .meta { color: var(--muted); font-size: 13px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.card blockquote { margin: 6px 0; padding-left: 10px; border-left: 3px solid var(--accent); white-space: pre-wrap; }
.card .note { white-space: pre-wrap; margin: 6px 0 0; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--line); }
.badge.pending, .badge.processing { background: var(--warn); color: #fff; }
.badge.error { background: var(--err); color: #fff; }
.badge.done { display: none; }
.tag { font-size: 12px; color: var(--accent); }
#previews { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0; }
#previews img { height: 96px; border-radius: 10px; border: 1px solid var(--line); }
.photo { max-width: 100%; border-radius: var(--radius); border: 1px solid var(--line); margin-top: 8px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
#toast { position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); background: var(--fg); color: var(--bg);
  padding: 10px 16px; border-radius: 999px; font-size: 14px; z-index: 10; max-width: 90vw; }
.digest { white-space: normal; }
.digest blockquote { margin: 8px 0; padding-left: 10px; border-left: 3px solid var(--accent); }
.digest hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
label.small { font-size: 13px; color: var(--muted); }
input[type=file] { display: none; }
.center { text-align: center; }
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
