:root {
  color-scheme: light dark;
  --paper: #faf7f0;
  --ink: #1d1b16;
  --muted: #6b665c;
  --unread: #a8a296;
  --rule: #e2ddd1;
  --surface: #ffffff;
  --accent: #1f5c4a;
  --accent-ink: #ffffff;
  --mark: #ffe066;
  --mark-ink: #1d1b16;
  --read: #3c3a33;
  --good: #e3f1e8;
  --good-ink: #17402f;
  --bad: #fbe6e1;
  --bad-ink: #7a2615;
  --serif: Charter, 'Bitstream Charter', 'Sitka Text', Cambria, Georgia, serif;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  --measure: 68ch;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #17160f;
    --ink: #ece7dc;
    --muted: #a39d90;
    --unread: #6d685d;
    --rule: #34322a;
    --surface: #211f18;
    --accent: #7cc4a8;
    --accent-ink: #10231c;
    --mark: #f2c94c;
    --mark-ink: #17160f;
    --read: #d6d0c3;
    --good: #1b3328;
    --good-ink: #bfe5d2;
    --bad: #3d1d16;
    --bad-ink: #f5c3b6;
  }
}

@media (prefers-reduced-motion: no-preference) {
  html {
    scroll-behavior: smooth;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.5;
}

[hidden] {
  display: none !important;
}

.masthead,
main {
  max-width: calc(var(--measure) + 2rem);
  margin-inline: auto;
  padding-inline: 1rem;
}

.masthead {
  padding-block: 1.25rem 0.5rem;
}

.masthead h1 {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 650;
  letter-spacing: 0.01em;
}

.masthead a {
  color: inherit;
  text-decoration: none;
}

main {
  padding-block-end: 4rem;
}

button,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-block-size: 2.5rem;
  padding: 0.5rem 1rem;
  border: 1px solid var(--rule);
  border-radius: 0.5rem;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 550;
  text-decoration: none;
  cursor: pointer;
}

button.primary,
.button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
}

button.ghost {
  min-block-size: 2rem;
  padding: 0.25rem 0.75rem;
  background: transparent;
}

button:hover,
.button:hover {
  filter: brightness(0.96);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Compose */

.compose {
  display: grid;
  gap: 0.5rem;
  margin-block-start: 1rem;
}

.intro {
  margin: 0 0 0.75rem;
  max-inline-size: 65ch;
  text-wrap: pretty;
}

.compose label {
  font-weight: 600;
}

.compose textarea {
  min-block-size: 50vh;
  padding: 0.75rem;
  border: 1px solid var(--rule);
  border-radius: 0.5rem;
  background: var(--surface);
  color: var(--ink);
  font: 0.9375rem/1.5 var(--mono);
  resize: vertical;
}

.compose button {
  justify-self: start;
}

.error {
  margin: 0;
  color: var(--bad-ink);
}

/* Reading toolbar */

.toolbar {
  position: sticky;
  inset-block-start: 0;
  z-index: 1;
  display: grid;
  gap: 0.25rem;
  margin-inline: -1rem;
  padding: 0.75rem 1rem;
  border-block-end: 1px solid var(--rule);
  background: var(--paper);
}

.progress-row,
.toolbar-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.toolbar-row {
  justify-content: space-between;
}

.toolbar-row > button {
  margin-inline-start: auto;
}

progress {
  flex: 1;
  block-size: 0.5rem;
  border: 0;
  border-radius: 0.25rem;
  background: var(--rule);
  accent-color: var(--accent);
  appearance: none;
}

progress::-webkit-progress-bar {
  border-radius: 0.25rem;
  background: var(--rule);
}

progress::-webkit-progress-value {
  border-radius: 0.25rem;
  background: var(--accent);
}

progress::-moz-progress-bar {
  border-radius: 0.25rem;
  background: var(--accent);
}

.count {
  color: var(--muted);
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.875rem;
}

.hint.slow {
  color: var(--bad-ink);
  font-weight: 600;
}

.hint.slow:empty,
.toolbar-row:has(.slow:not(:empty)) .hint:not(.slow) {
  display: none;
}

.hint-touch {
  display: none;
}

@media (hover: none) {
  .hint-pointer {
    display: none;
  }

  .hint-touch {
    display: inline;
  }
}

/* Receipt banner */

.banner {
  margin-block: 1rem 0;
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  background: var(--good);
  color: var(--good-ink);
  font-weight: 550;
}

.banner.bad {
  background: var(--bad);
  color: var(--bad-ink);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-block-start: 2rem;
}

/* The doc */

.doc {
  font-family: var(--serif);
  font-size: clamp(1.0625rem, 1rem + 0.3vw, 1.1875rem);
  line-height: 1.65;
  overflow-wrap: break-word;
}

.doc > :first-child {
  margin-block-start: 1.5rem;
}

.doc h1,
.doc h2,
.doc h3,
.doc h4,
.doc h5,
.doc h6 {
  margin: 1.6em 0 0.5em;
  font-family: var(--sans);
  line-height: 1.2;
  text-wrap: balance;
}

.doc h1 {
  font-size: 2rem;
}

.doc h2 {
  font-size: 1.5rem;
}

.doc h3 {
  font-size: 1.25rem;
}

.doc h4,
.doc h5,
.doc h6 {
  font-size: 1.0625rem;
}

.doc a {
  color: var(--accent);
}

.doc code {
  font-family: var(--mono);
  font-size: 0.875em;
}

.doc :not(pre) > code {
  padding: 0.1em 0.3em;
  border-radius: 0.25rem;
  background: var(--rule);
}

.doc pre {
  overflow-x: auto;
  padding: 0.75rem 1rem;
  border: 1px solid var(--rule);
  border-radius: 0.5rem;
  background: var(--surface);
  line-height: 1.5;
}

.doc blockquote {
  margin-inline: 0;
  padding-inline-start: 1rem;
  border-inline-start: 3px solid var(--rule);
  color: var(--muted);
}

.doc table {
  display: block;
  overflow-x: auto;
  border-collapse: collapse;
}

.doc th,
.doc td {
  padding: 0.375rem 0.75rem;
  border: 1px solid var(--rule);
  text-align: start;
}

.doc hr {
  border: 0;
  border-block-start: 1px solid var(--rule);
}

/* Word-by-word reading */

.doc.reading {
  /* Room to bring the last lines up to the middle of the screen. */
  padding-block-end: 50vh;
  user-select: none;
  -webkit-user-select: none;
}

/* Taps anywhere advance, so rapid taps mustn't zoom. */
html:has(.doc.reading) {
  touch-action: manipulation;
}

.doc.reading .word {
  border-radius: 0.2em;
  color: var(--unread);
}

.doc.reading .word.read {
  color: var(--read);
}

.doc.reading .word.current {
  padding: 0.05em 0.15em;
  margin: -0.05em -0.15em;
  background: var(--mark);
  color: var(--mark-ink);
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
  cursor: pointer;
}

.doc.reading a .word.read {
  color: var(--accent);
}

.doc.reading .word.nudge {
  animation: nudge 500ms ease-out;
}

/* Inline boxes ignore transforms, so the nudge is a ring that fades. */
@keyframes nudge {
  from {
    box-shadow: 0 0 0 0.3em var(--accent);
  }
  to {
    box-shadow: 0 0 0 0.3em transparent;
  }
}

/* Finished */

.done {
  margin-block-start: 1rem;
  padding: 1.25rem;
  border: 1px solid var(--rule);
  border-radius: 0.75rem;
  background: var(--surface);
}

.done h2 {
  margin: 0 0 0.25rem;
  font-size: 1.375rem;
}

.done h2:focus {
  outline: none;
}

.done p {
  margin: 0 0 1rem;
}

.done label {
  display: block;
  margin-block-end: 0.25rem;
  font-weight: 600;
}

.link-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.link-row input {
  flex: 1 1 16rem;
  min-inline-size: 0;
  min-block-size: 2.5rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--rule);
  border-radius: 0.5rem;
  background: var(--paper);
  color: var(--ink);
  font: 0.875rem var(--mono);
}

.copy {
  position: relative;
  display: inline-flex;
}

.tip {
  position: absolute;
  inset-block-end: calc(100% + 0.375rem);
  inset-inline-start: 50%;
  translate: -50% 0;
  padding: 0.125rem 0.5rem;
  border-radius: 0.375rem;
  background: var(--ink);
  color: var(--paper);
  font-size: 0.8125rem;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
}

.tip:not(:empty) {
  opacity: 1;
}

@media (prefers-reduced-motion: no-preference) {
  .tip {
    transition: opacity 150ms;
  }
}
