/* Light is the base palette. */
:root {
  --ground: #F5F9FA;
  --surface: #FFFFFF;
  --ink: #17262E;
  --muted: #5C7079;
  --accent: #1D7387;
  --accent-soft: #E1EFF2;
  --line: #D9E3E7;
  /* Text sitting on an --accent fill. White clears 4.5:1 on the light accent
     but only reaches 2.4:1 on the lighter dark-theme accent, so it flips. */
  --on-accent: #FFFFFF;
}

/* Dark follows the system, unless the reader has pinned light. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ground: #0D1519;
    --surface: #142027;
    --ink: #DAE5EA;
    --muted: #8CA3AD;
    --accent: #56B4C8;
    --accent-soft: #17323A;
    --line: #223440;
    --on-accent: #0D1519;
  }
}

/* Dark also applies when pinned, whatever the system says. */
:root[data-theme="dark"] {
  --ground: #0D1519;
  --surface: #142027;
  --ink: #DAE5EA;
  --muted: #8CA3AD;
  --accent: #56B4C8;
  --accent-soft: #17323A;
  --line: #223440;
  --on-accent: #0D1519;
}

* { box-sizing: border-box; }

/* A stylesheet display value outranks the browser's rule for [hidden], so any
   element toggled through the attribute needs this or it never goes away. */
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.6;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.9rem 1.25rem 0.5rem;
  max-width: 560px;
  width: 100%;
  margin: 0 auto;
}
.brand {
  font-family: Georgia, "Times New Roman", serif;
  letter-spacing: 0.3em;
  font-size: 0.95rem;
  color: var(--accent);
  margin-right: auto;
}
.day {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.75rem;
  color: var(--muted);
}
.theme {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  color: var(--muted);
  background: none;
  border: none;
  flex: none;
}
.theme:hover { color: var(--accent); }
.theme svg { display: none; width: 1.05rem; height: 1.05rem; }
.theme.is-dark .sun { display: block; }
.theme.is-light .moon { display: block; }

/* Every flex item in the chain down to the reader needs min-height: 0. The
   default of auto refuses to shrink below the content, so a long article
   would push the reader taller than the viewport, leaving nothing to scroll
   through: scrollHeight and clientHeight come out equal and the read ends on
   its first frame. */
main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  max-width: 560px;
  width: 100%;
  margin: 0 auto;
  padding: 0 1.25rem 1.25rem;
}

.screen { display: none; }
.screen.active {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

/* ---- today card / done ---- */
#screen-today, #screen-done, #screen-empty { justify-content: center; gap: 0.75rem; text-align: center; }
h1 {
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 500;
  font-size: 1.8rem;
  margin: 0;
  text-wrap: balance;
}
.meta { color: var(--muted); margin: 0; font-variant-numeric: tabular-nums; }
.meta.big { font-size: 1.15rem; }
.hint { color: var(--muted); font-size: 0.85rem; margin: 0; }
.attribution { color: var(--muted); font-size: 0.78rem; margin: 0; }
.sample-note {
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.78rem;
  border-radius: 8px;
  padding: 0.4rem 0.7rem;
  margin: 0 auto;
}
.preview {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin: 0.75rem 0;
  text-align: left;
}
.preview-word {
  display: flex;
  gap: 0.75rem;
  align-items: baseline;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.5rem 0.9rem;
  font-size: 0.92rem;
}
.preview-word b { font-family: Georgia, serif; font-weight: 600; white-space: nowrap; }
.preview-word span { color: var(--muted); }

button {
  font: inherit;
  cursor: pointer;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
}
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.primary {
  align-self: center;
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  padding: 0.8rem 2rem;
  font-size: 1.05rem;
}
.primary:hover { opacity: 0.92; }

/* ---- action stack on the results screen ---- */
.actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.75rem;
}
.share-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.wide { padding: 0.8rem 1.5rem; }
.wide:hover { border-color: var(--accent); color: var(--accent); }
.text-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.85rem;
  padding: 0.5rem 1rem;
}
.text-btn:hover { color: var(--accent); }

/* ---- reader ---- */
#screen-reader { padding-top: 0.25rem; }
.reader {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  cursor: pointer;
}
.track {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.2rem;
  line-height: 1.8;
  padding-left: 1.5rem;
  padding-right: 1.5rem;
  will-change: transform;
}
.track h2 {
  font-size: 1.35rem;
  font-weight: 500;
  margin: 0 0 1rem;
}
.track p { margin: 0 0 1.1em; }
.band {
  position: absolute;
  left: 0; right: 0;
  top: 37%;
  height: 26%;
  background: linear-gradient(180deg, transparent, var(--accent-soft) 30%, var(--accent-soft) 70%, transparent);
  opacity: 0.5;
  pointer-events: none;
}
.fade { position: absolute; left: 0; right: 0; height: 28%; pointer-events: none; }
.fade.top { top: 0; background: linear-gradient(180deg, var(--surface) 10%, transparent); }
.fade.bottom { bottom: 0; background: linear-gradient(0deg, var(--surface) 10%, transparent); }
.countdown {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: Georgia, serif;
  font-size: 4rem;
  color: var(--accent);
  background: var(--surface);
}
.progress { height: 3px; background: var(--line); border-radius: 2px; margin: 0.6rem 0 0; }
.progress i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 2px; }

.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.9rem;
  padding-top: 0.7rem;
}
.controls button { width: 2.5rem; height: 2.5rem; font-size: 1.05rem; }
.controls button:hover { border-color: var(--accent); }
.controls .play {
  width: 3.2rem;
  height: 3.2rem;
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  font-size: 1.15rem;
}
.wpm {
  font-family: ui-monospace, Consolas, monospace;
  font-variant-numeric: tabular-nums;
  font-size: 0.8rem;
  color: var(--muted);
  min-width: 4.5rem;
  text-align: center;
}
.wpm b { display: block; font-size: 1.1rem; color: var(--ink); }
