/* All colours, spacing and fonts are variables here; a redesign starts in this block. */
:root {
  --bg: #fbfbfa;
  --surface: #ffffff;
  --text: #1f2328;
  --muted: #656d76;
  --border: #d8dee4;
  --accent: #0a66c2;
  --accent-text: #ffffff;
  --quote: #f3f5f7;
  --answer-bg: #fffbea;
  --answer-border: #e3c75a;
  --ok: #1a7f37;
  --error: #cf222e;
  --radius: 8px;
  --gap: 16px;
  --width: 880px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --surface: #161b22;
    --text: #e6edf3;
    --muted: #8d96a0;
    --border: #30363d;
    --accent: #4493f8;
    --accent-text: #0f1216;
    --quote: #1c2128;
    --answer-bg: #2a2410;
    --answer-border: #9e8420;
    --ok: #3fb950;
    --error: #f85149;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.6 var(--font); }
main { max-width: var(--width); margin: 0 auto; padding: var(--gap); }
a { color: var(--accent); }
.muted { color: var(--muted); }

/* Top bar */
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px var(--gap);
  padding: 10px var(--gap); background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; text-decoration: none; color: var(--text); }
.topbar nav { display: flex; flex-wrap: wrap; gap: 4px 14px; flex: 1; }
.topbar nav a { text-decoration: none; }
.logout { margin: 0; }

/* Controls */
button, .button {
  font: inherit; cursor: pointer; border-radius: var(--radius); padding: 8px 16px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.linklike { border: 0; background: none; padding: 0; color: var(--accent); }
input[type=text], input[type=password], textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 10px; width: 100%;
}

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; }
.login { max-width: 360px; margin: 10vh auto; display: grid; gap: 10px; }
.login h1 { margin: 0 0 8px; }

.notice { padding: 10px 14px; border-radius: var(--radius); background: var(--quote); border-left: 4px solid var(--accent); }
.notice.error { border-left-color: var(--error); }
.notice.ok { border-left-color: var(--ok); }

ul.lessons { padding-left: 20px; }

/* Rendered Markdown */
.markdown h1 { font-size: 1.8rem; line-height: 1.25; }
.markdown pre {
  overflow-x: auto; padding: 12px; background: var(--quote); border-radius: var(--radius);
  font: 14px/1.4 var(--mono);
}
.markdown code { font-family: var(--mono); font-size: .92em; }
.markdown blockquote { margin: 12px 0; padding: 4px 14px; border-left: 4px solid var(--border); background: var(--quote); border-radius: 0 var(--radius) var(--radius) 0; }
.markdown table { display: block; overflow-x: auto; border-collapse: collapse; margin: 12px 0; }
.markdown th, .markdown td { border: 1px solid var(--border); padding: 6px 10px; vertical-align: top; }
.markdown details { margin: 10px 0; padding: 6px 12px; border: 1px dashed var(--border); border-radius: var(--radius); }
.markdown summary { cursor: pointer; color: var(--accent); }
.markdown img { max-width: 100%; }
.markdown pre.mermaid { background: none; }

/* Lesson page */
.lesson-title { margin-bottom: 8px; }
.tag { font-size: .8rem; padding: 2px 8px; border-radius: 99px; background: var(--quote); color: var(--muted); vertical-align: middle; }
.tabs { display: flex; flex-wrap: wrap; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: var(--gap); }
.tabs a { padding: 6px 14px; text-decoration: none; border-radius: var(--radius) var(--radius) 0 0; color: var(--muted); }
.tabs a.active { color: var(--text); background: var(--surface); border: 1px solid var(--border); border-bottom-color: var(--surface); margin-bottom: -1px; }
textarea.answer {
  display: block; min-height: 3em; resize: vertical; margin: 6px 0 14px;
  background: var(--answer-bg); border: 1px solid var(--answer-border);
}
input.cell { min-width: 7em; padding: 4px 6px; background: var(--answer-bg); border-color: var(--answer-border); }
textarea.notes { font-family: var(--mono); font-size: 14px; }
pre.unsaved { white-space: pre-wrap; background: var(--surface); padding: 8px; border-radius: var(--radius); }
.grade details.notice { margin: 0 0 var(--gap); }
.savebar {
  position: sticky; bottom: 0; display: flex; gap: 10px; align-items: center; justify-content: flex-end;
  padding: 10px 0; margin-top: var(--gap); background: var(--bg); border-top: 1px solid var(--border);
}
#dirty-note { margin-right: auto; }
