:root {
  --bg: #f6f6f4;
  --fg: #1d1d1b;
  --muted: #6b6b66;
  --accent: #2f5d8a;
  --border: #d8d8d2;
  --err: #c62828;
  --warn: #9a5b00;
  --notice-bg: #fff4d6;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161716;
    --fg: #ececea;
    --muted: #9c9c96;
    --accent: #7fb0e0;
    --border: #3a3b39;
    --err: #ff8a80;
    --warn: #ffb74d;
    --notice-bg: #3a3320;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
}

main {
  max-width: 1120px;
  margin: 0 auto;
  padding: 2rem 1.25rem;
}

h1 { font-size: 1.6rem; margin: 0 0 0.5rem; }
a { color: var(--accent); word-break: break-all; }
.muted { color: var(--muted); }
.hint { font-size: 0.9rem; }
.status { font-weight: 500; min-height: 1.5em; }

.qr {
  display: inline-block;
  background: #fff;
  padding: 0.5rem;
  border-radius: 8px;
  margin: 1rem 0;
}
/* segno's SVG has no viewBox, so forcing a fixed size clips it. Use its own size. */
.qr svg { display: block; max-width: 100%; height: auto; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

button, .file-btn {
  font: inherit;
  padding: 0.6rem 1.1rem;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}
button.secondary { background: transparent; color: var(--accent); border: 1px solid var(--accent); }

/* The text area. pre-wrap keeps line breaks and blank lines, so copied text matches the OCR output. */
.doc {
  width: 100%;
  min-height: 320px;
  max-height: 70vh;
  overflow: auto;
  padding: 1rem 1.2rem;
  font: 17px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  white-space: pre-wrap;  /* keeps the OCR line breaks and blank lines; long lines soft-wrap visually only */
  overflow-wrap: break-word;
  color: var(--fg);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  user-select: text;
}
.doc:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Marks use shape as well as colour: wavy red line for errors, dotted amber for doubt. */
.flag-spell, .flag-odd {
  color: var(--err);
  text-decoration: underline wavy var(--err);
  text-decoration-thickness: 1.5px;
  text-underline-offset: 3px;
}
.flag-unsure {
  color: var(--warn);
  text-decoration: underline dotted var(--warn);
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}

.notice {
  background: var(--notice-bg);
  border-radius: 8px;
  padding: 0.5rem 0.8rem;
  margin: 0 0 0.75rem;
}
.legend .key { font-weight: 600; }
.legend .key-spell { color: var(--err); text-decoration: underline wavy var(--err); }
.legend .key-unsure { color: var(--warn); text-decoration: underline dotted var(--warn); }

/* Phone page */
body.phone main { text-align: center; padding-top: 3rem; }
.file-btn {
  position: relative;
  display: inline-block;
  font-size: 1.2rem;
  padding: 1.1rem 2rem;
  margin-top: 1.5rem;
  overflow: hidden;
}
.file-btn input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}
.file-btn.disabled { opacity: 0.5; pointer-events: none; }

.debug { font-size: 0.9rem; margin: 0 0 0.75rem; }
.debug a { margin-right: 0.4rem; }
.editor { resize: vertical; }
.ai-row { display: block; margin: 0.75rem 0; }
.ai-row input { margin-right: 0.4rem; }

/* Editable result: a transparent textarea on top of a mirror that draws the marks. */
.editor-wrap { position: relative; }
.mirror {
  margin: 0;
  min-height: 320px;
  max-height: none;
  overflow: hidden;
  pointer-events: none;
}
.editor {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  max-height: none; /* same height as the mirror, so the whole text is one area; the page scrolls */
  margin: 0;
  resize: none;
  overflow: hidden;
  color: transparent;
  caret-color: var(--fg);
  background: transparent;
}
.editor:focus { outline: 2px solid var(--accent); outline-offset: 2px; }
/* The mirror text sits underneath, so the selection must be opaque and the selected text light. */
.editor::selection { background: var(--accent); color: #f2f2f2; }
.editor::-moz-selection { background: var(--accent); color: #f2f2f2; }
.flags { margin: 0.75rem 0 0; padding-left: 1.3rem; font-size: 0.92rem; }
.flags li { margin: 0.15rem 0; }
