:root {
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  --bg-main: #f8fafc;
  --bg-card: #ffffff;
  --bg-subtle: #f1f5f9;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --border-color: #e2e8f0;
  
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-light: #eff6ff;
  
  --success: #10b981;
  --success-bg: #ecfdf5;
  --success-border: #a7f3d0;
  
  --danger: #ef4444;
  --danger-bg: #fef2f2;
  --danger-border: #fecaca;
  
  --warning: #f59e0b;
  --warning-bg: #fffbeb;
  
  --accent: #8b5cf6;
  --accent-bg: #f5f3ff;
  
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --radius: 12px;
}

[data-theme="dark"] {
  --bg-main: #0b0f19;
  --bg-card: #131b2e;
  --bg-subtle: #1e293b;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --border-color: #334155;
  
  --primary: #60a5fa;
  --primary-hover: #3b82f6;
  --primary-light: #1e293b;
  
  --success: #34d399;
  --success-bg: #064e3b33;
  --success-border: #065f46;
  
  --danger: #f87171;
  --danger-bg: #7f1d1d33;
  --danger-border: #991b1b;
  
  --warning: #fbbf24;
  --warning-bg: #78350f33;
  
  --accent: #a78bfa;
  --accent-bg: #2e106533;
}

html {
  box-sizing: border-box;
  overflow-x: hidden;
  width: 100%;
  max-width: 100%;
  overscroll-behavior-x: none;
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-main);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background-color 0.2s ease, color 0.2s ease;
  overflow-x: hidden;
  width: 100%;
  max-width: 100%;
  position: relative;
  overscroll-behavior-x: none;
}

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 1.5rem 1rem;
  width: 100%;
  min-width: 0;
}

/* Header */
header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  padding: 1rem 0;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow-sm);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo-badge {
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  color: white;
  font-weight: 700;
  font-size: 0.9rem;
  padding: 0.35rem 0.65rem;
  border-radius: 8px;
  letter-spacing: 0.5px;
}

.brand-title {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-primary);
}

.brand-subtitle {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.icon-btn {
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  transition: all 0.15s ease;
}

.icon-btn:hover {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}

/* Navigation Tabs */
.tabs-nav {
  display: flex;
  gap: 0.5rem;
  margin: 1.25rem 0;
  overflow-x: auto;
  padding-bottom: 0.35rem;
  scrollbar-width: thin;
  max-width: 100%;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}

.tabs-nav::-webkit-scrollbar {
  height: 4px;
}

.tabs-nav::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}

.tab-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: 0.65rem 1.1rem;
  border-radius: var(--radius);
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.tab-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.tab-btn.active {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.badge-counter {
  background: var(--danger);
  color: white;
  border-radius: 9999px;
  padding: 0.1rem 0.45rem;
  font-size: 0.75rem;
  font-weight: 700;
  margin-left: 0.2rem;
}

/* Filter bar */
.filter-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  gap: 1rem;
  flex-wrap: wrap;
  max-width: 100%;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
  max-width: 100%;
  min-width: 0;
}

.filter-select {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 0.4rem 0.75rem;
  border-radius: 8px;
  font-size: 0.85rem;
  outline: none;
  max-width: 100%;
  min-width: 0;
  text-overflow: ellipsis;
}

.stats-pill {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  padding: 0.35rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.82rem;
  color: var(--text-secondary);
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  max-width: 100%;
}

.stats-pill strong {
  color: var(--primary);
}

/* Card Container */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 1.75rem;
  box-shadow: var(--shadow-sm);
  margin-bottom: 1.5rem;
  transition: transform 0.15s ease;
  min-width: 0;
  max-width: 100%;
}

/* Question Header */
.question-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.category-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.tag-basic {
  background: var(--primary-light);
  color: var(--primary);
}

.tag-advanced {
  background: var(--accent-bg);
  color: var(--accent);
}

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

/* Progress bar */
.progress-bar-container {
  width: 100%;
  height: 6px;
  background: var(--bg-subtle);
  border-radius: 9999px;
  overflow: hidden;
  margin-bottom: 1.5rem;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  width: 0;
  transition: width 0.3s ease;
}

/* Sentence Box */
.sentence-box {
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 1.25rem 1.5rem;
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 1.5rem;
  line-height: 1.6;
  overflow-wrap: break-word;
  word-break: break-word;
}

.sentence-blank {
  display: inline-block;
  min-width: 90px;
  padding: 0.1rem 0.6rem;
  margin: 0 0.3rem;
  border-bottom: 2px dashed var(--primary);
  color: var(--primary);
  font-style: normal;
  text-align: center;
}

.verb-prompt {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-top: 0.5rem;
}

.verb-badge {
  background: var(--bg-card);
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  font-family: monospace;
  color: var(--primary);
  font-weight: bold;
}

/* Options Grid */
.options-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 0.85rem;
  margin-bottom: 1.5rem;
}

.option-btn {
  background: var(--bg-card);
  border: 2px solid var(--border-color);
  border-radius: 10px;
  padding: 1rem 1.2rem;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-primary);
  text-align: left;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  word-break: break-word;
}

.option-btn:hover:not(:disabled) {
  border-color: var(--primary);
  background: var(--primary-light);
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

.option-btn:disabled {
  cursor: default;
}

.option-btn.correct {
  border-color: var(--success);
  background: var(--success-bg);
  color: var(--success);
}

.option-btn.wrong {
  border-color: var(--danger);
  background: var(--danger-bg);
  color: var(--danger);
}

.option-key {
  font-size: 0.75rem;
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* Input Form for Mode 2 */
.input-answer-wrap {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  max-width: 100%;
}

.answer-input {
  flex: 1;
  min-width: 200px;
  max-width: 100%;
  background: var(--bg-card);
  border: 2px solid var(--border-color);
  border-radius: 10px;
  padding: 0.85rem 1.15rem;
  font-size: 1.1rem;
  font-family: inherit;
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.15s ease;
}

.answer-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.submit-btn {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 10px;
  padding: 0.85rem 1.6rem;
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.submit-btn:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

.secondary-btn {
  background: var(--bg-subtle);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 0.85rem 1.25rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.secondary-btn:hover {
  background: var(--border-color);
}

/* Feedback Box */
.feedback-box {
  border-radius: 10px;
  padding: 1.25rem 1.5rem;
  margin-top: 1.5rem;
  animation: fadeIn 0.25s ease;
  border: 1px solid;
  overflow-wrap: break-word;
  word-break: break-word;
}

.feedback-box.correct {
  background: var(--success-bg);
  border-color: var(--success-border);
}

.feedback-box.wrong {
  background: var(--danger-bg);
  border-color: var(--danger-border);
}

.feedback-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.feedback-box.correct .feedback-title {
  color: var(--success);
}

.feedback-box.wrong .feedback-title {
  color: var(--danger);
}

.feedback-detail {
  color: var(--text-primary);
  margin-bottom: 0.6rem;
  font-size: 0.95rem;
}

.marker-highlight {
  display: inline-block;
  background: rgba(59, 130, 246, 0.15);
  color: var(--primary);
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: 6px;
  margin-top: 0.25rem;
  font-size: 0.88rem;
}

.feedback-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 1.25rem;
}

/* Guide / Cheat sheet */
.guide-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
}

.guide-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
  border-left: 5px solid var(--primary);
}

.guide-card.border-blue { border-left-color: #3b82f6; }
.guide-card.border-purple { border-left-color: #8b5cf6; }
.guide-card.border-green { border-left-color: #10b981; }
.guide-card.border-amber { border-left-color: #f59e0b; }
.guide-card.border-red { border-left-color: #ef4444; }
.guide-card.border-indigo { border-left-color: #6366f1; }

.guide-title-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.guide-title {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-primary);
}

.guide-formula {
  font-family: monospace;
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  padding: 0.25rem 0.6rem;
  border-radius: 6px;
  font-size: 0.9rem;
  color: var(--primary);
  font-weight: bold;
}

.guide-markers {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.6rem 0 1rem 0;
}

.marker-pill {
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  font-size: 0.8rem;
  padding: 0.15rem 0.5rem;
  border-radius: 9999px;
  color: var(--text-secondary);
}

.guide-case {
  background: var(--bg-subtle);
  border-radius: 8px;
  padding: 0.85rem 1rem;
  margin-top: 0.6rem;
}

.guide-case-rule {
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--text-primary);
  margin-bottom: 0.2rem;
}

.guide-case-example {
  font-style: italic;
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 0.2rem;
}

.guide-case-note {
  font-size: 0.82rem;
  color: var(--text-muted);
}

/* Traps Section */
.trap-card {
  background: var(--bg-card);
  border: 1px solid var(--warning-bg);
  border-left: 5px solid var(--warning);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1rem;
}

.trap-title {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}

.trap-comparison {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin: 0.5rem 0;
}

.trap-wrong {
  background: var(--danger-bg);
  border: 1px solid var(--danger-border);
  padding: 0.6rem 0.8rem;
  border-radius: 6px;
  color: var(--danger);
  font-weight: 600;
  font-size: 0.9rem;
}

.trap-right {
  background: var(--success-bg);
  border: 1px solid var(--success-border);
  padding: 0.6rem 0.8rem;
  border-radius: 6px;
  color: var(--success);
  font-weight: 600;
  font-size: 0.9rem;
}

.trap-expl {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 0.5rem;
}

/* Exam Screen */
.exam-summary {
  text-align: center;
  padding: 2rem 1rem;
}

.exam-grade-circle {
  width: 110px;
  height: 110px;
  border-radius: 50%;
  margin: 0 auto 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
  font-weight: 800;
  color: white;
  box-shadow: var(--shadow-lg);
}

.grade-5 { background: linear-gradient(135deg, #10b981, #059669); }
.grade-4 { background: linear-gradient(135deg, #3b82f6, #2563eb); }
.grade-3 { background: linear-gradient(135deg, #f59e0b, #d97706); }
.grade-2 { background: linear-gradient(135deg, #ef4444, #dc2626); }

.exam-score-text {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.4rem;
}

.exam-feedback-msg {
  color: var(--text-secondary);
  font-size: 1rem;
  margin-bottom: 1.75rem;
  max-width: 500px;
  margin-left: auto;
  margin-right: auto;
}

.exam-stats-row {
  display: flex;
  justify-content: center;
  gap: 2rem;
  margin-bottom: 2rem;
  flex-wrap: wrap;
}

.stat-item {
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  padding: 0.75rem 1.5rem;
  border-radius: 10px;
}

.stat-val {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
}

.stat-lbl {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--text-secondary);
}

.empty-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
}

/* Footer */
footer {
  margin-top: auto;
  padding: 1.5rem 0;
  text-align: center;
  font-size: 0.82rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border-color);
}

/* Responsive Mobile Layout */
@media (max-width: 640px) {
  .container {
    padding: 1rem 0.75rem;
  }

  header {
    padding: 0.75rem 0;
  }

  .header-inner {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }

  .brand {
    gap: 0.6rem;
    min-width: 0;
  }

  .brand-title {
    font-size: 1.1rem;
  }

  .brand-subtitle {
    font-size: 0.75rem;
    line-height: 1.3;
    word-break: break-word;
  }

  .header-actions {
    display: flex;
    width: 100%;
    gap: 0.5rem;
  }

  .header-actions .icon-btn {
    flex: 1;
    justify-content: center;
    padding: 0.5rem 0.6rem;
    font-size: 0.85rem;
  }

  .filter-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }

  .filter-group {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    gap: 0.35rem;
  }

  .filter-select {
    width: 100%;
    font-size: 0.85rem;
    padding: 0.5rem 0.65rem;
  }

  .stats-pill {
    width: 100%;
    justify-content: space-around;
    padding: 0.45rem 0.5rem;
    font-size: 0.78rem;
    gap: 0.4rem;
  }

  .card {
    padding: 1.25rem 0.85rem;
    margin-bottom: 1rem;
    border-radius: 10px;
  }

  .sentence-box {
    padding: 1rem 0.85rem;
    font-size: 1.05rem;
    margin-bottom: 1.2rem;
  }

  .sentence-blank {
    min-width: 60px;
  }

  .options-grid {
    grid-template-columns: 1fr;
    gap: 0.65rem;
    margin-bottom: 1.2rem;
  }

  .option-btn {
    padding: 0.85rem 1rem;
    font-size: 0.95rem;
  }

  .input-answer-wrap {
    flex-direction: column;
    gap: 0.65rem;
  }

  .answer-input {
    min-width: 0;
    width: 100%;
    padding: 0.75rem 0.85rem;
    font-size: 0.98rem;
  }

  .submit-btn {
    width: 100%;
    justify-content: center;
    padding: 0.75rem 1rem;
  }

  .feedback-box {
    padding: 1rem 0.85rem;
    margin-top: 1rem;
  }

  .feedback-actions .submit-btn {
    width: 100%;
    justify-content: center;
  }

  .guide-card {
    padding: 1.1rem 0.85rem;
  }

  .guide-title-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.35rem;
  }

  .guide-formula {
    word-break: break-all;
    font-size: 0.85rem;
  }

  .trap-card {
    padding: 1rem 0.85rem;
  }

  .trap-comparison {
    grid-template-columns: 1fr;
  }

  .exam-stats-row {
    gap: 0.75rem;
  }

  .stat-item {
    flex: 1;
    min-width: 110px;
    padding: 0.65rem 0.75rem;
    text-align: center;
  }
}
