:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #14141f;
  --bg-tertiary: #1e1e2e;
  --bg-card: #1a1a2e;
  --text-primary: #ffffff;
  --text-secondary: #a0a0b0;
  --text-muted: #606070;
  --accent-primary: #00d4ff;
  --accent-secondary: #00ff88;
  --accent-warm: #ff9f43;
  --danger: #ff4466;
  --focus-ring: #00d4ff;
  --focus-glow: rgba(0, 212, 255, 0.4);
  --success: #00ff88;
  --warning: #ffaa00;
  --info: #00b4d8;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  width: 600px;
  height: 600px;
  overflow: hidden;
}

#app {
  width: 100%;
  height: 100%;
  position: relative;
}

/* --- Screens --- */
.screen {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  position: absolute;
  top: 0;
  left: 0;
}
.screen.hidden { display: none; }

/* --- Header --- */
.header {
  display: flex;
  align-items: center;
  padding: 16px 20px;
  background: var(--bg-secondary);
  gap: 12px;
  flex-shrink: 0;
}
.header h1 {
  font-size: 22px;
  font-weight: 600;
  flex: 1;
}
.header-meta {
  font-size: 13px;
  color: var(--text-secondary);
}
.back-btn {
  background: transparent;
  color: var(--text-primary);
  font-size: 22px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
}

/* --- Content Area --- */
.content {
  flex: 1;
  padding: 16px 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* --- Focus States --- */
.focusable {
  transition: all 0.15s ease;
  border: 2px solid transparent;
  cursor: pointer;
  min-height: 44px;
}
.focusable:focus {
  outline: none;
  border-color: var(--focus-ring);
  box-shadow: 0 0 20px var(--focus-glow);
}

/* --- Navigation Bar --- */
.nav-bar {
  display: flex;
  gap: 8px;
  padding: 12px 20px;
  background: var(--bg-secondary);
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
}
.nav-item {
  flex: 1;
  padding: 14px 16px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 15px;
  font-weight: 500;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.nav-item:focus { background: var(--bg-card); }
.nav-item.primary {
  background: var(--accent-primary);
  color: var(--bg-primary);
}
.nav-item.primary:focus { background: #33ddff; }
.nav-hint {
  font-size: 12px;
  color: var(--text-muted);
}

/* --- Section Label --- */
.section-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

/* --- Exam Selector --- */
.exam-selector {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.exam-chip {
  padding: 10px 16px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 500;
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 120px;
  text-align: left;
}
.exam-chip.active {
  background: rgba(0, 212, 255, 0.15);
  border-color: var(--accent-primary) !important;
}
.exam-chip:focus.active {
  box-shadow: 0 0 20px var(--focus-glow);
}
.exam-chip-name {
  font-weight: 600;
}
.exam-chip-count {
  font-size: 11px;
  color: var(--text-secondary);
}

/* --- Divider --- */
.divider {
  height: 1px;
  background: var(--bg-tertiary);
  margin: 4px 0;
}

/* --- Action Buttons --- */
.action-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 16px;
  font-weight: 500;
  text-align: left;
}
.action-btn.primary {
  background: var(--accent-primary);
  color: var(--bg-primary);
}
.action-btn.primary:focus {
  background: #33ddff;
}
.action-icon {
  font-size: 22px;
  flex-shrink: 0;
}

/* --- Camera --- */
.camera-container {
  flex: 1;
  position: relative;
  background: #000;
  overflow: hidden;
}
#camera-preview {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.camera-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.scan-frame {
  width: 80%;
  height: 50%;
  border: 2px solid var(--accent-primary);
  border-radius: var(--radius-lg);
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.4);
}
.scan-hint {
  margin-top: 16px;
  font-size: 14px;
  color: var(--accent-primary);
  background: rgba(0, 0, 0, 0.6);
  padding: 6px 14px;
  border-radius: var(--radius-sm);
}

/* --- Loading States --- */
.loading-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--bg-tertiary);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text {
  font-size: 16px;
  color: var(--text-secondary);
}

/* --- Progress Bar --- */
.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--bg-tertiary);
  border-radius: 3px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--accent-primary);
  border-radius: 3px;
  transition: width 0.3s ease;
}

/* --- Text Input --- */
.text-input {
  width: 100%;
  padding: 14px 16px;
  font-size: 16px;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border-radius: var(--radius-md);
  border: 2px solid transparent;
}
.text-input:focus {
  border-color: var(--focus-ring);
  box-shadow: 0 0 20px var(--focus-glow);
  outline: none;
}
.text-input::placeholder { color: var(--text-muted); }

/* --- List / Results --- */
.list-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  flex: 1;
}
.result-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 14px 16px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 14px;
  text-align: left;
}
.result-item:focus {
  background: var(--bg-card);
}
.result-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.result-bank {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  background: rgba(0, 180, 216, 0.2);
  color: var(--info);
  font-weight: 600;
  flex-shrink: 0;
}
.result-score {
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
}
.result-question {
  font-size: 14px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.result-answer-preview {
  font-size: 13px;
  color: var(--accent-secondary);
  font-weight: 500;
}

/* --- OCR Text Preview --- */
.ocr-preview {
  margin-bottom: 8px;
}
.ocr-text {
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--bg-tertiary);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  max-height: 60px;
  overflow-y: auto;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
}

/* --- Detail Screen --- */
.detail-card {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: 20px;
}
.detail-id {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.detail-question {
  font-size: 17px;
  line-height: 1.5;
  font-weight: 500;
}
.detail-answer-section {
  margin-top: 4px;
}
.detail-answer {
  font-size: 18px;
  color: var(--accent-secondary);
  font-weight: 600;
  line-height: 1.4;
  padding: 16px;
  background: rgba(0, 255, 136, 0.08);
  border-radius: var(--radius-md);
  border: 1px solid rgba(0, 255, 136, 0.2);
}
.detail-choices {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.choice-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  font-size: 14px;
  line-height: 1.4;
}
.choice-letter {
  font-weight: 700;
  color: var(--text-muted);
  flex-shrink: 0;
  min-width: 20px;
}
.choice-item.correct {
  background: rgba(0, 255, 136, 0.1);
  border: 1px solid rgba(0, 255, 136, 0.3);
}
.choice-item.correct .choice-letter {
  color: var(--accent-secondary);
}

/* --- Empty State --- */
.empty-state {
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  padding: 40px 20px;
}

/* --- Toast Notifications --- */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--bg-card);
  color: var(--text-primary);
  padding: 12px 24px;
  border-radius: var(--radius-md);
  font-size: 14px;
  border: 1px solid var(--accent-primary);
  transition: transform 0.3s ease;
  z-index: 100;
  pointer-events: none;
}
.toast.visible { transform: translateX(-50%) translateY(0); }
.toast.error { border-color: var(--danger); }
.toast.success { border-color: var(--success); }

/* --- Utility --- */
.hidden { display: none !important; }
