:root {
  --ink: #14213d;
  --ink-soft: #4a5672;
  --paper: #eef1f5;
  --card: #ffffff;
  --line: #d5dbe5;
  --bus: #f2b705;
  --danger: #b3261e;
  --ok: #1f7a4d;
  --radius: 6px;
  --serif: Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--paper);
  line-height: 1.5;
}

h1, h2, h3 { font-family: var(--serif); font-weight: 700; margin: 0; }
button, input, textarea, select { font: inherit; color: inherit; }

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

/* ---------- auth ---------- */

.auth {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.auth-side {
  background: var(--ink);
  color: #fff;
  padding: 56px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  border-right: 10px solid var(--bus);
}

.auth-side h1 { font-size: clamp(2.4rem, 5vw, 4rem); line-height: 1.05; max-width: 10ch; }
.auth-side p { color: #c3cbdc; max-width: 34ch; margin: 16px 0 0; }

.auth-main { display: grid; place-items: center; padding: 32px; }

.auth-card { width: 100%; max-width: 380px; }
.auth-card h2 { font-size: 1.7rem; margin-bottom: 20px; }

.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: .9rem; font-weight: 600; margin-bottom: 4px; }

input, textarea, select {
  width: 100%;
  padding: 10px 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

textarea { min-height: 84px; resize: vertical; }

.role-pick { display: flex; gap: 8px; margin-bottom: 14px; }
.role-pick label {
  flex: 1;
  text-align: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  cursor: pointer;
  font-weight: 600;
}
.role-pick input { position: absolute; opacity: 0; width: 0; }
.role-pick label:has(input:checked) { background: var(--ink); color: #fff; border-color: var(--ink); }
.role-pick label:has(input:focus-visible) { outline: 3px solid var(--bus); outline-offset: 2px; }

.btn {
  display: inline-block;
  padding: 10px 18px;
  border: 0;
  border-radius: var(--radius);
  background: var(--ink);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { background: #0d1630; }
.btn.block { width: 100%; }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn.ghost:hover { background: #fff; }
.btn.small { padding: 5px 10px; font-size: .85rem; }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--line); }
.btn.danger:hover { background: #fdecea; }

.switch { margin-top: 18px; color: var(--ink-soft); font-size: .95rem; }
.link { background: none; border: 0; padding: 0; color: var(--ink); font-weight: 600; text-decoration: underline; cursor: pointer; }

.error { color: var(--danger); font-size: .92rem; min-height: 1.4em; margin: 0 0 10px; }

/* ---------- app shell ---------- */

.topbar {
  background: var(--ink);
  color: #fff;
  border-bottom: 4px solid var(--bus);
}
.topbar-inner {
  max-width: 980px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand { font-family: var(--serif); font-size: 1.3rem; font-weight: 700; }
.who { display: flex; align-items: center; gap: 12px; font-size: .92rem; }
.who .role { color: #c3cbdc; }
.topbar .btn.ghost { color: #fff; border-color: #44527a; }
.topbar .btn.ghost:hover { background: #1f2f55; }

main { max-width: 980px; margin: 0 auto; padding: 28px 20px 60px; }
main > h2 { font-size: 1.8rem; margin-bottom: 20px; }

/* owner tabs double as the summary */
.tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0; margin-bottom: 24px; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--card); }
.tab {
  text-align: left;
  padding: 16px 20px;
  background: var(--card);
  border: 0;
  border-right: 1px solid var(--line);
  cursor: pointer;
  border-bottom: 4px solid transparent;
}
.tab:last-child { border-right: 0; }
.tab .n { display: block; font-family: var(--serif); font-size: 2rem; font-weight: 700; line-height: 1.1; }
.tab .l { color: var(--ink-soft); font-size: .92rem; }
.tab[aria-selected="true"] { border-bottom-color: var(--bus); background: #fffaf0; }

.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.panel + .panel { margin-top: 20px; }
.panel-head { padding: 14px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.panel-head h3 { font-size: 1.15rem; }
.panel-body { padding: 20px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 20px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .85rem; color: var(--ink-soft); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
td.actions { text-align: right; white-space: nowrap; }

.list { list-style: none; margin: 0; padding: 0; }
.item { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 16px; }
.item:last-child { border-bottom: 0; }
.item h4 { margin: 0 0 2px; font-size: 1.05rem; font-family: var(--serif); }
.item p { margin: 4px 0 0; color: var(--ink-soft); white-space: pre-wrap; }
.meta { color: var(--ink-soft); font-size: .88rem; }
.due { display: inline-block; margin-top: 6px; padding: 2px 8px; border-radius: 99px; background: #fff3cc; font-size: .82rem; font-weight: 600; }
.due.late { background: #fdecea; color: var(--danger); }

.empty { padding: 28px 20px; color: var(--ink-soft); }

.form-grid { display: grid; grid-template-columns: 1fr 180px; gap: 14px; }
.form-grid .wide { grid-column: 1 / -1; }

#toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 20px);
  background: var(--ink);
  color: #fff;
  padding: 10px 18px;
  border-radius: var(--radius);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 760px) {
  .auth { grid-template-columns: 1fr; }
  .auth-side { padding: 28px; border-right: 0; border-bottom: 10px solid var(--bus); justify-content: flex-start; }
  .auth-side h1 { font-size: 2.2rem; max-width: none; }
  .tabs { grid-template-columns: 1fr; }
  .tab { border-right: 0; border-bottom: 1px solid var(--line); }
  .form-grid { grid-template-columns: 1fr; }
  th:nth-child(3), td:nth-child(3) { display: none; }
  .who .name { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  #toast { transition: none; }
}

/* ---------- v2: nav, stats, cards, admin ---------- */
.who-link { color: #fff; text-decoration: none; }
.who-link:hover { text-decoration: underline; }
.nav { background: #1b2c52; }
.nav-inner { max-width: 980px; margin: 0 auto; padding: 0 20px; display: flex; gap: 4px; overflow-x: auto; }
.nav a { color: #c3cbdc; text-decoration: none; padding: 10px 14px; font-weight: 600; font-size: .95rem; border-bottom: 3px solid transparent; white-space: nowrap; }
.nav a:hover { color: #fff; }
.nav a[aria-current="page"] { color: #fff; border-bottom-color: var(--bus); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); margin-bottom: 20px; overflow: hidden; }
.stat { padding: 16px 20px; text-decoration: none; color: inherit; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.stat:nth-child(3n) { border-right: 0; }
.stat:nth-last-child(-n+3) { border-bottom: 0; }
.stat:hover { background: #fffaf0; }
.stat .n { display: block; font-family: var(--serif); font-size: 2rem; font-weight: 700; line-height: 1.1; }
.stat .l { color: var(--ink-soft); font-size: .92rem; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; margin-top: 20px; }
.card { display: block; background: var(--card); border: 1px solid var(--line); border-top: 4px solid var(--bus); border-radius: var(--radius); padding: 16px 18px; text-decoration: none; color: inherit; }
.card:hover { border-color: var(--ink); border-top-color: var(--bus); }
.card h4 { font-family: var(--serif); font-size: 1.15rem; margin: 0 0 4px; }
.card-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; font-size: .9rem; color: var(--ink-soft); }
.code { font-family: ui-monospace, Menlo, Consolas, monospace; background: #fff3cc; padding: 2px 8px; border-radius: 4px; font-weight: 700; letter-spacing: .08em; color: var(--ink); }
.code.big { font-size: 1.6rem; padding: 4px 14px; }

.class-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.class-head h2 { font-size: 1.8rem; }
.joinbox { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.crumb { margin: 0 0 12px; }
.crumb a { color: var(--ink-soft); text-decoration: none; font-weight: 600; }
.crumb a:hover { color: var(--ink); text-decoration: underline; }
.danger-zone { margin-top: 24px; text-align: right; }

.item.col { flex-direction: column; }
.row-actions { display: flex; gap: 8px; }
.status { margin-top: 4px; }
.chip { display: inline-block; padding: 2px 10px; border-radius: 99px; background: #e4e9f2; font-size: .82rem; font-weight: 600; }
.chip.ok { background: #dcf3e6; color: var(--ok); }
.chip.warn { background: #fdecea; color: var(--danger); }
.feedback { margin: 6px 0 0; }
.submit summary { cursor: pointer; font-weight: 600; padding: 4px 0; }
.submit form { margin-top: 8px; }
.submit textarea { margin-bottom: 8px; }

.subs:empty { display: none; }
.subs { border-top: 1px solid var(--line); margin-top: 4px; }
.sub { padding: 12px 0; border-bottom: 1px solid var(--line); }
.sub:last-child { border-bottom: 0; }
.sub-head { display: flex; gap: 12px; align-items: center; }
.answer { background: var(--paper); padding: 10px 12px; border-radius: var(--radius); margin: 8px 0; white-space: pre-wrap; }
.grade { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.grade label { display: flex; gap: 6px; align-items: center; white-space: nowrap; }
.grade input[name="score"] { width: 80px; }
.grade input[name="feedback"] { flex: 1; min-width: 160px; width: auto; }
.grade .error { margin: 0; min-height: 0; }

.form-grid.three { grid-template-columns: 1fr 180px 110px; }
.form-grid.four { grid-template-columns: 1fr 1fr 1fr 150px; }
.inline { display: flex; gap: 12px; align-items: flex-end; }
.inline .field { margin: 0; flex: 1; max-width: 320px; }
.pad { padding: 0 20px 12px; margin: 0; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filters input { width: 220px; }
.filters select { width: auto; }
.scroll { overflow-x: auto; }
td select { width: auto; padding: 6px 8px; }
td.actions { display: table-cell; }
td.actions .btn { margin-left: 4px; }

@media (max-width: 760px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .stat:nth-child(3n) { border-right: 1px solid var(--line); }
  .stat:nth-child(2n) { border-right: 0; }
  .stat:nth-last-child(-n+3) { border-bottom: 1px solid var(--line); }
  .stat:nth-last-child(-n+2) { border-bottom: 0; }
  .form-grid.three, .form-grid.four { grid-template-columns: 1fr; }
  .inline { flex-direction: column; align-items: stretch; }
  .who-link { display: none; }
  th:nth-child(3), td:nth-child(3) { display: table-cell; }
}
