/* Commonplace — "manuscript, made modern". Refined literary reader. */

:root {
  /* Warm paper-and-ink palette in OKLCH; neutrals tinted toward the parchment hue (~88). */
  --ground:      oklch(0.928 0.026 86);   /* the desk the sheet rests on (deeper) */
  --paper:       oklch(0.972 0.018 88);   /* the sheet */
  --paper-edge:  oklch(0.90 0.03 86);     /* hairline at the sheet edge */
  --ink:         oklch(0.27 0.018 60);    /* deep warm ink (never pure black) */
  --ink-soft:    oklch(0.46 0.02 58);     /* secondary text */
  --ink-faint:   oklch(0.62 0.018 62);    /* tertiary / captions */
  --hair:        oklch(0.27 0.018 60 / 0.12);
  --hair-hover:  color-mix(in oklch, var(--ink) 22%, transparent);  /* ghost-button hover edge */
  --ochre:       oklch(0.585 0.085 67);   /* quiet labels */
  --oxblood:     oklch(0.47 0.115 32);    /* links + emphasis (rare) */
  --sage:        oklch(0.60 0.045 150);   /* verified badge */

  --serif: "Literata", "Iowan Old Style", Palatino, Georgia, serif;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;

  --measure: 40rem;
  --gutter: clamp(0.75rem, 2.5vw, 1.25rem);
  --pad: clamp(1.5rem, 6vw, 3.25rem);

  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; margin: 0; }
html, body { height: 100%; }
body {
  background: var(--ground);
  color: var(--ink);
  font-family: var(--serif);
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
.hidden { display: none !important; }
a { color: inherit; }

/* ---------- Login ---------- */
#login { min-height: 100dvh; display: grid; place-items: center; padding: 2rem; }
#login form { width: min(21rem, 100%); display: grid; gap: 1rem; text-align: center; }
.wordmark { font-size: clamp(2.2rem, 9vw, 2.9rem); font-weight: 600; letter-spacing: -0.015em; }
#login .lede { color: var(--ink-faint); font-style: italic; font-size: 1.05rem; margin-bottom: 0.5rem; }
input[type="password"], input[type="url"], input[type="text"] {
  font: inherit; width: 100%;
  padding: 0.8rem 1rem; border: 1px solid var(--paper-edge); border-radius: 0.6rem;
  background: var(--paper); color: var(--ink);
}
input:focus-visible { outline: 2px solid var(--ochre); outline-offset: 1px; }
button { font-family: var(--sans); cursor: pointer; }
.btn-primary {
  font-size: 0.95rem; font-weight: 600; letter-spacing: 0.01em;
  padding: 0.8rem 1rem; border: 0; border-radius: 0.6rem;
  background: var(--ink); color: var(--paper);
  transition: transform 0.18s var(--ease), background 0.18s var(--ease);
}
.btn-primary:hover { background: var(--oxblood); }
.btn-primary:active { transform: translateY(1px); }
.login-error { color: var(--oxblood); font-family: var(--sans); font-size: 0.85rem; }

/* ---------- Chrome: progress + counter + gear ---------- */
#progress {
  position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 20;
  background: var(--hair);
}
#progress::after {
  content: ""; display: block; height: 100%; width: var(--progress, 0%);
  background: var(--ochre); transition: width 0.15s linear;
}
/* Counter + gear are quiet, matched marks in the top corners — no boxes, so they sit in
   the margin rather than floating over the sheet. Vertically centered on the same line. */
#counter {
  position: fixed; top: calc(env(safe-area-inset-top, 0px) + 1.7rem); left: 1.7rem; z-index: 20;
  font-family: var(--sans); font-size: 0.72rem; letter-spacing: 0.08em; line-height: 1;
  color: var(--ink-faint); font-variant-numeric: tabular-nums;
}
#gear {
  position: fixed; top: calc(env(safe-area-inset-top, 0px) + 1.35rem); right: 1.55rem; z-index: 20;
  background: transparent; border: 0; padding: 0.25rem; margin: -0.25rem;  /* invisible tap target */
  font-size: 1.4rem; line-height: 1; color: var(--ink-faint);
  transition: color 0.18s var(--ease);
}
#gear:hover { color: var(--ink); }

/* ---------- Feed: one sheet per screen, snapped ---------- */
#feed {
  height: 100dvh; overflow-y: scroll; scroll-snap-type: y mandatory;
  scroll-behavior: smooth; scrollbar-width: none;
}
#feed::-webkit-scrollbar { display: none; }

.card {
  min-height: 100dvh; scroll-snap-align: center; scroll-snap-stop: always;
  display: grid; place-items: center; padding: var(--gutter);
}
.sheet {
  width: min(var(--measure), 100%);
  min-height: calc(100dvh - 2 * var(--gutter));
  background: var(--paper); border: 1px solid var(--paper-edge);
  border-radius: 1rem;
  box-shadow: 0 1px 2px oklch(0.27 0.02 60 / 0.04), 0 18px 40px -28px oklch(0.27 0.02 60 / 0.45);
  padding: var(--pad);
  /* Reserve top space so card content always clears the fixed counter + gear chrome. */
  padding-top: max(var(--pad), calc(env(safe-area-inset-top, 0px) + 3.5rem));
  display: grid; grid-template-rows: 1fr auto; gap: 1.5rem;
  /* entrance */
  opacity: 0; transform: translateY(10px);
  transition: opacity 0.6s var(--ease), transform 0.6s var(--ease);
}
.card.is-active .sheet { opacity: 1; transform: none; }

.body { align-self: center; display: grid; gap: 1rem; max-width: 34rem; }

.kicker {
  font-family: var(--sans); font-size: 0.72rem; font-weight: 600;
  letter-spacing: 0.14em; text-transform: uppercase; color: var(--ochre);
}
.title { font-size: clamp(1.6rem, 5.2vw, 2.2rem); font-weight: 600; line-height: 1.18; letter-spacing: -0.01em; }
.excerpt { font-size: 1.15rem; line-height: 1.62; color: var(--ink-soft); }

/* Insight-led link card: the line is the hero, the article title is a quiet subtitle. */
.insight { gap: 1.25rem; }
.insight .highlight {
  font-size: clamp(1.55rem, 4.6vw, 2.15rem); line-height: 1.32; font-weight: 500;
  letter-spacing: -0.006em; color: var(--ink); text-wrap: pretty;
}
.subtitle { font-family: var(--sans); font-size: 0.86rem; line-height: 1.4; color: var(--ink-faint); }
.card--summary .lead { font-size: 1.3rem; line-height: 1.5; color: var(--ink); text-wrap: pretty; }

/* Quote */
.quote { position: relative; }
.quote blockquote {
  font-size: clamp(1.7rem, 6vw, 2.35rem); line-height: 1.34; font-weight: 500;
  text-indent: -0.05em;
}
.quote blockquote::before {
  content: "\201C"; position: absolute; left: -0.62em; top: -0.34em;
  font-size: 3.4em; line-height: 1; color: color-mix(in oklch, var(--ochre) 55%, transparent);
}
.quote cite { display: block; margin-top: 1.4rem; font-style: normal;
  font-family: var(--sans); font-size: 0.85rem; letter-spacing: 0.02em; color: var(--ink-faint); }

/* Summary / scholarly link affordance */
.cta {
  font-family: var(--sans); font-size: 0.92rem; font-weight: 600;
  color: var(--oxblood); text-decoration: none; width: max-content;
  border-bottom: 1.5px solid color-mix(in oklch, var(--oxblood) 35%, transparent);
  padding-bottom: 1px; transition: border-color 0.2s var(--ease);
}
.cta:hover { border-bottom-color: var(--oxblood); }

.tag {
  font-family: var(--sans); font-size: 0.66rem; font-weight: 600; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--sage); width: max-content;
  border: 1px solid color-mix(in oklch, var(--sage) 45%, transparent);
  border-radius: 1rem; padding: 0.18rem 0.6rem;
}

/* Video */
.video iframe { width: 100%; aspect-ratio: 16/9; border: 0; border-radius: 0.6rem; }

/* Benediction */
.card--benediction .body { text-align: center; justify-items: center; gap: 1.25rem; }
.card--benediction .rule { width: 2.5rem; height: 1px; background: var(--ochre); opacity: 0.7; }
.card--benediction .title { font-style: italic; font-weight: 500; }
.card--benediction .excerpt { color: var(--ink-faint); }

/* Footer: provenance + actions */
.foot { display: grid; gap: 0.9rem; }
.why { font-family: var(--sans); font-size: 0.74rem; color: var(--ink-faint); font-style: italic; }
.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.actions button {
  display: inline-flex; align-items: center; gap: 0.35rem; min-height: 2.5rem;
  font-size: 0.85rem; color: var(--ink-soft); background: transparent;
  border: 1px solid var(--hair); border-radius: 0.55rem; padding: 0 0.8rem;
  transition: border-color 0.18s var(--ease), color 0.18s var(--ease), background 0.18s var(--ease);
}
.actions button:hover { border-color: var(--hair-hover); color: var(--ink); }
.actions button[aria-pressed="true"] { color: var(--oxblood); border-color: color-mix(in oklch, var(--oxblood) 40%, transparent); background: color-mix(in oklch, var(--oxblood) 7%, transparent); }
.actions button.reject:hover { color: var(--oxblood); }

/* ---------- Mobile refinements ---------- */
@media (max-width: 26rem) {
  :root { --pad: 1.4rem; }
  .actions { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
  .actions button { justify-content: center; min-height: 2.6rem; padding: 0 0.5rem; }
  .quote blockquote { font-size: 1.6rem; text-indent: 0; }
  /* The oversized hanging quote mark overflows narrow screens — shrink it and
     tuck it inline so it sits within the sheet rather than off the edge. */
  .quote blockquote::before { font-size: 2.4em; left: -0.04em; top: -0.2em; }
  .insight .highlight { font-size: 1.45rem; }
  .card--summary .lead { font-size: 1.15rem; line-height: 1.5; }
}

/* ---------- Settings ---------- */
#settings {
  position: fixed; inset: 0; z-index: 30; background: var(--ground);
  padding: clamp(1.5rem, 6vw, 3rem); overflow-y: auto;
}
#settings .panel { width: min(34rem, 100%); margin: 0 auto; display: grid; gap: 0.4rem; }
#settings h2 {
  font-family: var(--sans); font-size: 0.74rem; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--ochre); margin: 1.6rem 0 0.6rem;
}
#settings .row { display: grid; gap: 0.5rem; margin-bottom: 0.6rem; }
#settings label { font-family: var(--sans); font-size: 0.85rem; color: var(--ink-soft);
  display: grid; gap: 0.4rem; }
#settings input[type="range"] { accent-color: var(--ochre); }
.btn-ghost {
  font-family: var(--sans); font-size: 0.9rem; color: var(--ink); background: transparent;
  border: 1px solid var(--hair); border-radius: 0.55rem; padding: 0.6rem 0.9rem; width: max-content;
}
.btn-ghost:hover { border-color: var(--hair-hover); }
#settings .close { justify-self: end; margin-bottom: 0.5rem; }

@media (prefers-reduced-motion: reduce) {
  .sheet { opacity: 1; transform: none; transition: none; }
  #feed { scroll-behavior: auto; }
}
