:root {
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #202124;
  background: #f5f5f4;
  line-height: 1.5;
  color-scheme: light;
  --primary: #252525;
  --primary-hover: #000;
  --text: #202124;
  --muted: #6b6b68;
  --line: #deddda;
  --surface: #fff;
  --surface-subtle: #f7f7f6;
  --page: #f5f5f4;
  --success: #18794e;
  --success-bg: #edf8f1;
  --success-line: #b7dfc6;
  --danger: #c4322b;
  --danger-bg: #fff1f0;
  --danger-line: #f1c2be;
  --focus: #737373;
  --shadow: 0 3px 14px #00000008;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  color: #ededeb;
  background: #171717;
  --primary: #ededeb;
  --primary-hover: #fff;
  --text: #ededeb;
  --muted: #aaa9a5;
  --line: #3b3b39;
  --surface: #222221;
  --surface-subtle: #2a2a28;
  --page: #171717;
  --success: #68d391;
  --success-bg: #193326;
  --success-line: #2c6244;
  --danger: #f28b82;
  --danger-bg: #3b2221;
  --danger-line: #70403c;
  --focus: #b5b5b5;
  --shadow: 0 3px 14px #00000026;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--page); color: var(--text); }
button, input, select, textarea { font: inherit; }
button { background: var(--primary); color: var(--page); border: 1px solid var(--primary); border-radius: 8px; padding: 10px 17px; font-weight: 650; cursor: pointer; transition: background .15s, border-color .15s, transform .15s; }
button:hover { background: var(--primary-hover); border-color: var(--primary-hover); transform: translateY(-1px); }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
button.secondary { background: var(--surface); color: var(--text); border-color: var(--line); }
button.secondary:hover { background: var(--surface-subtle); border-color: var(--muted); }
button.small { padding: 7px 12px; font-size: 13px; }
button:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.full-width { width: 100%; }
.site-header { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 13px max(24px, calc((100vw - 1180px) / 2)); background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.header-controls { display: flex; align-items: center; gap: 18px; }
.selector-label { display: flex; align-items: center; gap: 7px; margin: 0; color: var(--muted); font-size: 12px; font-weight: 600; }
select { border: 1px solid var(--line); border-radius: 7px; background: var(--surface); color: var(--text); padding: 6px 25px 6px 8px; cursor: pointer; }
main { max-width: 1180px; margin: 0 auto; padding: 36px 24px 64px; }
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: clamp(28px, 4vw, 36px); line-height: 1.15; letter-spacing: -1px; margin-bottom: 10px; }
h2 { font-size: 20px; letter-spacing: -.3px; margin-bottom: 0; }
h3 { letter-spacing: -.2px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 24px; margin-bottom: 24px; box-shadow: var(--shadow); }
.page-heading { margin-bottom: 28px; }
.page-heading p, .login-intro p, .attempt-heading p { color: var(--muted); margin-bottom: 0; }
.teacher-heading { display: flex; align-items: end; justify-content: space-between; gap: 24px; }
.eyebrow { display: block; color: var(--muted); font-size: 11px; font-weight: 800; letter-spacing: 1.2px; text-transform: uppercase; margin-bottom: 8px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.section-heading.compact { margin-bottom: 14px; }
.section-heading h3 { margin: 0; }
.section-note { color: var(--muted); font-size: 13px; }
.badge { display: inline-flex; align-items: center; width: fit-content; border-radius: 999px; padding: 4px 10px; background: var(--surface-subtle); border: 1px solid var(--line); color: var(--muted); font-size: 12px; font-weight: 700; white-space: nowrap; }
.badge.success { color: var(--success); background: var(--success-bg); border-color: var(--success-line); }
.badge.danger { color: var(--danger); background: var(--danger-bg); border-color: var(--danger-line); }
#account { display: flex; align-items: center; gap: 14px; color: var(--muted); font-size: 14px; }
#message { min-height: 0; margin: 0 0 20px; border-radius: 8px; font-weight: 600; }
#message:not(:empty) { background: var(--success-bg); color: var(--success); border: 1px solid var(--success-line); padding: 11px 14px; }
#message.error { background: var(--danger-bg); color: var(--danger); border-color: var(--danger-line); }
[hidden] { display: none !important; }

#login-view { max-width: 480px; margin: 3vh auto 0; }
.login-card { padding: 34px; }
.login-intro { margin-bottom: 28px; text-align: center; }
.login-section h2 { font-size: 18px; }
.login-divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 12px; margin: 24px 0; }
.login-divider::before, .login-divider::after { content: ""; height: 1px; background: var(--line); flex: 1; }

label { display: block; margin: 13px 0; color: var(--text); font-size: 14px; font-weight: 600; }
input, textarea { width: 100%; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--text); padding: 11px 12px; margin-top: 6px; transition: border-color .15s, box-shadow .15s; }
textarea { resize: vertical; min-height: 74px; }
input::placeholder, textarea::placeholder { color: var(--muted); }
input:focus, textarea:focus { border-color: var(--focus); box-shadow: 0 0 0 3px var(--line); outline: none; }
fieldset { border: 1px solid var(--line); border-radius: 9px; margin: 16px 0; padding: 10px 14px; }
legend { color: var(--text); font-size: 13px; font-weight: 700; padding: 0 5px; }
fieldset label { margin: 0; }
fieldset input[type="checkbox"], fieldset input[type="radio"], .checkbox-row input { width: 16px; height: 16px; margin: 0 9px 0 0; accent-color: var(--primary); }
.check-list { display: grid; gap: 2px; max-height: 210px; overflow-y: auto; }
.checkbox-row { display: flex; align-items: center; border-radius: 7px; padding: 8px; margin: 0; font-weight: 500; cursor: pointer; }
.checkbox-row:hover { background: var(--surface-subtle); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.form-grid { grid-template-columns: 2fr 1fr; gap: 16px; }
.form-help { color: var(--muted); font-size: 14px; margin: 4px 0 12px; }
.recipient-fieldset { padding: 8px; }
#recipient-list { max-height: 400px; gap: 8px; }
.recipient-class { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.recipient-class-header { display: flex; align-items: center; gap: 8px; padding-right: 8px; }
.class-recipient { flex: 1; min-width: 0; }
.recipient-toggle { padding: 4px 8px; background: transparent; border-color: transparent; color: var(--muted); font-size: 12px; white-space: nowrap; }
.recipient-toggle:hover { background: var(--surface-subtle); border-color: var(--line); color: var(--text); }
.recipient-students { border-top: 1px solid var(--line); padding: 4px 12px 8px 34px; background: var(--surface-subtle); }
.recipient-students .empty-state { padding: 10px 0; font-size: 13px; }
.inline-form { display: flex; align-items: end; gap: 10px; }
.inline-form label { margin: 0 0 1px; }
.grow { flex: 1; }
pre { white-space: pre-wrap; background: var(--success-bg); color: var(--success); border: 1px solid var(--success-line); border-radius: 9px; padding: 14px; font: 600 13px/1.6 ui-monospace, SFMono-Regular, Consolas, monospace; }

.tabs { display: flex; gap: 4px; background: var(--surface-subtle); border: 1px solid var(--line); border-radius: 9px; padding: 4px; flex-shrink: 0; }
.tab { background: transparent; border-color: transparent; color: var(--muted); padding: 8px 14px; }
.tab:hover { background: var(--surface); color: var(--text); border-color: var(--line); }
.tab.active { background: var(--surface); color: var(--text); border-color: var(--line); box-shadow: 0 1px 3px #00000010; }
.classes-heading { margin: 30px 0 14px; }
.class-list { display: grid; gap: 18px; }
.class-card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 22px; box-shadow: var(--shadow); }
.class-card-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-bottom: 16px; border-bottom: 1px solid var(--line); }
.class-card-header h3 { margin: 0; }
.class-actions { display: flex; gap: 8px; margin-left: auto; }
.danger-button { color: var(--danger); }
.class-card-body { display: grid; grid-template-columns: minmax(240px, .8fr) 1.2fr; gap: 26px; padding-top: 18px; }
.add-student-title { font-size: 14px; margin: 0 0 8px; }
.student-name-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.student-name-fields label { margin-top: 0; }
.class-students { min-width: 0; }
.class-students > h4 { font-size: 14px; margin: 0 0 8px; }
.student-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; border-top: 1px solid var(--line); padding: 11px 0; }
.student-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 6px; }
.student-row strong { display: block; font-size: 14px; }
.student-login { color: var(--muted); font: 12px ui-monospace, SFMono-Regular, Consolas, monospace; letter-spacing: .3px; overflow-wrap: anywhere; }
.empty-state { color: var(--muted); padding: 16px 0; margin: 0; }
.credentials { margin: 14px 0 0; }

.homework-composer { margin-top: 0; }
.template-library { display: flex; align-items: center; justify-content: space-between; gap: 16px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-subtle); padding: 16px; margin: 20px 0; }
.template-library h3, .template-library p { margin: 0; }
.template-library p, .field-help { color: var(--muted); font-size: 12px; font-weight: 400; }
.template-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.oge-options { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 0 0 16px; padding: 16px; border: 1px solid var(--line); border-radius: 10px; }
.oge-options fieldset { margin: 0; min-width: 0; }
.oge-options > button { grid-column: 1 / -1; justify-self: start; }
.oge-check-list { display: grid; gap: 2px; max-height: 240px; overflow-y: auto; }
.question-builder-list { display: grid; gap: 16px; margin-bottom: 24px; }
.builder-question { border: 1px solid var(--line); border-radius: 10px; padding: 18px; }
.builder-question-header, .builder-question-header > div:first-child { display: flex; align-items: center; gap: 10px; }
.builder-question-header { justify-content: space-between; }
.builder-question-header h3 { margin: 0; }
.builder-question-actions { display: flex; gap: 8px; }
.question-prompt-row { display: grid; grid-template-columns: 1fr 120px; gap: 14px; }
.choice-editor { padding: 8px 12px 14px; }
.choice-editor-row { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px; margin: 8px 0; }
.choice-editor-row input[type="radio"] { margin: 0; }
.choice-editor-row input[type="text"] { margin: 0; }
.match-editor { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.match-editor fieldset { min-width: 0; }
.match-editor-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(120px, 1fr) auto; align-items: center; gap: 8px; margin: 8px 0; }
.match-target-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 8px; margin: 8px 0; }
.match-editor-row input, .match-target-row input { margin: 0; }
.match-editor-row select { width: 100%; }
.assignment-settings { padding: 8px; }
.field-help { display: block; margin-top: 5px; }
.teacher-assignment-list { display: grid; gap: 18px; }
.assignment-row { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 22px; box-shadow: var(--shadow); min-width: 0; }
.assignment-row h3 { margin-bottom: 6px; }
.assignment-row > p { color: var(--muted); }
.table-scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; margin-top: 16px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: center; border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); padding: 10px; white-space: nowrap; }
th:last-child, td:last-child { border-right: 0; }
tbody tr:last-child td, tbody tr:last-child th { border-bottom: 0; }
th { color: var(--muted); background: var(--surface-subtle); font-size: 11px; text-transform: uppercase; letter-spacing: .4px; }
th:first-child { text-align: left; position: sticky; left: 0; z-index: 1; min-width: 140px; }
td:first-child { text-align: left; position: sticky; left: 0; background: var(--surface); font-weight: 600; }
.grade-correct { color: var(--success); font-weight: 700; }
.grade-wrong { color: var(--danger); font-weight: 700; }
.grade-pending { color: var(--muted); }
.score-cell { font-weight: 750; }

.homework-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 20px; }
#student-pending-section h2, #student-completed-section h2 { margin-bottom: 16px; }
#student-completed-section, #student-expired-section { margin-top: 32px; }
#back-to-results { margin-bottom: 20px; }
.homework-card { display: flex; flex-direction: column; align-items: flex-start; min-height: 275px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 22px; box-shadow: var(--shadow); transition: transform .18s, border-color .18s; }
.homework-card:hover { transform: translateY(-2px); border-color: var(--muted); }
.homework-card h3 { font-size: 20px; line-height: 1.3; margin: 16px 0 6px; }
.homework-meta { color: var(--muted); font-size: 14px; white-space: pre-line; }
.card-description { color: var(--muted); font-size: 14px; margin-bottom: 20px; }
.card-score { display: flex; flex-direction: column; margin: 8px 0 20px; }
.card-score strong { color: var(--success); font-size: 30px; line-height: 1.1; }
.card-score span { color: var(--muted); font-size: 13px; margin-top: 4px; }
.card-action { margin-top: auto; }
.student-card-actions { display: grid; gap: 8px; width: 100%; margin-top: auto; }
.student-card-actions .card-action { margin-top: 0; }
.student-choices { display: grid; grid-template-columns: 1fr; gap: 8px; margin: 0; text-align: left; }
.student-choice { display: flex; align-items: center; gap: 10px; margin: 0; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); cursor: pointer; overflow-wrap: anywhere; }
.student-choice:hover { border-color: var(--muted); }
.student-choice input { flex: 0 0 16px; width: 16px; height: 16px; margin: 0; }
.student-choice:has(input:checked) { border-color: var(--primary); background: var(--surface-subtle); }
.student-choice:has(input:disabled) { cursor: default; }
.student-matches { display: grid; gap: 8px; text-align: left; }
.student-match { display: grid; grid-template-columns: minmax(0, 1fr) minmax(180px, 1fr); align-items: center; gap: 16px; margin: 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); overflow-wrap: anywhere; }
.student-match select { width: 100%; }
.attempt-panel { max-width: 1100px; margin: 0 auto; }
.attempt-heading { margin: 24px 0; }
.attempt-heading h2 { font-size: 28px; margin-bottom: 8px; }
.question { background: var(--surface-subtle); border: 1px solid var(--line); border-radius: 10px; padding: 28px; text-align: center; }
.question-count { display: block; color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; margin-bottom: 14px; }
.question > label, .student-prompt { display: block; margin: 0 0 18px; font-size: clamp(16px, 2vw, 22px); line-height: 1.4; overflow-wrap: anywhere; white-space: pre-wrap; }
.question > input { max-width: 300px; margin: 0 auto; font-size: 24px; text-align: center; }
.question-navigation { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 14px; margin: 20px 0; }
.question-switcher { display: flex; justify-content: center; flex-wrap: wrap; gap: 6px; }
.question-switcher button { width: 32px; height: 32px; padding: 0; border-radius: 50%; background: var(--surface); color: var(--muted); border-color: var(--line); font-size: 12px; }
.question-switcher button:hover { background: var(--surface-subtle); color: var(--text); border-color: var(--muted); }
.question-switcher button.answered { border-color: var(--success); color: var(--success); }
.question-switcher button.correct { border-color: var(--success); color: var(--success); background: var(--success-bg); }
.question-switcher button.wrong { border-color: var(--danger); color: var(--danger); background: var(--danger-bg); }
.question-switcher button.current, .question-switcher button.current:hover { background: var(--primary); color: var(--page); border-color: var(--primary); }
.feedback-option { width: fit-content; margin: 0 0 18px; }
.result-summary { border-top: 1px solid var(--line); margin-top: 24px; padding-top: 20px; }
.result-summary h3 { color: var(--success); }
.result-correct { color: var(--success); font-weight: 650; }
.result-wrong { color: var(--danger); font-weight: 650; }

@media (max-width: 800px) {
  .class-card-body { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; gap: 0; }
  main { padding: 26px 16px 48px; }
  .site-header { padding: 12px 16px; }
  .teacher-heading { align-items: stretch; flex-direction: column; }
  .tabs { align-self: flex-start; }
  .question-navigation { grid-template-columns: 1fr 1fr; }
  .question-switcher { grid-column: 1 / -1; grid-row: 1; }
  .template-library { align-items: stretch; flex-direction: column; }
}

@media (max-width: 520px) {
  .login-card { padding: 24px 20px; }
  .panel, .class-card, .assignment-row { padding: 18px; }
  #account-name { display: none; }
  .site-header { align-items: flex-start; }
  .header-controls { gap: 8px; }
  .selector-label > span { display: none; }
  .inline-form { align-items: stretch; flex-direction: column; }
  .student-name-fields { grid-template-columns: 1fr; gap: 0; }
  .class-card-header { flex-wrap: wrap; }
  .class-actions { width: 100%; margin-left: 0; }
  .recipient-class-header { align-items: flex-start; }
  .recipient-toggle { margin-top: 7px; }
  .recipient-students { padding-left: 16px; }
  .student-row { align-items: flex-start; }
  .homework-grid { grid-template-columns: 1fr; }
  .question { padding: 22px 14px; }
  .builder-question-header { align-items: flex-start; }
  .builder-question-header, .builder-question-header > div:first-child { flex-wrap: wrap; }
  .question-prompt-row { grid-template-columns: 1fr; gap: 0; }
  .match-editor { grid-template-columns: 1fr; gap: 0; }
  .oge-options { grid-template-columns: 1fr; }
  .question-navigation { gap: 8px; }
  .question-switcher button { width: 29px; height: 29px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
  button:hover, .homework-card:hover { transform: none; }
}
