:root,
:root[data-theme="light"] {
  --bg: #f7f3ec;
  --paper: #fdfaf5;
  --ink: #2b2925;
  --muted: #6f695f;
  --line: #e6dfd3;
  --hover: #ede6da;
  --accent: #6f8f72;
  --accent-ink: #4c6b50;
  --accent-soft: #dbe6d7;
  --on-accent: #fdfaf5;
  --warn: #a5582f;
  --shadow: 0 1px 2px rgba(60, 45, 20, 0.04), 0 8px 24px rgba(60, 45, 20, 0.06);
  --heat-0: #ece6db;
  --heat-1: #d6e2d2;
  --heat-2: #aec7aa;
  --heat-3: #86a983;
  --heat-4: #5e8a5d;
  --cell-edge: rgba(43, 41, 37, 0.13);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Noto Serif", "Noto Serif Devanagari", "Noto Serif Bengali", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  --sky: #f2dcc7;
  --glow: #f1c8a6;
  --mark: rgba(238, 196, 92, 0.38);
  --mark-on: rgba(238, 196, 92, 0.65);
  --sticky: #fbf0c9;
  --sticky-ink: #3a3322;
  --sticky-line: #ecdba1;
  color-scheme: light;
}

/* Dawn skies, one per season. Light mode is early morning just after
   sunrise; dark mode is the blue hour just before it. */
:root[data-season="winter"]  { --sky: #dfe5ee; --glow: #f6dccb; }
:root[data-season="spring"]  { --sky: #f1dfe4; --glow: #f8e8c8; }
:root[data-season="summer"]  { --sky: #f7e1c3; --glow: #fbd2ae; }
:root[data-season="monsoon"] { --sky: #d9e4df; --glow: #ece7d8; }
:root[data-season="autumn"]  { --sky: #f2dcc7; --glow: #f1c8a6; }
:root[data-theme="dark"][data-season="winter"]  { --sky: #1e2331; --glow: #312b33; }
:root[data-theme="dark"][data-season="spring"]  { --sky: #2a2129; --glow: #36292b; }
:root[data-theme="dark"][data-season="summer"]  { --sky: #2c2420; --glow: #3c2b22; }
:root[data-theme="dark"][data-season="monsoon"] { --sky: #1c2625; --glow: #272d29; }
:root[data-theme="dark"][data-season="autumn"]  { --sky: #2c221c; --glow: #3a2920; }

/* Warm, low-glare dark: brown-black paper, never pure black or pure white. */
:root[data-theme="dark"] {
  --bg: #1b1a18;
  --paper: #23211e;
  --ink: #e8e2d6;
  --muted: #a39c90;
  --line: #36332e;
  --hover: #2d2a26;
  --accent: #9cbc98;
  --accent-ink: #a9c8a5;
  --accent-soft: #33412f;
  --on-accent: #1b1a18;
  --warn: #e0a07a;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.2), 0 10px 30px rgba(0, 0, 0, 0.3);
  --heat-0: #2a2824;
  --heat-1: #34432f;
  --heat-2: #4a6446;
  --heat-3: #67875f;
  --heat-4: #8fb486;
  --cell-edge: rgba(232, 226, 214, 0.1);
  --mark: rgba(214, 176, 86, 0.24);
  --mark-on: rgba(214, 176, 86, 0.45);
  --sticky: #3a3424;
  --sticky-ink: #ece3cc;
  --sticky-line: #554b31;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}
html { background: var(--bg); transition: background-color 0.3s ease; }
body {
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* The sky sits on its own fixed layer so it stays put while the page scrolls
   (background-attachment: fixed is ignored on iOS). */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(90% 55% at 70% -5%, var(--glow) 0%, transparent 70%),
    linear-gradient(to bottom, var(--sky) 0%, var(--bg) 65%);
  transition: opacity 0.3s ease;
}

::selection { background: var(--accent-soft); color: var(--ink); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}

/* Line icons from the sprite in index.html */
.i {
  width: 1.15rem;
  height: 1.15rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
  vertical-align: -0.2em;
}

#app { min-height: 100%; display: flex; flex-direction: column; }

a { color: var(--accent-ink); text-underline-offset: 0.2em; text-decoration-thickness: 1px; }
h1, h2, h3 { font-family: var(--serif); font-weight: 500; }
/* Read out by screen readers and search engines, not shown. */
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
h3 { margin: 0; font-size: 1.15rem; display: flex; align-items: center; gap: 0.45rem; }
h3 .i { color: var(--accent); }

.loading { margin: auto; color: var(--muted); font-family: var(--serif); }

.center { margin: auto; padding: 2rem 1.25rem; }
.narrow { width: 100%; max-width: 30rem; }
.content { width: 100%; max-width: 46rem; margin: 0 auto; padding: 1rem 1.25rem 3rem; }
.content.wide { width: 90%; max-width: none; padding-left: 0; padding-right: 0; }
.stack > * + * { margin-top: 0.75rem; }
.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 1.25rem;
  box-shadow: var(--shadow);
}
.card .hint { margin-bottom: 0; }
.row { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }

.brand { font-size: 2.6rem; margin: 0 0 0.5rem; letter-spacing: 0.01em; }
.lede { font-family: var(--serif); font-size: 1.2rem; line-height: 1.55; color: var(--muted); margin: 0 0 1.75rem; }
.hint { color: var(--muted); font-size: 0.92rem; line-height: 1.5; }
.error { color: var(--warn); font-size: 0.92rem; }

/* Welcome / sign in */
.welcome { text-align: center; }
.welcome form { text-align: left; }
.welcome-head { display: flex; align-items: center; justify-content: center; gap: 0.6rem; margin-bottom: 0.75rem; }
.welcome .brand { font-size: 2.2rem; margin: 0; }
.mark { width: 2.4rem; height: 2.4rem; }
.mark-track { stroke: var(--line); }
.mark-fill { stroke: var(--accent); }
.welcome .lede { color: var(--ink); margin: 0 0 0.6rem; }
.why { color: var(--muted); font-size: 0.95rem; line-height: 1.55; margin: 0 auto 1.25rem; max-width: 25rem; }
.label-row { display: flex; justify-content: space-between; align-items: baseline; }
.label-row a { font-size: 0.88rem; }
.label-row a[hidden] { display: none; }
.switch { text-align: center; margin-bottom: 0; }
/* What a new password needs, ticked off as it's typed. */
.password-rules { list-style: none; margin: 0.4rem 0 0; padding: 0; display: grid; gap: 0.15rem; color: var(--muted); font-size: 0.84rem; line-height: 1.4; }
.password-rules[hidden] { display: none; }
.password-rules li { display: flex; gap: 0.45rem; align-items: baseline; }
.password-rules li::before { content: "○"; flex: none; width: 1em; text-align: center; }
.password-rules li.ok { color: var(--ink); }
.password-rules li.ok::before { content: "✓"; color: var(--accent); font-weight: 600; }
.promise { display: flex; gap: 0.55rem; justify-content: center; text-align: left; color: var(--muted); font-size: 0.86rem; line-height: 1.45; margin: 1.1rem auto 0; max-width: 24rem; }
.promise .i { color: var(--accent); margin-top: 0.05rem; }
.welcome-links { display: flex; justify-content: center; flex-wrap: wrap; gap: 0.35rem 1.5rem; margin-top: 0.85rem; font-size: 0.9rem; }

/* On a phone the whole welcome fits one screen: tighter gaps, no scrolling. */
@media (max-width: 30rem) {
  .welcome.center { padding: 1.25rem 1.25rem; }
  .welcome .stack > * + * { margin-top: 0.6rem; }
  .welcome .card { padding: 1.1rem; }
  .welcome .lede { font-size: 1.15rem; }
}

/* Landing page for visitors: what Unedited is, then a way in. */
.landing { width: 100%; text-align: center; }
.hero { max-width: 34rem; padding-top: 3.5rem; }
.landing .brand { font-family: var(--serif); font-size: 2.2rem; margin: 0; }
.hero-title { font-size: 2rem; line-height: 1.25; margin: 0.5rem 0 0.9rem; }
.hero .why { font-size: 1.05rem; max-width: 28rem; }
.cta { display: grid; justify-items: center; gap: 0.6rem; margin-top: 1.4rem; }
.cta .hint { margin: 0; }
.button.primary {
  background: var(--accent-ink);
  color: var(--on-accent);
  border-color: var(--accent-ink);
  padding: 0.85rem 1.6rem;
  font-weight: 500;
}
.button.primary:hover { filter: brightness(1.06); }
.usps {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  width: 100%;
  max-width: 46rem;
  margin: 1.5rem auto 0;
  padding: 0 1.25rem;
  text-align: left;
}
@media (min-width: 40rem) { .usps { grid-template-columns: 1fr 1fr; } }
.usp h2 { display: flex; align-items: center; gap: 0.5rem; font-size: 1.2rem; margin: 0 0 0.4rem; }
.usp h2 .i { color: var(--accent); flex: none; }
.usp p { margin: 0; color: var(--muted); line-height: 1.55; font-size: 0.95rem; }
.how { text-align: left; padding-top: 2.5rem; }
.how h2 { font-size: 1.5rem; text-align: center; margin: 0 0 1rem; }
.how ol { margin: 0 0 1.25rem; padding-left: 1.4rem; line-height: 1.6; }
.how li + li { margin-top: 0.6rem; }
.how .hint { text-align: center; }
.site-footer { border-top: 1px solid var(--line); margin-top: 2rem; padding: 1.5rem 1.25rem 2.5rem; color: var(--muted); font-size: 0.9rem; line-height: 1.55; }
.site-footer p { margin: 0 auto; max-width: 34rem; }
.site-footer nav { display: flex; justify-content: center; flex-wrap: wrap; gap: 0.35rem 1.25rem; margin: 0.75rem 0; }
.site-footer .made { font-size: 0.82rem; }
@media (max-width: 30rem) {
  .hero { padding-top: 2.25rem; }
  .hero-title { font-size: 1.65rem; }
}

label { display: block; font-size: 0.9rem; color: var(--muted); }
input, select {
  font: inherit;
  font-size: 1rem;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  color: var(--ink);
  width: 100%;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
select { max-width: 100%; }
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input::placeholder { color: var(--muted); opacity: 0.6; }
.row input { width: auto; flex: 1; min-width: 8rem; }

button, .button {
  font: inherit;
  font-size: 0.95rem;
  padding: 0.65rem 1.1rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
button.primary {
  background: var(--accent-ink);
  color: var(--on-accent);
  border-color: var(--accent-ink);
  width: 100%;
  padding: 0.8rem 1.1rem;
  font-weight: 500;
}
button.primary:hover:not(:disabled) { filter: brightness(1.06); }
button:disabled { opacity: 0.5; cursor: default; }
.ghost:hover { border-color: var(--muted); background: var(--hover); }
button.warn { color: var(--warn); border-color: currentColor; }
button.warn:hover { background: var(--hover); }

/* Theme and width pickers */
.segmented {
  display: flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg);
}
.segmented label { flex: 1; color: var(--ink); font-size: 0.92rem; }
.segmented input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.segmented span {
  display: block;
  text-align: center;
  padding: 0.5rem 0.6rem;
  border-radius: 999px;
  cursor: pointer;
  transition: background-color 0.2s ease;
}
.segmented input:checked + span { background: var(--paper); box-shadow: var(--shadow); font-weight: 500; }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Top bar */
.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: max(0.6rem, env(safe-area-inset-top)) 1rem 0.6rem;
  position: sticky;
  top: 0;
  z-index: 2;
}
/* Frosted and feathered at the bottom edge, so the sky shows through and
   words scroll softly under the bar instead of hitting a line. */
.bar::before {
  content: "";
  position: absolute;
  inset: 0 0 -0.75rem;
  z-index: -1;
  background: color-mix(in srgb, var(--sky) 40%, transparent);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  -webkit-mask-image: linear-gradient(#000 65%, transparent);
  mask-image: linear-gradient(#000 65%, transparent);
}
.bar-left, .bar-right { flex: 1; display: flex; gap: 0.25rem; align-items: center; }
.bar-right { justify-content: flex-end; }
.bar-title { margin: 0; font-family: var(--serif); font-weight: 500; font-size: 1.15rem; position: absolute; left: 50%; transform: translateX(-50%); }
.today-label, .season { font-family: var(--serif); color: var(--muted); white-space: nowrap; }
.season { opacity: 0.8; }
@media (max-width: 30rem) { .season { display: none; } }
.private { display: inline-flex; color: var(--accent); margin-right: 0.35rem; cursor: help; }
.private .i { width: 0.95rem; height: 0.95rem; }
.sync { font-size: 0.75rem; color: var(--muted); margin-left: 0.5rem; }
.icon {
  border: none;
  padding: 0.55rem;
  line-height: 0;
  color: var(--muted);
  text-decoration: none;
  border-radius: 12px;
  display: inline-flex;
  transition: background-color 0.2s ease, color 0.2s ease;
}
.icon:hover { color: var(--ink); background: var(--hover); }
.icon[aria-pressed="true"] { color: var(--accent-ink); background: var(--accent-soft); }

/* Progress ring: fills gently, never turns red */
.ring-wrap { position: relative; width: 44px; height: 44px; }
.ring { width: 44px; height: 44px; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 3; }
.ring-track { stroke: var(--line); }
.ring-fill {
  stroke: var(--accent);
  stroke-linecap: round;
  stroke-dasharray: 119.38;
  stroke-dashoffset: 119.38;
  transition: stroke-dashoffset 0.6s ease;
}
/* Two small beads mark the end of the first and second pages. */
.ring .ring-mark { fill: var(--muted); stroke: none; opacity: 0.6; transition: fill 0.6s ease, opacity 0.6s ease; }
.ring .ring-mark.met { fill: var(--paper); opacity: 0.95; }
/* A quiet line under the ring when a page is done. It fades on its own. */
.page-note {
  position: absolute;
  top: calc(100% + 0.3rem);
  left: 50%;
  transform: translate(-50%, -0.2rem);
  margin: 0;
  padding: 0.2rem 0.75rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--paper) 85%, transparent);
  box-shadow: 0 0 0 1px var(--line);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  white-space: nowrap;
  font-family: var(--serif);
  font-style: italic;
  font-size: 0.85rem;
  color: var(--accent-ink);
  opacity: 0;
  pointer-events: none;
  transition: opacity 1.2s ease, transform 1.2s ease;
}
.page-note.show { opacity: 1; transform: translate(-50%, 0); }
.count {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 0.7rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* The page */
.paper { flex: 1; display: flex; padding: 0 1rem 1rem; }
#page {
  flex: 1;
  width: 100%;
  max-width: var(--page-width, 100%);
  margin: 0 auto;
  min-height: calc(100vh - 5rem);
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1.22rem;
  line-height: 1.8;
  padding: 1.5rem 0 40vh;
  caret-color: var(--accent);
  /* The page still scrolls, but without a scrollbar beside the words. */
  scrollbar-width: none;
}
#page::-webkit-scrollbar { display: none; }
/* Writing width from Settings. Phones always use the whole width. */
@media (min-width: 40rem) {
  [data-page-width="75"] { --page-width: 75%; }
  [data-page-width="50"] { --page-width: 50%; }
}
#page::placeholder { color: var(--muted); opacity: 0.65; font-style: italic; }

/* Don't look back: earlier lines fade away */
/* Ruled paper from Settings: one faint line under each line of words. The
   lines scroll with the words and sit just below the baseline. */
#page { --lh: calc(1.22rem * 1.8); --rule-y: 1.2rem; }
.reader .text { --lh: calc(1.1rem * 1.7); --rule-y: 0.25rem; }
[data-paper="ruled"] #page,
[data-paper="ruled"] .reader .text {
  background-image: linear-gradient(to bottom, transparent calc(100% - 1px), var(--line) 0);
  background-size: 100% var(--lh);
  background-position: 0 var(--rule-y);
}
[data-paper="ruled"] #page { background-attachment: local; }

.dlb #page {
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, rgba(0,0,0,0.15) 25%, #000 55%);
  mask-image: linear-gradient(to bottom, transparent 0, rgba(0,0,0,0.15) 25%, #000 55%);
}

.done {
  position: fixed;
  left: 50%;
  bottom: max(1.25rem, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(26rem, calc(100% - 2rem));
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 1.1rem 1.25rem;
  box-shadow: var(--shadow);
  text-align: center;
  animation: rise 0.5s ease both;
}
@keyframes rise { from { opacity: 0; transform: translate(-50%, 0.75rem); } }
.done-title { font-family: var(--serif); font-size: 1.2rem; margin: 0 0 0.25rem; color: var(--accent-ink); }
.done-stats { color: var(--muted); margin: 0 0 0.75rem; }

/* Primer */
.primer-card { min-height: 15rem; }
.primer-card h2 { font-size: 1.7rem; margin: 0.5rem 0 0.75rem; }
.primer-card p { font-family: var(--serif); font-size: 1.15rem; line-height: 1.65; }
.primer-card .hint { font-family: var(--sans); font-size: 0.92rem; }
.book-cover { display: inline-block; margin-top: 0.25rem; }
.book-cover img { display: block; width: 110px; height: auto; border-radius: 3px; box-shadow: 0 6px 18px rgba(0,0,0,0.18); }
.book-stores { display: flex; flex-wrap: wrap; gap: 1rem 1.25rem; margin-top: 0.75rem; }
.book-store { display: flex; flex-direction: column; align-items: flex-start; width: 8.5rem; }
.book-store .book-cover { margin: 0 0 0.4rem; }
.book-store .book-cover img { height: 170px; object-fit: cover; }
.book-store h3 { margin: 0 0 0.15rem; font-family: var(--sans); font-size: 0.75rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; opacity: 0.7; }
.primer .row { justify-content: space-between; margin-top: 1.5rem; }
.primer .row .primary { width: auto; }
.dots { display: flex; gap: 6px; list-style: none; padding: 0; margin: 0 0 1rem; }
.dots li { width: 7px; height: 7px; border-radius: 999px; background: var(--line); transition: width 0.3s ease, background-color 0.3s ease; }
.dots li.on { background: var(--accent); width: 20px; }

/* Privacy story: brighter than the rest of the app, still warm. */
.story { --s-a: #e3a13a; --s-b: #e07a5f; --s-c: #5e9a6a; --s-d: #5b8fc0; --s-e: #9a6fb5;
  --t-a: #fbe9c9; --t-b: #fadcd2; --t-c: #dcefdc; --t-d: #dbe8f5; --t-e: #ece0f3; }
:root[data-theme="dark"] .story { --s-a: #f0b85a; --s-b: #ef9a80; --s-c: #8cc493; --s-d: #8db6e0; --s-e: #c4a0dc;
  --t-a: #3d3220; --t-b: #3e2a24; --t-c: #26372a; --t-d: #232f3d; --t-e: #33283c; }
.story-art { display: block; width: 100%; max-width: 20rem; height: auto; margin: 0 auto 0.5rem; }
.story-art .tint-a { fill: var(--t-a); } .story-art .tint-b { fill: var(--t-b); } .story-art .tint-c { fill: var(--t-c); }
.story-art .tint-d { fill: var(--t-d); } .story-art .tint-e { fill: var(--t-e); }
.story-art .fill-a { fill: var(--s-a); } .story-art .fill-b { fill: var(--s-b); } .story-art .fill-c { fill: var(--s-c); }
.story-art .fill-d { fill: var(--s-d); } .story-art .fill-e { fill: var(--s-e); }
.story-art .glow-a { fill: var(--s-a); opacity: 0.25; }
.story-art .paper { fill: var(--paper); }
.story-art .edge { stroke: var(--line); stroke-width: 1.5; }
.story-art .rule { stroke: var(--line); stroke-width: 3; stroke-linecap: round; fill: none; }
.story-art .rule-fill { fill: var(--line); }
.story-art .spine { stroke: var(--line); stroke-width: 2; }
.story-art .arrow, .story-art .shackle { fill: none; stroke: var(--muted); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.story-art .shackle { stroke: var(--s-b); stroke-width: 4; }
.story-art .tick { fill: none; stroke: var(--paper); stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
.story-art .spark-a { fill: var(--s-a); }
.story-art .scramble { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 11px; font-weight: 600; fill: var(--paper); }
.story-art .scramble.ink { fill: var(--muted); }
.story-art .ink-fill { fill: var(--ink); }
.story-art .line-ink { fill: none; stroke: var(--ink); stroke-width: 2.4; stroke-linecap: round; }
.story-art .paw { fill: var(--s-c); opacity: 0.75; }
/* The burglar keeps a dark mask and frown in both themes. */
.story-art .mask { fill: #2b2925; } .story-art .mask-eye { fill: #fdfaf5; }
.story-art .frown { fill: none; stroke: #2b2925; stroke-width: 2.4; stroke-linecap: round; }
.story-art .huh { font-family: var(--serif); font-size: 22px; font-weight: 700; fill: var(--s-b); }
/* Gentle motion; none for people who ask for less. */
.story-art { animation: pop-in 0.45s cubic-bezier(.2,1.4,.4,1) both; }
.story-art g, .story-art path, .story-art text { transform-box: fill-box; transform-origin: center; }
.story-art .beat { animation: beat 1.6s ease-in-out infinite; }
.story-art .bob { animation: bob 2.8s ease-in-out infinite; }
.story-art .wiggle { animation: wiggle 2.4s ease-in-out infinite; }
.story-art .sway { transform-origin: left center; animation: wiggle 3s ease-in-out infinite; }
.story-art .twinkle { animation: twinkle 1.8s ease-in-out infinite; }
.story-art .flow { animation: flow 1.4s ease-in-out infinite; }
.story-art .flicker { animation: flicker 1.2s steps(2) infinite; }
.story-art .paw { animation: paw 2.4s ease-in-out infinite; }
.story-art .huh { animation: bob 1.4s ease-in-out infinite; }
.story-art .late { animation-delay: 0.6s; }
@keyframes pop-in { from { opacity: 0; transform: scale(0.92) translateY(6px); } }
@keyframes beat { 0%, 100% { transform: scale(1); } 15% { transform: scale(1.18); } 30% { transform: scale(1); } 45% { transform: scale(1.1); } }
@keyframes bob { 50% { transform: translateY(-5px); } }
@keyframes wiggle { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-7deg); } 75% { transform: rotate(7deg); } }
@keyframes twinkle { 50% { transform: scale(0.55) rotate(20deg); opacity: 0.6; } }
@keyframes flow { 50% { transform: translateX(4px); } }
@keyframes flicker { 50% { opacity: 0.55; } }
@keyframes paw { 0%, 100% { opacity: 0; } 30%, 70% { opacity: 0.75; } }
@media (prefers-reduced-motion: reduce) {
  .story-art, .story-art * { animation: none !important; }
  .story-art .paw { opacity: 0.75; }
}
.story .primer-card h2 { margin-top: 0.25rem; }

/* Calendar */
.stats-row { display: flex; flex-wrap: wrap; gap: 0.3rem 1.1rem; margin-bottom: 1.25rem; color: var(--muted); font-size: 0.88rem; }
.stat b { font-weight: 600; color: var(--ink); margin-right: 0.25rem; }
.year-nav { display: flex; align-items: center; gap: 0.25rem; margin-bottom: 0.75rem; }
.year { font-family: var(--serif); font-size: 1.2rem; min-width: 9rem; text-align: center; }
/* Jump to a year and quarter: one row under the arrows, as wide as the tiles. */
.ym-jump { display: flex; gap: 0.5rem; align-items: center; margin: -0.25rem 0 0.9rem; }
.ym-jump[hidden], .ym-jump select[hidden] { display: none; }
.ym-jump select { width: auto; flex: none; padding: 0.35rem 0.5rem; font-size: 0.88rem; border-radius: 999px; }
.ym-q { display: flex; flex: 1; padding: 2px; border: 1px solid var(--line); border-radius: 999px; background: var(--bg); }
.ym-q button { flex: 1; border: 0; padding: 0.35rem 0; font-size: 0.85rem; color: var(--muted); min-width: 0; }
.ym-q button:hover:not(:disabled) { color: var(--ink); background: var(--hover); }
.ym-q button[aria-pressed="true"] { background: var(--paper); color: var(--ink); box-shadow: var(--shadow); font-weight: 500; }
.ym-q button:disabled { opacity: 0.35; }
.ym-q button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Year of pages (yearmap.js): GitHub-style week columns, three months at a time. */
.yearmap { display: grid; gap: 1rem; }
.ym-band {
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: auto repeat(7, auto);
  grid-template-columns: 1.6rem repeat(var(--cols), minmax(0, 1fr));
  gap: 2px;
  max-width: calc(1.6rem + var(--cols) * 1.05rem);
}
.ym-band > i, .ym-band > button { aspect-ratio: 1; min-width: 0; }
.ym-mo, .ym-wd { font-size: 0.68rem; color: var(--muted); line-height: 1; white-space: nowrap; }
.ym-mo { overflow: visible; width: 0; padding-bottom: 0.3rem; }
.ym-wd { align-self: center; }
.ym-band button, .legend i {
  padding: 0;
  border: none;
  border-radius: 2px;
  background: var(--heat-0);
  box-shadow: inset 0 0 0 1px var(--cell-edge);
}
.ym-band button[data-day] { cursor: pointer; }
.ym-band button[aria-disabled] { cursor: default; }
.ym-band button[data-l="later"] { background: transparent; opacity: 0.6; }
.ym-band button[data-l="1"], .legend i[data-l="1"] { background: var(--heat-1); }
.ym-band button[data-l="2"], .legend i[data-l="2"] { background: var(--heat-2); }
.ym-band button[data-l="3"], .legend i[data-l="3"] { background: var(--heat-3); }
.ym-band button[data-l="4"], .legend i[data-l="4"] { background: var(--heat-4); }
/* A full 750-word day carries a small star, in the page colour so it reads on the darkest tile. */
.ym-band button[data-l="4"], .legend i[data-l="4"] { position: relative; }
.ym-band button[data-l="4"]::after, .legend i[data-l="4"]::after {
  content: "\2605";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 0.6rem;
  line-height: 1;
  color: var(--bg);
  font-variant-emoji: text;
  pointer-events: none;
}
.legend i[data-l="4"]::after { font-size: 0.5rem; }
.star { color: var(--heat-4); }
.ym-band button[data-day]:hover { box-shadow: inset 0 0 0 1.5px var(--ink); }
.ym-band button.sel { outline: 2px solid var(--ink); outline-offset: 1px; }
.legend { display: flex; align-items: center; gap: 3px; color: var(--muted); font-size: 0.78rem; margin-top: 1rem; }
.legend span:first-child { margin-right: 0.35rem; }
.legend span:last-child { margin-left: 0.35rem; }
.legend i { width: 11px; height: 11px; }

.ym-tip {
  position: fixed;
  z-index: 20;
  transform: translate(-50%, calc(-100% - 8px));
  background: var(--ink);
  color: var(--bg);
  font-size: 0.78rem;
  line-height: 1.2;
  padding: 0.4rem 0.65rem;
  border-radius: 8px;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: var(--shadow);
}
.ym-tip::after {
  content: "";
  position: absolute;
  top: 100%;
  left: var(--arrow, 50%);
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: var(--ink);
}
.reader { margin-top: 1.5rem; border-top: 1px solid var(--line); padding-top: 1rem; }
/* Tiles beside the page on wide screens, above it on narrow ones. The tiles
   stay put while you page through, and the page is always at least a screen
   tall, so a short page never pulls the view up. */
.cal-pane { width: min(100%, 17rem); }
.cal-layout .reader { min-height: calc(100vh - 5rem); }
@media (min-width: 52rem) {
  .cal-layout { display: grid; grid-template-columns: 17rem minmax(0, 1fr); gap: 3rem; align-items: start; }
  .cal-pane { position: sticky; top: 4.5rem; }
  .cal-layout .reader { margin-top: 0; border-top: none; padding-top: 0; }
}
.reader h3 { margin-top: 0; }
.reader-head { display: flex; align-items: center; gap: 0.25rem; margin-bottom: 0.25rem; }
/* Both arrows sit before the date, so they stay put whatever its length. */
.reader-head h3 { margin: 0 0 0 0.5rem; flex: 1; order: 1; }
.reader .text { white-space: pre-wrap; font-family: var(--serif); font-size: 1.1rem; line-height: 1.7; }

/* Notes on past pages: a reaction, highlights and sticky notes. Quiet until used. */
.reader { position: relative; }
.reactions { display: flex; gap: 0.2rem; margin: 0.1rem 0 0.9rem; }
.reactions button {
  padding: 0;
  width: 2.25rem;
  height: 2.25rem;
  border-color: transparent;
  font-size: 1.15rem;
  line-height: 1;
  filter: grayscale(0.6);
  opacity: 0.6;
  transition: opacity 0.15s, filter 0.15s, background-color 0.15s;
}
.reactions button:hover, .reactions button:focus-visible { opacity: 0.9; filter: none; background: var(--hover); }
.reactions.chosen button { opacity: 0.4; }
.reactions button[aria-pressed="true"] { opacity: 1; filter: none; background: var(--hover); border-color: var(--line); }
mark.hl {
  background: var(--mark);
  color: inherit;
  border-radius: 3px;
  padding: 0.05em 0;
  cursor: pointer;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}
mark.hl.has-note { border-bottom: 2px solid var(--mark-on); }
mark.hl[data-emoji]::after {
  content: attr(data-emoji);
  display: inline-block;
  margin-left: 0.15em;
  padding: 0.05em 0.2em;
  font-size: 0.72em;
  line-height: 1.2;
  vertical-align: 0.35em;
  border-radius: 999px;
  background: var(--sticky);
  border: 1px solid var(--sticky-line);
  user-select: none;
}
mark.hl.on, mark.hl:focus-visible { background: var(--mark-on); outline: none; }
.hl-add {
  position: absolute;
  z-index: 5;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.8rem;
  font-size: 0.85rem;
  background: var(--paper);
  box-shadow: var(--shadow);
}
.hl-add .i { width: 1rem; height: 1rem; }
.hl-add[hidden], .sticky[hidden] { display: none; }
.sticky {
  position: absolute;
  z-index: 6;
  width: min(100%, 22rem);
  padding: 0.75rem 0.85rem 0.6rem;
  background: var(--sticky);
  color: var(--sticky-ink);
  border: 1px solid var(--sticky-line);
  border-radius: 4px 4px 12px 4px;
  box-shadow: var(--shadow);
}
.sticky-quote {
  margin: 0 0 0.5rem;
  font-family: var(--serif);
  font-style: italic;
  font-size: 0.92rem;
  line-height: 1.45;
  opacity: 0.8;
  white-space: pre-wrap;
}
.sticky-reactions { margin: 0 0 0.35rem; }
.sticky-reactions button { width: 2rem; height: 2rem; font-size: 1rem; }
.sticky-reactions button[aria-pressed="true"], .sticky-reactions button:hover { background: rgba(255, 255, 255, 0.35); border-color: var(--sticky-line); }
:root[data-theme="dark"] .sticky-reactions button[aria-pressed="true"], :root[data-theme="dark"] .sticky-reactions button:hover { background: rgba(0, 0, 0, 0.2); }
.sticky textarea {
  display: block;
  width: 100%;
  resize: vertical;
  font: 1rem/1.5 var(--serif);
  color: inherit;
  background: transparent;
  border: none;
  border-top: 1px dashed var(--sticky-line);
  padding: 0.5rem 0 0;
  outline: none;
}
.sticky textarea::placeholder { color: inherit; opacity: 0.5; }
.sticky-row { display: flex; align-items: center; gap: 0.5rem; margin-top: 0.4rem; }
.sticky-row button { padding: 0.35rem 0.8rem; font-size: 0.85rem; color: inherit; border-color: var(--sticky-line); }
.sticky-row .sticky-remove { border-color: transparent; padding-left: 0; opacity: 0.7; }
.sticky-status { flex: 1; font-size: 0.8rem; opacity: 0.7; text-align: right; }
.notes-foot { margin-top: 1.5rem; }
.notes-foot h4 { margin: 0 0 0.5rem; font-size: 0.85rem; font-weight: 500; color: var(--muted); }
.notes-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.5rem; }
.notes-list button {
  display: block;
  width: 100%;
  text-align: left;
  border-radius: 4px 4px 10px 4px;
  border-color: var(--sticky-line);
  background: var(--sticky);
  color: var(--sticky-ink);
  padding: 0.55rem 0.8rem;
  line-height: 1.45;
}
.notes-list q { display: block; font-family: var(--serif); font-style: italic; opacity: 0.8; quotes: "“" "”"; }
.notes-list span { display: block; margin-top: 0.2rem; white-space: pre-wrap; }

/* Settings */
.settings { max-width: 34rem; }
.settings > * + * { margin-top: 1rem; }
.settings .signed-in-as { margin: 0.25rem 0 0; }
details.danger summary { cursor: pointer; color: var(--muted); margin-top: 0.5rem; font-size: 0.92rem; }
details.danger[open] summary { color: var(--warn); }

/* Recovery code and its warnings */
.warning { border: 1px solid var(--warn); border-radius: 10px; padding: 0.75rem 0.9rem; font-size: 0.92rem; line-height: 1.5; }
.warning p { margin: 0; }
.warning strong { color: var(--warn); }
.warning[hidden], .stack[hidden], #have-code[hidden] { display: none; }
.code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 1.15rem;
  letter-spacing: 0.04em;
  text-align: center;
  word-spacing: 0.2em;
  background: var(--hover);
  border-radius: 8px;
  padding: 0.75rem;
  margin: 0;
  user-select: all;
  overflow-wrap: anywhere;
}
label.check { display: flex; gap: 0.5rem; align-items: flex-start; color: var(--ink); font-size: 0.95rem; }
label.check input { width: auto; margin-top: 0.2rem; }
.recovery .brand { font-size: 1.8rem; }
.welcome .warning, .welcome label.check { text-align: left; }

/* Export and import progress */
#export-progress, #import-progress { width: 100%; height: 0.5rem; appearance: none; border: 0; border-radius: 999px; background: var(--hover); overflow: hidden; accent-color: var(--accent); }
#export-progress::-webkit-progress-bar, #import-progress::-webkit-progress-bar { background: var(--hover); border-radius: 999px; }
#export-progress::-webkit-progress-value, #import-progress::-webkit-progress-value { background: var(--accent); border-radius: 999px; }
#export-progress::-moz-progress-bar, #import-progress::-moz-progress-bar { background: var(--accent); border-radius: 999px; }
#export-progress[hidden], #import-progress[hidden] { display: none; }
#import-start { background: var(--accent-ink); color: var(--on-accent); border-color: var(--accent-ink); font-weight: 500; }
#import-start[hidden] { display: none; }
.import-issues { margin: 0; padding-left: 1.2rem; max-height: 12rem; overflow-y: auto; }
.import-issues[hidden] { display: none; }

/* Days off: hatched tiles, so they read apart from both blank days and pages. */
.ym-band button[data-l="off"], .ym-band button[data-l="off-later"], .legend i[data-l="off"] {
  background: repeating-linear-gradient(135deg, var(--heat-0) 0 2px, color-mix(in srgb, var(--accent) 50%, var(--heat-0)) 2px 3.5px);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 60%, transparent);
}
.ym-band button[data-l="off-later"] { opacity: 0.7; }
.legend-off { display: inline-flex; align-items: center; gap: 3px; margin-left: 0.9rem; }
.legend-off[hidden] { display: none; }
.today-wrap { display: inline-flex; align-items: baseline; min-width: 0; }
.streak { font-family: var(--serif); color: var(--muted); white-space: nowrap; font-size: 0.9rem; }
.streak::before { content: " · "; white-space: pre; }
/* Phones: the streak sits under the date, so the ring keeps its place. */
@media (max-width: 30rem) {
  .today-wrap { flex-direction: column; align-items: flex-start; line-height: 1.2; }
  .streak { font-size: 0.75rem; }
  .streak::before { content: none; }
}
.done-streak { font-family: var(--serif); color: var(--accent-ink); margin: -0.4rem 0 0.75rem; }
.off-form { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: flex-end; }
.off-form label { display: flex; flex-direction: column; gap: 0.2rem; flex: 1; min-width: 8.5rem; font-size: 0.8rem; color: var(--muted); }
.off-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.4rem; }
.off-list[hidden] { display: none; }
.off-list li { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; padding: 0.45rem 0.6rem; border: 1px solid var(--line); border-radius: 10px; font-size: 0.9rem; }
.off-list button { padding: 0.3rem 0.75rem; font-size: 0.85rem; }
