/* ---------- Fonts (self-hosted Newsreader, variable: opsz 6–72, wght 300–500) ---------- */
@font-face {
  font-family: "Newsreader";
  font-style: normal;
  font-weight: 300 500;
  font-display: swap;
  src: url("fonts/newsreader-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Newsreader";
  font-style: normal;
  font-weight: 300 500;
  font-display: swap;
  src: url("fonts/newsreader-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Newsreader";
  font-style: italic;
  font-weight: 300 400;
  font-display: swap;
  src: url("fonts/newsreader-italic-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Newsreader";
  font-style: italic;
  font-weight: 300 400;
  font-display: swap;
  src: url("fonts/newsreader-italic-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* ---------- Tokens ---------- */
:root {
  --bg: #F3F1EC;
  --ink: #1A1C1E;
  --muted: #5E6268;
  --accent: #4F6B5A;
  --backdrop: #DCD9D2;
  --hairline: #DCD9D2;
  --grabber: #C9C6BF;
  --on-accent: #F3F1EC;
  --shadow-rgb: 26, 28, 30;
  --serif: "Newsreader", Georgia, serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --bg: #131517;
    --ink: #E8E6E1;
    --muted: #9DA1A6;
    --accent: #8FB09B;
    --backdrop: #0B0C0D;
    --hairline: #2A2D30;
    --grabber: #3A3E42;
    --on-accent: #131517;
    --shadow-rgb: 0, 0, 0;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #131517;
  --ink: #E8E6E1;
  --muted: #9DA1A6;
  --accent: #8FB09B;
  --backdrop: #0B0C0D;
  --hairline: #2A2D30;
  --grabber: #3A3E42;
  --on-accent: #131517;
  --shadow-rgb: 0, 0, 0;
  color-scheme: dark;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 350ms ease, color 350ms ease;
}
button { font: inherit; color: inherit; }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

/* ---------- Quote screen ---------- */
.app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding:
    max(54px, calc(env(safe-area-inset-top) + 10px))
    18px
    max(36px, calc(env(safe-area-inset-bottom) + 12px))
    40px;
}

.topbar {
  flex: none;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
  z-index: 2;
}
.date {
  margin: 0;
  font-size: 14px;
  font-style: italic;
  letter-spacing: 0.06em;
  color: var(--muted);
  white-space: nowrap;
}
.actions { display: flex; align-items: center; gap: 2px; }
.theme-label {
  font-size: 14px;
  font-style: italic;
  color: var(--muted);
  margin-right: 6px;
  opacity: 0;
  transition: opacity 400ms ease;
  pointer-events: none;
}
.theme-label.show { opacity: 1; }

.icon-btn {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  padding: 0; border: 0; background: none;
  color: var(--muted);
  cursor: pointer;
  border-radius: 22px;
}
.icon-btn svg, .share-row svg {
  width: 20px; height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-btn:active { opacity: .55; }
button svg { pointer-events: none; }

.stage {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  cursor: grab;
}
.stage::before { content: ""; flex: 1 1 auto; min-height: 16px; }

.quote {
  margin: 0;
  /* 72px below the source line + 44px bottom spacer */
  padding: 0 14px calc(72px + 44px) 0;
  display: flex;
  flex-direction: column;
  gap: 26px;
  will-change: transform, opacity;
}

.mark {
  display: block;
  font-size: 64px;
  line-height: 0.5;
  font-weight: 300;
  color: var(--accent);
  height: 0.5em;
  transition: color 350ms ease;
}
.quote-text {
  margin: 0;
  font-size: 34px;
  line-height: 1.22;
  font-weight: 300;
  letter-spacing: -0.01em;
  hyphens: manual;
  overflow-wrap: break-word;
}
.quote-text.s1 { font-size: 30px; }
.quote-text.s2 { font-size: 26px; }
.quote-text.s3 { font-size: 23px; }
.quote-text.s4 { font-size: 20px; }

.attribution { display: flex; flex-direction: column; gap: 2px; }
.author { font-size: 17px; font-weight: 400; }
.source { font-size: 15px; font-style: italic; color: var(--muted); }
.source:empty { display: none; }

.toast {
  position: fixed;
  left: 40px;
  bottom: max(48px, calc(env(safe-area-inset-bottom) + 24px));
  margin: 0;
  font-size: 16px;
  font-style: italic;
  color: var(--muted);
  opacity: 0;
  transition: opacity 400ms ease;
  pointer-events: none;
}
.toast.show { opacity: 1; }

/* ---------- Sheets ---------- */
.backdrop {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: var(--backdrop);
  opacity: 0;
  transition: opacity 300ms ease-out;
}
.backdrop.open { opacity: .92; }
#shareBackdrop.open { opacity: 1; }
.backdrop[hidden], .sheet[hidden] { display: none; }

.sheet {
  position: fixed;
  left: 0; right: 0;
  bottom: var(--kb, 0px);
  z-index: 11;
  max-height: calc(var(--vvh, 100dvh) - max(20px, env(safe-area-inset-top)));
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--ink);
  border-radius: 22px 22px 0 0;
  padding: 12px 24px calc(40px + env(safe-area-inset-bottom)) 40px;
  box-shadow: 0 -8px 30px rgba(var(--shadow-rgb), .08);
  transform: translateY(100%);
  transition: transform 300ms ease-out;
}
.sheet.open { transform: translateY(0); }
.sheet.dragging { transition: none; }
.sheet.kb { padding-bottom: 16px; }

.sheet-grip { display: flex; justify-content: center; padding-bottom: 10px; touch-action: none; }
.grabber { width: 36px; height: 4px; border-radius: 2px; background: var(--grabber); }

.sheet-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
  touch-action: none;
}
.text-btn {
  border: 0; background: none; padding: 0 4px;
  min-height: 44px;
  font-size: 17px;
  color: var(--muted);
  cursor: pointer;
}
.pill {
  min-width: 76px; min-height: 44px;
  padding: 0 20px;
  border: 0; border-radius: 22px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 17px; font-weight: 500;
  cursor: pointer;
  transition: opacity 200ms ease;
}
.pill:disabled { opacity: .4; cursor: default; }

.sheet-body {
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  padding-right: 16px;
  margin-right: -16px;
}
.sheet-body .mark { margin: 14px 0 22px; }
.sheet-body textarea,
.sheet-body input {
  width: 100%;
  border: 0;
  background: none;
  color: var(--ink);
  font-family: var(--serif);
  padding: 0;
  margin: 0;
  border-radius: 0;
  -webkit-appearance: none;
  appearance: none;
}
.sheet-body textarea:focus-visible,
.sheet-body input:focus-visible { outline: none; }
.sheet-body textarea {
  font-size: 28px;
  line-height: 1.25;
  font-weight: 300;
  letter-spacing: -0.01em;
  resize: none;
  overflow: hidden;
  min-height: 70px;
  margin-bottom: 22px;
}
.sheet-body input { font-size: 19px; line-height: 1.3; padding: 4px 0 6px; }
.sheet-body input.italic { font-style: italic; }
::placeholder { color: var(--muted); opacity: .7; }

.field {
  border-top: 1px solid var(--hairline);
  padding-top: 14px;
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.field label { font-size: 14px; font-style: italic; color: var(--muted); }

/* Share */
.preview-wrap {
  position: absolute;
  left: 0; right: 0;
  top: max(24px, env(safe-area-inset-top));
  bottom: calc(190px + env(safe-area-inset-bottom));
  display: grid;
  place-items: center;
  padding: 16px;
}
.preview {
  width: min(286px, 100%);
  max-height: 100%;
  aspect-ratio: 4 / 5;
  object-fit: contain;
  background: #F3F1EC;
  box-shadow: 0 18px 40px rgba(26, 28, 30, .14);
  transform: scale(.96);
  transition: transform 300ms ease-out;
}
#shareBackdrop.open .preview { transform: scale(1); }
.share-sheet { padding-left: 24px; }
.caption {
  margin: 4px 0 16px;
  text-align: center;
  font-size: 15px;
  font-style: italic;
  color: var(--muted);
}
.share-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.share-row button {
  height: 50px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  font-size: 17px;
  cursor: pointer;
}
.btn-outline { border: 1px solid var(--grabber); background: none; color: var(--ink); }
.btn-ink { border: 0; background: var(--ink); color: var(--bg); }

@media (prefers-reduced-motion: reduce) {
  .sheet { transition: transform 1ms, opacity 200ms ease; }
}
