:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-elevated: #f4f6f9;
  --text: #1a2332;
  --muted: #5c6b7a;
  --accent: #2563eb;
  --accent-soft: rgba(37, 99, 235, 0.12);
  --success: #059669;
  --danger: #dc2626;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 8px 28px rgba(15, 23, 42, 0.08);
  font-family: "Nunito", system-ui, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  line-height: 1.5;
}

.bg-pattern {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(37, 99, 235, 0.06), transparent),
    radial-gradient(ellipse 60% 40% at 100% 50%, rgba(5, 150, 105, 0.04), transparent),
    radial-gradient(ellipse 50% 30% at 0% 80%, rgba(37, 99, 235, 0.03), transparent);
  z-index: 0;
}

.app {
  position: relative;
  z-index: 1;
  max-width: 720px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.screen {
  display: none;
  animation: fadeIn 0.35s ease;
}

.screen--active {
  display: block;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.75rem 1.5rem;
  box-shadow: var(--shadow);
  border: 1px solid rgba(15, 23, 42, 0.08);
}

.card--login {
  text-align: center;
}

.title {
  margin: 0 0 0.5rem;
  font-size: 1.65rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.title--sm {
  font-size: 1.35rem;
}

.subtitle {
  margin: 0 0 1.5rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.login-error {
  margin: -0.5rem 0 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: #b91c1c;
  line-height: 1.4;
  text-align: left;
}

.section-title {
  margin: 0 0 0.35rem;
  font-size: 1.35rem;
  font-weight: 800;
}

.hint {
  margin: 0 0 1.25rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.field {
  display: block;
  text-align: left;
  margin-bottom: 1.25rem;
}

.field__label {
  display: block;
  font-size: 0.85rem;
  font-weight: 700;
  margin-bottom: 0.4rem;
  color: var(--muted);
}

input[type="text"],
input[type="password"] {
  width: 100%;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(15, 23, 42, 0.12);
  background: var(--surface-elevated);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
}

input[type="text"]:focus,
input[type="password"]:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius-sm);
  border: none;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.btn:active {
  transform: scale(0.98);
}

.btn--primary {
  width: 100%;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: #ffffff;
  box-shadow: 0 4px 16px rgba(37, 99, 235, 0.28);
}

.btn--primary:hover:not(:disabled) {
  box-shadow: 0 6px 22px rgba(37, 99, 235, 0.35);
}

.btn--primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

.btn--ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid rgba(15, 23, 42, 0.12);
}

.btn--ghost:hover {
  color: var(--text);
  border-color: rgba(15, 23, 42, 0.2);
}

.btn--small {
  padding: 0.45rem 0.75rem;
  font-size: 0.85rem;
}

.top-bar {
  margin-bottom: 1rem;
}

.top-bar--split {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.quiz-top-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.55rem;
  justify-content: flex-end;
}

.summary-toolbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 0.75rem;
}

.badge {
  display: inline-block;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 700;
}

.progress {
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 700;
}

.quiz-progress-wrap {
  margin-bottom: 0.85rem;
}

.quiz-progress-bar {
  height: 8px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.08);
  overflow: hidden;
}

.quiz-progress-bar__fill {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, #2563eb, #1d4ed8);
  transition: width 0.35s ease;
}

.group-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
}

.group-card {
  position: relative;
  padding: 1.05rem 0.8rem;
  border-radius: var(--radius-sm);
  background: var(--surface-elevated);
  border: 2px solid rgba(15, 23, 42, 0.06);
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  color: var(--text);
  transition: border-color 0.2s, transform 0.15s;
}

.group-card:hover {
  border-color: rgba(37, 99, 235, 0.45);
  transform: translateY(-2px);
}

.group-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.group-card__icon {
  font-size: 1.85rem;
  line-height: 1;
  margin-bottom: 0.45rem;
}

.group-card__name {
  font-size: 1rem;
  font-weight: 800;
  margin: 0 0 0.3rem;
  line-height: 1.25;
}

.group-card__desc {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.35;
}

.group-card--cohort-allowed {
  border-color: rgba(37, 99, 235, 0.55);
  box-shadow: 0 6px 22px rgba(37, 99, 235, 0.14);
}

.group-card--cohort-other {
  opacity: 0.58;
}

.group-card--cohort-other:hover {
  opacity: 0.72;
}

/* 选组首页：加宽容器、放大标题与四张卡片（仅当前屏激活时） */
.app:has(#screen-groups.screen--active) {
  max-width: min(1120px, 96vw);
  padding: 2rem clamp(1rem, 3vw, 2rem) 3.5rem;
}

.app:has(#screen-groups.screen--active) .top-bar {
  margin-bottom: 1.35rem;
}

.app:has(#screen-groups.screen--active) .badge {
  font-size: 0.95rem;
  padding: 0.45rem 1rem;
}

.app:has(#screen-groups.screen--active) .section-title {
  font-size: clamp(1.5rem, 2.8vw, 1.85rem);
  margin-bottom: 0.5rem;
}

.app:has(#screen-groups.screen--active) .hint {
  font-size: 1.05rem;
  margin-bottom: 1.75rem;
  max-width: 42rem;
}

.app:has(#screen-groups.screen--active) .group-grid {
  gap: 1.35rem;
}

.app:has(#screen-groups.screen--active) .group-card {
  padding: 1.45rem 1.15rem;
  border-radius: var(--radius);
}

.app:has(#screen-groups.screen--active) .group-card__icon {
  font-size: 2.4rem;
  margin-bottom: 0.6rem;
}

.app:has(#screen-groups.screen--active) .group-card__name {
  font-size: 1.12rem;
  margin-bottom: 0.4rem;
}

.app:has(#screen-groups.screen--active) .group-card__desc {
  font-size: 0.9rem;
}

@media (max-width: 900px) {
  .app:has(#screen-groups.screen--active) .group-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1.1rem;
  }
}

/* 教师统计页：与选组页类似加宽容器，避免内容挤在窄列中间 */
.app:has(#screen-teacher-dash.screen--active) {
  max-width: min(1200px, 96vw);
  padding: 2rem clamp(1rem, 3vw, 2rem) 3.5rem;
  justify-content: flex-start;
}

.app:has(#screen-teacher-dash.screen--active) .top-bar {
  margin-bottom: 1.35rem;
}

.app:has(#screen-teacher-dash.screen--active) .badge {
  font-size: 0.95rem;
  padding: 0.45rem 1rem;
}

.card--quiz {
  margin-top: 0.5rem;
}

.btn--submit {
  margin-top: 1.35rem;
}

.question {
  margin: 0 0 1.25rem;
  font-size: 1.15rem;
  font-weight: 700;
}

.options {
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

.option-btn {
  display: block;
  width: 100%;
  padding: 0.95rem 1.1rem;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(15, 23, 42, 0.12);
  background: var(--surface-elevated);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}

.option-btn:hover:not(:disabled) {
  border-color: rgba(37, 99, 235, 0.35);
  background: rgba(37, 99, 235, 0.06);
}

.option-btn--selected {
  border-color: rgba(37, 99, 235, 0.55);
  background: rgba(37, 99, 235, 0.1);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

.option-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.option-btn--wrong {
  border-color: var(--danger);
  animation: shake 0.4s ease;
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-6px);
  }
  75% {
    transform: translateX(6px);
  }
}

.card--summary {
  text-align: center;
}

.summary-stats {
  margin: 1rem 0 1.5rem;
  color: var(--muted);
  font-size: 1rem;
}

.summary-stats--compact {
  margin: 0 0 1.25rem;
  font-size: 0.88rem;
  line-height: 1.45;
}

/* 结算页（参考成绩单卡片：渐变底 + 白卡片） */
body.result-screen-bg {
  background: linear-gradient(165deg, #ff8a3d 0%, #ff6b6b 45%, #e056c8 100%);
  background-attachment: fixed;
}

body.result-screen-bg .bg-pattern {
  opacity: 0.28;
}

.screen--result {
  padding-top: 0.5rem;
}

.screen--result.screen--active {
  min-height: min(100vh, 640px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.card--result {
  text-align: center;
  padding: 1.75rem 1.35rem 1.5rem;
  max-width: 400px;
  margin: 0 auto;
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.12);
}

.result-hero {
  width: 120px;
  height: 120px;
  margin: 0 auto 1rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3.25rem;
  line-height: 1;
  background: linear-gradient(145deg, rgba(255, 214, 120, 0.35), rgba(120, 200, 255, 0.25));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.6);
}

.result-hero--win {
  background: linear-gradient(145deg, rgba(255, 220, 100, 0.55), rgba(255, 180, 80, 0.35));
}

.result-hero--loss {
  background: linear-gradient(145deg, rgba(180, 210, 255, 0.5), rgba(140, 190, 255, 0.3));
}

.result-title {
  margin: 0 0 0.6rem;
  font-size: 1.65rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: #0f172a;
}

.result-subject {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
  color: #1e293b;
}

.result-institution {
  margin: 0.2rem 0 1rem;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--muted);
}

.result-divider {
  border: none;
  border-top: 1px solid rgba(15, 23, 42, 0.1);
  margin: 0 0 1.15rem;
}

.result-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem 0.35rem;
  align-items: start;
  margin-bottom: 0.25rem;
}

.result-stats.result-stats--experience {
  grid-template-columns: repeat(2, 1fr);
}

@media (min-width: 520px) {
  .result-stats.result-stats--experience {
    grid-template-columns: repeat(4, 1fr);
  }
}

.result-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  padding: 0 0.2rem;
}

.result-stat__value {
  font-size: 1.25rem;
  font-weight: 800;
  color: #0f172a;
  letter-spacing: -0.02em;
}

.result-stat__value--medal {
  font-size: 1.45rem;
}

.result-stat__value--yellow {
  color: #ca8a04;
}

.result-stat__value--blue {
  color: #2563eb;
}

.result-stat__value--exp {
  color: #059669;
}

.result-stat__label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: none;
  letter-spacing: 0.02em;
}

.btn--cta {
  width: 100%;
  padding: 0.85rem 1.25rem;
  border-radius: 999px;
  background: linear-gradient(135deg, #ffb020, #ff7a45);
  color: #ffffff;
  box-shadow: 0 8px 24px rgba(255, 120, 60, 0.38);
  font-weight: 800;
  letter-spacing: 0.04em;
}

.btn--cta:hover:not(:disabled) {
  box-shadow: 0 10px 28px rgba(255, 120, 60, 0.45);
}

/* 庆祝层 */
.celebration {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.celebration[hidden] {
  display: none !important;
}

.celebration__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(6px);
}

.celebration__box {
  position: relative;
  width: 100%;
  max-width: 380px;
  padding: 1.5rem;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid rgba(15, 23, 42, 0.08);
  box-shadow: var(--shadow);
  text-align: center;
  animation: popIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes popIn {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.celebration__title {
  margin: 0 0 1rem;
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--success);
}

/* [hidden] 须强制隐藏：否则 .celebration__media 的 display:flex 会盖住 hidden，第四组仍会留出灰框 */
.celebration__media[hidden] {
  display: none !important;
}

.celebration__media {
  min-height: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 1rem;
  border-radius: var(--radius-sm);
  background: var(--surface-elevated);
  overflow: hidden;
}

/* 第四组等无 GIF：仅文案 + 按钮，不占动画区域 */
.celebration--text-only .celebration__media {
  display: none !important;
  min-height: 0;
  margin: 0;
  padding: 0;
}

.celebration--text-only .celebration__title {
  margin-bottom: 1.35rem;
  font-size: 1.45rem;
}

.celebration--text-only .celebration__box {
  padding: 1.65rem 1.5rem 1.45rem;
}

.celebration__gif {
  max-width: 100%;
  max-height: 220px;
  display: block;
  object-fit: contain;
}

.celebration__fallback {
  padding: 2rem;
  animation: bounce 0.8s ease infinite alternate;
}

.celebration__emoji {
  font-size: 4rem;
  line-height: 1;
}

@keyframes bounce {
  from {
    transform: translateY(0);
  }
  to {
    transform: translateY(-8px);
  }
}

.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 90;
  padding: 0.65rem 1.25rem;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid rgba(220, 38, 38, 0.35);
  color: var(--danger);
  font-weight: 700;
  box-shadow: var(--shadow);
  animation: toastUp 0.35s ease;
}

.toast[hidden] {
  display: none !important;
}

@keyframes toastUp {
  from {
    opacity: 0;
    transform: translate(-50%, 12px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

@media (max-width: 400px) {
  .app {
    padding-left: 0.85rem;
    padding-right: 0.85rem;
  }

  .group-grid {
    gap: 0.55rem;
  }

  .group-card {
    padding: 0.9rem 0.45rem;
  }

  .group-card__icon {
    font-size: 1.55rem;
  }

  .group-card__name {
    font-size: 0.9rem;
  }

  .group-card__desc {
    font-size: 0.7rem;
  }

  /* 极窄屏仍保持选组页略大于默认缩放 */
  .app:has(#screen-groups.screen--active) .group-grid {
    gap: 0.75rem;
  }

  .app:has(#screen-groups.screen--active) .group-card {
    padding: 1.05rem 0.55rem;
  }

  .app:has(#screen-groups.screen--active) .group-card__icon {
    font-size: 1.85rem;
  }

  .app:has(#screen-groups.screen--active) .group-card__name {
    font-size: 0.98rem;
  }

  .app:has(#screen-groups.screen--active) .group-card__desc {
    font-size: 0.78rem;
  }
}
