/* Ancora Imparo — a page from an old master's sketchbook */

:root {
  --graphite: #2B2723;
  --graphite-deep: #211E1B;
  --chalk: #EDE6DA;
  --sanguine: #A8462E;        /* ink: fills, rules — never small text */
  --sanguine-lift: #C4623F;   /* the mark glyph: 3.65:1, passes non-text AA */
  --faded: #9A9284;           /* metadata: 4.81:1, passes AA normal text */
  --slate: #5B6B73;           /* thread-line indicator */

  --serif: "Source Serif 4", "Source Serif Pro", Charter, Georgia, serif;
  --display: "Cormorant Garamond", Garamond, "Times New Roman", serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --gutter: clamp(1.5rem, 7vw, 3.25rem);
  --fade: 520ms cubic-bezier(0.22, 0.61, 0.36, 1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--graphite);
  color: var(--chalk);
  font-family: var(--serif);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  overscroll-behavior: none;   /* no bounce — wrong texture */
  overflow: hidden;
}

:focus-visible {
  outline: 2px solid var(--sanguine-lift);
  outline-offset: 3px;
  border-radius: 1px;
}

.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  clip-path: inset(50%); overflow: hidden; white-space: nowrap;
}

/* ── Running header ─────────────────────────────────────────── */

.running-head {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: max(0.9rem, env(safe-area-inset-top)) var(--gutter) 0.9rem;
  background: linear-gradient(to bottom, var(--graphite) 55%, transparent);
  pointer-events: none;
}
.running-head > * { pointer-events: auto; }

.tag {
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--faded);
  display: inline-flex;
  align-items: center;
  gap: 0.6em;
  min-width: 0;
  transition: opacity var(--fade);
}
.tag .sep {
  display: inline-block;
  width: 1.6em;
  height: 1px;
  background: var(--slate);
  flex: none;
}
.tag .thread { color: var(--faded); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Marginalia button — the index of what's been kept */
.margin-btn {
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  background: none;
  border: 0;
  color: var(--faded);
  display: inline-flex;
  align-items: baseline;
  gap: 0.4em;
  padding: 0.35rem 0.1rem 0.35rem 0.6rem;
  cursor: pointer;
  flex: none;
}
.margin-btn .glyph { font-size: 1rem; color: var(--sanguine-lift); }
.margin-btn:disabled { opacity: 0.45; cursor: default; }
.margin-btn:disabled .glyph { color: var(--faded); }

/* ── The feed ───────────────────────────────────────────────── */

.feed {
  height: 100dvh;
  overflow-y: scroll;
  scroll-snap-type: y mandatory;
  scrollbar-width: none;
  overscroll-behavior-y: contain;
}
.feed::-webkit-scrollbar { display: none; }

.card {
  height: 100dvh;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  position: relative;
  display: grid;
  align-content: center;
  padding: 5.5rem var(--gutter) 5rem;
  max-width: 42rem;
  margin: 0 auto;
}

/* soft crossfade in, nothing springy */
.card .lesson {
  opacity: 0;
  transform: translateY(0.6rem);
  transition: opacity var(--fade), transform var(--fade);
}
.card.is-active .lesson { opacity: 1; transform: none; }

.card .title {
  font-family: var(--display);
  font-style: italic;
  font-weight: 400;
  font-size: clamp(2.05rem, 8.5vw, 3rem);
  line-height: 1.08;
  letter-spacing: 0.005em;
  margin: 0 0 1.5rem;
  text-wrap: balance;
}

.card .body {
  font-size: clamp(1.02rem, 4.3vw, 1.14rem);
  line-height: 1.72;
  margin: 0;
  color: var(--chalk);
  hanging-punctuation: first;
}

.card .source {
  font-family: var(--mono);
  font-size: 0.68rem;
  line-height: 1.6;
  letter-spacing: 0.02em;
  color: var(--faded);
  margin: 1.9rem 0 0;
  padding-top: 1rem;
  border-top: 1px solid rgba(154, 146, 132, 0.22);
  max-width: 34rem;
}

/* ── The kept mark ──────────────────────────────────────────── */

.keep {
  position: absolute;
  right: calc(var(--gutter) - 0.5rem);
  bottom: max(1.6rem, env(safe-area-inset-bottom));
  width: 3rem;
  height: 3rem;
  display: grid;
  place-items: center;
  background: none;
  border: 0;
  cursor: pointer;
  color: var(--faded);
  font-size: 1.35rem;
  line-height: 1;
  opacity: 0.5;
  transition: opacity var(--fade), color var(--fade), transform var(--fade);
}
.card.is-active .keep { opacity: 1; }
.keep[aria-pressed="true"] {
  color: var(--sanguine-lift);
  transform: rotate(-8deg) scale(1.06);
}

/* ── Marginalia sheet ───────────────────────────────────────── */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: var(--graphite-deep);
  display: flex;
  flex-direction: column;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--fade), visibility var(--fade);
}
.sheet.is-open { opacity: 1; visibility: visible; }

.sheet-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding: max(1.4rem, env(safe-area-inset-top)) var(--gutter) 1.1rem;
  border-bottom: 1px solid rgba(154, 146, 132, 0.2);
}
.sheet-head h2 {
  font-family: var(--display);
  font-style: italic;
  font-weight: 400;
  font-size: 1.9rem;
  margin: 0;
}
.sheet-close {
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  background: none;
  border: 0;
  color: var(--faded);
  padding: 0.5rem 0 0.5rem 0.8rem;
  cursor: pointer;
}

.sheet-body {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0.5rem var(--gutter) max(3rem, env(safe-area-inset-bottom));
  -webkit-overflow-scrolling: touch;
}

.empty {
  color: var(--faded);
  font-size: 1rem;
  line-height: 1.7;
  margin: 3.5rem 0 0;
  max-width: 26rem;
}
.empty .glyph { color: var(--sanguine-lift); font-style: normal; }

.entries { list-style: none; margin: 0; padding: 0; }

.entry { border-bottom: 1px solid rgba(154, 146, 132, 0.16); }

.entry-head {
  width: 100%;
  display: flex;
  align-items: baseline;
  gap: 1rem;
  background: none;
  border: 0;
  text-align: left;
  color: inherit;
  padding: 1.3rem 0;
  cursor: pointer;
  font: inherit;
}
.entry-num {
  font-family: var(--mono);
  font-size: 0.68rem;
  color: var(--sanguine-lift);
  flex: none;
  width: 2ch;
  font-variant-numeric: tabular-nums;
}
.entry-text { flex: 1; min-width: 0; }
.entry-title {
  font-family: var(--display);
  font-style: italic;
  font-size: 1.4rem;
  line-height: 1.2;
  display: block;
}
.entry-tag {
  font-family: var(--mono);
  font-size: 0.6rem;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--faded);
  display: block;
  margin-top: 0.5rem;
}

.entry-panel { display: none; padding: 0 0 1.6rem calc(2ch + 1rem); }
.entry.is-open .entry-panel { display: block; }
.entry-panel .body { font-size: 1rem; line-height: 1.7; margin: 0; }
.entry-panel .source {
  font-family: var(--mono);
  font-size: 0.66rem;
  line-height: 1.6;
  color: var(--faded);
  margin: 1.2rem 0 0;
}
.entry-remove {
  font-family: var(--mono);
  font-size: 0.63rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  background: none;
  border: 0;
  border-bottom: 1px solid rgba(196, 98, 63, 0.5);
  color: var(--sanguine-lift);
  padding: 0.25rem 0;
  margin-top: 1.4rem;
  cursor: pointer;
}

/* ── Loading / failure ──────────────────────────────────────── */

.notice {
  position: fixed;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  padding: var(--gutter);
  color: var(--faded);
  font-family: var(--mono);
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.notice[hidden] { display: none; }
.notice .msg { text-transform: none; letter-spacing: 0; font-family: var(--serif); font-size: 1rem; margin-top: 0.9rem; color: var(--chalk); }

/* ── Preferences ────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 1ms !important; animation-duration: 1ms !important; }
  .card .lesson { opacity: 1; transform: none; }
  .keep[aria-pressed="true"] { transform: none; }
  .feed { scroll-behavior: auto; }
}

@media (min-width: 48rem) {
  .card { padding-top: 6.5rem; }
  .card .body { font-size: 1.16rem; }
}
