:root {
  --ink: #1f2937;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --page-max: 1180px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: #eef4ff; }
body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  color: var(--ink);
  font-family: "DM Sans", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 8% 8%, rgba(96, 165, 250, 0.18), transparent 32rem),
    radial-gradient(circle at 92% 16%, rgba(167, 139, 250, 0.17), transparent 30rem),
    linear-gradient(135deg, #eff6ff, #ffffff 52%, #f5f3ff);
}
button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
html.modal-open { overflow: hidden; }
body.modal-open {
  position: fixed;
  width: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}
.site-shell {
  width: min(100%, var(--page-max));
  min-height: 100vh;
  min-height: 100dvh;
  margin-inline: auto;
  padding: clamp(16px, 3vw, 32px);
}
.screen { display: none; }
.screen.active { display: block; }
.hidden { display: none !important; }
.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.loading-panel {
  min-height: 68vh;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 16px;
  color: var(--muted);
}
.spinner {
  width: 44px;
  aspect-ratio: 1;
  border: 4px solid #bfdbfe;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.home-panel {
  min-height: calc(100vh - 64px);
  min-height: calc(100dvh - 64px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding-block: 42px;
}
.hero-icons {
  margin-bottom: 12px;
  font-size: clamp(32px, 7vw, 48px);
  letter-spacing: 0.14em;
}
h1, h2, p { margin-top: 0; }
h1 {
  margin-bottom: 8px;
  color: #1e3a5f;
  font-size: clamp(34px, 7vw, 48px);
  line-height: 1.05;
}
.subtitle {
  max-width: 560px;
  margin-bottom: 34px;
  color: var(--muted);
  font-size: clamp(15px, 3vw, 18px);
}
.class-grid {
  width: min(100%, 600px);
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}
.class-button {
  min-height: 92px;
  border: 2px solid #bfdbfe;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.88);
  color: #1d4ed8;
  font-size: clamp(18px, 4vw, 22px);
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 8px 30px rgba(37, 99, 235, 0.06);
  transition: transform 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}
.class-button:hover {
  transform: translateY(-3px);
  border-color: #60a5fa;
  box-shadow: 0 14px 34px rgba(37, 99, 235, 0.14);
}
.class-button:focus-visible,
.icon-button:focus-visible,
.primary-button:focus-visible,
.house-filter:focus-visible,
.student-card:focus-visible,
.dialog-close:focus-visible,
.search-box:focus-within {
  outline: 3px solid rgba(37, 99, 235, 0.28);
  outline-offset: 3px;
}
.primary-button {
  border: 0;
  border-radius: 14px;
  background: var(--primary);
  color: white;
  font-weight: 700;
  cursor: pointer;
  transition: background 160ms ease, transform 160ms ease;
}
.primary-button:hover { background: var(--primary-dark); transform: translateY(-1px); }
.primary-button:disabled, .icon-button:disabled { cursor: wait; opacity: 0.58; }
.refresh-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 28px;
  padding: 11px 20px;
}
.status-message {
  width: min(100%, 600px);
  margin-bottom: 20px;
  padding: 12px 14px;
  border-radius: 14px;
  text-align: left;
  font-size: 14px;
}
.status-message.error { border: 1px solid #fecaca; background: #fff1f2; color: #b91c1c; }

.students-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}
.title-row, .toolbar { display: flex; align-items: center; gap: 12px; }
.eyebrow {
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
#class-title { margin-bottom: 0; font-size: clamp(26px, 6vw, 34px); }
.icon-button {
  width: 42px;
  height: 42px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  border: 1px solid #dbeafe;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.92);
  color: #334155;
  font-size: 20px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.06);
}
.primary-icon { border-color: var(--primary); background: var(--primary); color: white; }
.search-box {
  min-width: min(64vw, 280px);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 13px;
  border: 1px solid #cbd5e1;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.95);
  color: var(--muted);
}
.search-box input {
  width: 100%;
  padding: 11px 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
}
.house-filters { display: flex; flex-wrap: wrap; gap: 9px; margin-bottom: 14px; }
.house-filter {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 13px;
  border: 2px solid var(--house-color);
  border-radius: 999px;
  background: var(--house-bg);
  color: var(--house-color);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 150ms ease, box-shadow 150ms ease;
}
.house-filter.active {
  background: var(--house-color);
  color: white;
  transform: translateY(-1px);
  box-shadow: 0 7px 18px rgba(15, 23, 42, 0.12);
}
.house-filter .filter-icon { font-size: 17px; line-height: 1; }
.legend { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 22px; color: var(--muted); font-size: 12px; }
.legend-divider { color: #cbd5e1; }
.student-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }

.student-card {
  --theme-color: #6366f1;
  --theme-bg: #eef2ff;
  position: relative;
  min-width: 0;
  overflow: hidden;
  padding: 16px;
  border: 2px solid var(--theme-color);
  border-radius: 26px;
  background: linear-gradient(135deg, var(--theme-bg) 0%, #ffffff 55%, var(--theme-bg) 100%);
  color: inherit;
  text-align: left;
  cursor: pointer;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.07);
  transition: transform 170ms ease, box-shadow 170ms ease;
}
.student-card:hover { transform: translateY(-4px); box-shadow: 0 16px 35px rgba(15, 23, 42, 0.12); }
.student-card::before, .student-card::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
  background: var(--theme-color);
}
.student-card::before { width: 92px; height: 92px; top: -38px; right: -34px; opacity: 0.17; }
.student-card::after { width: 116px; height: 116px; bottom: -56px; left: -48px; opacity: 0.08; }
.card-content { position: relative; z-index: 1; }
.card-top, .student-identity { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.card-top { margin-bottom: 14px; }
.number-badge, .total-badge, .house-icon, .task-panel {
  border: 1px solid rgba(255, 255, 255, 0.8);
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 5px 16px rgba(15, 23, 42, 0.06);
  backdrop-filter: blur(5px);
}
.number-badge { padding: 5px 10px; border-radius: 999px; color: var(--theme-color); font-size: 12px; font-weight: 800; }
.total-badge { min-width: 48px; padding: 6px 11px; border-radius: 14px; color: var(--theme-color); text-align: center; font-size: 18px; font-weight: 800; }
.student-identity { justify-content: flex-start; align-items: center; margin-bottom: 13px; }
.house-icon {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 14px;
  font-size: 21px;
}
.student-text { min-width: 0; }
.student-name { margin: 0 0 2px; overflow: hidden; color: #1f2937; font-size: 14px; font-weight: 800; text-overflow: ellipsis; white-space: nowrap; }
.student-house { margin: 0; color: var(--theme-color); font-size: 12px; font-weight: 700; }
.task-panel { padding: 9px; border-radius: 16px; }
.task-chips { display: flex; flex-wrap: wrap; gap: 5px; }
.task-chip { display: inline-flex; align-items: center; gap: 4px; padding: 4px 7px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.task-chip.submitted { background: #ecfdf5; color: #047857; }
.task-chip.missing { background: #fff1f2; color: #be123c; }
.empty-state { padding: 48px 0; color: var(--muted); text-align: center; }

.detail-overlay {
  --viewport-width: 100vw;
  --viewport-height: 100dvh;
  --viewport-top: 0px;
  --viewport-left: 0px;
  position: fixed !important;
  z-index: 10000;
  top: var(--viewport-top);
  left: var(--viewport-left);
  width: var(--viewport-width);
  height: var(--viewport-height);
  display: grid;
  place-items: center;
  padding:
    max(12px, env(safe-area-inset-top))
    max(12px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
  overflow: hidden;
  isolation: isolate;
}

.detail-overlay[hidden] {
  display: none !important;
}

.detail-backdrop {
  position: absolute;
  z-index: 0;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  background: rgba(15, 23, 42, 0.48);
  backdrop-filter: blur(2px);
  cursor: default;
}

.detail-modal {
  position: relative;
  z-index: 1;
  width: min(100%, 450px);
  max-height: calc(var(--viewport-height) - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 24px;
  border-radius: 28px;
  background: white;
  box-shadow: 0 24px 80px rgba(15, 23, 42, 0.28);
}
.detail-header { text-align: center; }
.detail-number { width: 58px; height: 58px; display: grid; place-items: center; margin: 0 auto 10px; border-radius: 50%; background: var(--detail-color); color: white; font-size: 21px; font-weight: 800; }
.detail-name { margin: 0 44px 3px; color: #1f2937; font-size: 22px; }
.detail-meta, .detail-id { margin-bottom: 3px; color: var(--muted); font-size: 13px; }
.detail-total { margin: 18px 0; text-align: center; }
.detail-total strong { display: block; color: var(--detail-color); font-size: 36px; line-height: 1; }
.detail-total span { color: #94a3b8; font-size: 12px; }
.score-list { display: grid; }
.score-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 9px 2px; border-bottom: 1px solid #eef2f7; }
.score-label { color: var(--muted); font-size: 14px; }
.score-value { color: #1f2937; font-size: 14px; font-weight: 800; }

.toast-region {
  position: fixed;
  z-index: 9999;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  width: min(calc(100vw - 24px), 520px);
  transform: translateX(-50%);
  pointer-events: none;
}
.toast { margin-top: 8px; padding: 12px 15px; border-radius: 14px; background: #0f172a; color: white; text-align: center; font-size: 13px; box-shadow: 0 12px 34px rgba(15, 23, 42, 0.24); animation: toast-in 180ms ease; }
.toast.error { background: #b91c1c; }
.toast.success { background: #047857; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

@media (max-width: 980px) { .student-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 720px) {
  .site-shell { padding: 16px; }
  .students-header { align-items: stretch; flex-direction: column; }
  .toolbar { width: 100%; }
  .search-box { min-width: 0; flex: 1; }
  .student-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .class-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 470px) {
  .student-grid { grid-template-columns: 1fr; }
  .home-panel { justify-content: flex-start; padding-top: 64px; }
  .detail-overlay {
    padding:
      max(10px, env(safe-area-inset-top))
      max(10px, env(safe-area-inset-right))
      max(10px, env(safe-area-inset-bottom))
      max(10px, env(safe-area-inset-left));
  }
  .detail-modal {
    width: 100%;
    max-height: calc(var(--viewport-height) - 20px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    padding: 21px;
    border-radius: 24px;
  }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}
