:root {
  color-scheme: light;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 18px;
  line-height: 1.6;
  margin: 0;
  background: #fdfdfb;
  color: #1a1a1a;
}

.site-header {
  border-bottom: 2px solid #1a1a1a;
  padding: 12px 24px;
}

.site-title {
  font-size: 1.4em;
  font-weight: 700;
  color: #1a1a1a;
  text-decoration: none;
}

.content {
  max-width: 46rem;
  margin: 0 auto;
  padding: 24px;
}

h1 {
  font-size: 1.8em;
  line-height: 1.25;
}

a {
  color: #0b57d0;
}

.site-header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
}

.site-nav {
  margin-left: auto;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.user-name {
  font-weight: 700;
}

button {
  font: inherit;
  padding: 6px 14px;
  min-height: 44px;
  border: 2px solid #1a1a1a;
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
}

button:hover {
  background: #1a1a1a;
  color: #fff;
}

form label {
  display: block;
  margin-top: 12px;
  font-weight: 700;
}

form input[type="text"],
form input[type="username"],
form input[type="password"] {
  font: inherit;
  padding: 8px;
  border: 2px solid #1a1a1a;
  border-radius: 8px;
  width: 100%;
  max-width: 22rem;
  box-sizing: border-box;
}

.error {
  color: #b00020;
  font-weight: 700;
}

.unit {
  margin-top: 32px;
}

.unit-summary {
  color: #444;
}

.unit-items {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
}

.item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 2px solid #e3e3de;
  border-radius: 8px;
  margin-bottom: 8px;
}

.item-title {
  font-weight: 600;
  text-decoration: none;
}

a.item-title {
  color: #0b57d0;
}

.item-badge {
  font-weight: 700;
  min-width: 1.2em;
}

.item-done .item-badge {
  color: #0a7a2f;
}

.item-available .item-badge {
  color: #0b57d0;
}

.item-locked {
  color: #666;
  background: #f4f4f1;
}

.lesson-body table {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
}

.lesson-body th,
.lesson-body td {
  border: 1px solid #ccc;
  padding: 4px 10px;
}

.lesson-body pre {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: #f0f0ec;
  padding: 12px;
  border-radius: 8px;
  white-space: pre-wrap;
}

.run-btn {
  margin: 6px 0 14px;
  min-height: 44px;
}

.run-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.py-status {
  font-weight: 700;
  margin: 0 0 16px;
  padding: 8px 12px;
  border: 2px solid #e3e3de;
  border-radius: 8px;
  background: #f4f4f1;
}

.snippet {
  margin: 16px 0 28px;
}

.snippet-editor .cm-editor {
  border: 2px solid #888;
  border-radius: 6px;
  min-height: 12em;
}

.snippet-editor .cm-editor.cm-focused {
  outline: 3px solid #4a90e2;
}

.editor-hint {
  color: #555;
  font-size: 0.9em;
  margin: 4px 0 8px;
}

.program-input-label {
  display: block;
  font-weight: 700;
  margin-top: 8px;
}

.program-input {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 16px;
  padding: 8px;
  border: 2px solid #1a1a1a;
  border-radius: 8px;
  width: 100%;
  box-sizing: border-box;
  margin-top: 4px;
}

.snippet-output {
  min-height: 2.4em;
}

.snippet-output .error {
  color: #b00020;
  font-weight: 700;
}

.snippet-output .friendly-hint {
  color: #333;
  font-weight: 400;
}

.lesson-nav {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 32px;
  padding-top: 16px;
  border-top: 2px solid #e3e3de;
}

.nav-locked {
  color: #666;
}

/* ---- Exercise page (Phase 6) ---- */

.content.wide {
  max-width: 900px;
}

.exercise-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 28px;
  margin-top: 8px;
}

@media (min-width: 900px) {
  .exercise-layout {
    grid-template-columns: 1fr 1fr;
    align-items: start;
  }
}

.exercise-prompt {
  min-width: 0;
}

.exercise-work {
  min-width: 0;
}

#editor .cm-editor {
  border: 2px solid #888;
  border-radius: 6px;
  min-height: 12em;
}

#editor .cm-editor.cm-focused {
  outline: 3px solid #4a90e2;
}

.exercise-feedback h2 {
  font-size: 1.1em;
  margin: 0 0 8px;
}

.feedback-item {
  border: 2px solid #e3e3de;
  background: #f4f4f1;
  border-radius: 8px;
  padding: 10px 12px;
  margin: 0 0 8px;
}

.feedback-body {
  margin: 0;
}

.feedback-meta {
  color: #555;
  font-size: 0.85em;
  margin: 4px 0 0;
}

.exercise-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 12px 0 4px;
}

#run-btn, #submit-btn, #hint-btn, #reset-btn {
  min-height: 44px;
}

.submit-btn {
  background: #0a7a2f;
  border-color: #0a7a2f;
  color: #fff;
}

.submit-btn:hover {
  background: #065c22;
  color: #fff;
}

.hint {
  border-left: 4px solid #4a90e2;
  background: #eef4fc;
  border-radius: 0 8px 8px 0;
  padding: 8px 12px;
  margin: 10px 0 0;
}

.hint p {
  margin: 0;
}

.reset-confirm {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  border: 2px solid #b00020;
  border-radius: 8px;
  padding: 10px 12px;
  margin: 10px 0 0;
  background: #fdf0f2;
}

.exercise-output {
  min-height: 2em;
}

.results {
  margin-top: 8px;
}

.check-error {
  color: #b00020;
  font-weight: 700;
  font-size: 1.1em;
  margin: 8px 0 0;
}

.check-error-line {
  margin: 4px 0 0;
  color: #b00020;
}

.check-hint {
  margin: 4px 0 0;
  color: #333;
  font-weight: 400;
}

.traceback pre {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: #f0f0ec;
  padding: 12px;
  border-radius: 8px;
  white-space: pre-wrap;
  font-size: 0.9em;
}

.result-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
  border: 2px solid #e3e3de;
  border-radius: 8px;
  padding: 8px 12px;
  margin: 8px 0;
}

.result-pass {
  border-color: #0a7a2f;
}

.result-fail {
  border-color: #b00020;
}

.result-mark {
  font-weight: 700;
}

.result-pass .result-mark {
  color: #0a7a2f;
}

.result-fail .result-mark {
  color: #b00020;
}

.result-label {
  font-weight: 600;
}

.result-message {
  color: #b00020;
}

.expected-box {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-top: 6px;
}

@media (min-width: 600px) {
  .expected-box {
    grid-template-columns: 1fr 1fr;
  }
}

.expected-title {
  font-weight: 700;
  margin: 0 0 4px;
}

.expected-box pre {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: #f0f0ec;
  padding: 10px;
  border-radius: 8px;
  white-space: pre-wrap;
  margin: 0;
}

.celebration {
  border: 2px solid #0a7a2f;
  background: #eef8f1;
  border-radius: 8px;
  padding: 12px 16px;
  margin: 12px 0;
}

.celebration p {
  font-size: 1.15em;
  font-weight: 700;
  color: #0a7a2f;
  margin: 0;
}

.save-status {
  font-size: 0.85em;
  color: #555;
  min-height: 1.2em;
  margin: 8px 0 0;
}

/* ---------------------------------------------------------------- teacher */

.grid-legend {
  color: #555;
  margin: 0 0 12px;
}

.grid-scroll {
  overflow-x: auto;
}

.progress-grid {
  border-collapse: collapse;
  min-width: 100%;
}

.progress-grid th,
.progress-grid td {
  border: 1px solid #ccc;
  padding: 4px 8px;
  text-align: center;
  white-space: nowrap;
}

.progress-grid thead th {
  background: #f0f0ec;
  font-size: 0.85em;
}

.progress-grid .student-col {
  text-align: left;
  position: sticky;
  left: 0;
  background: #fdfdfb;
  min-width: 10rem;
}

.progress-grid thead .student-col {
  background: #f0f0ec;
}

.progress-grid tr.inactive {
  color: #777;
}

.progress-grid tr.inactive .student-col {
  background: #f0f0ec;
}

.cell {
  display: inline-block;
  min-width: 1.6em;
  font-weight: 700;
  text-decoration: none;
}

.cell.pass {
  color: #0a7a2f;
}

.cell.fail {
  color: #b3261e;
}

td .cell {
  background: #f0f0ec;
  border-radius: 4px;
}

td .cell:hover {
  background: #e4e4de;
}

.grid-legend .cell {
  min-width: auto;
}

.submission-meta {
  color: #555;
}

.submission-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: #f0f0ec;
  padding: 12px;
  border-radius: 8px;
  white-space: pre-wrap;
}

.results-table {
  border-collapse: collapse;
  width: 100%;
}

.results-table td {
  border: 1px solid #ccc;
  padding: 8px;
  vertical-align: top;
}

.results-table td:first-child {
  text-align: center;
  width: 2rem;
}

.result-message {
  margin: 0 0 6px;
}

.result-pre {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: #f0f0ec;
  padding: 8px;
  border-radius: 6px;
  white-space: pre-wrap;
  margin: 6px 0 0;
}

.result-error {
  color: #b3261e;
}

.form-error {
  color: #b3261e;
  font-weight: 700;
}

.form-error,
textarea[name="body"] {
  display: block;
}

textarea[name="body"] {
  width: 100%;
  font: inherit;
  padding: 8px;
  border: 2px solid #1a1a1a;
  border-radius: 8px;
  box-sizing: border-box;
}

.history {
  list-style: none;
  padding: 0;
}

.history li {
  border-bottom: 1px solid #ccc;
  padding: 6px 0;
}

.history-meta {
  display: block;
  font-size: 0.85em;
  color: #555;
}

/* /teacher/users */
.user-form {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
}

.new-password-box {
  border: 3px solid #1a7f37;
  background: #e6f4ea;
  border-radius: 8px;
  padding: 12px 16px;
  margin: 12px 0;
}

.new-password {
  display: inline-block;
  font-size: 1.5em;
  font-weight: 700;
  background: #fff;
  border: 1px solid #1a7f37;
  border-radius: 6px;
  padding: 4px 12px;
}

.user-message {
  font-weight: 700;
}

.user-list {
  width: 100%;
  border-collapse: collapse;
  margin-top: 16px;
}

.user-list th,
.user-list td {
  text-align: left;
  padding: 6px 8px;
  border-bottom: 1px solid #ccc;
}

.user-list tr.inactive td {
  color: #777;
}

.user-actions form {
  display: inline;
}

.hint {
  font-size: 0.9em;
  color: #555;
}

/* /teacher/reload */
.reload-problems li {
  margin: 4px 0;
  font-family: monospace;
}

/* exercise preview: the solution block (teacher only) */
.exercise-solution {
  border: 2px solid #1a7f37;
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: 12px;
}

.exercise-solution pre {
  margin: 8px 0 0;
  padding: 8px;
  background: #f2f8f4;
  border-radius: 6px;
  overflow-x: auto;
}

/* ---------------------------------------------------------------- mobile */
/* No horizontal page scroll at phone widths: wide tables scroll inside
   themselves, flex rows wrap. The exercise page is already one column
   below 900px and the teacher grid scrolls horizontally with a sticky
   first column. */

.lesson-nav {
  flex-wrap: wrap;
}

.user-list {
  display: block;
  max-width: 100%;
  overflow-x: auto;
}
