:root {
  color-scheme: light;
  --ink: #183d3b;
  --muted: #697774;
  --paper: #f5f4ef;
  --surface: #fffefa;
  --line: #d9dfd8;
  --teal: #176c63;
  --teal-dark: #10574f;
  --coral: #c76349;
  --gold: #e6b95d;
  --shadow: 0 14px 40px rgb(24 61 59 / 8%);
  font-family: "DM Sans", sans-serif;
  color: var(--ink);
  background: var(--paper);
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: var(--paper); }
button, input, select { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.auth-screen { min-height: 100vh; display: grid; place-items: center; padding: 28px 18px; background: radial-gradient(ellipse at 12% 10%, #e7ece3 0, transparent 38%), var(--paper); }
.auth-panel { width: min(100%, 440px); padding: 34px clamp(24px, 7vw, 46px) 38px; background: var(--surface); border: 1px solid var(--line); border-top: 5px solid var(--teal); box-shadow: var(--shadow); }
.auth-logo { display: block; width: 100px; height: 100px; margin: 0 auto 18px; object-fit: contain; }
.eyebrow { margin: 0 0 8px; color: var(--coral); font-size: 11px; font-weight: 700; letter-spacing: 1.2px; text-transform: uppercase; }
.auth-panel .eyebrow, .auth-panel h1 { text-align: center; }
h1, h2 { margin: 0; }
h1, .auth-panel h1 { font-family: "DM Serif Display", Georgia, serif; font-weight: 400; }
.auth-panel h1 { font-size: 30px; }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin: 26px 0 22px; padding: 4px; background: #edf0e9; }
.auth-tab { min-height: 40px; border: 0; color: var(--muted); background: transparent; font-size: 13px; font-weight: 700; }
.auth-tab.is-active { color: var(--ink); background: var(--surface); box-shadow: 0 1px 4px rgb(24 61 59 / 12%); }
.auth-form { display: grid; gap: 9px; }
.auth-form label, .field label { margin-top: 5px; font-size: 12px; font-weight: 700; }
.auth-form input, .field input, .field select, .filter-form input, .grade-input { width: 100%; min-height: 43px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 3px; color: var(--ink); background: white; }
.account-type { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 5px 0 0; padding: 0; border: 0; }
.account-type legend { margin-bottom: 7px; padding: 0; font-size: 12px; font-weight: 700; }
.auth-form .account-type label { display: flex; align-items: center; gap: 8px; min-height: 43px; margin: 0; padding: 0 12px; border: 1px solid var(--line); border-radius: 3px; background: white; font-weight: 600; cursor: pointer; }
.auth-form .account-type label:has(input:checked) { border-color: var(--teal); box-shadow: inset 0 0 0 1px var(--teal); }
.auth-form .account-type input { width: auto; min-height: 0; margin: 0; accent-color: var(--teal); }
#teacher-code-field { display: grid; gap: 9px; }
#teacher-code-field[hidden] { display: none; }
input:focus, select:focus { outline: 2px solid rgb(23 108 99 / 24%); border-color: var(--teal); }
.button { min-height: 39px; padding: 9px 14px; border: 1px solid transparent; border-radius: 3px; font-size: 12px; font-weight: 700; transition: background .15s ease, border-color .15s ease, transform .15s ease; }
.button:active { transform: translateY(1px); }
.button-primary { color: white; background: var(--teal); }
.button-primary:hover { background: var(--teal-dark); }
.auth-form .button { min-height: 45px; margin-top: 12px; }
.button-dark { color: white; background: var(--ink); }
.button-dark:hover { background: #285754; }
.button-quiet { color: var(--ink); background: #e6ece4; }
.button-outline { color: var(--ink); border-color: var(--line); background: transparent; }
.button-text { color: var(--teal-dark); background: transparent; }
.button-export { color: white; background: var(--coral); }
.button-export:hover { background: #a94e38; }
.form-note, .config-help { margin: 8px 0 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.config-help { padding: 12px; border-left: 3px solid var(--gold); background: #fbf5e8; }
.config-help code { font-size: 11px; }

.topbar { min-height: 78px; padding: 10px max(22px, calc((100vw - 1240px) / 2)); display: flex; align-items: center; justify-content: space-between; gap: 20px; color: white; background: var(--ink); }
.brand { display: inline-flex; align-items: center; gap: 12px; color: white; text-decoration: none; font-size: 14px; font-weight: 700; }
.brand img { width: 48px; height: 48px; padding: 3px; object-fit: contain; background: white; }
.topbar-actions { display: flex; align-items: center; justify-content: flex-end; gap: 9px; }
.account-label { margin-right: 8px; color: #d4e1da; font-size: 12px; }
.topbar .button-outline { color: white; border-color: #63817a; }
.workspace { width: min(1240px, 100%); margin: 0 auto; padding: 38px 28px 64px; }
.page-heading { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 24px; }
.page-heading h1 { font-size: 42px; }
.role-label { margin: 0 0 4px; color: var(--muted); font-size: 12px; }
.home-grid { display: grid; grid-template-columns: minmax(280px, 0.72fr) minmax(0, 1.5fr); gap: 28px; align-items: start; }
.entry-panel, .users-panel { padding: 24px; border: 1px solid var(--line); background: var(--surface); box-shadow: 0 8px 22px rgb(24 61 59 / 4%); }
.entry-panel h2, .section-heading h2 { font-size: 19px; }
.entry-panel h2 { margin-bottom: 20px; }
.test-form { display: grid; grid-template-columns: 1fr 1fr; gap: 13px 14px; }
.field { display: flex; min-width: 0; flex-direction: column; gap: 7px; }
.field-wide { grid-column: 1 / -1; }
.field input, .field select { min-height: 41px; font-size: 13px; }
.label-hint { color: var(--muted); font-size: 11px; font-weight: 400; }
.records-panel { min-width: 0; }
.section-heading { min-height: 68px; margin: 0 0 18px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.record-count { min-width: 34px; padding: 7px 10px; color: var(--teal-dark); background: #e2eee7; text-align: center; font-size: 12px; font-weight: 700; }
.toolbar { min-height: 42px; margin-bottom: 14px; display: flex; flex-wrap: wrap; align-items: center; gap: 7px; }
.filter-form { display: flex; gap: 6px; flex: 1 1 260px; }
.filter-form input { min-width: 120px; min-height: 39px; font-size: 12px; }
.filter-form .button { flex: 0 0 auto; }
.test-list { display: grid; gap: 9px; }
.test-item { display: grid; grid-template-columns: minmax(120px, 1.1fr) minmax(110px, 1fr) minmax(150px, auto); align-items: center; gap: 12px; padding: 14px 15px; border-left: 3px solid var(--gold); background: #fffefa; box-shadow: 0 2px 9px rgb(24 61 59 / 5%); }
.student-name { display: block; margin-bottom: 4px; color: var(--ink); font-size: 14px; font-weight: 700; overflow-wrap: anywhere; }
.student-meta, .test-date { color: var(--muted); font-size: 11px; line-height: 1.5; }
.grade-area { display: flex; justify-content: flex-end; align-items: center; gap: 7px; }
.grade-input { width: 82px; min-height: 36px; padding: 7px 8px; font-size: 12px; }
.grade-button { min-height: 36px; padding: 7px 9px; color: white; background: var(--teal); font-size: 11px; }
.empty-state { padding: 28px 14px; color: var(--muted); background: #eeefe9; text-align: center; font-size: 13px; }
.users-panel { padding: 0 22px; }
.user-table-head, .user-row { display: grid; grid-template-columns: 1fr 0.6fr 1fr; align-items: center; gap: 16px; }
.user-table-head { min-height: 46px; color: var(--muted); border-bottom: 1px solid var(--line); font-size: 11px; font-weight: 700; text-transform: uppercase; }
.user-row { min-height: 60px; border-bottom: 1px solid #e9ece6; font-size: 13px; }
.user-row:last-child { border-bottom: 0; }
.user-row form { display: flex; gap: 8px; }
.user-row select { min-width: 110px; padding: 7px 8px; border: 1px solid var(--line); border-radius: 3px; background: white; font-size: 12px; }
.user-row .button { min-height: 34px; padding: 7px 10px; }
.notice { position: fixed; z-index: 5; top: 16px; left: 50%; width: min(600px, calc(100% - 28px)); padding: 13px 16px; transform: translateX(-50%); border: 1px solid var(--line); border-left: 4px solid var(--teal); background: var(--surface); box-shadow: var(--shadow); color: var(--ink); font-size: 13px; }
.notice.is-error { border-left-color: var(--coral); }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@media (max-width: 820px) {
  .workspace { padding: 28px 18px 48px; }
  .home-grid { grid-template-columns: 1fr; gap: 30px; }
  .entry-panel { max-width: 620px; }
}
@media (max-width: 560px) {
  .topbar { min-height: 68px; padding: 9px 14px; }
  .brand { gap: 8px; font-size: 12px; }
  .brand img { width: 40px; height: 40px; }
  .topbar-actions { gap: 5px; }
  .account-label { display: none; }
  .topbar .button { padding: 8px 9px; font-size: 11px; }
  .workspace { padding: 24px 14px 40px; }
  .page-heading { align-items: start; flex-direction: column; gap: 10px; }
  .page-heading h1 { font-size: 32px; }
  .entry-panel { padding: 19px 16px; }
  .test-form { grid-template-columns: 1fr; }
  .field-wide { grid-column: auto; }
  .test-item { grid-template-columns: 1fr auto; gap: 7px 12px; }
  .test-item .grade-area { grid-column: 1 / -1; justify-content: flex-start; }
  .test-date { text-align: right; }
  .toolbar { align-items: stretch; }
  .filter-form { flex-basis: 100%; }
  .users-panel { padding: 0 12px; }
  .user-table-head, .user-row { grid-template-columns: 1fr auto; gap: 8px; }
  .user-table-head span:nth-child(2), .user-row > .current-role { display: none; }
  .user-row form { justify-content: flex-end; }
}