:root {
  --paper: #f6f3ec;
  --paper-2: #fffdf8;
  --line: #e2dccf;
  --ink: #1c2420;
  --ink-2: #4b5751;
  --muted: #76807a;
  --accent: #1f4d3a;
  --accent-ink: #ffffff;
  --accent-soft: #e3ece6;
  --danger: #a3372b;
  --shadow: 0 1px 2px rgb(28 36 32 / 6%), 0 6px 18px rgb(28 36 32 / 6%);
  --radius: 14px;
  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #151a17;
    --paper-2: #1d2420;
    --line: #2e3833;
    --ink: #e9ece7;
    --ink-2: #bcc6c0;
    --muted: #8b958f;
    --accent: #7fc3a0;
    --accent-ink: #10201a;
    --accent-soft: #23332b;
    --danger: #f08d80;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #151a17; --paper-2: #1d2420; --line: #2e3833; --ink: #e9ece7; --ink-2: #bcc6c0;
  --muted: #8b958f; --accent: #7fc3a0; --accent-ink: #10201a; --accent-soft: #23332b; --danger: #f08d80;
  --shadow: 0 1px 2px rgb(0 0 0 / 30%); color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.5 var(--font-body);
  min-height: 100dvh;
}
[hidden] { display: none !important; }
a { color: var(--accent); }
h1, h2 { font-family: var(--font-display); font-weight: 650; letter-spacing: -0.01em; line-height: 1.15; margin: 0 0 .35em; }
h1 { font-size: 1.85rem; }
h2 { font-size: 1.35rem; }
code { font-size: .9em; background: var(--accent-soft); padding: 0 .3em; border-radius: 4px; }

/* layout */
main { max-width: 680px; margin: 0 auto; padding: 16px 16px calc(96px + env(safe-area-inset-bottom)); }
.view { animation: rise .25s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
@media (prefers-reduced-motion: reduce) { .view { animation: none; } }
.center { text-align: center; }
.muted { color: var(--muted); margin: 0; }
.small { font-size: .85rem; }
.fine { font-size: .82rem; color: var(--muted); margin: 12px 0 0; }
.view-head { margin: 8px 0 18px; }
.row-between { display: flex; justify-content: space-between; align-items: center; margin-top: 18px; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-family: var(--font-display); font-weight: 650; font-size: 1.15rem; color: var(--ink); text-decoration: none; }
.brand-mark { width: 18px; height: 22px; border: 2px solid var(--ink); border-radius: 3px; background: linear-gradient(var(--accent) 0 0) 3px 5px / 8px 2px no-repeat, linear-gradient(var(--accent) 0 0) 3px 10px / 10px 2px no-repeat, var(--paper-2); }
.topnav { display: flex; gap: 14px; align-items: center; font-size: .95rem; }
.topnav a { color: var(--ink-2); text-decoration: none; padding: 4px 2px; }
.topnav a[aria-current="page"] { color: var(--ink); font-weight: 600; box-shadow: inset 0 -2px var(--accent); }
.linkish { background: none; border: 0; color: var(--muted); font: inherit; padding: 4px 2px; cursor: pointer; }

/* buttons & fields */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px; border-radius: 12px; border: 1px solid transparent;
  font: 600 1rem var(--font-body); text-decoration: none; cursor: pointer;
  transition: transform .08s, background .15s;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-secondary { background: var(--paper-2); color: var(--ink); border-color: var(--line); }
.btn-quiet { background: none; color: var(--ink-2); padding: 0 6px; }
.btn-danger-quiet { background: none; color: var(--danger); padding: 0 6px; min-height: 40px; }
.btn-block { width: 100%; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; }

label, .field > span { display: block; font-weight: 600; font-size: .92rem; margin-bottom: 6px; }
.field em { font-weight: 400; color: var(--muted); font-style: normal; }
input[type="email"], input[type="text"] {
  width: 100%; min-height: 48px; padding: 0 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--paper-2); color: var(--ink); font: 1rem var(--font-body);
}
.field { display: block; margin-bottom: 18px; }

.card { background: var(--paper-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }

/* login */
.hero { text-align: center; padding: 28px 8px 22px; }
.hero h1 { font-size: 2.3rem; }
.hero-mark { display: inline-block; margin-bottom: 10px; }
.lede { color: var(--ink-2); max-width: 30em; margin: 0 auto; font-size: 1.05rem; }
.turnstile { margin: 16px 0; min-height: 65px; }
.dev { word-break: break-all; font-size: .85rem; background: var(--accent-soft); padding: 10px; border-radius: 8px; }

/* capture */
.pages { list-style: none; padding: 0; margin: 0 0 16px; display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.page {
  position: relative; border-radius: 10px; overflow: hidden; background: var(--paper-2);
  border: 1px solid var(--line); box-shadow: var(--shadow); aspect-ratio: 3 / 4;
}
.page img { width: 100%; height: 100%; object-fit: cover; display: block; }
.page .num { position: absolute; top: 6px; left: 6px; background: var(--ink); color: var(--paper); font-size: .78rem; font-weight: 600; padding: 2px 8px; border-radius: 99px; }
.page .tools { position: absolute; inset: auto 0 0 0; display: flex; justify-content: space-between; padding: 6px; background: linear-gradient(transparent, rgb(0 0 0 / 55%)); }
.page .tools button { width: 36px; height: 36px; border-radius: 99px; border: 0; background: rgb(255 255 255 / 92%); color: #1c2420; font-size: 1rem; cursor: pointer; }
.page .tools button:disabled { opacity: .35; }
.capture-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tip { font-size: .85rem; color: var(--muted); margin: 12px 0 0; }
.sticky-bottom {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--paper) 92%, transparent); backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
}
.sticky-bottom .btn { max-width: 648px; margin: 0 auto; display: flex; }

/* working */
.working { padding-top: 18vh; }
.pen { width: 56px; height: 56px; margin: 0 auto 18px; border-radius: 50%; border: 4px solid var(--accent-soft); border-top-color: var(--accent); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* review */
.review-head { margin: 4px 0 12px; }
.title-input { font-family: var(--font-display) !important; font-size: 1.5rem !important; font-weight: 650; border-color: transparent !important; background: transparent !important; padding: 0 !important; }
.title-input:focus { border-bottom: 2px solid var(--accent) !important; border-radius: 0 !important; }
.thumbs { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 12px; }
.thumbs button { flex: 0 0 auto; width: 64px; height: 84px; padding: 0; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); background: var(--paper-2); cursor: zoom-in; }
.thumbs img { width: 100%; height: 100%; object-fit: cover; }
.tabs { display: flex; gap: 4px; background: var(--accent-soft); padding: 4px; border-radius: 12px; margin-bottom: 10px; }
.tab { flex: 1; min-height: 40px; border: 0; border-radius: 9px; background: none; font: 600 .95rem var(--font-body); color: var(--ink-2); cursor: pointer; }
.tab[aria-selected="true"] { background: var(--paper-2); color: var(--ink); box-shadow: var(--shadow); }
.editor {
  width: 100%; min-height: 50vh; padding: 16px; border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--paper-2); color: var(--ink); font: 15px/1.6 ui-monospace, "SF Mono", Menlo, Consolas, monospace; resize: vertical;
}
.preview { background: var(--paper-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; min-height: 50vh; overflow-wrap: anywhere; }
.preview h1, .preview h2, .preview h3 { margin: .8em 0 .35em; }
.preview h1:first-child, .preview h2:first-child { margin-top: 0; }
.preview ul, .preview ol { padding-left: 1.4em; margin: .2em 0 .8em; }
.preview li.check { list-style: none; margin-left: -1.3em; }
.preview blockquote { margin: .4em 0 .8em; padding-left: 12px; border-left: 3px solid var(--line); color: var(--ink-2); font-style: italic; }
.preview table { border-collapse: collapse; margin: .4em 0 1em; width: 100%; }
.preview td, .preview th { border: 1px solid var(--line); padding: 6px 8px; text-align: left; }
.preview hr { border: 0; border-top: 1px dashed var(--line); margin: 1.2em 0; }
.preview p { margin: 0 0 .8em; }
.export-bar { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 16px; }
.export-bar .btn { padding: 0 8px; }

/* history */
.history { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.history a { display: block; text-decoration: none; color: inherit; background: var(--paper-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.history .h-title { font-weight: 600; margin: 0 0 2px; }
.history .h-meta { font-size: .82rem; color: var(--muted); }
.history .h-preview { font-size: .9rem; color: var(--ink-2); margin: 6px 0 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }
.account-zone { margin-top: 36px; padding-top: 16px; border-top: 1px solid var(--line); display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }

/* toast & lightbox */
.toast {
  position: fixed; left: 50%; bottom: calc(88px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 10px; font-size: .92rem;
  max-width: calc(100% - 32px); box-shadow: var(--shadow); z-index: 30;
}
.toast.error { background: var(--danger); color: #fff; }
.lightbox { border: 0; padding: 12px; background: var(--paper-2); border-radius: var(--radius); max-width: 96vw; max-height: 92dvh; }
.lightbox::backdrop { background: rgb(0 0 0 / 70%); }
.lightbox img { display: block; max-width: 100%; max-height: 78dvh; margin: 0 auto 10px; border-radius: 8px; }
.lightbox form { text-align: center; }

@media (min-width: 560px) {
  .capture-actions { grid-template-columns: 1fr 1fr; max-width: 460px; }
  h1 { font-size: 2.1rem; }
}
