/* ========================================
   嵌入式操作系统刷题 — Mobile-first 样式
   ======================================== */

/* ========================================
   白天主题（默认）
   ======================================== */
:root {
  --bg: #f0f4f3;
  --surface: #ffffff;
  --surface-soft: #e8efec;
  --text: #1a2422;
  --muted: #5f716d;
  --line: #d4dfdb;
  --accent: #136b5c;
  --accent-strong: #0d4f43;
  --accent-soft: #ddf2ed;
  --warn: #b2462d;
  --warn-soft: #fde8e2;
  --ok: #1d7a45;
  --ok-soft: #e2f3e8;
  --focus: #d98a2b;
  --answer-color: #c0392b;
  --radius: 12px;
  --shadow: 0 8px 32px rgba(30, 50, 46, 0.10);
  --login-bg: linear-gradient(160deg, #d8eae4 0%, #eef5f2 60%, #f4f8f6 100%);
}

/* ========================================
   黑夜主题
   ======================================== */
[data-theme="dark"] {
  --bg: #121b19;
  --surface: #1e2a27;
  --surface-soft: #283632;
  --text: #dce8e4;
  --muted: #8a9e98;
  --line: #334541;
  --accent: #28a68e;
  --accent-strong: #40c4aa;
  --accent-soft: #1a3a33;
  --warn: #e8705a;
  --warn-soft: #3d2420;
  --ok: #3dbb6f;
  --ok-soft: #1a3a28;
  --focus: #e8a040;
  --answer-color: #ef6b5a;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  --login-bg: linear-gradient(160deg, #0d1a16 0%, #162420 60%, #1b2d27 100%);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; border: 0; background: none; }
a { color: var(--accent); text-decoration: none; }

/* ---- screen system ---- */
.screen {
  display: none;
  min-height: 100vh;
  min-height: 100dvh;
}
.screen.active { display: flex; }

/* ========================================
   登录屏
   ======================================== */
#login-screen.active {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background: var(--login-bg);
}

.login-card {
  width: 100%;
  max-width: 380px;
  padding: 40px 28px 32px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
}

.login-badge {
  display: inline-block;
  padding: 4px 14px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 16px;
}

.login-title {
  font-size: 26px;
  font-weight: 800;
  line-height: 1.25;
  margin-bottom: 6px;
  color: var(--accent-strong);
}

.login-sub {
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 28px;
}

.login-card .field {
  display: grid;
  gap: 6px;
  margin-bottom: 16px;
  text-align: left;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}

.login-card input {
  width: 100%;
  height: 48px;
  padding: 0 14px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  font-size: 16px;
  outline: none;
  transition: border-color 0.15s;
}
.login-card input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(19, 107, 92, 0.15);
}

.login-error {
  margin-top: 14px;
  font-size: 14px;
  color: var(--warn);
  font-weight: 600;
}

/* ========================================
   菜单屏
   ======================================== */
#menu-screen.active {
  flex-direction: column;
  padding: 20px 16px;
}

.menu-container {
  max-width: 520px;
  width: 100%;
  margin: 0 auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.menu-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 0 8px;
}

.menu-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.menu-welcome {
  font-size: 20px;
  font-weight: 700;
  color: var(--accent-strong);
}

.menu-class {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 700;
}

.text-button {
  padding: 8px 12px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  border-radius: 8px;
  transition: background 0.15s;
}
.text-button:hover { background: var(--surface-soft); }

/* 主题切换按钮 */
.theme-btn {
  font-size: 20px;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  color: var(--muted);
}
.theme-btn:hover { background: var(--surface-soft); }

.menu-cards {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.menu-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 32px 20px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  transition: transform 0.12s, box-shadow 0.12s;
  text-align: center;
}
.menu-card:active {
  transform: scale(0.97);
  box-shadow: 0 4px 16px rgba(30, 50, 46, 0.08);
}

.menu-icon {
  font-size: 40px;
  line-height: 1;
}

.menu-label {
  font-size: 20px;
  font-weight: 800;
  color: var(--accent-strong);
}

.menu-desc {
  font-size: 14px;
  color: var(--muted);
}

.menu-progress {
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  padding: 8px 0;
}

/* ========================================
   刷题屏
   ======================================== */
#quiz-screen.active {
  flex-direction: column;
  padding: 12px 12px 20px;
}

.quiz-shell {
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.quiz-topbar {
  display: flex;
  align-items: center;
  gap: 10px;
}

.quiz-topbar .icon-button {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: 0 4px 12px rgba(0,0,0,0.04);
  font-size: 26px;
  line-height: 1;
  color: var(--accent-strong);
  display: flex;
  align-items: center;
  justify-content: center;
}

.quiz-meta {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}

.quiz-meta span {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.quiz-top-right {
  flex-shrink: 0;
}

/* ---- 进度条 ---- */
.progress-line {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #dce6e2;
}

#progressBar {
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--focus));
  transition: width 180ms ease;
  border-radius: 999px;
}

/* ---- 题目卡片 ---- */
.question-card {
  flex: 1;
  padding: 20px 18px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

#questionPrompt {
  font-size: clamp(17px, 4vw, 24px);
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-weight: 600;
}

/* ---- 选项 ---- */
.options {
  display: grid;
  gap: 10px;
}

.option-button {
  display: grid;
  grid-template-columns: 40px 1fr;
  gap: 12px;
  align-items: start;
  min-height: 52px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  padding: 12px;
  text-align: left;
  line-height: 1.5;
  font-size: 15px;
  transition: border-color 0.12s, background 0.12s;
}
.option-button:active { background: var(--surface-soft); }

.option-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--accent-strong);
  font-weight: 800;
  font-size: 15px;
}

.option-button.correct {
  border-color: rgba(29, 122, 69, 0.4);
  background: var(--ok-soft);
}
.option-button.wrong {
  border-color: rgba(178, 70, 45, 0.4);
  background: var(--warn-soft);
}
.option-button:disabled { cursor: default; }

/* ---- 填空/简答输入 ---- */
.card-answer {
  display: grid;
  gap: 12px;
}

.card-answer .field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}

.card-answer textarea {
  width: 100%;
  min-height: 100px;
  padding: 12px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  resize: vertical;
  outline: none;
}
.card-answer textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(19, 107, 92, 0.12);
}

.answer-box {
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fafcfb;
  line-height: 1.7;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 15px;
  color: var(--answer-color);
}

[data-theme="dark"] .answer-box {
  background: #1e2a27;
}

.self-check {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* ---- 反馈 ---- */
.feedback {
  padding: 12px 14px;
  border-radius: 10px;
  line-height: 1.5;
  font-size: 14px;
  font-weight: 600;
}
.feedback.ok { background: var(--ok-soft); color: var(--ok); }
.feedback.warn { background: var(--warn-soft); color: var(--warn); }

/* ---- 导航 ---- */
.nav-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.jump-box {
  display: flex;
  gap: 6px;
  flex: 1;
  min-width: 0;
}

.jump-box input {
  width: 0;
  flex: 1;
  min-width: 50px;
  height: 44px;
  padding: 0 10px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  font-size: 15px;
  text-align: center;
  outline: none;
}
.jump-box input:focus {
  border-color: var(--accent);
}

/* ---- 按钮系统 ---- */
.primary-button, .secondary-button {
  height: 48px;
  border-radius: 10px;
  padding: 0 20px;
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap;
}
.full-button { width: 100%; }

.primary-button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
}
.primary-button:active { background: var(--accent-strong); }

.secondary-button {
  border: 1.5px solid var(--line);
  background: #fff;
  color: var(--accent-strong);
}
.secondary-button:active { background: var(--surface-soft); }

/* ---- 空状态 ---- */
.empty-state { color: var(--muted); font-size: 16px; }

/* ========================================
   排行榜
   ======================================== */
.leaderboard-section {
  margin-top: 8px;
}

.leaderboard-title {
  font-size: 17px;
  font-weight: 800;
  color: var(--accent-strong);
  margin-bottom: 12px;
}

.leaderboard-body {
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 4px 16px rgba(30,50,46,0.06);
  overflow: hidden;
}

.leaderboard-loading,
.leaderboard-empty {
  padding: 24px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

.leaderboard-table {
  display: flex;
  flex-direction: column;
}

.lb-header,
.lb-row {
  display: grid;
  grid-template-columns: 48px 1fr 56px 80px 48px;
  gap: 6px;
  align-items: center;
  padding: 10px 14px;
  font-size: 13px;
}

.lb-header {
  background: var(--surface-soft);
  color: var(--muted);
  font-weight: 700;
  font-size: 12px;
  border-bottom: 1px solid var(--line);
}

.lb-row {
  border-bottom: 1px solid var(--line);
  color: var(--text);
}

.lb-row:last-child { border-bottom: none; }

.lb-row-me {
  background: var(--accent-soft);
  font-weight: 700;
}

.lb-rank { text-align: center; }
.lb-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-rate { text-align: right; font-weight: 700; color: var(--accent); }
.lb-count { text-align: right; color: var(--muted); }
.lb-wrong { text-align: center; color: var(--warn); }

@media (min-width: 640px) {
  .lb-header, .lb-row {
    grid-template-columns: 56px 1fr 64px 96px 56px;
    padding: 12px 18px;
    font-size: 14px;
  }
}

/* ========================================
   平板 / 桌面
   ======================================== */
@media (min-width: 640px) {
  .menu-cards {
    flex-direction: row;
    gap: 16px;
  }
  .menu-card {
    flex: 1;
    padding: 40px 16px;
  }
}

@media (min-width: 768px) {
  #quiz-screen.active { padding: 20px 24px 28px; }
  .quiz-topbar .icon-button { width: 48px; height: 48px; font-size: 28px; }
  .quiz-topbar { gap: 14px; }
  .quiz-meta span { font-size: 13px; }
  .question-card { padding: 28px 26px; border-radius: 14px; }
  #questionPrompt { font-size: clamp(18px, 2.5vw, 26px); }
  .nav-row { gap: 14px; }
  .jump-box input { height: 48px; }
  .primary-button, .secondary-button { height: 48px; padding: 0 28px; }

  /* 登录页稍微更大 */
  .login-card { padding: 48px 36px 36px; }
  .login-title { font-size: 30px; }
}

/* ========================================
   辅助
   ======================================== */
.hidden { display: none !important; }

/* ========================================
   黑夜模式覆盖 — 将白色元素改为灰色
   ======================================== */
[data-theme="dark"] .login-card input,
[data-theme="dark"] .option-button,
[data-theme="dark"] .card-answer textarea,
[data-theme="dark"] .jump-box input,
[data-theme="dark"] input,
[data-theme="dark"] textarea,
[data-theme="dark"] select {
  background: #283632;
  color: var(--text);
}

[data-theme="dark"] .secondary-button {
  background: #283632;
  color: var(--accent-strong);
  border-color: var(--line);
}

[data-theme="dark"] .option-button.correct {
  background: var(--ok-soft);
}
[data-theme="dark"] .option-button.wrong {
  background: var(--warn-soft);
}
