:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --accent: #0284c7;
  --success: #10b981;
  --success-light: #ecfdf5;
  --danger: #ef4444;
  --danger-light: #fef2f2;
  --warning: #f59e0b;
  --warning-light: #fffbeb;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --bg-page: #f8fafc;
  --bg-card: #ffffff;
  --border-color: #e2e8f0;
  --border-active: #3b82f6;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --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);
}

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

body {
  font-family: 'IBM Plex Sans Thai', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-page);
  color: var(--text-main);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

h1, h2, h3, h4, h5, h6, .font-heading {
  font-family: 'Prompt', sans-serif;
  font-weight: 600;
}

/* App Header */
.app-header {
  background: #ffffff;
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0.75rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand-wrapper {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  color: inherit;
}

.brand-logo {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: white;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Prompt', sans-serif;
  font-weight: 700;
  font-size: 1.2rem;
  box-shadow: 0 2px 4px rgba(37, 99, 235, 0.3);
}

.brand-text h1 {
  font-size: 1.1rem;
  color: #0f172a;
  line-height: 1.2;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.badge-sub {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 700;
  background: #e0f2fe;
  color: #0284c7;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

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

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

/* Timer Badge */
.timer-badge {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: #f1f5f9;
  border: 1px solid var(--border-color);
  padding: 0.4rem 0.85rem;
  border-radius: 9999px;
  font-family: 'Prompt', monospace;
  font-weight: 600;
  font-size: 1rem;
  color: #334155;
  transition: all 0.3s ease;
}

.timer-badge.warning {
  background: var(--warning-light);
  border-color: var(--warning);
  color: #b45309;
}

.timer-badge.danger {
  background: var(--danger-light);
  border-color: var(--danger);
  color: #b91c1c;
  animation: pulse-danger 1s infinite alternate;
}

@keyframes pulse-danger {
  from { transform: scale(1); }
  to { transform: scale(1.05); }
}

/* Action Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  font-family: 'Prompt', sans-serif;
  font-weight: 500;
  font-size: 0.95rem;
  padding: 0.55rem 1.15rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
}

.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover {
  background: var(--primary-hover);
  box-shadow: 0 4px 6px -1px rgba(37, 99, 235, 0.3);
}

.btn-outline {
  background: white;
  border-color: var(--border-color);
  color: var(--text-main);
}
.btn-outline:hover {
  background: #f8fafc;
  border-color: #cbd5e1;
}

.btn-flag {
  background: white;
  border-color: var(--border-color);
  color: var(--text-muted);
}
.btn-flag.active {
  background: var(--warning-light);
  border-color: var(--warning);
  color: #b45309;
}

.btn-success {
  background: var(--success);
  color: white;
}
.btn-success:hover {
  background: #059669;
}

.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.85rem;
}

/* Progress bar top */
.progress-container {
  width: 100%;
  height: 4px;
  background-color: #e2e8f0;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #2563eb, #38bdf8);
  width: 0%;
  transition: width 0.3s ease;
}

/* Main Container */
.main-wrapper {
  flex: 1;
  max-width: 1200px;
  width: 100%;
  margin: 1.5rem auto;
  padding: 0 1.25rem;
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 1.5rem;
  align-items: start;
}

@media (max-width: 992px) {
  .main-wrapper {
    grid-template-columns: 1fr;
  }
}

/* Question Area */
.question-card {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  padding: 1.75rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.question-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-color);
}

.category-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.85rem;
  font-weight: 500;
  background: var(--primary-light);
  color: var(--primary);
}

.category-tag.conversation {
  background: #f0fdf4;
  color: #166534;
}
.category-tag.vocabulary {
  background: #fef3c7;
  color: #92400e;
}
.category-tag.grammar {
  background: #ede9fe;
  color: #5b21b6;
}
.category-tag.reading {
  background: #e0f2fe;
  color: #0369a1;
}

.question-counter {
  font-family: 'Prompt', sans-serif;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-muted);
}

/* Passage Area (for reading) */
.passage-box {
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  border-left: 4px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 1.25rem;
  font-size: 0.95rem;
  line-height: 1.7;
  max-height: 380px;
  overflow-y: auto;
  white-space: pre-line;
}

.passage-title {
  font-weight: 600;
  color: #0f172a;
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

/* Question Title */
.question-title {
  font-size: 1.15rem;
  font-weight: 600;
  color: #0f172a;
  line-height: 1.5;
}

/* Options Grid */
.options-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.option-item {
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
  background: #ffffff;
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.9rem 1.1rem;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
}

.option-item:hover {
  border-color: #94a3b8;
  background: #f8fafc;
}

.option-item.selected {
  border-color: var(--primary);
  background: var(--primary-light);
}

.option-letter {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  color: #475569;
  font-family: 'Prompt', sans-serif;
  font-weight: 600;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s ease;
}

.option-item.selected .option-letter {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.option-text {
  flex: 1;
  font-size: 1rem;
  color: #1e293b;
  padding-top: 1px;
}

/* Practice Mode Explanation Box */
.instant-feedback-box {
  margin-top: 1rem;
  padding: 1rem 1.25rem;
  border-radius: var(--radius-sm);
  background: #f8fafc;
  border: 1px solid var(--border-color);
  display: none;
}
.instant-feedback-box.correct {
  background: var(--success-light);
  border-color: #86efac;
}
.instant-feedback-box.incorrect {
  background: var(--danger-light);
  border-color: #fca5a5;
}

/* Footer Navigation inside Question card */
.question-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 0.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-color);
}

/* Sidebar Navigator */
.sidebar-panel {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  padding: 1.25rem;
  position: sticky;
  top: 85px;
}

.sidebar-title {
  font-size: 1rem;
  color: #0f172a;
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.legend-wrapper {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
  margin-bottom: 1rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}
.legend-dot.answered { background: var(--success); }
.legend-dot.unanswered { background: #e2e8f0; }
.legend-dot.flagged { background: var(--warning); }
.legend-dot.current { background: var(--primary); }

.palette-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.palette-btn {
  aspect-ratio: 1;
  background: #f8fafc;
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-family: 'Prompt', sans-serif;
  font-weight: 600;
  font-size: 0.9rem;
  color: #475569;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.palette-btn:hover {
  border-color: #94a3b8;
  background: #f1f5f9;
}

.palette-btn.current {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}

.palette-btn.answered {
  background: var(--success);
  border-color: var(--success);
  color: white;
}

.palette-btn.flagged::after {
  content: '★';
  position: absolute;
  top: -4px;
  right: -2px;
  color: #d97706;
  font-size: 11px;
}

.palette-btn.answered.flagged {
  background: var(--success);
}

.sidebar-stats {
  background: #f8fafc;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.25rem;
}
.stat-row:last-child {
  margin-bottom: 0;
}

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  background: white;
  border-radius: var(--radius-lg);
  max-width: 500px;
  width: 100%;
  padding: 1.75rem;
  box-shadow: var(--shadow-lg);
  transform: translateY(10px);
  transition: transform 0.2s ease;
}

.modal-overlay.active .modal-content {
  transform: translateY(0);
}

.modal-title {
  font-size: 1.25rem;
  color: #0f172a;
  margin-bottom: 0.75rem;
}

.modal-body {
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1.6;
  margin-bottom: 1.5rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

/* Result Screen */
.result-container {
  display: none;
  max-width: 900px;
  margin: 2rem auto;
  padding: 0 1.25rem;
  width: 100%;
}

.result-card {
  background: white;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-md);
  padding: 2.25rem;
  text-align: center;
  margin-bottom: 2rem;
}

.score-circle-wrapper {
  margin: 1rem auto 1.5rem;
  width: 150px;
  height: 150px;
  border-radius: 50%;
  background: conic-gradient(var(--primary) calc(var(--percent) * 1%), #e2e8f0 0);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.score-circle-inner {
  width: 125px;
  height: 125px;
  background: white;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.score-number {
  font-family: 'Prompt', sans-serif;
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
  color: #0f172a;
}

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

.ocsc-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1.25rem;
  border-radius: 9999px;
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 1.25rem;
}

.ocsc-badge.pass {
  background: var(--success-light);
  color: #065f46;
  border: 1px solid #a7f3d0;
}

.ocsc-badge.fail {
  background: var(--danger-light);
  color: #991b1b;
  border: 1px solid #fecaca;
}

/* Category Diagnostics */
.category-diagnostics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin: 2rem 0;
  text-align: left;
}

.diag-card {
  background: #f8fafc;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 1rem;
}

.diag-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.5rem;
}

.diag-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: #334155;
}

.diag-score {
  font-family: 'Prompt', sans-serif;
  font-weight: 600;
  font-size: 0.95rem;
  color: #0f172a;
}

.diag-bar {
  height: 6px;
  background: #e2e8f0;
  border-radius: 3px;
  overflow: hidden;
}

.diag-bar-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 3px;
  transition: width 0.6s ease;
}

/* Review Filter & Cards */
.review-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.filter-pills {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.filter-pill {
  padding: 0.4rem 0.9rem;
  border-radius: 9999px;
  background: white;
  border: 1px solid var(--border-color);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s ease;
}

.filter-pill.active {
  background: #1e293b;
  border-color: #1e293b;
  color: white;
}

.review-list {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.review-card {
  background: white;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
}

.review-card.correct {
  border-left: 4px solid var(--success);
}

.review-card.incorrect {
  border-left: 4px solid var(--danger);
}

.review-card.unanswered {
  border-left: 4px solid var(--warning);
}

.explanation-box {
  margin-top: 1.25rem;
  padding: 1.15rem;
  background: #f8fafc;
  border-radius: var(--radius-sm);
  border: 1px solid #e2e8f0;
  font-size: 0.92rem;
  line-height: 1.7;
}

.explanation-title {
  font-weight: 600;
  color: #0f172a;
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

/* Print Styling */
@media print {
  .app-header, .sidebar-panel, .question-footer, .filter-pills, .btn {
    display: none !important;
  }
  .main-wrapper {
    grid-template-columns: 1fr;
    margin: 0;
    padding: 0;
  }
  .result-container {
    display: block !important;
  }
  .review-card {
    page-break-inside: avoid;
  }
}

/* ========================================================
   LOBBY & SET SELECTION STYLES
   ======================================================== */
.lobby-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1.25rem 4rem;
  width: 100%;
}

.lobby-hero {
  background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 100%);
  color: white;
  border-radius: var(--radius-lg);
  padding: 2.25rem 2rem;
  margin-bottom: 2rem;
  box-shadow: 0 10px 25px -5px rgba(37, 99, 235, 0.25);
  position: relative;
  overflow: hidden;
}

.lobby-hero::after {
  content: '';
  position: absolute;
  right: -40px;
  bottom: -40px;
  width: 220px;
  height: 220px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  pointer-events: none;
}

.lobby-hero h1 {
  font-size: 1.85rem;
  margin-bottom: 0.5rem;
  font-weight: 700;
  color: white;
}

.lobby-hero p {
  color: #dbeafe;
  font-size: 1rem;
  max-width: 750px;
  line-height: 1.6;
}

.lobby-stats-row {
  display: flex;
  gap: 1.5rem;
  margin-top: 1.5rem;
  flex-wrap: wrap;
}

.lobby-stat-box {
  background: rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(8px);
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.lobby-stat-box .stat-val {
  font-size: 1.4rem;
  font-weight: 700;
  font-family: 'Prompt', sans-serif;
  color: #ffffff;
}

.lobby-stat-box .stat-lbl {
  font-size: 0.8rem;
  color: #bfdbfe;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
}

.section-header h2 {
  font-size: 1.35rem;
  color: #0f172a;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.sets-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.25rem;
}

.set-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.35rem;
  display: flex;
  flex-direction: column;
  transition: all 0.25s ease;
  position: relative;
  box-shadow: var(--shadow-sm);
}

.set-card.ready:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: #93c5fd;
}

.set-card.upcoming {
  opacity: 0.78;
  background: #f8fafc;
}

.set-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.85rem;
}

.set-badge-num {
  font-family: 'Prompt', sans-serif;
  font-weight: 700;
  font-size: 0.85rem;
  padding: 0.25rem 0.65rem;
  border-radius: 6px;
  background: #eff6ff;
  color: var(--primary);
  border: 1px solid #bfdbfe;
}

.set-badge-status {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.2rem 0.55rem;
  border-radius: 9999px;
}

.set-badge-status.ready {
  background: #ecfdf5;
  color: #059669;
}

.set-badge-status.upcoming {
  background: #f1f5f9;
  color: #64748b;
}

.set-card-title {
  font-size: 1.15rem;
  color: #0f172a;
  margin-bottom: 0.4rem;
}

.set-card-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 1rem;
  flex-grow: 1;
}

.set-card-meta {
  display: flex;
  gap: 1rem;
  font-size: 0.82rem;
  color: #475569;
  margin-bottom: 1.1rem;
  padding-top: 0.75rem;
  border-top: 1px dashed var(--border-color);
}

.set-card-meta span {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.set-history-badge {
  font-size: 0.8rem;
  padding: 0.35rem 0.65rem;
  border-radius: 6px;
  margin-bottom: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.set-history-badge.passed {
  background: #ecfdf5;
  color: #065f46;
  border: 1px solid #a7f3d0;
}

.set-history-badge.failed {
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

/* Header Set Switcher / Back to Lobby button */
.header-nav-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.btn-lobby {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.38rem 0.7rem;
  border-radius: var(--radius-sm);
  background: #f1f5f9;
  color: #334155;
  font-size: 0.82rem;
  font-weight: 500;
  text-decoration: none;
  border: 1px solid var(--border-color);
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-lobby:hover {
  background: #e2e8f0;
  color: #0f172a;
}

.set-indicator-tag {
  background: #eff6ff;
  color: #1d4ed8;
  font-weight: 600;
  font-size: 0.82rem;
  padding: 0.25rem 0.6rem;
  border-radius: 4px;
  border: 1px solid #dbeafe;
}
