/* The palette: six colours, six roles, no overlap (DESIGN §1). The rest is
   derived from them — terracotta is 3.1:1 on paper, so every terracotta
   *word* uses --terra-ink instead. Only the card page uses these so far. */
:root {
  --paper: #F7F4EC;
  --forest: #294B3B;
  --encre: #2C5A87;
  --terracotta: #C87552;
  --sage: #D9E3D5;
  --rule: #E8E4D9;

  --surface: #FFFCF5;
  --sage-deep: #B9CDB4;
  --terra-ink: #A34F2A;
  --ink: #222A24;
  --ink-soft: #5F6A62;

  /* Outside the palette on purpose: only the operator ever sees it, and it
     must not read as anything a kid's screen means (DESIGN §1). 7.4:1 under
     white text. */
  --operator: #6B3FA0;
  --operator-tint: #EFE8F6;
}

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

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  /* Pages start at the top and grow down; the session centres its own
     question inside `.session` rather than making the whole page do it. */
  justify-content: flex-start;
  background: var(--paper);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  font-size: 17px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  gap: 2rem;
  padding: 2rem 1rem 3rem;
}

#screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
}

.title {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
  color: var(--forest);
}

.subtitle {
  font-size: 1.05rem;
  color: var(--ink-soft);
}

/* ── the shell the four reading screens share (DESIGN §2, §3) ────────── */
/* Like the card page, the width is explicit so the element is a resolvable
   query container. */
.page {
  width: min(90vw, 620px);
  container-type: inline-size;
  container-name: page;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.75rem;
  text-align: left;
}
.topbar {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--rule);
}
.wordmark {
  font-weight: 700;
  font-size: 22px;
  letter-spacing: -0.02em;
  color: var(--forest);
  text-decoration: none;
}
.spacer { flex: 1; }

/* The address bar, spelled out: every segment but the last is a link to
   that page (DESIGN §2). */
.crumbs { font-size: 14px; color: var(--ink-soft); }
.crumbs a { color: inherit; text-decoration: none; }
.crumbs a:hover { color: var(--forest); text-decoration: underline; }
.crumbs b { color: var(--ink); font-weight: 600; }
.crumbs i { font-style: normal; opacity: 0.4; padding: 0 5px; }

/* Renaming happens in the head the title sits in: the field takes the row,
   and the refusal the one below it. */
.head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.head .add-form, .head .add-error { flex: 1 1 100%; }
.head button.btn-quiet { padding: 0; font-size: 0.9rem; }
.head + .head { margin-top: 0.5rem; }
.head h1 {
  font-size: 1.6rem;
  line-height: 1.2;
  letter-spacing: -0.02em;
  font-weight: 700;
  color: var(--forest);
}
.head h2 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  font-weight: 600;
  color: var(--ink-soft);
}
.lede { color: var(--ink-soft); }
.privacy { margin-top: 24px; font-size: 0.9rem; }
/* The operator reading what is not theirs. Loud on purpose, in the one colour
   no kid's screen uses — never terracotta, which means a missed answer. */
.notice {
  margin: 12px 0 0;
  padding: 8px 12px;
  border: 1px solid var(--operator);
  border-left-width: 4px;
  border-radius: 8px;
  background: var(--operator-tint);
  color: var(--operator);
  font-size: 0.9rem;
  font-weight: 600;
}
.grid { display: grid; gap: 8px; }

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 12px 14px;
  color: inherit;
  font-weight: 400;
  font-size: 1rem;
}
.row:hover { border-color: var(--sage-deep); }
.row .name { font-weight: 600; color: var(--ink); }
.row .meta { font-size: 0.85rem; color: var(--ink-soft); }
.row .chev { color: var(--ink-soft); }
/* The monogram is derived from the label at render time — nothing is
   stored, so renaming moves it too (DESIGN §3). */
.tile {
  width: 32px;
  height: 32px;
  flex: none;
  border-radius: 6px;
  background: var(--sage);
  color: var(--forest);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.8rem;
  letter-spacing: -0.02em;
}

/* ── adding, at the end of a list (DESIGN §3) ───────────────────────── */
/* Dashed and muted: creating a year happens once a year, and it must not
   compete with the rows above it. Open, the same box holds the field. */
.add {
  display: block;
  width: 100%;
  text-align: left;
  color: var(--ink-soft);
  font-weight: 500;
  font-size: 0.95rem;
  padding: 10px 14px;
  border: 1px dashed var(--rule);
  border-radius: 8px;
}
.add:hover { border-color: var(--sage-deep); color: var(--forest); }
.add-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.add-field {
  font: inherit;
  flex: 1 1 8rem;
  min-width: 0;
  padding: 10px 14px;
  border: 1px solid var(--sage-deep);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
}
.add-field:focus { outline: none; border-color: var(--forest); }
.add-field:disabled { color: var(--ink-soft); }
/* Terracotta is the "look again" colour (DESIGN §1); nothing else in the
   palette says "not this". */
.add-error { margin-top: 6px; color: var(--terra-ink); font-size: 0.9rem; }

/* ── unmaking, past the end of the page ──────────────────────────────── */
/* Deleting is the last thing on the page, under a rule, in the same grey
   as any quiet control: terracotta is "an answer that missed" (DESIGN §1)
   and is not borrowed to mean danger. */
.foot { margin-top: 2.5rem; padding-top: 0.75rem; border-top: 1px solid var(--rule); }
.foot button.btn-quiet { padding-left: 0; padding-right: 0; font-size: 0.9rem; }

/* ── the landing (DESIGN §3) ─────────────────────────────────────────── */
.landing { padding: 1.5rem 0; }
.landing-page .wordmark { font-size: 28px; }
.landing h1 {
  font-size: 2rem;
  line-height: 1.2;
  letter-spacing: -0.02em;
  font-weight: 700;
  color: var(--forest);
  max-width: 14ch;
}
.landing .lede { font-size: 1.05rem; max-width: 36ch; margin: 0.75rem 0 1.5rem; }
.landing ul { list-style: none; margin-top: 2.75rem; color: var(--ink-soft); font-size: 0.95rem; }
.landing li { padding: 8px 0; border-top: 1px solid var(--rule); }
@container page (max-width: 560px) {
  .landing h1 { font-size: 1.6rem; }
  .landing-page .wordmark { font-size: 24px; }
}

/* ── the card page (DESIGN §3) ───────────────────────────────────────── */
/* The width is explicit so the element is a resolvable query container:
   the blocks inside adapt to the width they are given, not the window's. */
/* The preview is the same page in a narrower column, so it is the same
   query container under another width — not a second set of rules. */
.card-page, .card-preview {
  container-type: inline-size;
  container-name: card;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 1rem;
  text-align: left;
  min-width: 0;
}
.card-page { width: min(90vw, 620px); }
.card-title {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
  color: var(--forest);
}
.card-section {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  font-weight: 600;
  color: var(--ink-soft);
  margin-top: 0.5rem;
}
/* A section tag is a quiet marker, which is sage's role (DESIGN §1): it says
   how the section is drawn, it is not something to press. */
.card-section:has(.section-tag) { display: flex; align-items: center; flex-wrap: wrap; gap: 0.5rem; }
.section-tag {
  padding: 0.1rem 0.45rem;
  border-radius: 6px;
  background: var(--sage);
  color: var(--forest);
  font-size: 0.7rem;
  letter-spacing: 0.06em;
}
.card-prose {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 0.875rem 1rem;
  color: var(--ink);
  /* A kid typing in the editor can produce a word longer than the column;
     it wraps rather than pushing the page sideways. */
  overflow-wrap: anywhere;
}
.card-prose > * + * { margin-top: 0.5rem; }
.card-prose ul, .card-prose ol { margin-left: 1.1rem; }
/* A parameter the engine could not use: look again, in terracotta's
   readable ink (DESIGN §1), never in place of what was generated. */
.section-issue { font-size: 0.9rem; color: var(--terra-ink); }
.card-prose code { background: var(--sage); padding: 0.1rem 0.3rem; border-radius: 3px; font-size: 0.9em; }

/* One grid for every line of a section: the key column takes the width of
   the longest key (capped), so all the values start at the same x. The row
   is `display: contents` so its cells land in that grid (DESIGN §3, §7). */
.cards {
  display: grid;
  grid-template-columns: fit-content(42%) 1fr;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 8px;
  overflow: hidden;
}
.card-line { display: contents; }
.card-line > * { padding: 10px 0; }
.card-line > :first-child { padding-left: 14px; }
.card-line > :last-child { padding-right: 14px; }
.card-line + .card-line > * { border-top: 1px solid var(--rule); }
.card-line .k {
  font-weight: 600;
  color: var(--forest);
  padding-right: 16px;
  font-variant-numeric: tabular-nums;
}
.card-line .v { color: var(--ink); }
/* Tables side by side while they fit, each its own small grid. */
.times-tables {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr));
  gap: 0.75rem;
}
/* a × b = c, one column each: operands right-aligned so units line up. */
.times-table {
  display: grid;
  grid-template-columns: repeat(5, auto);
  justify-self: start;
  column-gap: 0.5rem;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 8px;
  overflow: hidden;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.times-line { display: contents; color: var(--ink); }
.times-line > * { padding: 8px 0; text-align: right; }
.times-line > :first-child { padding-left: 14px; }
.times-line > :last-child { padding-right: 14px; }
.times-line + .times-line > * { border-top: 1px solid var(--rule); }
.times-line.extra { color: var(--ink-soft); }
.times-line .factor { font-weight: 600; }
/* One paradigm per verb and tense, side by side while they fit. */
.paradigms {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr));
  gap: 1rem;
}
.paradigm-title { margin: 0 0 0.35rem; font-size: 0.95rem; font-weight: 600; color: var(--forest); }
@container card (max-width: 560px) {
  .cards { grid-template-columns: fit-content(46%) 1fr; }
}


/* ── the editor (DESIGN §3) ──────────────────────────────────────────── */
/* Two panes while the page is wide enough for two readable columns, one
   column below that — a container query on the page, not on the window
   (DESIGN §7). The page itself is wider here than anywhere else: a card
   and its source side by side do not fit in a reading column. */
.edit-page { width: min(94vw, 1060px); }
.editor { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; align-items: start; }
.pane { display: flex; flex-direction: column; gap: 0.75rem; min-width: 0; }
.pane-label { margin-top: 0; }
@container page (max-width: 760px) {
  .editor { grid-template-columns: 1fr; }
}

/* Monospace, because the grammar is made of line starts — a bullet and a
   colon have to be findable at a glance. */
.edit-source {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.95rem;
  line-height: 1.5;
  min-height: min(60vh, 28rem);
  resize: vertical;
  padding: 0.875rem 1rem;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  tab-size: 2;
}
.edit-source:focus { outline: none; border-color: var(--sage-deep); }
.edit-actions { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.edit-count {
  font-size: 0.85rem;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
  margin-left: auto;
}
.edit-count.over { color: var(--terra-ink); font-weight: 600; }

.review-listen {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  padding: 0 0.25rem;
  margin-left: 0.25rem;
  opacity: 0.6;
  transition: opacity 0.15s;
}
.review-listen:hover { opacity: 1; }
.review-listen:disabled { opacity: 0.3; cursor: default; }
.timeline {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(5rem, auto) 1.5rem 1fr;
  column-gap: 0.75rem;
  row-gap: 0;
}
.t-row {
  display: contents;
}
.t-row > .t-date {
  text-align: right;
  font-weight: 600;
  color: var(--forest);
  font-variant-numeric: tabular-nums;
  font-size: 0.95rem;
  padding: 0.35rem 0;
  white-space: nowrap;
  align-self: center;
}
.t-row > .t-axis {
  position: relative;
  background: linear-gradient(var(--sage-deep), var(--sage-deep)) center/2px 100% no-repeat;
  min-height: 1.8rem;
}
.t-row > .t-axis > .t-dot {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--forest);
}
.t-row > .t-event {
  padding: 0.35rem 0;
  color: var(--ink);
  font-size: 1rem;
  align-self: center;
  line-height: 1.35;
}
.t-sep {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0;
}
.t-sep-line {
  flex: 1;
  height: 0;
  border-top: 1px dashed var(--rule);
}
.t-sep-label {
  font-size: 0.8rem;
  color: var(--ink-soft);
  font-variant: small-caps;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

/* ── a session (DESIGN §4) ───────────────────────────────────────────── */
/* One screen per question: the correction appears under the answer, never
   on a screen of its own. Colour belongs to the answer — the buttons are an
   outline and grey text, and the only saturated things here are the verdict
   and the dots. */
.session {
  width: min(90vw, 620px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  /* A question owns the screen: it centres itself, now that the page
     itself starts at the top for the reading screens. */
  min-height: calc(100dvh - 11rem);
  gap: 1.25rem;
  text-align: left;
  /* The score and the exit cross sit fixed at the top of the page: the
     question starts below them. */
  padding-top: 1.5rem;
}
.session .prompt {
  font-size: 1.85rem;
  line-height: 1.15;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--forest);
}
/* Belongs to the prompt, so it sits closer to it than the session's gap. */
.session .several {
  margin-top: -0.9rem;
  font-size: 0.95rem;
  color: var(--ink-soft);
}
.session .answer {
  font-family: inherit;
  font-size: 1.3rem;
  width: 100%;
  padding: 0.8rem 0.9rem;
  border: 2px solid var(--rule);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  outline: none;
}
.session .answer:focus { border-color: var(--sage-deep); }
.session .answer.ok { border-color: var(--forest); color: var(--forest); }
.session .answer.no { border-color: var(--terracotta); color: var(--terra-ink); }
.session .answer.skipped { border-color: var(--rule); color: var(--ink-soft); }
.session .answer:disabled { background: var(--surface); }
.verdict { min-height: 1.5rem; font-size: 1rem; }
.verdict.ok { color: var(--forest); font-weight: 600; }
.verdict.no { color: var(--terra-ink); }
.session-bottom { display: flex; gap: 0.6rem; align-items: center; }
button.btn-answer {
  flex: 1;
  justify-content: center;
  background: var(--surface);
  border: 1.5px solid var(--encre);
  color: var(--encre);
  padding: 0.8rem 1.25rem;
  font-size: 1.05rem;
  white-space: nowrap;
}
button.btn-answer:hover { background: var(--sage); }
button.btn-answer:disabled { background: var(--surface); color: var(--ink-soft); border-color: var(--rule); }
button.btn-quiet {
  background: transparent;
  color: var(--ink-soft);
  font-weight: 500;
  padding: 0.8rem 0.75rem;
  font-size: 1rem;
}
button.btn-quiet:hover { background: transparent; color: var(--forest); }
button.btn-quiet:disabled { background: transparent; color: var(--rule); }
/* Quiet, and flush with the title above it: *Réviser* is the card page's
   one filled accent (DESIGN §1). */
button.card-edit { align-self: flex-start; padding-left: 0; padding-right: 0; }

/* ── the recap (DESIGN §4) ───────────────────────────────────────────── */
.recap-page {
  width: min(90vw, 620px);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  text-align: left;
}
.recap {
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--surface);
  overflow: hidden;
}
/* The left edge is what makes a miss findable without reading a word. */
.rec {
  display: flex;
  gap: 0.6rem;
  padding: 0.6rem 0.9rem;
  align-items: baseline;
  border-left: 3px solid transparent;
}
.rec + .rec { border-top: 1px solid var(--rule); }
.rec.ok { border-left-color: var(--forest); }
.rec.no { border-left-color: var(--terracotta); }
.rec .sign { width: 0.9rem; font-weight: 700; color: var(--forest); }
.rec.no .sign { color: var(--terra-ink); }
.rec .q { flex: 1; color: var(--ink); line-height: 1.4; }
.rec .q b { color: var(--forest); font-weight: 600; }
.rec .mine { color: var(--terra-ink); font-size: 0.9rem; }
.rec .mine s { opacity: 0.75; }
.recap-actions { display: flex; flex-direction: column; gap: 0.5rem; }

/* One base, one filled accent — the screen decides which single button
   wears it (DESIGN §1). */
button {
  font: inherit;
  font-weight: 600;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  background: none;
  color: var(--forest);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  user-select: none;
  -webkit-user-select: none;
}
button:disabled { color: var(--ink-soft); cursor: not-allowed; }

.btn-primary { background: var(--encre); color: #fff; }
.btn-primary:hover { filter: brightness(0.88); }
/* Nothing to save reads as nothing to press: the accent leaves entirely
   rather than dimming into an unreadable blue. */
.btn-primary:disabled { background: var(--rule); color: var(--ink-soft); filter: none; }
.btn-sm { padding: 8px 13px; font-size: 0.95rem; }
.btn-lg { width: 100%; justify-content: center; padding: 0.85rem 1.4rem; font-size: 1.05rem; }

button.back {
  background: transparent;
  color: var(--ink-soft);
  font-weight: 500;
  font-size: 0.95rem;
  padding: 0.3rem 0.8rem;
}
button.back:hover { color: var(--forest); }

#score {
  position: fixed;
  top: 1rem;
  right: 1.5rem;
  font-size: 1rem;
  color: var(--ink-soft);
}

#exit {
  position: fixed;
  top: 0.75rem;
  left: 1rem;
}

button.exit {
  background: transparent;
  color: var(--ink-soft);
  font-size: 1.4rem;
  font-weight: 400;
  padding: 0.2rem 0.6rem;
  line-height: 1;
}
button.exit:hover { color: var(--forest); }

#progress {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
  max-width: min(90vw, 40rem);
}

.dot {
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 50%;
  background: var(--rule);
  transition: background 0.2s, box-shadow 0.2s;
}
.dot.correct { background: var(--forest); }
.dot.wrong   { background: var(--terracotta); }
.dot.current { background: var(--sage-deep); box-shadow: 0 0 0 3px var(--sage); }
.dot.current.wrong { background: var(--terracotta); }

/* Who you are, and the way out, at the top right of every page. */
.who { display: flex; align-items: center; gap: 0.6rem; font-size: 0.9rem; color: var(--ink-soft); }
.who a { color: inherit; text-decoration: none; }
.who a:hover { color: var(--forest); }
.who form { margin: 0; }
.who .btn-quiet { padding: 0.2rem 0; font-size: 0.9rem; }
/* The section tag's shape, in the operator's colour: a mode, not a page. */
.who a.operator-badge {
  padding: 0.15rem 0.5rem;
  border-radius: 6px;
  background: var(--operator);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.who a.operator-badge:hover { color: #fff; opacity: 0.85; }


/* ── the help page (/aide) ───────────────────────────────────────────── */
/* An example is its source beside what it becomes — the editor's two panes,
   read-only and smaller. */
.help-page { width: min(94vw, 1060px); }
.help-example { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; align-items: start; }
@container page (max-width: 760px) {
  .help-example { grid-template-columns: 1fr; }
}
.help-source {
  margin: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9rem;
  line-height: 1.5;
  white-space: pre-wrap;
  padding: 0.875rem 1rem;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
}
.help-page .card-preview .card-title { font-size: 1.3rem; }
.help-aliases, .help-credits { margin: 0; padding-left: 1.2rem; color: var(--ink-soft); }
.help-aliases code, .help-tenses code { color: var(--ink); }
.help-tenses summary { cursor: pointer; color: var(--ink-soft); }
.help-credits a, .edit-help { color: var(--encre); }
.edit-help { font-size: 0.9rem; align-self: flex-start; }
