:root {
  --bg: #f6f5f1; --card: #fff; --text: #1d1d1b; --muted: #6b6b66; --line: #e5e3dc;
  --accent: #2f7d6d; --accent-text: #fff; --danger: #c2413a; --warn: #b7791f;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #141413; --card: #1e1e1c; --text: #ededea; --muted: #9a9a94; --line: #2e2e2b;
          --accent: #4fb39d; --accent-text: #0d1f1b; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text);
       font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; }
main { max-width: 760px; margin: 0 auto; padding: 32px 20px 64px; }
main.narrow { max-width: 380px; padding-top: 12vh; }
[hidden] { display: none !important; }

.brand { font-size: 22px; letter-spacing: -0.01em; margin: 0; }
.muted { color: var(--muted); margin: 6px 0 20px; }
.error { color: var(--danger); font-size: 14px; margin: 8px 0 0; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.stack { display: grid; gap: 14px; }
label { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
input { font: inherit; color: inherit; background: var(--bg); border: 1px solid var(--line);
        border-radius: 8px; padding: 10px 12px; width: 100%; }
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
button { font: inherit; cursor: pointer; }
button.primary { background: var(--accent); color: var(--accent-text); border: 0; border-radius: 8px;
                 padding: 10px 18px; font-weight: 600; }
button.primary:disabled { opacity: .6; cursor: wait; }
.link-button { background: none; border: 0; color: var(--muted); font-size: 14px; }
.link-button:hover { color: var(--text); }

.top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.save { display: flex; gap: 8px; }
.save input { background: var(--card); }

.tabs { display: flex; gap: 4px; margin: 24px 0 12px; border-bottom: 1px solid var(--line); }
.tabs button { background: none; border: 0; border-bottom: 2px solid transparent; color: var(--muted);
               padding: 8px 12px; margin-bottom: -1px; font-size: 15px; }
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.count { font-size: 12px; color: var(--muted); font-weight: 400; margin-left: 2px; }

.links { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.link { display: grid; grid-template-columns: 96px 1fr; gap: 14px; background: var(--card);
        border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.link.flash { animation: flash 1.6s ease-out; }
@keyframes flash { from { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); } }
.thumb { width: 96px; height: 72px; border-radius: 6px; overflow: hidden; background: var(--line);
         display: grid; place-items: center; text-decoration: none; color: var(--muted);
         font-weight: 700; font-size: 26px; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb.no-image img { display: none; }
.body { min-width: 0; }
.title { color: var(--text); font-weight: 600; text-decoration: none; display: -webkit-box;
         -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.title:hover { text-decoration: underline; }
.meta { color: var(--muted); font-size: 13px; margin: 2px 0 0; }
.excerpt { font-size: 14px; color: var(--muted); margin: 6px 0 0; display: -webkit-box;
           -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.status { font-size: 13px; margin: 6px 0 0; }
.is-pending .status { color: var(--muted); }
.is-pending .status::before { content: ""; display: inline-block; width: 10px; height: 10px; margin-right: 6px;
  border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%;
  animation: spin .8s linear infinite; vertical-align: -1px; }
@keyframes spin { to { transform: rotate(360deg); } }
.is-failed .status { color: var(--danger); }
.actions { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 8px; }
.actions button { background: none; border: 0; padding: 0; color: var(--muted); font-size: 13px; }
.actions button:hover { color: var(--text); text-decoration: underline; }
.actions button.accent { color: var(--accent); font-weight: 600; }
.actions button.danger:hover { color: var(--danger); }

.empty { color: var(--muted); text-align: center; padding: 40px 0; }
.foot { margin-top: 40px; font-size: 13px; color: var(--muted); }
.bookmarklet { color: var(--accent); font-weight: 600; text-decoration: none; padding: 2px 8px;
               border: 1px dashed var(--accent); border-radius: 6px; cursor: grab; }

@media (max-width: 520px) {
  .link { grid-template-columns: 64px 1fr; gap: 10px; }
  .thumb { width: 64px; height: 64px; }
  .excerpt { display: none; }
}

/* ---------- v1: Today ---------- */
.today-note { font-size: 14px; color: var(--muted); background: var(--card); border: 1px solid var(--line);
              border-radius: 8px; padding: 8px 12px; margin: 0 0 10px; }
.today-note.is-flash { color: var(--text); border-color: var(--accent);
                       background: color-mix(in srgb, var(--accent) 10%, var(--card)); }
.actions button.pill { background: var(--accent); color: var(--accent-text); border-radius: 999px;
                       padding: 3px 14px; font-weight: 600; }
.actions button.pill:hover { color: var(--accent-text); text-decoration: none; filter: brightness(1.08); }
.empty .big { font-size: 20px; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.empty p { margin: 4px 0; }

/* ---------- v1: Reader ---------- */
.reader-page { --measure: 680px; }
.progress { position: fixed; inset: 0 0 auto 0; height: 3px; z-index: 10; }
.progress-bar { height: 100%; background: var(--accent); transform-origin: 0 50%; transform: scaleX(0); }
.reader-top { position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center;
              max-width: calc(var(--measure) + 40px); margin: 0 auto; padding: 14px 20px;
              background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(6px); }
.reader-top a { color: var(--muted); text-decoration: none; font-size: 14px; }
.reader-top a:hover { color: var(--text); }
.reader { max-width: calc(var(--measure) + 40px); padding-top: 12px; }
.kicker { color: var(--accent); font-size: 13px; font-weight: 600; text-transform: uppercase;
          letter-spacing: .06em; margin: 8px 0 6px; }
.reader h1 { font-size: clamp(28px, 5vw, 40px); line-height: 1.15; letter-spacing: -0.015em; margin: 0 0 10px; }
.byline { color: var(--muted); font-size: 15px; margin: 0 0 28px; }

.prose { font-family: Charter, "Iowan Old Style", "Palatino Linotype", Georgia, serif;
         font-size: 20px; line-height: 1.7; overflow-wrap: break-word; }
.prose > * { margin: 0 0 1.1em; }
.prose h2, .prose h3, .prose h4 { font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
         line-height: 1.3; margin: 1.6em 0 .6em; }
.prose h2 { font-size: 1.3em; } .prose h3 { font-size: 1.12em; } .prose h4 { font-size: 1em; }
.prose a { color: var(--accent); text-underline-offset: 2px; }
.prose img, .prose video { max-width: 100%; height: auto; border-radius: 6px; display: block; margin: 1.4em auto; }
.prose figure { margin: 1.6em 0; }
.prose figcaption { font-family: system-ui, sans-serif; font-size: 14px; color: var(--muted); text-align: center; }
.prose blockquote { margin: 1.4em 0; padding: .2em 0 .2em 1.1em; border-left: 3px solid var(--accent); color: var(--muted); }
.prose pre { font-size: 15px; line-height: 1.5; background: var(--card); border: 1px solid var(--line);
             border-radius: 8px; padding: 14px 16px; overflow-x: auto; }
.prose code { font-size: .85em; background: var(--card); border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; }
.prose pre code { border: 0; padding: 0; background: none; font-size: inherit; }
.prose table { width: 100%; border-collapse: collapse; font-size: 16px; display: block; overflow-x: auto; }
.prose th, .prose td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 2em 0; }
.prose ul, .prose ol { padding-left: 1.3em; }
.prose li { margin: .3em 0; }

.no-article { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; }
.button-link { display: inline-block; background: var(--accent); color: var(--accent-text); text-decoration: none;
               font-weight: 600; border-radius: 8px; padding: 8px 16px; }

.finish { margin: 48px 0 24px; padding-top: 24px; border-top: 1px solid var(--line); text-align: center; }
.finish-title { font-weight: 600; font-size: 18px; margin: 0 0 12px; }
.finish-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.finish-actions button { font-size: 15px; border: 1px solid var(--line); background: var(--card); color: var(--text);
                         border-radius: 999px; padding: 8px 18px; }
.finish-actions button:hover { border-color: var(--muted); }
.finish-actions button.pill { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
.finish-actions button:disabled { opacity: .6; cursor: wait; }
.finish-note { font-size: 14px; margin-top: 12px; }

@media (max-width: 520px) {
  .prose { font-size: 18px; }
}

/* ---------- v2: header, search, offline ---------- */
.top-links { display: flex; align-items: center; gap: 14px; font-size: 14px; }
.top-links a { color: var(--muted); text-decoration: none; }
.top-links a:hover { color: var(--text); }
.offline-banner { position: sticky; top: 0; z-index: 20; margin: 0; padding: 8px 16px; text-align: center;
                  font-size: 14px; background: var(--warn); color: #fff; }
.tabs-row { display: flex; align-items: flex-end; gap: 12px; margin: 24px 0 12px; border-bottom: 1px solid var(--line); }
.tabs-row .tabs { margin: 0; border: 0; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.tabs button { white-space: nowrap; }
.search { width: 220px; margin-bottom: 6px; padding: 7px 12px; font-size: 14px; background: var(--card); border-radius: 999px; }
.is-searching .tabs button { opacity: .6; }
.snippet { font-size: 14px; color: var(--muted); margin: 6px 0 0; }
.snippet mark, .prose mark:not(.hl) { background: color-mix(in srgb, var(--warn) 30%, transparent); color: var(--text);
                                      border-radius: 2px; padding: 0 1px; }

/* ---------- v2: tags ---------- */
.tag-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: -2px 0 12px; font-size: 13px; }
.tag-bar-label { color: var(--muted); margin-right: 2px; }
.tags { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 8px; }
.tags[hidden] { display: none; }
.chip { display: inline-flex; align-items: center; gap: 2px; border-radius: 999px; font-size: 13px;
        background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); }
button.chip, .chip .chip-name { background: none; border: 0; color: var(--accent); font: inherit; font-size: 13px;
                                padding: 2px 9px; cursor: pointer; }
button.chip { background: color-mix(in srgb, var(--accent) 12%, transparent); border-radius: 999px; }
button.chip:hover, .chip .chip-name:hover { text-decoration: underline; }
.chip-count { color: var(--muted); }
.chip.is-active { background: var(--accent); }
.chip.is-active .chip-name, .chip.is-active .chip-remove { color: var(--accent-text); }
.chip-remove { background: none; border: 0; color: var(--accent); font-size: 15px; line-height: 1; padding: 2px 8px 2px 0; cursor: pointer; }
.tag-input { width: 150px; padding: 4px 10px; font-size: 13px; border-radius: 999px; }

/* ---------- v2: reader extras ---------- */
.reader-tags { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: -16px 0 24px; }
.reader-tags .tags { margin: 0; }
.reader-tags .link-button { font-size: 13px; padding: 2px 0; }

.prose mark.hl { background: color-mix(in srgb, #f2c94c 45%, transparent); color: inherit; border-radius: 2px;
                 padding: 1px 0; cursor: pointer; box-decoration-break: clone; -webkit-box-decoration-break: clone; }
@media (prefers-color-scheme: dark) { .prose mark.hl { background: color-mix(in srgb, #f2c94c 32%, transparent); } }
.prose mark.hl.has-note { border-bottom: 2px dotted var(--warn); }
.prose mark.hl.has-note.hl-end::after { content: "✎"; font-size: .7em; vertical-align: super; margin-left: 1px; color: var(--warn); }
.prose mark.hl:focus-visible { outline: 2px solid var(--accent); }
.prose mark.hl.flash { animation: flash 1.6s ease-out; outline: 2px solid var(--accent); }

.hl-toolbar { position: absolute; z-index: 30; display: flex; gap: 2px; padding: 4px; border-radius: 10px;
              background: var(--text); box-shadow: 0 6px 20px rgba(0,0,0,.25); }
.hl-toolbar button { background: none; border: 0; color: var(--bg); font-size: 14px; font-weight: 600; padding: 8px 12px; border-radius: 7px; }
.hl-toolbar button:hover { background: color-mix(in srgb, var(--bg) 15%, transparent); }
.hl-toolbar.is-overlap { opacity: .5; pointer-events: none; }

.hl-popover { position: absolute; z-index: 30; width: min(360px, calc(100vw - 16px)); padding: 14px; border-radius: 12px;
              background: var(--card); border: 1px solid var(--line); box-shadow: 0 10px 30px rgba(0,0,0,.18); }
.hl-popover blockquote { margin: 0 0 10px; padding-left: 10px; border-left: 3px solid #f2c94c; color: var(--muted);
                         font-size: 14px; max-height: 6.5em; overflow: hidden; }
.hl-popover textarea, .side-section textarea { width: 100%; font: inherit; font-size: 15px; color: inherit; resize: vertical;
                         background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.hl-popover-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.hl-popover-actions button { font-size: 14px; border: 1px solid var(--line); background: var(--card); color: var(--text);
                             border-radius: 999px; padding: 6px 14px; }
.hl-popover-actions .pill { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
.hl-popover-actions .danger { color: var(--danger); }

.side-section { margin: 40px 0 0; padding-top: 20px; border-top: 1px solid var(--line); }
.side-section h2 { font-size: 15px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 12px; }
.highlights-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 14px; }
.highlights-list li { padding-left: 12px; border-left: 3px solid #f2c94c; }
.hl-quote { display: block; text-align: left; background: none; border: 0; padding: 0; color: var(--text); cursor: pointer;
            font-family: Charter, "Iowan Old Style", Georgia, serif; font-size: 17px; line-height: 1.5; }
.hl-quote:hover { text-decoration: underline; text-decoration-color: var(--line); }
.hl-list-note { margin: 4px 0 0; font-size: 14px; color: var(--muted); white-space: pre-wrap; }
.highlights-list .link-button { font-size: 13px; padding: 4px 0 0; }
.note-status { font-size: 13px; min-height: 1.2em; margin: 6px 0 0; }

/* ---------- v2: iPhone home-screen app ---------- */
@supports (padding: env(safe-area-inset-top)) {
  body { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
  main { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
  .reader-top { padding-top: calc(14px + env(safe-area-inset-top)); }
}
@media (display-mode: standalone) {
  main:not(.reader) { padding-top: calc(16px + env(safe-area-inset-top)); }
}
@media (max-width: 620px) {
  .tabs-row { flex-direction: column-reverse; align-items: stretch; gap: 10px; border: 0; }
  .tabs-row .tabs { border-bottom: 1px solid var(--line); }
  .search { width: 100%; margin: 0; font-size: 16px; } /* 16px stops iOS zooming in on focus */
  .save input, .tag-input, textarea { font-size: 16px !important; }
  .actions { gap: 8px 14px; }
  .actions button { font-size: 14px; padding: 4px 0; }
  .actions button.pill { padding: 5px 14px; }
}

/* ---------- v2: setup page ---------- */
.setup h2 { font-size: 18px; margin: 32px 0 8px; }
.setup ol { padding-left: 1.3em; }
.setup li { margin: 8px 0; }
.setup code, .setup .copy-field { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.copy-field { display: flex; gap: 6px; margin: 6px 0; }
.copy-field input { flex: 1; font-family: inherit; font-size: 13px; }
.copy-field button { border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 8px; padding: 6px 12px; }
.callout { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; font-size: 14px; }
.callout.ok { border-color: var(--accent); }
.callout.warn { border-color: var(--warn); }
.foot a:not(.bookmarklet), .setup a { color: var(--accent); }

/* Listen (read aloud) */
.listen-button { background: none; border: 0; color: var(--accent); font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; padding: 4px 8px; }
.prose .is-speaking { background: color-mix(in srgb, var(--accent) 12%, transparent); border-radius: 6px;
                      box-shadow: 0 0 0 6px color-mix(in srgb, var(--accent) 12%, transparent); transition: background .2s; }
.player { position: fixed; z-index: 20; left: 50%; transform: translateX(-50%);
          bottom: calc(16px + env(safe-area-inset-bottom)); display: flex; align-items: center; gap: 4px;
          padding: 6px 8px; border-radius: 999px; background: var(--card, var(--bg)); border: 1px solid var(--line);
          box-shadow: 0 6px 24px rgb(0 0 0 / .18); font-size: 15px; }
.player button { background: none; border: 0; color: var(--text); font: inherit; cursor: pointer;
                 min-width: 40px; height: 40px; border-radius: 999px; letter-spacing: -2px; }
.player button:hover { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.player .player-main { background: var(--accent); color: var(--accent-text); letter-spacing: 0; }
.player .player-main:hover { background: var(--accent); filter: brightness(1.08); }
.player .player-speed { letter-spacing: 0; font-size: 13px; font-weight: 600; min-width: 48px; }
.player-pos { color: var(--muted); font-size: 12px; padding: 0 4px; font-variant-numeric: tabular-nums; }
body.is-listening .reader { padding-bottom: 90px; }
