/* ============================================
   style.css - สไตล์หลักสำหรับเว็บฝึกข้อสอบ สป.กห. (Refactored)
   ============================================ */

/* CSS Variables */
:root {
  /* Category Colors - สีประจำหมวด */
  --t1: #1e6091; /* จริยธรรม กห. - สีฟ้า */
  --t2: #0e7c6b; /* รปภ.แห่งชาติ - สีเขียว */
  --t3: #a35e12; /* งานสารบรรณ - สีส้ม */
  --t4: #7c3aed; /* พรบ.ข้อมูลฯ - สีม่วง */
  --t5: #8b5cf6; /* ภาษาไทย */
  --t6: #3b82f6; /* ภาษาอังกฤษ */
  --t7: #10b981; /* ความสามารถทั่วไป */

  /* UI Colors (Default to Dark) */
  --bg: #0f1419;
  --bg-alt: #1a2028;
  --bg-card: #232b35;
  --fg: #e8eaed;
  --fg-muted: #9aa0a6;
  --accent: #00d4aa;
  --accent-hover: #00f5c4;
  --success: #10b981;
  --error: #ef4444;
  --warning: #f59e0b;

  /* Typography */
  --font-main: "Sarabun", sans-serif;
  --font-size-base: 18px;
  --line-height: 1.8;

  /* Spacing */
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 20px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
  --shadow-hover: 0 8px 32px rgba(0, 0, 0, 0.4);

  /* Transitions */
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Category Colors & Badge Styles (Moved out of :root) */
.cat-ethics {
  background: linear-gradient(135deg, var(--t1), #2d8bc9);
}
.cat-security {
  background: linear-gradient(135deg, var(--t2), #14b8a6);
}
.cat-archives {
  background: linear-gradient(135deg, var(--t3), #d97706);
}
.cat-infoact {
  background: linear-gradient(135deg, var(--t4), #8b5cf6);
}
.cat-thai {
  background: linear-gradient(135deg, var(--t5), #a78bfa);
}
.cat-english {
  background: linear-gradient(135deg, var(--t6), #60a5fa);
}
.cat-aptitude {
  background: linear-gradient(135deg, var(--t7), #34d399);
}
.cat-logic {
  background: linear-gradient(135deg, #ec4899, #f472b6);
}

.quiz-category-badge.logic {
  background: rgba(236, 72, 153, 0.15);
  color: #ec4899;
}
.accordion-icon.logic {
  background: #ec4899;
}

/* Light Theme */
[data-theme="light"] {
  --bg: #f8fafc;
  --bg-alt: #ffffff;
  --bg-card: #ffffff;
  --fg: #1a2028;
  --fg-muted: #64748b;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
  --shadow-hover: 0 8px 32px rgba(0, 0, 0, 0.12);
}

/* ============================================
   Base Styles
   ============================================ */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: var(--font-size-base);
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-main);
  font-size: 1rem;
  line-height: var(--line-height);
  background: var(--bg);
  color: var(--fg);
  min-height: 100vh;
  overflow-x: hidden;
  transition:
    background var(--transition),
    color var(--transition);
}

/* Subtle background pattern */
body::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background:
    radial-gradient(
      circle at 20% 20%,
      rgba(0, 212, 170, 0.03) 0%,
      transparent 50%
    ),
    radial-gradient(
      circle at 80% 80%,
      rgba(30, 96, 145, 0.03) 0%,
      transparent 50%
    );
  pointer-events: none;
  z-index: -1;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.5rem;
}

/* ============================================
   Typography
   ============================================ */
h1,
h2,
h3,
h4,
h5,
h6 {
  font-weight: 700;
  line-height: 1.3;
  margin-bottom: 0.5em;
}

h1 {
  font-size: 2.5rem;
}
h2 {
  font-size: 2rem;
}
h3 {
  font-size: 1.5rem;
}

p {
  margin-bottom: 1rem;
  color: var(--fg-muted);
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color var(--transition);
}

a:hover {
  color: var(--accent-hover);
}

/* Key Term Highlight - ไฮไลต์ข้อมูลสำคัญ */
.kt {
  background: rgba(253, 246, 227, 0.15);
  color: #ffd966;
  padding: 0.1em 0.4em;
  border-radius: 4px;
  border: 1px solid rgba(230, 213, 168, 0.3);
  font-weight: 600;
  display: inline-block;
  max-width: 100%;
  white-space: normal;
}

[data-theme="light"] .kt {
  background: #fdf6e3;
  border-color: #e6d5a8;
  color: #8b5a00;
}

/* ============================================
   Buttons
   ============================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  font-family: var(--font-main);
  font-size: 1rem;
  font-weight: 600;
  border: 2px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.btn-primary {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 212, 170, 0.3);
}

.btn-outline {
  background: transparent;
  color: var(--fg);
  border-color: var(--fg-muted);
}

.btn-outline:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-danger {
  background: var(--error);
  color: white;
  border-color: var(--error);
}

.btn-danger:hover {
  background: #dc2626;
  transform: translateY(-2px);
}

.btn-lg {
  padding: 1rem 2rem;
  font-size: 1.125rem;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

/* ============================================
   Header
   ============================================ */
.main-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-alt);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

[data-theme="light"] .main-header {
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 0;
  gap: 1rem;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  cursor: pointer;
  transition: transform var(--transition);
}

.logo:hover {
  transform: scale(1.02);
}

.logo-icon {
  width: 48px;
  height: 48px;
  background: linear-gradient(135deg, var(--t1), var(--accent));
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  color: white;
}

.logo-text {
  display: flex;
  flex-direction: column;
}

.logo-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--fg);
}

.logo-subtitle {
  font-size: 0.75rem;
  color: var(--fg-muted);
}

.main-nav {
  display: flex;
  gap: 0.5rem;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  color: var(--fg-muted);
  border-radius: var(--radius-sm);
  font-weight: 500;
  transition: all var(--transition);
}

.nav-link:hover {
  color: var(--fg);
  background: rgba(255, 255, 255, 0.05);
}

[data-theme="light"] .nav-link:hover {
  background: rgba(0, 0, 0, 0.05);
}

.nav-link.active {
  color: var(--accent);
  background: rgba(0, 212, 170, 0.1);
}

.menu-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--fg);
  cursor: pointer;
  padding: 0.5rem;
}

.theme-toggle {
  background: none;
  border: none;
  font-size: 1.25rem;
  color: var(--fg-muted);
  cursor: pointer;
  padding: 0.5rem;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}

.theme-toggle:hover {
  color: var(--accent);
  background: rgba(0, 212, 170, 0.1);
}

/* ============================================
   Hero Section
   ============================================ */
.hero {
  position: relative;
  padding: 4rem 0 3rem;
  text-align: center;
  overflow: hidden;
}

.hero-bg {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 800px;
  height: 400px;
  background: radial-gradient(
    ellipse at center,
    rgba(0, 212, 170, 0.1) 0%,
    transparent 70%
  );
  pointer-events: none;
}

.hero-content {
  position: relative;
  z-index: 1;
}

.hero-title {
  font-size: 3rem;
  font-weight: 800;
  margin-bottom: 0.5rem;
  background: linear-gradient(135deg, var(--fg) 0%, var(--accent) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero-subtitle {
  font-size: 1.25rem;
  color: var(--fg-muted);
  margin-bottom: 0.5rem;
}

.hero-desc {
  max-width: 600px;
  margin: 0 auto 2rem;
  font-size: 1rem;
}

.hero-actions {
  display: flex;
  gap: 1rem;
  justify-content: center;
  flex-wrap: wrap;
}

/* ============================================
   Section Header
   ============================================ */
.section-header {
  text-align: center;
  margin-bottom: 2rem;
}

.section-header h2 {
  color: var(--fg);
  margin-bottom: 0.5rem;
}

.section-header p {
  color: var(--fg-muted);
  margin-bottom: 0;
}

/* ============================================
   Category Cards
   ============================================ */
/* ค้นหาและแทนที่ หรือเพิ่มโค้ดนี้ลงไปครับ */
.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
  padding: 1rem 0;
  width: 100%;
}

/* ทำให้การ์ดมีความสูงขั้นต่ำและยืดตามเนื้อหาได้ดี */
.category-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.5rem;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid rgba(255, 255, 255, 0.05);
  cursor: pointer;
  transition: all var(--transition);
  min-height: 140px;           /* เพิ่มเพื่อให้การ์ดสูงเท่ากัน */
  box-sizing: border-box;
  width: 100%;
}

[data-theme="light"] .category-card {
  border: 1px solid rgba(0, 0, 0, 0.05);
}

.category-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-hover);
  border-color: rgba(255, 255, 255, 0.1);
}

.category-card:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.category-icon {
  width: 60px;
  height: 60px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  color: white;
  flex-shrink: 0;
}

.category-info {
  flex: 1;
  min-width: 0;
}

.category-info h3 {
  font-size: 1.125rem;
  margin-bottom: 0.25rem;
  color: var(--fg);
}

.category-info p {
  font-size: 0.85rem;
  color: var(--fg-muted);
  margin-bottom: 0.5rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.category-meta {
  display: flex;
  align-items: center;
  gap: 1rem;
  font-size: 0.85rem;
}

.category-meta span {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  color: var(--fg-muted);
}

.progress-badge {
  background: rgba(0, 212, 170, 0.15);
  color: var(--accent);
  padding: 0.2em 0.6em;
  border-radius: 20px;
  font-weight: 600;
  font-size: 0.8rem;
}

.category-arrow {
  color: var(--fg-muted);
  transition: transform var(--transition);
}

.category-card:hover .category-arrow {
  transform: translateX(4px);
  color: var(--accent);
}

/* ============================================
   Stats Section
   ============================================ */
.stats-section {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.stat-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.25rem;
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

[data-theme="light"] .stat-card {
  border: 1px solid rgba(0, 0, 0, 0.05);
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  background: rgba(0, 212, 170, 0.1);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
}

.stat-icon.success {
  background: rgba(16, 185, 129, 0.1);
  color: var(--success);
}
.stat-icon.warning {
  background: rgba(245, 158, 11, 0.1);
  color: var(--warning);
}
.stat-icon.info {
  background: rgba(30, 96, 145, 0.1);
  color: var(--t1);
}

.stat-info {
  display: flex;
  flex-direction: column;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--fg);
  line-height: 1.2;
}

.stat-label {
  font-size: 0.85rem;
  color: var(--fg-muted);
}

/* ============================================
   Quiz Page
   ============================================ */
.page {
  display: none;
  padding: 2rem 0;
  animation: fadeIn 0.3s ease;
}

.page.active {
  display: block;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.quiz-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: 1rem;
}

.quiz-category-badge {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  background: rgba(30, 96, 145, 0.15);
  color: var(--t1);
  border-radius: 20px;
  font-weight: 600;
}

.quiz-category-badge.security {
  background: rgba(14, 124, 107, 0.15);
  color: var(--t2);
}
.quiz-category-badge.archives {
  background: rgba(163, 94, 18, 0.15);
  color: var(--t3);
}
.quiz-category-badge.infoact {
  background: rgba(124, 58, 237, 0.15);
  color: var(--t4);
}

.quiz-progress-info {
  color: var(--fg-muted);
  font-weight: 500;
}

.progress-bar-container {
  height: 8px;
  background: var(--bg-card);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 2rem;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--t1));
  border-radius: 10px;
  transition: width 0.4s ease;
}

/* Quiz Questions Container */
.quiz-questions-container {
  display: flex;
  flex-direction: column;
  gap: 30px;
  margin-top: 20px;
}

.quiz-question-card {
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: var(--radius-lg);
  padding: 20px;
  transition: box-shadow 0.2s;
}

[data-theme="light"] .quiz-question-card {
  border: 1px solid rgba(0, 0, 0, 0.05);
}

.quiz-question-card:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.question-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
  padding-bottom: 10px;
  border-bottom: 2px solid rgba(255, 255, 255, 0.05);
}

[data-theme="light"] .question-header {
  border-bottom: 2px solid rgba(0, 0, 0, 0.05);
}

.question-num {
  font-weight: bold;
  font-size: 1.1rem;
  color: var(--accent);
}

.question-status {
  font-size: 0.85rem;
}

.question-text {
  font-size: 1.1rem;
  line-height: 1.6;
  margin-bottom: 15px;
  font-weight: 500;
  color: var(--fg);
  word-break: break-word;
  overflow-wrap: break-word;
}

/* Choices */
.choices-container {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.choice-btn {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  padding: 1rem 1.25rem;
  background: var(--bg-alt);
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: left;
  transition: all var(--transition);
  font-family: var(--font-main);
  font-size: 1rem;
  color: var(--fg);
  line-height: 1.6;
  white-space: normal;
  height: auto;
}

[data-theme="light"] .choice-btn {
  border: 2px solid rgba(0, 0, 0, 0.1);
}

.choice-btn:hover:not(.selected):not(.correct):not(.wrong) {
  border-color: var(--accent);
  background: rgba(0, 212, 170, 0.05);
  transform: translateX(5px);
}

.choice-btn:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.choice-letter {
  width: 32px;
  height: 32px;
  min-width: 32px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
  transition: all var(--transition);
}

[data-theme="light"] .choice-letter {
  background: rgba(0, 0, 0, 0.05);
}

.choice-text {
  flex: 1;
  word-break: break-word;
  overflow-wrap: break-word;
}

.choice-btn.selected {
  border-color: var(--accent);
  background: rgba(0, 212, 170, 0.1);
}

.choice-btn.selected .choice-letter {
  background: var(--accent);
  color: var(--bg);
}

.choice-btn.correct {
  border-color: var(--success);
  background: rgba(16, 185, 129, 0.15);
}

.choice-btn.correct .choice-letter {
  background: var(--success);
  color: white;
}

.choice-btn.wrong {
  border-color: var(--error);
  background: rgba(239, 68, 68, 0.15);
}

.choice-btn.wrong .choice-letter {
  background: var(--error);
  color: white;
}

/* Explanation Box */
.explanation-box {
  margin-top: 1.5rem;
  padding: 1.25rem;
  background: rgba(0, 212, 170, 0.05);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-sm);
  animation: fadeIn 0.3s ease;
}

.explanation-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 0.75rem;
}

.explanation-content {
  color: var(--fg);
  line-height: 1.8;
  white-space: normal;
  word-break: break-word;
  overflow-wrap: break-word;
}

/* Quiz Actions */
.quiz-actions {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

/* ============================================
   Cheat Sheet Page
   ============================================ */
.cheatsheet-container {
  max-width: 900px;
  margin: 0 auto;
}

.accordion-item {
  background: var(--bg-card);
  border-radius: var(--radius);
  margin-bottom: 1rem;
  border: 1px solid rgba(255, 255, 255, 0.05);
  overflow: hidden;
}

[data-theme="light"] .accordion-item {
  border: 1px solid rgba(0, 0, 0, 0.05);
}

.accordion-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.25rem 1.5rem;
  cursor: pointer;
  transition: all var(--transition);
  background: transparent;
  border: none;
  width: 100%;
  text-align: left;
  font-family: var(--font-main);
  color: var(--fg);
}

.accordion-header:hover {
  background: rgba(255, 255, 255, 0.02);
}

[data-theme="light"] .accordion-header:hover {
  background: rgba(0, 0, 0, 0.02);
}

.accordion-icon {
  width: 44px;
  height: 44px;
  min-width: 44px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.125rem;
  color: white;
}

.accordion-icon.ethics {
  background: var(--t1);
}
.accordion-icon.security {
  background: var(--t2);
}
.accordion-icon.archives {
  background: var(--t3);
}
.accordion-icon.infoact {
  background: var(--t4);
}

.accordion-title-group {
  flex: 1;
}

.accordion-title {
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.accordion-subtitle {
  font-size: 0.85rem;
  color: var(--fg-muted);
}

.accordion-chevron {
  color: var(--fg-muted);
  transition: transform var(--transition);
}

.accordion-item.open .accordion-chevron {
  transform: rotate(180deg);
}

.accordion-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.25s ease;
}

.accordion-item.open .accordion-content {
  max-height: 5000px; /* Increased for long cheat sheets */
}

.accordion-body {
  padding: 0 1.5rem 1.5rem;
}

.accordion-body pre {
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: break-word;
  color: var(--fg);
  font-family: var(--font-main);
  font-size: 0.95rem;
  line-height: 1.7;
  margin: 0;
  background: transparent;
  border: none;
  padding: 0;
}

/* ============================================
   Progress Page
   ============================================ */
.progress-overview {
  display: flex;
  justify-content: center;
  margin-bottom: 3rem;
}

.progress-circle-container {
  position: relative;
  width: 200px;
  height: 200px;
}

.progress-circle {
  transform: rotate(-90deg);
  width: 200px;
  height: 200px;
}

.progress-bg {
  fill: none;
  stroke: var(--bg-card);
  stroke-width: 12;
}

.progress-fill {
  fill: none;
  stroke: var(--accent);
  stroke-width: 12;
  stroke-linecap: round;
  stroke-dasharray: 565;
  stroke-dashoffset: 565; /* Start empty */
  transition: stroke-dashoffset 0.6s ease;
}

.progress-center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
}

.progress-percent {
  display: block;
  font-size: 2.5rem;
  font-weight: 800;
  color: var(--fg);
  line-height: 1;
}

.progress-label {
  font-size: 0.85rem;
  color: var(--fg-muted);
}

/* Category Progress List (Added for future use/script fix) */
.category-progress-list {
  display: grid;
  gap: 1rem;
  margin-bottom: 3rem;
}

.category-progress-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.25rem;
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.category-progress-icon {
  width: 48px;
  height: 48px;
  min-width: 48px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 1.25rem;
}

.category-progress-info {
  flex: 1;
}

.category-progress-name {
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.category-progress-bar {
  height: 8px;
  background: var(--bg-alt);
  border-radius: 10px;
  overflow: hidden;
}

.category-progress-fill {
  height: 100%;
  border-radius: 10px;
  transition: width 0.4s ease;
}

.category-progress-stats {
  text-align: right;
  min-width: 100px;
}

.category-progress-percent {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--fg);
}

.category-progress-count {
  font-size: 0.85rem;
  color: var(--fg-muted);
}

/* History Section */
.history-section {
  margin-bottom: 2rem;
}

.history-section h3 {
  margin-bottom: 1rem;
  color: var(--fg);
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

[data-theme="light"] .history-item {
  border: 1px solid rgba(0, 0, 0, 0.05);
}

.history-item-info {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.history-item-category {
  font-weight: 500;
}

.history-item-score {
  font-weight: 700;
  color: var(--accent);
}

.history-item-date {
  font-size: 0.85rem;
  color: var(--fg-muted);
}

/* Actions Section */
.actions-section {
  text-align: center;
  padding: 2rem 0;
}

/* ============================================
   Modal
   ============================================ */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition);
}

.modal.open {
  opacity: 1;
  visibility: visible;
}

.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 2.5rem;
  max-width: 400px;
  width: 90%;
  text-align: center;
  transform: scale(0.9);
  transition: transform var(--transition);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

[data-theme="light"] .modal-content {
  border: 1px solid rgba(0, 0, 0, 0.1);
}

.modal.open .modal-content {
  transform: scale(1);
}

.result-icon {
  width: 80px;
  height: 80px;
  margin: 0 auto 1rem;
  background: linear-gradient(135deg, var(--accent), var(--t1));
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  color: white;
  animation: bounceIn 0.5s ease;
}

@keyframes bounceIn {
  0% {
    transform: scale(0);
  }
  50% {
    transform: scale(1.2);
  }
  100% {
    transform: scale(1);
  }
}

.result-icon.good {
  background: linear-gradient(135deg, var(--success), #059669);
}

.result-icon.average {
  background: linear-gradient(135deg, var(--warning), #d97706);
}

.result-icon.poor {
  background: linear-gradient(135deg, var(--error), #dc2626);
}

.modal-header h2 {
  color: var(--fg);
  margin-bottom: 1rem;
}

.result-score {
  margin-bottom: 1rem;
}

.score-number {
  font-size: 3rem;
  font-weight: 800;
  color: var(--accent);
}

.score-total {
  font-size: 1.5rem;
  color: var(--fg-muted);
}

.result-message {
  color: var(--fg-muted);
  margin-bottom: 1rem;
}

.result-time {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  color: var(--fg-muted);
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
}

.modal-actions {
  display: flex;
  gap: 1rem;
  justify-content: center;
}

/* ============================================
   Toast Notifications
   ============================================ */
#toast-container {
  position: fixed;
  top: 80px;
  right: 1rem;
  z-index: 1001;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  animation: slideInRight 0.3s ease;
  min-width: 280px;
  border-left: 4px solid var(--accent);
}

@keyframes slideInRight {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

.toast.success {
  border-left-color: var(--success);
}
.toast.error {
  border-left-color: var(--error);
}
.toast.warning {
  border-left-color: var(--warning);
}

.toast-icon {
  font-size: 1.25rem;
}

.toast.success .toast-icon {
  color: var(--success);
}
.toast.error .toast-icon {
  color: var(--error);
}
.toast.warning .toast-icon {
  color: var(--warning);
}

.toast-message {
  flex: 1;
  color: var(--fg);
  font-weight: 500;
}

.toast-close {
  background: none;
  border: none;
  color: var(--fg-muted);
  cursor: pointer;
  padding: 0.25rem;
  transition: color var(--transition);
}

.toast-close:hover {
  color: var(--fg);
}

/* ============================================
   Footer
   ============================================ */
.main-footer {
  padding: 2rem 0;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  margin-top: 2rem;
}

[data-theme="light"] .main-footer {
  border-top: 1px solid rgba(0, 0, 0, 0.05);
}

.footer-content {
  text-align: center;
}

.footer-content p {
  margin-bottom: 0.25rem;
  font-size: 0.9rem;
}

.footer-note {
  font-size: 0.8rem !important;
  color: var(--fg-muted);
}

/* ============================================
   Fraction Styling - สไตล์สำหรับแสดงเศษส่วน
   ============================================ */
.fraction {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  vertical-align: middle;
  margin: 0 4px;
  font-size: 0.9em;
  line-height: 1;
}

.fraction .numerator {
  border-bottom: 2px solid var(--fg);
  padding: 0 4px;
  text-align: center;
  width: 100%;
}

.fraction .denominator {
  padding: 2px 4px 0;
  text-align: center;
  width: 100%;
}

/* ============================================
   Responsive Design
   ============================================ */
/* ============================================
Responsive Design - ปรับปรุงสำหรับมือถือ
============================================ */
/* ============================================
Responsive Design - แก้ไขจุดบกพร่องบนมือถือ
============================================ */
/* ============================================
Responsive Design - แก้ไขจุดบกพร่องบนมือถือ
============================================ */
/* สำหรับหน้าจอเล็ก (มือถือ) - บังคับ 1 คอลัมน์ แต่ให้การ์ดขยายเต็มพื้นที่ */
/* ============================================
   Responsive Design - หมวดหมู่แสดงถูกต้องบนมือถือ
   ============================================ */

@media (max-width: 768px) {
  .category-grid {
    grid-template-columns: repeat(auto-fit, minmax(100%, 1fr)) !important;
    gap: 1.25rem;
    padding: 1.25rem 1rem 3.5rem 1rem;
    width: 100%;
  }

  .category-card {
    min-height: 168px;           /* ปรับให้สูงขึ้นเล็กน้อย ดูสมดุล */
    width: 100% !important;
    margin: 0 auto;
    box-sizing: border-box;
  }

  /* ปรับ Hero บนมือถือ */
  .hero-title {
    font-size: 2.25rem;
  }

  .hero-desc {
    font-size: 1rem;
    padding: 0 0.5rem;
  }

  /* Stats Section */
  .stats-section {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.8rem;
    padding: 0 0.5rem;
  }
}

/* สำหรับหน้าจอเล็กมาก (≤ 480px) */
@media (max-width: 480px) {
  .category-grid {
    grid-template-columns: repeat(auto-fit, minmax(100%, 1fr)) !important;
    gap: 1rem;
    padding: 1rem 0.75rem 3rem 0.75rem;
  }

  .category-card {
    min-height: 155px;
    padding: 1.25rem;
    font-size: 0.95rem;           /* ปรับตัวอักษรให้พอดี */
  }

  .hero-title {
    font-size: 2rem;
  }
}

/* ============================================
   Reduced Motion
   ============================================ */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============================================
   Print Styles
   ============================================ */
@media print {
  .main-header,
  .main-footer,
  .toast,
  .modal,
  .quiz-actions,
  .actions-section {
    display: none !important;
  }

  body {
    background: white;
    color: black;
  }

  .kt {
    background: #fdf6e3;
    border-color: #e6d5a8;
    color: #8b5a00;
  }
}

/* สีประจำหมวด Logic */
.cat-logic {
  background: linear-gradient(135deg, #ec4899, #f472b6); /* สีชมพู */
}

/* Badge ในหน้า Quiz */
.quiz-category-badge.logic {
  background: rgba(236, 72, 153, 0.15);
  color: #ec4899;
}

/* ไอคอนในหน้า Cheat Sheet (ถ้ามีในอนาคต) */
.accordion-icon.logic {
  background: #ec4899;
}

/* Progress Bar ในหน้าความคืบหน้า */
.category-progress-icon.cat-logic {
  background: #ec4899;
}
.category-progress-fill.logic-color {
  background: #ec4899 !important;
}

/* English Tabs */
.english-tabs {
  width: 100%;
}

.tab-container {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  background: var(--bg-card);
  padding: 8px;
  border-radius: var(--radius);
  border: 1px solid rgba(255,255,255,0.08);
}

.tab-btn {
  flex: 1;
  min-width: 100px;
  padding: 12px 16px;
  background: transparent;
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--fg-muted);
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.tab-btn:hover {
  background: rgba(0, 212, 170, 0.1);
  color: var(--accent);
}

.tab-btn.active {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}

@media (max-width: 576px) {
  .tab-container {
    flex-direction: column;
  }
  .tab-btn {
    min-width: auto;
  }
}

/* Reading Passage Styling */
.reading-passage {
  background: var(--bg-alt);
  border-left: 5px solid var(--accent);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  line-height: 1.7;
  color: var(--fg);
  white-space: pre-wrap;
  word-break: break-word;
}

.passage-header {
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 0.75rem;
  font-size: 1.05rem;
}

.passage-content {
  font-family: var(--font-main);
}

.question-type-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  margin-left: 12px;
}
.question-type-badge.conversation { background: #3b82f620; color: #3b82f6; }
.question-type-badge.grammar { background: #10b98120; color: #10b981; }
.question-type-badge.reading { background: #f59e0b20; color: #f59e0b; }
