:root {
  /* 日间模式（默认）：白底黑字 + 蓝色边框 */
  --bg: #f8fafc;
  --bg-gradient: radial-gradient(1200px 800px at 10% 10%, #eff6ff, #f8fafc);
  --panel: #ffffff;
  --panel-soft: rgba(15, 23, 42, 0.03);
  --text: #0f172a;
  --muted: #475569;
  --primary: #2563eb;
  --primary-soft: rgba(37, 99, 235, 0.12);
  --success: #16a34a;
  --danger: #dc2626;
  --border: #3b82f6;
  --well-bg: rgba(2, 6, 23, 0.04);
  --option-bg: linear-gradient(180deg, #ffffff, #f8fafc);
  --header-bg: linear-gradient(180deg, rgba(2, 6, 23, 0.03), rgba(2, 6, 23, 0.0));
  --controls-gradient: linear-gradient(180deg, rgba(248, 250, 252, 0), rgba(248, 250, 252, 0.96));
}

html[data-theme="dark"] {
  /* 夜间模式：保留原来的配色 */
  --bg: #0b1020;
  --bg-gradient: radial-gradient(1200px 800px at 10% 10%, #0f1530, #0b1020);
  --panel: #121835;
  --panel-soft: rgba(255, 255, 255, 0.03);
  --text: #e7ecff;
  --muted: #9aa7d7;
  --primary: #6c8cff;
  --primary-soft: rgba(108, 140, 255, 0.14);
  --success: #22c55e;
  --danger: #ef4444;
  --border: #22306b;
  --well-bg: rgba(0, 0, 0, 0.2);
  --option-bg: linear-gradient(180deg, #1a2350, #12183a);
  --header-bg: linear-gradient(180deg, rgba(255, 255, 255, 0.03), rgba(0, 0, 0, 0.0));
  --controls-gradient: linear-gradient(180deg, rgba(11, 16, 32, 0), rgba(11, 16, 32, 0.95));
}

* { box-sizing: border-box; }

html, body { 
  height: 100%; 
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, 'Noto Sans', 'Apple Color Emoji', 'Segoe UI Emoji';
  color: var(--text);
  background: var(--bg-gradient);
  overflow-x: hidden;
}

#app { 
  min-height: 100vh; 
  display: flex; 
  flex-direction: column; 
}

.app-header {
  padding: 12px 16px;
  background: var(--header-bg);
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(10px);
}

.back-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background 0.2s;
}

.back-link:active {
  background: var(--panel-soft);
}

.app-header h1 { 
  margin: 0; 
  font-weight: 800; 
  font-size: 20px; 
  letter-spacing: .3px; 
  flex: 1;
}

.menu-btn {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: transparent;
  border: none;
  padding: 8px;
  cursor: pointer;
  width: 32px;
  height: 32px;
  justify-content: center;
  align-items: center;
}

.menu-btn span {
  width: 20px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: all 0.2s;
}

.menu-btn:active span {
  background: var(--primary);
}

.quiz { 
  width: 100%;
  max-width: 800px;
  margin: 0 auto; 
  flex: 1; 
  display: flex; 
  flex-direction: column; 
  gap: 12px; 
  padding: 12px;
  /* 预留出底部固定按钮区域的高度，避免最后一行被遮住 */
  padding-bottom: 140px;
}

.document-selector {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.document-selector label {
  color: var(--muted);
  font-size: 14px;
}

.mode-selector {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.mode-selector > label:first-child {
  margin-right: 8px;
}

.radio-label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 14px;
}

.radio-label input[type="radio"] {
  margin: 0;
  cursor: pointer;
}

.quiz-selector {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.quiz-selector-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.quiz-checkboxes {
  max-height: 300px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
  background: var(--well-bg);
  border-radius: 8px;
  border: 1px solid var(--border);
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  transition: background 0.2s;
  font-size: 14px;
}

.checkbox-label:hover {
  background: var(--panel-soft);
}

.checkbox-label input[type="checkbox"] {
  /* 自绘复选框，保证各平台尺寸一致 */
  -webkit-appearance: none;
  appearance: none;
  margin: 0;
  cursor: pointer;
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  border: 2px solid var(--border);
  border-radius: 4px;
  background: var(--panel-soft);
  position: relative;
  box-sizing: border-box;
}

.checkbox-label input[type="checkbox"]:checked {
  background: var(--primary);
  border-color: var(--primary);
}

.checkbox-label input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 5px;
  top: 1px;
  width: 4px;
  height: 9px;
  border: solid #ffffff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.pdf-select {
  width: 100%;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  font-size: 16px;
  -webkit-appearance: none;
  appearance: none;
}

.load-btn {
  width: 100%;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 10px;
  padding: 14px;
  font-weight: 600;
  font-size: 16px;
  cursor: pointer;
  transition: opacity 0.2s;
}

.load-btn:active { opacity: 0.8; }

.question-controls {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.question-info {
  color: var(--muted);
  font-size: 14px;
}

.question-nav {
  display: flex;
  gap: 8px;
}

.nav-btn {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
  min-width: 80px;
}

.nav-btn:active:not(:disabled) {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.nav-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.question-viewer {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  min-height: 120px;
}

.question-content {
  width: 100%;
}

.question-text {
  color: var(--text);
  font-size: 16px;
  line-height: 1.8;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.options {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

#option-e {
  display: none; /* 默认隐藏，如果有E选项会显示 */
}

.option {
  background: var(--option-bg);
  color: var(--text);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  font-size: 16px;
  text-align: left;
  cursor: pointer;
  transition: all 0.2s;
  min-height: 56px;
  display: flex;
  align-items: center;
}

.option:active:not(:disabled) {
  transform: scale(0.98);
  border-color: var(--primary);
}

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

.option.correct {
  border-color: var(--success);
  background: rgba(34, 197, 94, 0.1);
}

.option.wrong {
  border-color: var(--danger);
  background: rgba(239, 68, 68, 0.1);
}

.feedback {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  display: grid;
  gap: 12px;
}

.result {
  font-weight: 600;
  font-size: 18px;
}

.result.ok { color: var(--success); }
.result.no { color: var(--danger); }

.answer-explanation {
  color: var(--muted);
  line-height: 1.8;
  font-size: 15px;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--controls-gradient);
  padding: 12px;
  z-index: 50;
  backdrop-filter: blur(10px);
}

.menu-panel {
  position: fixed;
  top: 60px;
  right: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  z-index: 200;
  min-width: 180px;
  overflow: hidden;
}

.menu-content {
  display: flex;
  flex-direction: column;
}

.menu-item {
  background: transparent;
  border: none;
  color: var(--text);
  padding: 12px 16px;
  text-align: left;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.2s;
  border-bottom: 1px solid var(--border);
}

.menu-item:last-child {
  border-bottom: none;
}

.menu-item:hover {
  background: var(--panel-soft);
}

.menu-item:active {
  background: var(--primary-soft);
}

.next {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 10px;
  padding: 14px;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  transition: opacity 0.2s;
  width: 100%;
}

.next:active { opacity: 0.8; }

.loading {
  text-align: center;
  color: var(--muted);
  font-size: 16px;
  padding: 40px 20px;
}

/* 平板和桌面端优化 */
@media (min-width: 640px) {
  .quiz {
    padding: 20px;
    /* 桌面端同样多留一点空间 */
    padding-bottom: 140px;
  }

  .app-header {
    padding: 16px 20px;
  }

  .app-header h1 {
    font-size: 22px;
  }

  .document-selector {
    gap: 16px;
  }

  .mode-selector {
    flex-wrap: nowrap;
  }

  .quiz-checkboxes {
    max-height: 400px;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .load-btn {
    width: auto;
    min-width: 120px;
    align-self: flex-start;
  }

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

  .controls {
    position: relative;
    flex-direction: row;
    justify-content: space-between;
    background: transparent;
    backdrop-filter: none;
  }

  .next {
    width: auto;
    flex: 1;
  }
  
  .menu-panel {
    top: 70px;
    right: 20px;
  }
}

/* 大屏幕优化 */
@media (min-width: 1024px) {
  .quiz {
    max-width: 900px;
    padding: 24px;
  }
}
