:root {
  color-scheme: light;
  --page: #edf2ef;
  --surface: #ffffff;
  --surface-soft: #f5f8f6;
  --ink: #17231f;
  --muted: #62706a;
  --line: #d5dfda;
  --line-strong: #bdcbc4;
  --brand: #145f57;
  --brand-dark: #103f3a;
  --brand-soft: #dcece8;
  --accent: #b44728;
  --accent-soft: #f8e5dd;
  --warning: #8a5a12;
  --danger: #a12d2d;
  --danger-soft: #f9e2e2;
  --shadow: 0 10px 30px rgb(23 35 31 / 8%);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--page);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: var(--page);
  font-family:
    "Noto Sans SC",
    "Source Han Sans SC",
    "Microsoft YaHei",
    system-ui,
    sans-serif;
  line-height: 1.55;
}

button,
input,
select {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

.site-header {
  color: #f7fbf9;
  background: var(--brand-dark);
  border-bottom: 3px solid var(--accent);
}

.site-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  width: min(1180px, calc(100% - 32px));
  min-height: 74px;
  margin: 0 auto;
}

.brand {
  min-width: 0;
}

.brand-title {
  margin: 0;
  font-size: 19px;
  font-weight: 750;
  letter-spacing: 0;
}

.brand-subtitle {
  margin: 2px 0 0;
  color: #c9ded9;
  font-size: 13px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-label {
  max-width: 180px;
  overflow: hidden;
  color: #d8e9e5;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 30px 0 56px;
}

.page-narrow {
  width: min(860px, calc(100% - 32px));
}

.login-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(320px, 0.75fr);
  gap: 28px;
  align-items: stretch;
  min-height: calc(100vh - 164px);
}

.login-intro {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 48px 26px 48px 0;
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 750;
}

.login-intro h1 {
  max-width: 720px;
  margin: 0;
  font-family:
    "Noto Serif SC",
    "Source Han Serif SC",
    "Songti SC",
    serif;
  font-size: clamp(34px, 5vw, 58px);
  font-weight: 700;
  letter-spacing: 0;
  line-height: 1.15;
}

.login-intro p {
  max-width: 650px;
  margin: 22px 0 0;
  color: var(--muted);
  font-size: 17px;
}

.rule-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 34px;
}

.rule-item {
  padding-top: 14px;
  border-top: 2px solid var(--line-strong);
}

.rule-item strong {
  display: block;
  color: var(--brand);
  font-size: 24px;
  line-height: 1.2;
}

.rule-item span {
  color: var(--muted);
  font-size: 13px;
}

.form-panel {
  align-self: center;
  padding: 30px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.form-panel h2 {
  margin: 0;
  font-size: 24px;
  line-height: 1.3;
}

.form-help {
  margin: 8px 0 24px;
  color: var(--muted);
  font-size: 14px;
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 18px;
}

.field label {
  font-size: 14px;
  font-weight: 650;
}

.field input,
.field select,
.search-input {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  color: var(--ink);
  background: #fbfcfb;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  outline: none;
}

.field input:focus,
.field select:focus,
.search-input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgb(20 95 87 / 13%);
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 9px 15px;
  color: #ffffff;
  background: var(--brand);
  border: 1px solid var(--brand);
  border-radius: 5px;
  cursor: pointer;
  font-weight: 700;
  text-decoration: none;
  transition:
    background-color 140ms ease,
    border-color 140ms ease,
    transform 140ms ease;
}

.button:hover {
  background: var(--brand-dark);
  border-color: var(--brand-dark);
}

.button:active {
  transform: translateY(1px);
}

.button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.button-block {
  width: 100%;
}

.button-secondary {
  color: var(--brand-dark);
  background: var(--surface);
  border-color: var(--line-strong);
}

.button-secondary:hover {
  color: var(--brand-dark);
  background: var(--brand-soft);
  border-color: var(--brand);
}

.button-quiet {
  color: var(--ink);
  background: transparent;
  border-color: transparent;
}

.button-quiet:hover {
  color: var(--brand-dark);
  background: rgb(255 255 255 / 12%);
  border-color: transparent;
}

.button-danger {
  background: var(--danger);
  border-color: var(--danger);
}

.button-danger:hover {
  background: #842323;
  border-color: #842323;
}

.form-message {
  min-height: 22px;
  margin: 14px 0 0;
  color: var(--danger);
  font-size: 14px;
}

.page-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 22px;
  margin-bottom: 22px;
}

.page-heading h1 {
  margin: 0;
  font-family:
    "Noto Serif SC",
    "Source Han Serif SC",
    "Songti SC",
    serif;
  font-size: 32px;
  line-height: 1.25;
}

.page-heading p {
  margin: 5px 0 0;
  color: var(--muted);
}

.summary-grid {
  display: grid;
  grid-template-columns: 1.2fr repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 22px;
}

.summary-item {
  min-height: 112px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.summary-item.primary {
  color: #ffffff;
  background: var(--brand-dark);
  border-color: var(--brand-dark);
}

.summary-label {
  color: var(--muted);
  font-size: 13px;
}

.summary-item.primary .summary-label {
  color: #c4ddd8;
}

.summary-value {
  display: block;
  margin-top: 8px;
  font-size: 30px;
  font-weight: 780;
  line-height: 1;
}

.summary-note {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.summary-item.primary .summary-note {
  color: #c4ddd8;
}

.progress-track {
  height: 8px;
  margin-top: 14px;
  overflow: hidden;
  background: rgb(255 255 255 / 18%);
  border-radius: 999px;
}

.progress-fill {
  width: 0;
  height: 100%;
  background: #f1a57f;
  border-radius: inherit;
  transition: width 220ms ease;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 64px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.panel-header h2 {
  margin: 0;
  font-size: 18px;
}

.panel-header p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
}

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

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.data-table th,
.data-table td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

.data-table th {
  color: var(--muted);
  background: var(--surface-soft);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.data-table tbody tr:last-child td {
  border-bottom: 0;
}

.data-table tbody tr:hover td {
  background: #f8faf9;
}

.lesson-date {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.number-cell {
  font-variant-numeric: tabular-nums;
  font-weight: 750;
}

.number-cell.is-positive {
  color: var(--brand);
}

.empty-row {
  padding: 34px 18px !important;
  color: var(--muted);
  text-align: center !important;
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
}

.checkbox-label input {
  width: 17px;
  height: 17px;
  accent-color: var(--brand);
}

.disclaimer {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.teacher-toolbar {
  position: sticky;
  z-index: 5;
  top: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 12px;
  background: rgb(237 242 239 / 96%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 8px 18px rgb(23 35 31 / 6%);
}

.lesson-controls {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 8px;
}

.lesson-controls select {
  min-width: 0;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  min-width: 42px;
  height: 42px;
  padding: 0;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  cursor: pointer;
  font-size: 20px;
  font-weight: 700;
}

.icon-button:hover {
  color: var(--brand);
  border-color: var(--brand);
}

.toolbar-actions {
  display: flex;
  gap: 8px;
}

.segmented {
  display: inline-flex;
  padding: 3px;
  background: #dfe7e3;
  border-radius: 6px;
}

.segmented button {
  min-height: 36px;
  padding: 6px 14px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 700;
}

.segmented button[aria-selected="true"] {
  color: var(--brand-dark);
  background: var(--surface);
  box-shadow: 0 1px 4px rgb(23 35 31 / 12%);
}

.teacher-content {
  margin-top: 18px;
}

.session-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-top: 3px solid var(--accent);
  border-radius: var(--radius);
}

.session-kicker {
  color: var(--accent);
  font-size: 13px;
  font-weight: 750;
}

.session-banner h2 {
  margin: 5px 0 0;
  font-size: 23px;
  line-height: 1.3;
}

.session-banner p {
  margin: 5px 0 0;
  color: var(--muted);
}

.session-metrics {
  display: flex;
  gap: 24px;
  text-align: right;
}

.session-metric strong {
  display: block;
  color: var(--brand);
  font-size: 24px;
  line-height: 1;
}

.session-metric span {
  color: var(--muted);
  font-size: 12px;
}

.entry-panel {
  margin-top: 14px;
  overflow: hidden;
}

.entry-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.entry-tools .search-input {
  max-width: 360px;
}

.student-list {
  display: grid;
}

.student-row {
  display: grid;
  grid-template-columns:
    42px minmax(160px, 1fr) minmax(112px, 0.5fr)
    minmax(132px, 0.55fr) 132px;
  gap: 14px;
  align-items: center;
  min-height: 76px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.student-row:last-child {
  border-bottom: 0;
}

.student-order {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.student-name {
  display: block;
  font-size: 16px;
  font-weight: 750;
}

.student-id {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.count-display {
  display: flex;
  align-items: baseline;
  gap: 7px;
}

.count-display strong {
  min-width: 28px;
  font-size: 25px;
  line-height: 1;
}

.count-display span {
  color: var(--muted);
  font-size: 12px;
}

.credit-label {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 9px;
  color: var(--brand);
  background: var(--brand-soft);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 750;
}

.credit-label.is-maxed {
  color: var(--warning);
  background: #f6ecd4;
}

.count-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.count-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 42px;
  padding: 0;
  border-radius: 5px;
  cursor: pointer;
  font-size: 22px;
  font-weight: 700;
}

.count-button.minus {
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line-strong);
}

.count-button.plus {
  color: #ffffff;
  background: var(--brand);
  border: 1px solid var(--brand);
}

.count-button:hover {
  border-color: var(--brand-dark);
}

.count-button.plus:hover {
  background: var(--brand-dark);
}

.count-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.summary-panel {
  overflow: hidden;
}

.summary-panel .panel-header {
  flex-wrap: wrap;
}

.summary-table {
  min-width: 1900px;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
}

.summary-table th,
.summary-table td {
  min-width: 66px;
  padding: 9px 8px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  text-align: center;
  white-space: nowrap;
}

.summary-table thead th {
  position: sticky;
  z-index: 3;
  top: 0;
  color: var(--muted);
  background: var(--surface-soft);
}

.summary-table thead tr:nth-child(2) th {
  top: 42px;
  font-size: 11px;
  font-weight: 500;
}

.summary-table .student-column {
  position: sticky;
  z-index: 2;
  left: 0;
  min-width: 118px;
  text-align: left;
  background: var(--surface);
}

.summary-table thead .student-column {
  z-index: 4;
  background: var(--surface-soft);
}

.summary-table .id-column {
  position: sticky;
  z-index: 2;
  left: 118px;
  min-width: 120px;
  text-align: left;
  background: var(--surface);
}

.summary-table thead .id-column {
  z-index: 4;
  background: var(--surface-soft);
}

.summary-table .total-column {
  color: var(--brand-dark);
  background: #edf7f4;
  font-weight: 750;
}

.summary-table tbody tr:hover td {
  background: #f7faf8;
}

.summary-table tbody tr:hover .student-column,
.summary-table tbody tr:hover .id-column {
  background: #f7faf8;
}

.grade-panel {
  overflow: hidden;
}

.grade-panel-header {
  flex-wrap: wrap;
}

.grade-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 9px;
  flex-wrap: wrap;
}

.grade-actions select {
  min-width: 260px;
  min-height: 42px;
  padding: 8px 10px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 5px;
}

.grade-status-line {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 18px;
  background: var(--surface-soft);
  border-bottom: 1px solid var(--line);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 27px;
  padding: 4px 9px;
  color: var(--warning);
  background: #f6ecd4;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 750;
  white-space: nowrap;
}

.status-pill.is-published {
  color: var(--brand);
  background: var(--brand-soft);
}

.grade-table {
  width: 100%;
  min-width: 880px;
  border-collapse: collapse;
}

.grade-table th,
.grade-table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

.grade-table th {
  color: var(--muted);
  background: var(--surface-soft);
  font-size: 12px;
  white-space: nowrap;
}

.grade-table tbody tr:last-child td {
  border-bottom: 0;
}

.grade-table .grade-input {
  width: 96px;
  min-height: 38px;
  padding: 7px 8px;
  color: var(--ink);
  background: #fbfcfb;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
}

.grade-table .feedback-input {
  width: min(360px, 32vw);
  min-height: 38px;
  padding: 7px 9px;
  color: var(--ink);
  background: #fbfcfb;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
}

.grade-table .grade-input:focus,
.grade-table .feedback-input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgb(20 95 87 / 13%);
  outline: none;
}

.save-state {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.save-state.is-saving {
  color: var(--warning);
}

.save-state.is-saved {
  color: var(--brand);
  font-weight: 700;
}

.save-state.is-error {
  color: var(--danger);
  font-weight: 700;
}

.grade-detail-panel {
  margin-top: 14px;
  overflow: hidden;
}

.grade-detail-body {
  display: grid;
  gap: 20px;
  padding: 18px;
}

.grade-detail-section h3 {
  margin: 0 0 10px;
  font-size: 16px;
}

.exam-summary {
  padding: 16px;
  color: var(--muted);
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.exam-result-grid {
  display: grid;
  grid-template-columns:
    repeat(2, minmax(130px, 0.4fr))
    minmax(200px, 1fr);
  gap: 16px;
}

.exam-result-grid > div {
  display: grid;
  gap: 4px;
}

.exam-result-grid span {
  color: var(--muted);
  font-size: 12px;
}

.exam-result-grid strong {
  font-size: 17px;
}

.exam-feedback strong {
  font-weight: 600;
}

.dialog {
  width: min(760px, calc(100% - 28px));
  max-height: min(760px, calc(100vh - 40px));
  padding: 0;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: 0 24px 70px rgb(16 63 58 / 24%);
}

.dialog::backdrop {
  background: rgb(16 35 31 / 55%);
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.dialog-header h2 {
  margin: 0;
  font-size: 20px;
}

.dialog-body {
  max-height: 540px;
  padding: 20px;
  overflow: auto;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--line);
}

.code-list {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.code-list th,
.code-list td {
  padding: 9px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

.code-list th {
  color: var(--muted);
  font-size: 12px;
}

.access-code {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 15px;
  font-weight: 750;
  letter-spacing: 1px;
}

.toast {
  position: fixed;
  z-index: 50;
  right: 18px;
  bottom: 18px;
  max-width: min(420px, calc(100% - 36px));
  padding: 13px 16px;
  color: #ffffff;
  background: var(--brand-dark);
  border-left: 4px solid #f1a57f;
  border-radius: 5px;
  box-shadow: var(--shadow);
}

.toast.is-error {
  background: #772525;
  border-left-color: #ffc7c7;
}

.skeleton {
  color: var(--muted);
  text-align: center;
}

@media (max-width: 900px) {
  .login-layout {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .login-intro {
    padding: 32px 0 6px;
  }

  .form-panel {
    align-self: auto;
  }

  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .teacher-toolbar {
    grid-template-columns: 1fr;
  }

  .toolbar-actions {
    justify-content: space-between;
  }

  .student-row {
    grid-template-columns: 36px minmax(120px, 1fr) 104px 108px;
  }

  .student-row .credit-column {
    display: none;
  }

  .session-banner {
    align-items: flex-start;
    flex-direction: column;
  }

  .session-metrics {
    width: 100%;
    justify-content: flex-start;
    text-align: left;
  }

  .grade-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .grade-actions select {
    width: 100%;
    min-width: 0;
  }

  .grade-table .feedback-input {
    width: 260px;
  }

  .exam-result-grid {
    grid-template-columns: 1fr 1fr;
  }

  .exam-feedback {
    grid-column: 1 / -1;
  }
}

@media (max-width: 620px) {
  .site-header-inner,
  .page,
  .page-narrow {
    width: min(100% - 22px, 1180px);
  }

  .site-header-inner {
    min-height: 66px;
  }

  .brand-subtitle,
  .user-label {
    display: none;
  }

  .page {
    padding-top: 20px;
  }

  .login-intro h1 {
    font-size: 34px;
  }

  .rule-list {
    grid-template-columns: 1fr;
  }

  .rule-item {
    display: flex;
    align-items: baseline;
    gap: 8px;
  }

  .form-panel {
    padding: 22px;
  }

  .page-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .page-heading h1 {
    font-size: 27px;
  }

  .summary-grid {
    grid-template-columns: 1fr 1fr;
  }

  .summary-item {
    min-height: 98px;
    padding: 14px;
  }

  .summary-item.primary {
    grid-column: 1 / -1;
  }

  .summary-value {
    font-size: 26px;
  }

  .teacher-toolbar {
    position: static;
  }

  .lesson-controls {
    grid-template-columns: 38px minmax(0, 1fr) 38px;
  }

  .icon-button {
    width: 38px;
    min-width: 38px;
    height: 40px;
  }

  .toolbar-actions {
    flex-wrap: wrap;
  }

  .entry-tools {
    align-items: stretch;
    flex-direction: column;
  }

  .entry-tools .search-input {
    max-width: none;
  }

  .student-row {
    grid-template-columns: 30px minmax(0, 1fr) 66px 94px;
    gap: 8px;
    min-height: 70px;
    padding: 10px;
  }

  .count-display span {
    display: none;
  }

  .count-actions {
    gap: 6px;
  }

  .count-button {
    width: 42px;
  }

  .session-metrics {
    gap: 16px;
  }

  .session-metric strong {
    font-size: 21px;
  }

  .summary-table .id-column {
    display: none;
  }

  .grade-status-line {
    align-items: flex-start;
    flex-direction: column;
  }

  .grade-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .grade-actions .button {
    width: 100%;
  }

  .grade-detail-body {
    padding: 14px;
  }

  .exam-result-grid {
    grid-template-columns: 1fr;
  }

  .exam-feedback {
    grid-column: auto;
  }
}
