/* Commonplace — built exactly to DESIGN.md. Tokens first, components after.
   The only saturated hue anywhere is the highlighter yellow, and it appears
   only as: the arrival swipe, the favorite star fill, selection states. */

@font-face {
  font-family: 'Literata';
  src: url('../fonts/Literata-var-latin.woff2') format('woff2');
  font-weight: 200 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Literata';
  src: url('../fonts/Literata-Italic-var-latin.woff2') format('woff2');
  font-weight: 200 900;
  font-style: italic;
  font-display: swap;
}

:root {
  /* palette — light ("paper") */
  --paper: #f3efe6;
  --paper-raised: #fbf8f1;
  --ink: #262119;
  --ink-muted: #6b6355;
  --rule: #dbd3c3;
  --highlighter: #f2d64b;
  --highlighter-tint: rgba(242, 214, 75, 0.26);
  --swipe-opacity: 0.32;
  --swipe-blend: multiply;
  --overlay: rgba(38, 33, 25, 0.4);

  --font-quote: 'Literata', 'Iowan Old Style', Georgia, serif;
  --font-ui: -apple-system, BlinkMacSystemFont, system-ui, 'Segoe UI', sans-serif;

  /* spacing — page margins, not dashboard density */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px;
  --s5: 24px; --s6: 36px; --s7: 56px;

  --radius-s: 6px;
  --radius-m: 10px;
  --radius-sheet: 16px;

  color-scheme: light dark;
}

:root[data-theme='light'] { color-scheme: light; }
:root[data-theme='dark'] { color-scheme: dark; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --paper: #211d17;
    --paper-raised: #2b2620;
    --ink: #e9e3d3;
    --ink-muted: #a39a87;
    --rule: #3c362b;
    --highlighter: #e5c93f;
    --highlighter-tint: rgba(229, 201, 63, 0.16);
    --swipe-opacity: 0.2;
    --swipe-blend: normal;
    --overlay: rgba(0, 0, 0, 0.5);
  }
}
:root[data-theme='dark'] {
  --paper: #211d17;
  --paper-raised: #2b2620;
  --ink: #e9e3d3;
  --ink-muted: #a39a87;
  --rule: #3c362b;
  --highlighter: #e5c93f;
  --highlighter-tint: rgba(229, 201, 63, 0.16);
  --swipe-opacity: 0.2;
  --swipe-blend: normal;
  --overlay: rgba(0, 0, 0, 0.5);
}

/* ---------- base ---------- */

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}
a { color: inherit; text-decoration: none; }

:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}
.screen:focus-visible { outline: none; }

button, a, label, input, textarea {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- screen scaffold ---------- */

.screen {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  padding-bottom: env(safe-area-inset-bottom);
}

.topbar {
  display: flex;
  align-items: center;
  gap: var(--s2);
  padding: var(--s2) var(--s3);
  min-height: 56px;
}
.topbar .screen-title {
  flex: 1;
  font-family: var(--font-quote);
  font-size: 19px;
  font-weight: 500;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-trailing { display: flex; gap: var(--s1); }
.quote-screen .topbar { justify-content: space-between; }

.icon-btn {
  width: 44px;
  height: 44px;
  display: inline-grid;
  place-items: center;
  border-radius: var(--radius-s);
  color: var(--ink-muted);
}
.icon-btn:active { background: var(--rule); }
.icon-btn.is-active { color: var(--ink); }
/* Active-filter dot: ink, not yellow — the accent is reserved for the
   star, selection states, and the swipe (DESIGN.md). */
.icon-btn.is-active::after {
  content: '';
  position: relative;
  top: -13px;
  left: 13px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ink);
  display: block;
  margin: -6px 0 0;
}

.screen-body {
  flex: 1;
  padding: var(--s3) var(--s4) var(--s6);
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
}

/* ---------- quote screen ---------- */

.quote-stage {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 0 var(--s5);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  min-height: 0;
}

.quote {
  margin: 0;
  max-width: 34em;
}

.quote-text {
  position: relative;
  margin: 0;
  font-family: var(--font-quote);
  font-optical-sizing: auto;
  font-weight: 400;
  white-space: pre-line;
  text-wrap: pretty;
}
.tier-l { font-size: 30px; line-height: 1.32; letter-spacing: -0.01em; }
.tier-m { font-size: 22px; line-height: 1.45; }
.tier-s { font-size: 17px; line-height: 1.6; }

/* The signature: one translucent highlighter stroke across the first line
   of a newly arrived quote. ≤400ms, CSS-only, gone under reduced motion. */
.swipe {
  position: absolute;
  top: -0.08em;
  left: -0.35em;
  width: calc(100% + 0.7em);
  height: 1.28em;
  border-radius: 0.45em 0.6em 0.5em 0.4em;
  background: var(--highlighter);
  mix-blend-mode: var(--swipe-blend);
  opacity: 0;
  transform: skewX(-8deg) scaleX(0);
  transform-origin: left center;
  pointer-events: none;
}
.arrive .swipe {
  animation: swipe-mark 400ms cubic-bezier(0.33, 0, 0.2, 1) 1 both;
}
@keyframes swipe-mark {
  0% { transform: skewX(-8deg) scaleX(0); opacity: var(--swipe-opacity); }
  65% { transform: skewX(-8deg) scaleX(1); opacity: var(--swipe-opacity); }
  100% { transform: skewX(-8deg) scaleX(1); opacity: 0; }
}

.quote-clamp {
  position: relative;
  max-height: 60dvh;
  overflow: hidden;
}
.quote-clamp::after {
  content: '';
  position: absolute;
  inset: auto 0 0 0;
  height: 4.5em;
  background: linear-gradient(to bottom, transparent, var(--paper));
  pointer-events: none;
}
.quote.is-expanded .quote-text { font-size: 17px; line-height: 1.6; }
.quote.is-expanded {
  max-height: 62dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.more-btn {
  display: block;
  margin: var(--s3) auto 0;
  min-height: 44px;
  padding: 0 var(--s4);
  color: var(--ink-muted);
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.quote-foot {
  padding: 0 var(--s5) var(--s4);
  text-align: center;
}
.attribution {
  font-family: var(--font-quote);
  font-style: italic;
  font-size: 15px;
  color: var(--ink-muted);
  margin: 0 0 var(--s3);
}
.actions {
  display: flex;
  justify-content: center;
  gap: var(--s4);
}

.is-starred .star-shape {
  fill: var(--highlighter);
  stroke: var(--ink-muted);
}

/* ---------- empty states ---------- */

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--s4);
  padding: var(--s5);
  text-align: center;
}
.empty-title {
  font-family: var(--font-quote);
  font-size: 19px;
  color: var(--ink-muted);
  max-width: 22em;
  margin: 0;
}

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 var(--s5);
  border-radius: var(--radius-m);
  font-weight: 550;
}
.btn-primary {
  background: var(--ink);
  color: var(--paper);
}
.btn-secondary {
  border: 1px solid var(--rule);
  background: var(--paper-raised);
}

/* ---------- filter bottom sheet ---------- */

.sheet-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  display: flex;
  align-items: flex-end;
  z-index: 20;
}
.sheet {
  background: var(--paper-raised);
  border-radius: var(--radius-sheet) var(--radius-sheet) 0 0;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  max-height: 75dvh;
  overflow-y: auto;
  padding: var(--s2) var(--s4) calc(var(--s5) + env(safe-area-inset-bottom));
}
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--s2) 0;
}
.sheet-title {
  font-family: var(--font-quote);
  font-size: 17px;
  font-weight: 500;
  margin: 0;
}
.sheet-row {
  display: flex;
  align-items: center;
  gap: var(--s3);
  width: 100%;
  min-height: 48px;
  padding: var(--s2) var(--s3);
  border-radius: var(--radius-s);
  text-align: left;
}
.sheet-row.is-selected { background: var(--highlighter-tint); }
.sheet-row-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sheet-row-count { color: var(--ink-muted); font-size: 13px; }
.sheet-row-check { width: 22px; color: var(--ink); display: inline-grid; }
.sheet-divider { border-top: 1px solid var(--rule); margin: var(--s2) 0; }

/* ---------- library ---------- */

.search-wrap { margin-bottom: var(--s4); }
.search-input {
  width: 100%;
  min-height: 44px;
  padding: 0 var(--s4);
  border: 1px solid var(--rule);
  border-radius: var(--radius-m);
  background: var(--paper-raised);
  color: var(--ink);
  font: inherit;
  -webkit-appearance: none;
  appearance: none;
}
.search-input::placeholder { color: var(--ink-muted); }
/* The native clear affordance is webkit-blue — off-palette; hide it. */
.search-input::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
}

.book-row {
  display: flex;
  align-items: center;
  gap: var(--s3);
  min-height: 56px;
  padding: var(--s2) var(--s1);
  border-bottom: 1px solid var(--rule);
}
.book-row-icon { color: var(--ink-muted); display: inline-grid; }
.book-row-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.book-row-title {
  font-family: var(--font-quote);
  font-size: 16px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.book-row-author { color: var(--ink-muted); font-size: 13px; }
.book-row-count { color: var(--ink-muted); font-size: 13px; }

.search-count, .search-empty { color: var(--ink-muted); font-size: 13px; }
.hit-row {
  padding: var(--s3) 0;
  border-bottom: 1px solid var(--rule);
}
.hit-text {
  font-family: var(--font-quote);
  font-size: 15px;
  line-height: 1.55;
  margin: 0 0 var(--s1);
  white-space: pre-line;
}
.hit-meta { color: var(--ink-muted); font-size: 13px; margin: 0; }

/* ---------- book detail ---------- */

.book-author {
  font-family: var(--font-quote);
  font-style: italic;
  color: var(--ink-muted);
  margin: 0 0 var(--s4);
}
.passage {
  padding: var(--s4) 0;
  border-bottom: 1px solid var(--rule);
}
.passage-text {
  font-family: var(--font-quote);
  font-size: 16px;
  line-height: 1.55;
  margin: 0 0 var(--s2);
  white-space: pre-line;
}
.passage.is-hidden .passage-text { opacity: 0.45; }
.passage-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--ink-muted);
  font-size: 13px;
}
.passage-actions { display: flex; gap: var(--s1); }
.mini-btn {
  width: 44px;
  height: 44px;
  display: inline-grid;
  place-items: center;
  border-radius: var(--radius-s);
  color: var(--ink-muted);
}
.mini-btn:active { background: var(--rule); }

/* ---------- import ---------- */

.file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
}
.drop-zone {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s2);
  padding: var(--s6) var(--s4);
  border: 1.5px dashed var(--rule);
  border-radius: var(--radius-m);
  background: var(--paper-raised);
  text-align: center;
  cursor: pointer;
}
.drop-zone.is-drag { border-color: var(--ink); background: var(--paper); }
.drop-zone:focus-within { outline: 2px solid var(--ink); outline-offset: 2px; }
.drop-icon { color: var(--ink-muted); }
.drop-title { font-weight: 550; }
.drop-sub { color: var(--ink-muted); font-size: 13px; }

.paste-wrap {
  margin-top: var(--s4);
  display: flex;
  flex-direction: column;
  gap: var(--s3);
}
.paste-area {
  width: 100%;
  border: 1px solid var(--rule);
  border-radius: var(--radius-m);
  background: var(--paper-raised);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  padding: var(--s3);
  resize: vertical;
}
.paste-area::placeholder { color: var(--ink-muted); }

.card {
  border: 1px solid var(--rule);
  border-radius: var(--radius-m);
  background: var(--paper-raised);
  padding: var(--s4);
  margin-top: var(--s4);
}
.report-line {
  font-family: var(--font-quote);
  font-size: 17px;
  margin: 0;
}
.report-books {
  margin: var(--s3) 0 0;
  padding-left: 1.2em;
  color: var(--ink-muted);
}
.report-books li { margin-bottom: var(--s1); }
.report-note { color: var(--ink-muted); font-size: 13px; margin: var(--s3) 0 0; }
.nudge-card p { margin: 0 0 var(--s3); }
.warn-card { border-color: var(--ink-muted); }
.warn-card p { margin: 0; }

/* ---------- settings ---------- */

.settings-heading {
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-muted);
  font-weight: 600;
  margin: var(--s5) 0 var(--s3);
}
.settings-heading:first-child { margin-top: 0; }
.settings-actions { display: flex; gap: var(--s3); flex-wrap: wrap; }
.settings-note { color: var(--ink-muted); font-size: 13px; margin: var(--s2) 0 0; }

.seg {
  display: inline-flex;
  border: 1px solid var(--rule);
  border-radius: var(--radius-m);
  background: var(--paper-raised);
  overflow: hidden;
}
.seg-btn {
  min-height: 44px;
  padding: 0 var(--s4);
  color: var(--ink-muted);
}
.seg-btn.is-selected {
  background: var(--highlighter-tint);
  color: var(--ink);
}
.seg-btn + .seg-btn { border-left: 1px solid var(--rule); }

/* ---------- onboarding ---------- */

.onboard-screen {
  align-items: center;
  justify-content: space-between;
  text-align: left;
  padding-top: calc(env(safe-area-inset-top) + var(--s7));
  padding-bottom: calc(env(safe-area-inset-bottom) + var(--s6));
}
.onboard-wordmark {
  font-family: var(--font-quote);
  font-size: 17px;
  letter-spacing: 0.02em;
  color: var(--ink-muted);
  font-style: italic;
}
.onboard-body {
  max-width: 26em;
  padding: 0 var(--s5);
  display: flex;
  flex-direction: column;
  gap: var(--s4);
}
.onboard-title {
  font-family: var(--font-quote);
  font-size: 26px;
  line-height: 1.3;
  font-weight: 500;
  margin: 0;
}
.onboard-body p { margin: 0; }
.onboard-steps {
  margin: 0;
  padding-left: 1.3em;
  display: flex;
  flex-direction: column;
  gap: var(--s2);
}
.onboard-fineprint { color: var(--ink-muted); font-size: 13px; }
.onboard-body .btn { align-self: flex-start; }
.inline-glyph {
  display: inline-block;
  vertical-align: -5px;
  color: var(--ink);
}
.inline-glyph svg { width: 18px; height: 18px; }
.onboard-dots { display: flex; gap: var(--s2); }
.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--rule);
}
.dot.is-current { background: var(--ink-muted); }

/* ---------- toast ---------- */

#toast-root {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(env(safe-area-inset-bottom) + var(--s5));
  display: flex;
  justify-content: center;
  pointer-events: none;
  z-index: 30;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: var(--s4);
  background: var(--ink);
  color: var(--paper);
  border-radius: var(--radius-m);
  padding: var(--s3) var(--s4);
  max-width: min(90vw, 480px);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.18);
}
.toast-action {
  font-weight: 650;
  text-decoration: underline;
  text-underline-offset: 3px;
  /* 44px touch floor without inflating the toast visually */
  min-height: 44px;
  min-width: 44px;
  padding: 0 var(--s3);
  margin: calc(-1 * var(--s2)) calc(-1 * var(--s2)) calc(-1 * var(--s2)) 0;
}

/* ---------- motion discipline ---------- */

@media (prefers-reduced-motion: reduce) {
  .arrive .swipe { animation: none; }
  .swipe { display: none; }
  * { transition: none !important; }
}
