:root {
  --bg: #f5f1e8;
  --surface: #fffdf7;
  --ink: #1c1a15;
  --ink-2: #3d3a32;
  --muted: #736d60;
  --line: #e4ddcd;
  --accent: #1c1a15;
  --on-accent: #fffdf7;
  --danger: #b4321f;
  --scrim: rgba(28, 26, 21, .38);
  --shadow: 0 10px 30px rgba(40, 32, 10, .16), 0 2px 6px rgba(40, 32, 10, .08);

  --c-yellow: #ffd60a;
  --c-green: #51915b;
  --c-blue: #4462bd;
  --c-pink: #ff5c9a;
  /* CalCo Five (calcifercomputing.com/branding) */
  --c-flame: #ea5526;
  --c-purple: #8064a2;
  --c-gold: #e5b700;
  --hl-yellow: rgba(255, 214, 10, .45);
  --hl-green: rgba(81, 145, 91, .30);
  --hl-blue: rgba(68, 98, 189, .26);
  --hl-pink: rgba(255, 92, 154, .28);
  --hl-flame: rgba(234, 85, 38, .28);
  --hl-purple: rgba(128, 100, 162, .28);
  --hl-gold: rgba(229, 183, 0, .38);

  --ui: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --read: "Source Serif 4", "Iowan Old Style", Georgia, serif;
  --display: "Fraunces", "Source Serif 4", Georgia, serif;

  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14130f;
    --surface: #1e1c17;
    --ink: #ede8db;
    --ink-2: #d2ccbd;
    --muted: #9d9686;
    --line: #2f2c24;
    --accent: #ede8db;
    --on-accent: #14130f;
    --danger: #ff7a62;
    --scrim: rgba(0, 0, 0, .55);
    --shadow: 0 10px 30px rgba(0, 0, 0, .5), 0 2px 6px rgba(0, 0, 0, .4);
    --hl-yellow: rgba(255, 214, 10, .32);
    --hl-green: rgba(81, 145, 91, .38);
    --hl-blue: rgba(68, 98, 189, .42);
    --hl-pink: rgba(255, 92, 154, .30);
    --hl-flame: rgba(234, 85, 38, .34);
    --hl-purple: rgba(128, 100, 162, .40);
    --hl-gold: rgba(229, 183, 0, .34);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--ui);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; flex: none; }
button { font: inherit; color: inherit; }
a { color: inherit; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 18px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font-weight: 600; font-size: 15px; text-decoration: none; cursor: pointer;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.btn-danger { color: var(--danger); }
.btn-small { min-height: 36px; padding: 0 14px; font-size: 14px; border-radius: 10px; }
.icon-btn {
  width: 44px; height: 44px; display: grid; place-items: center;
  border: 0; background: none; border-radius: 12px; cursor: pointer; color: var(--ink);
}
.icon-btn:active { background: var(--line); }
.icon-btn svg { width: 22px; height: 22px; }

/* ---------- home ---------- */
#home {
  max-width: 640px; margin: 0 auto;
  padding: calc(28px + var(--safe-t)) 16px calc(32px + var(--safe-b));
}
.home-head { padding: 18px 0 20px; }
.wordmark {
  font-family: var(--display); font-weight: 700; font-size: clamp(34px, 10vw, 52px);
  line-height: 1.02; letter-spacing: -.02em; margin: 0;
  font-variation-settings: "opsz" 144;
}
.swash {
  background: linear-gradient(transparent 52%, var(--hl-yellow) 52%, var(--hl-yellow) 92%, transparent 92%);
  padding: 0 .06em; margin: 0 -.06em;
}
@media (prefers-color-scheme: dark) { .swash { background: linear-gradient(transparent 52%, rgba(255,214,10,.45) 52%, rgba(255,214,10,.45) 92%, transparent 92%); } }
.tagline { color: var(--muted); font-size: 17px; margin: 12px 0 0; }
.account { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.acct-who { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; min-width: 0; }
.acct-who span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acct-pic { width: 26px; height: 26px; border-radius: 50%; flex: none; }
.acct-why { color: var(--muted); font-size: 14px; }
.btn-google { text-decoration: none; }

.open-form {
  display: flex; gap: 8px; padding: 6px; border-radius: 16px;
  background: var(--surface); border: 1px solid var(--line); box-shadow: 0 1px 2px rgba(0,0,0,.04);
}
.open-form:focus-within { border-color: var(--ink); }
.open-form input {
  flex: 1; min-width: 0; border: 0; background: none; color: var(--ink);
  font: 16px var(--ui); padding: 0 10px; outline: none;
}
.open-form input::placeholder { color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 0; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 36px; padding: 0 12px; border-radius: 999px;
  border: 1px solid var(--line); background: transparent; font-size: 14px; color: var(--ink-2); cursor: pointer;
}
.chip svg { width: 16px; height: 16px; }

.section-head { display: flex; align-items: baseline; gap: 8px; margin: 36px 0 10px; }
.section-head h2, .how h2 { font-family: var(--display); font-weight: 500; font-size: 22px; margin: 0; letter-spacing: -.01em; }
.count { color: var(--muted); font-size: 14px; }
.saved-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.page-card {
  position: relative; display: flex; gap: 12px; align-items: stretch;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; overflow: hidden;
}
.page-card a.card-main { flex: 1; min-width: 0; padding: 14px 4px 14px 16px; text-decoration: none; }
.card-title { font-weight: 600; font-size: 16px; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-meta { color: var(--muted); font-size: 13px; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-snippet {
  font-family: var(--read); font-size: 15px; line-height: 1.45; color: var(--ink-2); margin-top: 8px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card-snippet span { padding: 0 2px; border-radius: 2px; -webkit-box-decoration-break: clone; box-decoration-break: clone; }
.card-remove { align-self: flex-start; margin: 6px 4px 0 0; color: var(--muted); }
.card-remove svg { width: 18px; height: 18px; }
.empty { color: var(--muted); font-size: 15px; padding: 18px 16px; border: 1px dashed var(--line); border-radius: 14px; }
.empty p { margin: 0; }

.how { margin-top: 36px; }
.how ol { margin: 12px 0 0; padding: 0; list-style: none; counter-reset: s; display: grid; gap: 10px; }
.how li { counter-increment: s; display: flex; gap: 12px; color: var(--ink-2); font-size: 15px; }
.how li::before {
  content: counter(s); flex: none; width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center; font-size: 13px; font-weight: 600;
  background: var(--hl-yellow); color: var(--ink);
}
.home-foot { color: var(--muted); font-size: 13px; margin-top: 36px; }

/* ---------- reader ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 4px;
  padding: calc(4px + var(--safe-t)) 8px 4px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(14px); backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--line);
}
.topbar-title { flex: 1; min-width: 0; font-size: 14px; color: var(--muted); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 4px; }
.pill-btn {
  display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 12px;
  border-radius: 999px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 600; font-size: 14px;
}
.pill-btn svg { width: 16px; height: 16px; }
.pill-btn.has { background: var(--hl-yellow); border-color: transparent; }
.progress { position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; }
#progress-bar { height: 100%; width: 0; background: var(--ink); opacity: .55; transition: width .1s linear; }

.shared-banner {
  max-width: 680px; margin: 12px auto 0; padding: 10px 14px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--line); font-size: 14px; color: var(--ink-2);
  width: calc(100% - 32px);
}

/* the page itself, in a script-free sandboxed frame (highlight styles live in app.js FRAME_CSS) */
#reader:not([hidden]) { position: fixed; inset: 0; display: flex; flex-direction: column; }
#reader .topbar { position: relative; flex: none; }
.stage { position: relative; flex: 1; min-height: 0; background: #fff; }
#frame { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; display: block; background: #fff; }
#reader .shared-banner { position: absolute; z-index: 15; left: 50%; transform: translateX(-50%); top: calc(52px + var(--safe-t)); margin: 0; box-shadow: 0 6px 24px rgba(0,0,0,.14); cursor: pointer; }
.panel { position: absolute; inset: 0; overflow: auto; background: var(--bg); padding: 22px 20px; }
.panel > * { max-width: 640px; margin-left: auto; margin-right: auto; }

/* loading & error */
.loading { padding-top: 20px; }
.sk { height: 18px; border-radius: 6px; margin: 0 0 14px; background: linear-gradient(90deg, var(--line), color-mix(in srgb, var(--line) 50%, transparent), var(--line)); background-size: 200% 100%; animation: sh 1.2s infinite linear; }
.w100 { width: 100%; } .w95 { width: 95%; } .w90 { width: 90%; } .w80 { width: 80%; } .w60 { width: 60%; }
@keyframes sh { to { background-position: -200% 0; } }
.loading-note { color: var(--muted); font-size: 14px; }
.error { padding-top: 28px; }
.error h2 { font-family: var(--display); font-weight: 600; margin: 0 0 6px; }
.error p { color: var(--ink-2); margin: 0 0 18px; }
.error-actions { display: flex; flex-wrap: wrap; gap: 10px; }

/* ---------- floating layer ---------- */
/* Holds the toolbar, scrim, sheets and toast. app.js sizes and moves it to cover the visible part
   of the screen at normal scale, so pinch-zoom and the on-screen keyboard can't push them out of
   view. A transformed element is the containing block for its fixed-position children. */
#hud { position: fixed; left: 0; top: 0; width: 100%; height: 100%; z-index: 40; pointer-events: none; transform-origin: 0 0; }
#hud > .selbar, #hud > .sheet { pointer-events: auto; }
#hud > .selbar:not(.show) { pointer-events: none; }

/* ---------- selection toolbar ---------- */
.selbar {
  position: fixed; left: 50%; bottom: calc(64px + var(--safe-b)); z-index: 40; visibility: hidden;
  display: flex; align-items: center; gap: 4px; padding: 6px 6px 6px 8px;
  background: #1c1a15; color: #fffdf7; border-radius: 999px; box-shadow: var(--shadow);
  transform: translate(-50%, 24px); opacity: 0; transition: transform .22s cubic-bezier(.2,.8,.2,1), opacity .18s, visibility 0s .22s;
  touch-action: manipulation;
}
@media (prefers-color-scheme: dark) { .selbar { background: #ede8db; color: #14130f; } }
.selbar.show { transform: translate(-50%, 0); opacity: 1; visibility: visible; transition-delay: 0s; }
.swatch {
  width: 44px; height: 44px; border: 0; border-radius: 50%; background: none; cursor: pointer; padding: 0;
  display: grid; place-items: center; position: relative;
}
.swatch::before { content: ""; width: 28px; height: 28px; border-radius: 50%; background: var(--sw); box-shadow: inset 0 0 0 1px rgba(0,0,0,.12); }
.swatch[data-color="yellow"] { --sw: var(--c-yellow); }
.swatch[data-color="green"] { --sw: var(--c-green); }
.swatch[data-color="blue"] { --sw: var(--c-blue); }
.swatch[data-color="pink"] { --sw: var(--c-pink); }
.swatch[data-color="flame"] { --sw: var(--c-flame); }
.swatch[data-color="purple"] { --sw: var(--c-purple); }
.swatch[data-color="gold"] { --sw: var(--c-gold); }
.swatch:active::before { transform: scale(.88); }
.swatch[aria-pressed="true"]::after {
  content: ""; position: absolute; inset: 4px; border-radius: 50%; border: 2px solid currentColor;
}
.sep { width: 1px; height: 24px; background: currentColor; opacity: .25; margin: 0 3px; flex: none; }
/* 6 colours + 3 tools: buttons shrink to fit a phone, full size where there's room */
.selbar { --sz: clamp(32px, calc((100vw - 80px) / 10), 44px); gap: 2px; padding: 6px; flex-wrap: wrap; justify-content: center; }
.selbar .brk { display: none; }
/* phones: colours on one row, tools + undo/redo on the next, so buttons stay finger-sized */
@media (max-width: 520px) {
  .selbar { --sz: clamp(36px, calc((100vw - 60px) / 6), 44px); width: calc(var(--sz) * 5 + 29px); border-radius: 26px; row-gap: 2px; }
  .selbar .brk { display: block; flex-basis: 100%; height: 0; }
  .selbar .sep.between { display: none; }
  #hud > .toast { bottom: calc(184px + var(--safe-b)); }   /* above the two-row toolbar */
}
.selbar .swatch, .selbar .tool { width: var(--sz); height: var(--sz); flex: none; }
.selbar .swatch::before { width: calc(var(--sz) - 16px); height: calc(var(--sz) - 16px); }
.selbar .tool svg { width: calc(var(--sz) * .5); height: calc(var(--sz) * .5); }
/* corner circle that opens and closes the toolbar */
.mark-toggle {
  position: fixed; right: 12px; bottom: calc(14px + var(--safe-b)); z-index: 41; pointer-events: auto;
  width: 40px; height: 40px; border-radius: 50%; border: 0; padding: 0; cursor: pointer;
  display: grid; place-items: center; background: #1c1a15; color: #fffdf7; box-shadow: var(--shadow);
  opacity: 0; visibility: hidden; transition: opacity .18s, visibility 0s .18s; touch-action: manipulation;
}
.mark-toggle.show { opacity: 1; visibility: visible; transition-delay: 0s; }
.mark-toggle svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.mark-toggle .dot { position: absolute; right: 5px; bottom: 5px; width: 11px; height: 11px; border-radius: 50%; background: var(--sw, var(--c-yellow)); box-shadow: 0 0 0 2px #1c1a15; }
.mark-toggle[aria-expanded="true"] .when-closed, .mark-toggle[aria-expanded="false"] .when-open { display: none; }
@media (prefers-color-scheme: dark) { .mark-toggle { background: #ede8db; color: #14130f; } .mark-toggle .dot { box-shadow: 0 0 0 2px #ede8db; } }
.tool {
  width: 44px; height: 44px; border: 0; border-radius: 50%; background: none; color: inherit; padding: 0;
  display: grid; place-items: center; cursor: pointer;
}
.tool svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.tool[aria-pressed="true"] { background: rgba(255,255,255,.2); box-shadow: inset 0 0 0 2px currentColor; }
@media (prefers-color-scheme: dark) { .tool[aria-pressed="true"] { background: rgba(0,0,0,.1); } }
.tool[aria-disabled="true"] { opacity: .45; }

/* ---------- sheets ---------- */
.scrim { position: fixed; inset: 0; background: var(--scrim); opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 50; }
.scrim.show { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
  max-width: 640px; margin: 0 auto; max-height: 88%;
  display: flex; flex-direction: column;
  background: var(--surface); border-radius: 20px 20px 0 0; box-shadow: var(--shadow);
  padding: 8px 16px calc(16px + var(--safe-b));
  transform: translateY(105%); transition: transform .28s cubic-bezier(.2,.8,.2,1), bottom .15s;
  visibility: hidden;
}
.sheet.open { transform: translateY(0); visibility: visible; }
.sheet.dragging { transition: none; }
.sheet-grip { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 2px auto 12px; flex: none; }
.sheet h2 { font-family: var(--display); font-weight: 600; font-size: 22px; margin: 0; letter-spacing: -.01em; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; flex: none; }

.edit-quote {
  margin: 0 0 12px; padding: 4px 0 4px 12px; border-left: 4px solid var(--c-yellow);
  font-family: var(--read); font-size: 16px; line-height: 1.5; color: var(--ink-2);
  max-height: 7.5em; overflow-y: auto;
}
.color-row { display: flex; gap: 4px; margin-bottom: 8px; color: var(--ink); }
#edit-note {
  width: 100%; resize: none; min-height: 88px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink); padding: 12px; font: 16px/1.45 var(--ui); outline: none;
}
#edit-note:focus { border-color: var(--ink); }
.sheet-actions { display: flex; justify-content: space-between; gap: 10px; margin-top: 12px; }
.sheet-actions .btn { flex: 1; }

.marks-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.marks-list li + li { border-top: 1px solid var(--line); }
.mark-item { display: flex; gap: 12px; width: 100%; text-align: left; border: 0; background: none; padding: 14px 2px; cursor: pointer; }
.mark-bar { width: 4px; border-radius: 2px; flex: none; background: var(--c-yellow); }
.mark-body { min-width: 0; }
.mark-quote { font-family: var(--read); font-size: 16px; line-height: 1.45; color: var(--ink); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.mark-note { font-size: 14px; color: var(--ink-2); margin-top: 6px; white-space: pre-wrap; }
.mark-note::before { content: "✎ "; color: var(--muted); }
.mark-orphan { font-size: 12px; color: var(--danger); margin-top: 4px; }

.share-sub { color: var(--muted); font-size: 14px; margin: 6px 0 14px; }
.share-actions { display: grid; gap: 8px; }
.share-act {
  display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 0 16px;
  border-radius: 14px; border: 1px solid var(--line); background: var(--bg); font-weight: 600; font-size: 16px; cursor: pointer; text-align: left;
}
.share-act:active { transform: scale(.99); }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(124px + var(--safe-b)); z-index: 80;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  display: flex; align-items: center; gap: 14px;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 500;
  box-shadow: var(--shadow); transition: opacity .2s, transform .2s; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast button { border: 0; background: none; color: inherit; font-weight: 700; text-decoration: underline; padding: 6px 0; cursor: pointer; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
@media (min-width: 720px) {
  .sheet { border-radius: 20px; bottom: 16px; }
}

/* ---------- privacy policy, terms ---------- */
.legal { max-width: 680px; margin: 0 auto; padding: calc(24px + var(--safe-t)) 18px calc(48px + var(--safe-b)); font-family: "Source Serif 4", Georgia, serif; line-height: 1.6; }
.legal h1 { font-family: var(--display); font-size: 34px; letter-spacing: -.02em; margin: 8px 0 4px; }
.legal h2 { font-family: var(--display); font-size: 21px; margin: 28px 0 6px; }
.legal h3 { font-size: 16px; margin: 16px 0 2px; font-family: inherit; }
.legal p, .legal li { font-size: 17px; }
.legal ul { padding-left: 1.2em; }
.legal a { color: inherit; }
.legal-meta, .legal-back { font-family: Inter, system-ui, sans-serif; font-size: 13px !important; color: var(--muted); }
.legal-back a, .legal-meta a { color: var(--muted); }
.home-legal { color: var(--muted); font-size: 13px; margin-top: 8px; }
.home-legal a, .acct-terms a { color: inherit; }
.acct-terms { flex-basis: 100%; color: var(--muted); font-size: 12px; margin: -2px 0 0; }
