/* Readability first: large type, generous spacing, soft background, no italics. */
:root {
  --bg: #f7f4ec;
  --card: #fffdf8;
  --text: #1f2328;
  --muted: #59606b;
  --accent: #2458b3;
  --accent-text: #ffffff;
  --border: #e3ddcf;
  --error-bg: #fdecea;
  --error-text: #8a1c14;
  --ok-bg: #e3f4e8;
  --ok-text: #1b5e33;
  --warn-bg: #fff2d6;
  --warn-text: #7a4b00;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #181a1f;
    --card: #20232a;
    --text: #ecebe6;
    --muted: #a3a8b1;
    --accent: #7ea6ff;
    --accent-text: #0e1320;
    --border: #30343d;
    --error-bg: #3a1f1d;
    --error-text: #ffb4ab;
    --ok-bg: #1d3526;
    --ok-text: #9fe0b5;
    --warn-bg: #3a2e14;
    --warn-text: #ffd48a;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Verdana, "Atkinson Hyperlegible", Arial, sans-serif;
  font-size: 19px;
  line-height: 1.7;
  letter-spacing: 0.02em;
  word-spacing: 0.08em;
}
main { max-width: 760px; margin: 0 auto; padding: 24px 16px 64px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  max-width: 760px; margin: 0 auto; padding: 16px;
}
.brand { font-weight: 700; color: var(--text); text-decoration: none; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
}
.card.narrow { max-width: 440px; margin: 8vh auto 0; }
h1 { font-size: 1.6rem; margin: 0 0 16px; line-height: 1.3; }

label { display: block; font-weight: 700; margin: 16px 0 6px; }
input, textarea {
  width: 100%;
  font: inherit;
  padding: 12px 14px;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
}
input:focus, textarea:focus { outline: 3px solid var(--accent); outline-offset: 1px; }

textarea { resize: vertical; line-height: 1.8; }

button, a.button {
  display: inline-block; text-decoration: none;
  font: inherit; font-weight: 700;
  margin-top: 24px; padding: 12px 22px;
  border: 0; border-radius: 10px;
  background: var(--accent); color: var(--accent-text);
  cursor: pointer;
}
button.link {
  margin: 0; padding: 0; background: none; color: var(--accent);
  font-weight: 400; text-decoration: underline;
}

.error {
  background: var(--error-bg); color: var(--error-text);
  padding: 10px 14px; border-radius: 10px;
}

button:disabled { opacity: .6; cursor: progress; }
button.secondary, a.button.secondary {
  background: transparent; color: var(--accent); border: 2px solid var(--accent);
}
a.button { margin-right: 8px; }

.card + .card, .card + section, details.card { margin-top: 16px; }
h2 { font-size: 1.25rem; margin: 0 0 12px; }
a { color: var(--accent); }
.muted { color: var(--muted); font-weight: 400; }
.prewrap { white-space: pre-wrap; }
.list { list-style: none; padding: 0; margin: 0; }
.list li { padding: 10px 0; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }

.badge {
  display: inline-block; font-size: .8rem; font-weight: 700;
  padding: 2px 10px; border-radius: 999px; background: var(--border); color: var(--text);
}
.badge.ok { background: var(--ok-bg); color: var(--ok-text); }
.badge.warn { background: var(--warn-bg); color: var(--warn-text); }

.feedback .encouragement { font-size: 1.1rem; }
.feedback.ready { border-color: var(--ok-text); background: var(--ok-bg); color: var(--ok-text); }
.items { list-style: none; padding: 0; margin: 0; }
.item { padding: 12px 0; border-bottom: 1px solid var(--border); }
.item:last-child { border-bottom: 0; }
label.check {
  display: flex; gap: 12px; align-items: flex-start;
  margin: 0; font-weight: 400; cursor: pointer;
}
label.check input {
  width: 22px; height: 22px; flex: none; margin-top: 5px; padding: 0;
  accent-color: var(--ok-text);
}
label.check .where, label.check .guidance { display: block; }
label.check .where { margin-bottom: 2px; }
.item:has(.done-box:checked) .guidance,
.item:has(.done-box:checked) .where { text-decoration: line-through; color: var(--muted); }

summary { cursor: pointer; font-weight: 700; }
details.history { padding: 10px 0; border-bottom: 1px solid var(--border); }
details.history summary { font-weight: 400; }

table.log { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.log th, table.log td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: top; }
@media (max-width: 640px) {
  table.log thead { display: none; }
  table.log td { display: block; border: 0; padding: 2px 0; }
  table.log tr { display: block; padding: 10px 0; border-bottom: 1px solid var(--border); }
}

/* ---- Wide workspace (writing pages) ------------------------------------ */
/* Writing pages use the whole screen: feedback/assignment on the side, a
   writing box that fills the remaining height. Stacks on phones/tablets. */
body.wide main, body.wide .topbar { max-width: 1600px; }
body.wide main { padding-left: 24px; padding-right: 24px; }

.workspace { display: grid; gap: 20px; grid-template-columns: 1fr; align-items: start; }
.workspace > .card, .workspace > .side > .card { margin-top: 0; }
.side { display: grid; gap: 16px; align-content: start; }
.side > .card + .card { margin-top: 0; }

.work-card { display: flex; flex-direction: column; }
.work-card label:first-child { margin-top: 0; }
.side label:first-of-type { margin-top: 0; }

textarea.work-box {
  min-height: max(260px, 55vh); /* phones/tablets: most of the screen */
  font-size: 1.1rem;
  line-height: 1.9;
  padding: 16px 18px;
}
textarea.assignment-box { min-height: 9rem; }
.actions { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.actions .checking-note { margin: 24px 0 0; }
.final-text { font-size: 1.1rem; line-height: 1.9; }
.history-card { margin-top: 20px; }

@media (min-width: 1100px) {
  /* Feedback and writing side by side, equal width, each at its full height. */
  .workspace { grid-template-columns: 1fr 1fr; }
  /* Fill the screen below the page title; grows further as she types. */
  textarea.work-box { min-height: max(320px, calc(100vh - 400px)); }
  textarea.assignment-box { min-height: 30vh; }
}
/* The "new writing" page has a short side form, so give the writing more room there. */
@media (min-width: 1100px) {
  form.workspace { grid-template-columns: minmax(320px, 1fr) 2fr; }
}

/* ---- Feedback: spelling table, rule items ------------------------------- */
.feedback h3 { font-size: 1.1rem; margin: 20px 0 8px; }
.feedback .step { margin: 8px 0 4px; }
.feedback .tip { margin-top: 16px; }
.rule, .fix { display: block; }
.fix { margin-top: 2px; }

table.spelling { width: 100%; border-collapse: collapse; }
table.spelling th { text-align: left; font-size: .85rem; color: var(--muted); padding: 6px 8px; border-bottom: 2px solid var(--border); }
table.spelling td { padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.spelling td.tick, table.spelling th.tick { width: 36px; padding-right: 0; }
table.spelling input.done-box { width: 22px; height: 22px; margin: 4px 0 0; padding: 0; accent-color: var(--ok-text); }
table.spelling .wrong { text-decoration: underline wavy var(--error-text); text-underline-offset: 4px; }
table.spelling .right { font-size: 1.15rem; letter-spacing: .06em; }
table.spelling .note, table.spelling .sentence { display: block; }
table.spelling .sentence { font-size: .9rem; margin-top: 4px; }
tr.item:has(.done-box:checked) td:not(.tick) { text-decoration: line-through; color: var(--muted); }
tr.item:has(.done-box:checked) .wrong { text-decoration: line-through; }

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

/* Phones: each spelling row becomes a small card. */
@media (max-width: 640px) {
  table.spelling thead { display: none; }
  table.spelling tr { display: grid; grid-template-columns: 36px 1fr; padding: 10px 0; border-bottom: 1px solid var(--border); }
  table.spelling td { border: 0; padding: 2px 0; }
  table.spelling td.tick { grid-row: span 3; }
  table.spelling td[data-label]::before { content: attr(data-label) ": "; font-weight: 700; font-size: .85rem; color: var(--muted); }
}

.history-items h3 { font-size: 1rem; }
@media (max-width: 640px) {
  table.spelling:not(:has(td.tick)) tr { grid-template-columns: 1fr; }
}

/* ---- Her paragraph with mistakes highlighted -------------------------- */
:root {
  --hl-spelling: #ffd6d6;     --hl-spelling-line: #c62828;
  --hl-capitalization: #d6e6ff; --hl-capitalization-line: #1f5bd1;
  --hl-punctuation: #ffe3bf;  --hl-punctuation-line: #c25e00;
  --hl-writing: #fff3a8;      --hl-writing-line: #9a7b00;
}
@media (prefers-color-scheme: dark) {
  :root {
    --hl-spelling: #5a2626;     --hl-spelling-line: #ff8a80;
    --hl-capitalization: #1f3559; --hl-capitalization-line: #8cb4ff;
    --hl-punctuation: #553a17;  --hl-punctuation-line: #ffb870;
    --hl-writing: #4d4415;      --hl-writing-line: #f2d45c;
  }
}
.marked-text {
  white-space: pre-wrap;
  font-size: 1.1rem; line-height: 2.2;
  padding: 16px 18px; margin: 12px 0 8px;
  background: var(--bg); border: 2px solid var(--border); border-radius: 10px;
}
mark.hl {
  color: inherit; padding: 2px 2px; border-radius: 4px; cursor: pointer;
  border-bottom: 3px solid; box-decoration-break: clone; -webkit-box-decoration-break: clone;
}
mark.hl .hl-n, a.num {
  display: inline-block; min-width: 1.4em; padding: 0 .35em; margin-left: 2px;
  font-size: .72rem; font-weight: 700; line-height: 1.5; text-align: center;
  border-radius: 999px; color: #fff; vertical-align: super; text-decoration: none;
}
a.num { vertical-align: baseline; font-size: .8rem; margin: 0 4px 0 0; }
mark.hl-point { padding: 0; border-bottom: 0; background: none; }
mark.hl-point .hl-n::before { content: "‸"; margin-right: 2px; }
mark.hl:focus-visible { outline: 3px solid var(--accent); }
mark.hl.done { background: none; border-bottom-style: dotted; opacity: .55; }

.hl-spelling { background: var(--hl-spelling); border-color: var(--hl-spelling-line); }
.hl-capitalization { background: var(--hl-capitalization); border-color: var(--hl-capitalization-line); }
.hl-punctuation { background: var(--hl-punctuation); border-color: var(--hl-punctuation-line); }
.hl-writing { background: var(--hl-writing); border-color: var(--hl-writing-line); }
.hl-spelling .hl-n, .num-spelling { background: var(--hl-spelling-line); }
.hl-capitalization .hl-n, .num-capitalization { background: var(--hl-capitalization-line); }
.hl-punctuation .hl-n, .num-punctuation { background: var(--hl-punctuation-line); }
.hl-writing .hl-n, .num-writing { background: var(--hl-writing-line); }
@media (prefers-color-scheme: dark) {
  mark.hl .hl-n, a.num { color: #111; }
}

.legend { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 0; }
.chip { font-size: .85rem; font-weight: 700; padding: 2px 12px; border-radius: 999px; border-bottom: 3px solid; }
.small { font-size: .9rem; }
.flash { animation: flash 1.2s ease-out; }
@keyframes flash { 0% { box-shadow: 0 0 0 4px var(--accent); } 100% { box-shadow: 0 0 0 0 transparent; } }
table.spelling td[data-label="You wrote"] { white-space: nowrap; }

ol.steps { margin: 0 0 8px; padding-left: 1.4em; }
ol.steps li { margin: 4px 0; }
.how { margin: 0 0 8px; }
