/* ── 变量 ─────────────────────────────────────────── */
:root {
  --blue:    #1F497D;
  --blue-lt: #2E75B6;
  --blue-bg: #EBF2FA;
  --green:   #1A7A4A;
  --green-lt:#E8F5EE;
  --orange:  #E07B00;
  --orange-lt:#FFF3E0;
  --red:     #C0392B;
  --gray:    #6C757D;
  --gray-lt: #F5F6FA;
  --border:  #DDE3EC;
  --white:   #FFFFFF;
  --text:    #1A2340;
  --radius:  12px;
  --shadow:  0 2px 12px rgba(31,73,125,.12);
}

/* ── Reset ───────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--gray-lt);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Header ──────────────────────────────────────── */
.app-header {
  background: var(--blue);
  color: var(--white);
  padding: 0 16px;
  height: 52px;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-inner {
  max-width: 640px;
  margin: 0 auto;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand { font-weight: 700; font-size: 1rem; letter-spacing: .05em; }
.brand-logo {
  height: 26px;
  width: auto;
  display: block;
  filter: brightness(0) invert(1);
  opacity: .92;
}
.header-right { font-size: .85rem; opacity: .85; }

/* ── Main ────────────────────────────────────────── */
.app-main {
  flex: 1;
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
  padding: 20px 16px 40px;
}

/* ── Card ────────────────────────────────────────── */
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px 20px;
  margin-bottom: 16px;
}
.card-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--blue);
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--blue-bg);
}

/* ── Buttons ─────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: opacity .2s, transform .1s;
  text-decoration: none;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--blue); color: var(--white); }
.btn-primary:hover { opacity: .9; }
.btn-success { background: var(--green); color: var(--white); }
.btn-success:hover { opacity: .9; }
.btn-outline {
  background: transparent;
  color: var(--blue);
  border: 2px solid var(--blue);
}
.btn-outline:hover { background: var(--blue-bg); }
.btn-full { width: 100%; }
.btn-sm { padding: 8px 16px; font-size: .875rem; }
.btn:disabled { opacity: .4; cursor: not-allowed; }

/* ── Form ────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: .875rem;
  font-weight: 600;
  color: var(--gray);
  margin-bottom: 6px;
}
.form-input {
  width: 100%;
  padding: 12px 14px;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
  transition: border-color .2s;
  background: var(--white);
}
.form-input:focus {
  outline: none;
  border-color: var(--blue-lt);
}

/* ── Hero / Welcome ──────────────────────────────── */
.hero {
  text-align: center;
  padding: 40px 0 24px;
}
.hero-icon {
  font-size: 3.5rem;
  margin-bottom: 16px;
  display: block;
}
.hero-title {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--blue);
  margin-bottom: 8px;
  line-height: 1.3;
}
.hero-sub {
  color: var(--gray);
  font-size: .95rem;
  line-height: 1.6;
}

/* ── Status badge ────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: .8rem;
  font-weight: 600;
  gap: 5px;
}
.badge-waiting { background: var(--orange-lt); color: var(--orange); }
.badge-active  { background: var(--green-lt);  color: var(--green);  }
.badge-done    { background: var(--blue-bg);   color: var(--blue);   }

/* ── Module list ─────────────────────────────────── */
.module-list { list-style: none; }
.module-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.module-item:last-child { border-bottom: none; }
.module-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--border);
  flex-shrink: 0;
}
.module-dot.done   { background: var(--green); }
.module-dot.active { background: var(--orange); box-shadow: 0 0 0 3px var(--orange-lt); }
.module-name { flex: 1; font-size: .95rem; }
.module-score { font-size: .85rem; font-weight: 700; color: var(--blue); }

/* ── Progress bar ────────────────────────────────── */
.progress {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 8px;
}
.progress-fill {
  height: 100%;
  background: var(--blue-lt);
  border-radius: 3px;
  transition: width .4s ease;
}

/* ── Question card ───────────────────────────────── */
.q-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.q-counter { font-size: .85rem; color: var(--gray); font-weight: 600; }
.q-text {
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.6;
  margin-bottom: 20px;
  color: var(--text);
}
.options-list { list-style: none; display: flex; flex-direction: column; gap: 10px; }
.option-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  border: 2px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  user-select: none;
}
/* hover 只在真正的鼠标设备上生效，触摸屏不触发 */
@media (hover: hover) {
  .option-item:hover { border-color: var(--blue-lt); background: var(--blue-bg); }
}
.option-item.selected        { border-color: var(--blue); background: var(--blue-bg); }
.option-item.pending-select  { border-color: var(--blue); background: var(--blue-bg); box-shadow: 0 0 0 2px rgba(31,73,125,.18); }
.option-item.correct  { border-color: var(--green); background: var(--green-lt); }
.option-item.wrong    { border-color: var(--red); background: #FEF0EE; }
.option-label {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--border);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .85rem;
  flex-shrink: 0;
  transition: background .15s;
}
.option-item.selected        .option-label { background: var(--blue); color: var(--white); }
.option-item.pending-select  .option-label { background: var(--blue); color: var(--white); }
.option-item.correct  .option-label { background: var(--green); color: var(--white); }
.option-item.wrong    .option-label { background: var(--red); color: var(--white); }
.option-text { flex: 1; font-size: .95rem; line-height: 1.5; padding-top: 2px; }

/* ── Result feedback ─────────────────────────────── */
.feedback-box {
  padding: 12px 16px;
  border-radius: 8px;
  margin-top: 16px;
  font-size: .9rem;
  line-height: 1.5;
}
.feedback-correct  { background: var(--green-lt); color: var(--green); border-left: 3px solid var(--green); }
.feedback-wrong    { background: #FEF0EE; color: var(--red); border-left: 3px solid var(--red); }
.feedback-pending  { background: #FFF8E6; color: #B07800; border-left: 3px solid #F5C242; }

/* ── Nav dots (test progress) ────────────────────── */
.nav-dots {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: 20px;
}
.nav-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--border);
  transition: background .2s;
}
.nav-dot.answered { background: var(--blue-lt); }
.nav-dot.current  { background: var(--blue); width: 20px; border-radius: 4px; }

/* ── Radar chart ─────────────────────────────────── */
.chart-wrap {
  position: relative;
  max-width: 320px;
  margin: 0 auto;
}

/* ── Score table ─────────────────────────────────── */
.score-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.score-table th, .score-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.score-table th { background: var(--blue-bg); font-weight: 700; color: var(--blue); }
.score-table tr:last-child td { border-bottom: none; }
.score-up   { color: var(--green); font-weight: 700; }
.score-down { color: var(--red); }
.score-same { color: var(--gray); }

/* ── Display (big screen) ────────────────────────── */
body.display-mode {
  background: #0D1B3E;
  color: var(--white);
}
body.display-mode .app-header { background: rgba(255,255,255,.08); }
body.display-mode .app-main { max-width: 1200px; padding: 24px; }
.display-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
.display-card {
  background: rgba(255,255,255,.07);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 16px;
  padding: 20px 24px;
}
.display-card-full { grid-column: 1 / -1; }
.display-title {
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .1em;
  opacity: .55;
  margin-bottom: 14px;
  font-weight: 700;
}
.display-stat {
  font-size: 3rem;
  font-weight: 800;
  color: #64C8FF;
  line-height: 1;
}
.display-stat-label { font-size: .85rem; opacity: .65; margin-top: 4px; }

/* Bar chart for answer distribution */
.answer-bar-wrap { display: flex; flex-direction: column; gap: 10px; }
.answer-bar-row { display: flex; align-items: center; gap: 10px; font-size: .95rem; }
.answer-bar-label { width: 28px; text-align: center; font-weight: 700; opacity: .75; }
.answer-bar-track {
  flex: 1; height: 28px;
  background: rgba(255,255,255,.1);
  border-radius: 6px;
  overflow: hidden;
}
.answer-bar-fill {
  height: 100%;
  background: #2E75B6;
  border-radius: 6px;
  transition: width .5s ease;
  display: flex; align-items: center; padding-left: 8px;
  font-size: .8rem; font-weight: 700;
}
.answer-bar-fill.correct-bar { background: #1A7A4A; }
.answer-bar-count { width: 28px; text-align: right; opacity: .75; font-size: .85rem; }

/* Ranking list */
.rank-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.rank-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  background: rgba(255,255,255,.05);
  border-radius: 8px;
}
.rank-num {
  width: 28px; height: 28px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: .85rem;
  background: rgba(255,255,255,.1);
  flex-shrink: 0;
}
.rank-num.gold   { background: #F5C242; color: #1A2340; }
.rank-num.silver { background: #B8C0CC; color: #1A2340; }
.rank-num.bronze { background: #CD7F32; color: #1A2340; }
.rank-name { flex: 1; font-size: .95rem; }
.rank-sub  { font-size: .75rem; opacity: .6; margin-top: 2px; }
.rank-score { font-size: 1.1rem; font-weight: 800; color: #64C8FF; }

/* ── Admin ───────────────────────────────────────── */
.admin-header { background: var(--blue); color: var(--white); }
.session-row {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.session-row:last-child { border-bottom: none; }
.session-info { flex: 1; }
.session-name { font-weight: 600; }
.session-meta { font-size: .8rem; color: var(--gray); margin-top: 3px; }
.control-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.control-btn {
  padding: 12px 10px;
  border-radius: 8px;
  font-size: .875rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  background: var(--blue-bg);
  color: var(--blue);
  transition: background .15s;
}
.control-btn:hover { background: var(--blue-lt); color: var(--white); }
.control-btn.active-btn { background: var(--green); color: var(--white); }
.control-btn.danger-btn { background: #FEE; color: var(--red); }
.control-btn.danger-btn:hover { background: var(--red); color: var(--white); }

.participant-table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.participant-table th, .participant-table td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.participant-table th { background: var(--gray-lt); font-weight: 700; }

/* QR code */
.qr-wrap {
  text-align: center;
  padding: 16px;
}
.qr-wrap img { max-width: 180px; border-radius: 8px; }
.qr-url {
  font-size: .8rem;
  color: var(--gray);
  margin-top: 8px;
  word-break: break-all;
}

/* ── Waiting screen ──────────────────────────────── */
.waiting-anim {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 24px 0;
}
.waiting-dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--blue-lt);
  animation: bounce 1.2s infinite ease-in-out;
}
.waiting-dot:nth-child(1) { animation-delay: 0s; }
.waiting-dot:nth-child(2) { animation-delay: .2s; }
.waiting-dot:nth-child(3) { animation-delay: .4s; }
@keyframes bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: .5; }
  40%           { transform: scale(1);   opacity: 1;  }
}

/* ── Utilities ───────────────────────────────────── */
.text-center { text-align: center; }
.text-muted  { color: var(--gray); }
.mt-8  { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-8  { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.divider { height: 1px; background: var(--border); margin: 16px 0; }

@media (max-width: 480px) {
  .display-grid { grid-template-columns: 1fr; }
  .control-grid { grid-template-columns: 1fr; }
}

/* ── iPhone 安全区域（X/11/12/13/14/15 底部横条）────── */
.app-main {
  padding-bottom: max(40px, calc(24px + env(safe-area-inset-bottom)));
}

/* ── 触摸优化：去除点击延迟 & 高亮 ──────────────────── */
.btn, .option-item, .control-btn {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* ── 最小触摸目标 44px（苹果 HIG 规范）────────────── */
.btn       { min-height: 44px; }
.option-item { min-height: 48px; }

/* ── 小屏手机适配（iPhone SE / 旧款华为，≤390px）──── */
@media (max-width: 390px) {
  .card {
    padding: 16px 14px;
  }
  .hero-title {
    font-size: 1.25rem;
  }
  .q-text {
    font-size: 1rem;
  }
  .option-item {
    padding: 12px 10px;
    gap: 10px;
  }
  .option-text {
    font-size: .9rem;
  }
  .option-label {
    width: 24px;
    height: 24px;
    font-size: .8rem;
  }
  /* 答题导航按钮：两行布局 */
  .test-nav-row {
    flex-wrap: wrap;
  }
  .test-nav-row .btn-prev-btn {
    order: 2;
    flex: 1;
  }
  .test-nav-row .btn-next-btn {
    order: 1;
    flex: 1 0 100%;
  }
  .btn {
    font-size: .9rem;
    padding: 11px 14px;
  }
}


/* 参与者完成进度指示点 */
.prog-dot { font-size:.8rem; font-weight:700; }
.prog-done    { color:var(--green); }
.prog-pending { color:#bbb; }
.prog-unknown { color:#ccc; font-size:.7rem; }
