/* Algebra Engine AI tutor (round 6). Mobile first; no external fonts or assets. */
:root {
  --bg: #ffffff;
  --fg: #1b1f24;
  --muted: #545d68;
  --line: #c9d1d9;
  --card: #f6f8fa;
  --accent: #0b5cad;
  --accent-fg: #ffffff;
  --focus: #b35c00;
  --feedback: #e8f1fb;
  --info: #f3f4f6;
  --error-bg: #fdecec;
  --error-fg: #8a1c1c;
  --assisted: #fff4d6;
  /* Round UI (U8): result blocks. Text pairs meet WCAG AA (4.5:1); borders and icons 3:1. */
  --ok-bg: #e7f5ec;
  --ok-line: #1a7f37;
  --ok-fg: #0f5323;
  --ok-icon-fg: #ffffff;
  --notyet-bg: #f3f4f6;
  --notyet-line: #6e7781;
  --notyet-fg: #1b1f24;
  --chosen: #e8f1fb;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1419;
    --fg: #e6edf3;
    --muted: #a8b3bf;
    --line: #3b4552;
    --card: #161c23;
    --accent: #5aa7f0;
    --accent-fg: #0b1218;
    --focus: #ffb35c;
    --feedback: #13283d;
    --info: #1c232b;
    --error-bg: #3a1717;
    --error-fg: #ffb4b4;
    --assisted: #3a2f12;
    --ok-bg: #10291a;
    --ok-line: #3fb950;
    --ok-fg: #7ee787;
    --ok-icon-fg: #0f1419;
    --notyet-bg: #1c232b;
    --notyet-line: #8b949e;
    --notyet-fg: #e6edf3;
    --chosen: #13283d;
  }
}

[hidden] { display: none !important; }

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 1.0625rem;
  line-height: 1.5;
  overflow-wrap: break-word;
}

.wrap { max-width: 760px; margin: 0 auto; padding: 0 16px; }

.skip-link {
  position: absolute; left: -9999px; top: 0;
  background: var(--accent); color: var(--accent-fg); padding: 8px 12px; z-index: 10;
}
.skip-link:focus { left: 8px; top: 8px; }

.site-header { border-bottom: 1px solid var(--line); }
.site-header .wrap { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: space-between; padding-top: 10px; padding-bottom: 10px; }
.brand { margin: 0; font-weight: 700; font-size: 1.1rem; }
.brand-beta { font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.mock-badge {
  margin: 0; padding: 2px 10px; border: 1px solid var(--focus); border-radius: 999px;
  font-size: 0.85rem; font-weight: 600; color: var(--fg); background: var(--assisted);
}

main { padding-top: 16px; padding-bottom: 32px; }
main:focus { outline: none; }

h1 { font-size: 1.5rem; line-height: 1.25; margin: 0.25em 0 0.5em; }
h2 { font-size: 1.15rem; margin: 1.25em 0 0.5em; }
h3 { font-size: 1.05rem; margin: 1em 0 0.4em; }
h4 { font-size: 0.95rem; margin: 0.8em 0 0.3em; }
h5 { font-size: 0.9rem; margin: 0.7em 0 0.25em; color: var(--muted); }

p { margin: 0.5em 0; }
.lead { color: var(--muted); }
.muted { color: var(--muted); }
.loading { color: var(--muted); }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 14px 16px; margin: 16px 0;
}
.card h2:first-child { margin-top: 0; }

.row { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }

button, .button-link {
  font: inherit; font-size: 1rem; min-height: 44px; padding: 8px 16px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--fg); cursor: pointer;
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center;
  max-width: 100%; text-align: center;
}
button:hover:not(:disabled), .button-link:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); font-weight: 600; }
button.wide { width: 100%; margin: 8px 0; }
button.small { min-height: 36px; padding: 4px 12px; font-size: 0.9rem; }
button.quiet { background: transparent; }
button:disabled { opacity: 0.55; cursor: not-allowed; }
.link-button { background: none; border: none; color: var(--accent); text-decoration: underline; padding: 8px 0; min-height: 44px; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
input:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; }

label, .field-label { display: block; font-weight: 600; margin: 12px 0 4px; }

input[type="text"], input[type="search"] {
  width: 100%; font: inherit; font-size: 1.05rem; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--fg);
}

fieldset.options { border: 0; margin: 12px 0 0; padding: 0; min-width: 0; display: grid; gap: 8px; }
fieldset.options legend { font-weight: 600; padding: 0; margin-bottom: 8px; }
/* U3: each option row is one large target: the checkbox and its full text. */
.option { position: relative; display: flex; align-items: flex-start; gap: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); padding: 10px 12px; min-height: 48px; }
.option:hover { border-color: var(--accent); }
.option:has(input:checked) { border-color: var(--accent); background: var(--chosen); box-shadow: inset 3px 0 0 var(--accent); }
.option input { position: relative; z-index: 1; width: 22px; height: 22px; margin: 2px 0 0; flex: none; accent-color: var(--accent); }
.option label { margin: 0; font-weight: 400; display: block; flex: 1; cursor: pointer; }
.option label::after { content: ""; position: absolute; inset: 0; }
.option-letter { font-weight: 600; }

/* An equation or expression never breaks across lines; the sentence around it may wrap. */
.math { white-space: nowrap; font-variant-numeric: tabular-nums; }
.math-main { font-weight: 650; }

.ws-heading { margin-bottom: 0.1em; }
.focus-line { margin: 0 0 4px; color: var(--muted); font-weight: 600; }

/* Goal dots: code's count of check questions correct in a row without help. */
.goal { display: flex; align-items: flex-start; gap: 12px; margin: 8px 0 4px; }
.goal p { margin: 0; }
.goal-skill { font-size: 0.9rem; color: var(--muted); }
.goal-count { font-weight: 600; }
.goal-note { color: var(--muted); font-size: 0.95rem; }
.dots { display: inline-flex; gap: 6px; padding-top: 0.3em; flex: none; }
.dot { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--accent); background: transparent; transition: background-color 0.25s ease, transform 0.25s ease; }
.dot-filled { background: var(--accent); transform: scale(1.08); }

/* The conversation: scrolls, newest at the bottom. */
/* Narrow screens: the page scrolls like a chat and the composer stays at the bottom of the screen.
   Wide screens: the conversation scrolls in its own box above the composer. */
.conversation { list-style: none; margin: 12px 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.line { padding: 8px 12px; border-radius: 10px; max-width: 92%; }
.line p { margin: 0.2em 0; white-space: pre-wrap; }
.speaker { font-size: 0.8rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.line-tutor { align-self: flex-start; background: var(--card); border: 1px solid var(--line); }
.line-student { align-self: flex-end; background: var(--chosen); border: 1px solid var(--accent); }
.line-clarify { border-style: dashed; }
.line-notice { align-self: stretch; max-width: 100%; background: var(--info); border-left: 4px solid var(--notyet-line); }
.line-error { align-self: stretch; max-width: 100%; background: var(--error-bg); color: var(--error-fg); border-left: 4px solid var(--error-fg); }
.line-writing { align-self: flex-start; color: var(--muted); font-style: italic; }
.line-problem .problem-text, .check-card .problem-text { font-size: 1.1rem; }
.option-lines { list-style: none; margin: 4px 0; padding: 0; display: grid; gap: 2px; }

/* A result from the app: one block; words and an icon carry the meaning, the tint only supports them. */
.line-result { align-self: stretch; max-width: 100%; border-left: 4px solid var(--line); color: var(--fg); }
.result-head { display: flex; align-items: center; gap: 10px; margin: 0.15em 0 0.35em; }
.result-word { font-weight: 700; }
.result-icon { flex: none; width: 1.5em; height: 1.5em; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; line-height: 1; }
.result-correct { background: var(--ok-bg); border-left-color: var(--ok-line); }
.result-correct .result-word { color: var(--ok-fg); }
.result-correct .result-icon { background: var(--ok-line); color: var(--ok-icon-fg); }
.result-notyet, .result-partial { background: var(--notyet-bg); border-left-color: var(--notyet-line); }
.result-notyet .result-word, .result-partial .result-word { color: var(--notyet-fg); }
.result-notyet .result-icon { border: 2px solid var(--notyet-line); }
.result-partial .result-icon { border: 2px solid var(--notyet-line); background: linear-gradient(90deg, var(--notyet-line) 50%, transparent 50%); }
.result-partial .result-word { font-weight: 600; }
.result-context { font-weight: 600; }
.result-note { color: var(--muted); }

/* Round 6 §5.1: a check question is a distinct card, in the conversation and pinned above the input. */
.line-check { align-self: stretch; max-width: 100%; padding: 0; }
.check-card { border: 2px solid var(--focus); border-radius: 10px; background: var(--assisted); padding: 10px 14px; }
.card-label { font-size: 0.85rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; margin: 0 0 4px; }
.check-card .card-label { color: var(--fg); }

/* The composer: the open problem pinned above one input for an answer or a message. */
.composer { position: sticky; bottom: 0; z-index: 2; background: var(--bg); padding: 8px 0 4px; border-top: 1px solid var(--line); box-shadow: 0 -6px 12px -10px rgba(0, 0, 0, 0.35); }
.pinned { border: 1px solid var(--line); border-radius: 10px; background: var(--card); padding: 8px 12px; margin: 4px 0 6px; }
.pinned .card-label { color: var(--muted); }
.pinned.pinned-check { border: 2px solid var(--focus); background: var(--assisted); }
.pinned.pinned-check .card-label { color: var(--fg); }
.pinned .prompt { font-size: 1.1rem; margin: 2px 0; white-space: pre-wrap; }
.with-help { font-size: 0.9rem; color: var(--muted); margin: 2px 0 0; }
.composer .field-label { font-weight: 500; color: var(--muted); font-size: 0.95rem; margin-top: 6px; }
.composer fieldset.options legend { font-weight: 500; color: var(--muted); font-size: 0.95rem; }
.entry-row { display: flex; gap: 8px; }
.entry-row input { flex: 1; min-width: 0; }
.composer .controls { margin: 8px 0 4px; }
.wrap-up { border-color: var(--accent); }

/* Help choices open from "I'm stuck". */
.stuck-toggle[aria-expanded="true"] { border-color: var(--accent); background: var(--chosen); }
.stuck-menu { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 4px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.session-controls { margin-top: 16px; }

/* Round UI v3 (U10): "Your code" in the header area; the code form and "Welcome back". */
.code-bar { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; margin: 0 0 10px; padding: 8px 12px; border: 1px dashed var(--line); border-radius: 8px; background: var(--card); }
.code-label { font-size: 0.85rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.code-value { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-weight: 700; font-size: 1.05rem; letter-spacing: 0.06em; white-space: nowrap; }
.code-note { flex-basis: 100%; font-size: 0.9rem; color: var(--muted); }
.code-row { display: flex; gap: 8px; }
.code-row input { flex: 1; min-width: 0; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: 0.06em; text-transform: uppercase; }
.welcome-back { border-top: 1px solid var(--line); margin-top: 14px; }
.learner-summary.compact { margin: 8px 0; }
.learner-summary.compact .summary-part h3 { margin: 0.6em 0 0.3em; }
.empty-line { font-style: italic; }
.next-row { margin-top: 4px; }
a.primary-link { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); font-weight: 600; }
.pending { font-weight: 600; }

.error-banner { background: var(--error-bg); color: var(--error-fg); padding: 10px 12px; border-radius: 8px; }

.status { min-height: 1.5em; color: var(--muted); font-size: 0.95rem; }

.skill-list, .catalog { list-style: none; margin: 8px 0; padding: 0; display: grid; gap: 8px; }
.skill-button { width: 100%; justify-content: flex-start; text-align: left; }
.skill-id { font-weight: 700; font-variant-numeric: tabular-nums; }
.catalog-row { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; display: grid; gap: 4px; }
.catalog-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.tag { font-size: 0.8rem; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.avail-available_scored { border-color: var(--accent); color: var(--fg); }
.avail-partial_components { border-color: var(--focus); color: var(--fg); }
.domain h2 { font-size: 1.05rem; }
.count { color: var(--muted); font-size: 0.9rem; }

.notices { border-top: 1px solid var(--line); margin-top: 24px; color: var(--muted); font-size: 0.95rem; }

.summary .provider-label { font-weight: 700; padding: 8px 12px; border: 2px solid var(--focus); border-radius: 8px; background: var(--assisted); }
/* U2: the learner level, then the teacher level behind a disclosure. */
.learner-summary { display: grid; gap: 12px; margin: 16px 0; }
.summary-part { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 4px 16px 8px; }
.summary-part h2 { margin: 0.6em 0 0.3em; }
.summary-part ul { margin: 0.3em 0; padding-left: 1.2em; }
.summary-note { margin: 0; }
.teacher-details { border: 1px solid var(--line); border-radius: 10px; margin: 16px 0; }
.teacher-details > summary { cursor: pointer; padding: 12px 16px; font-weight: 600; min-height: 44px; list-style-position: inside; }
.teacher-details[open] > summary { border-bottom: 1px solid var(--line); }
.teacher-body { padding: 4px 16px 12px; }
.teacher-section h3 { margin-top: 1em; }
.teacher-body ul { padding-left: 1.2em; }
.teacher-body li + li { margin-top: 4px; }
.table-wrap { overflow-x: auto; max-width: 100%; }
.skills-table { border-collapse: collapse; width: 100%; font-size: 0.92rem; }
.skills-table caption { text-align: left; font-weight: 600; padding: 4px 0; }
.skills-table th, .skills-table td { border: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; overflow-wrap: normal; word-break: normal; hyphens: manual; }
.skill-detail { border-top: 1px solid var(--line); margin-top: 12px; }

/* U2: under 600px each skill row becomes a card; no cell wraps a word letter by letter. */
@media (max-width: 599px) {
  .skills-table, .skills-table thead, .skills-table tbody, .skills-table tr, .skills-table th, .skills-table td { display: block; width: auto; }
  .skills-table caption { display: block; }
  .skills-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .skills-table tr { border: 1px solid var(--line); border-radius: 8px; margin: 8px 0; padding: 4px 0; background: var(--card); }
  .skills-table th, .skills-table td { border: 0; padding: 4px 12px; }
  .skills-table tbody th { font-weight: 700; }
  .skills-table td { display: flex; justify-content: space-between; gap: 12px; }
  .skills-table td::before { content: attr(data-label); color: var(--muted); }
  .skills-table td:nth-of-type(4), .skills-table td:nth-of-type(5) { display: block; }
  .skills-table td:nth-of-type(4)::before, .skills-table td:nth-of-type(5)::before { display: block; }
}

.site-footer { border-top: 1px solid var(--line); color: var(--muted); font-size: 0.9rem; }
.site-footer .wrap { padding-top: 8px; padding-bottom: 16px; }
.privacy-note { margin: 4px 0; }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

@media (min-width: 640px) {
  h1 { font-size: 1.75rem; }
  .conversation {
    padding: 10px; max-height: max(260px, calc(100vh - 460px)); overflow-y: auto; overscroll-behavior: contain;
    border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
  }
  .composer { position: static; box-shadow: none; border-top: 0; }
  button.wide { width: auto; }
  .catalog-row { grid-template-columns: 1fr auto; align-items: center; }
  .learner-summary { grid-template-columns: 1fr 1fr; }
  .summary-note { grid-column: 1 / -1; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

@media print {
  .site-header, .site-footer, .controls, .session-controls, .status, .skip-link, button, .button-link { display: none !important; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .card, .line, .summary .provider-label, .summary-part { background: none; border-color: #999; }
  .composer { display: none !important; }
  .conversation { max-height: none; overflow: visible; }
  .table-wrap { overflow: visible; }
  .teacher-details > summary { list-style: none; }
}
