/* Clean, Developer-Centric Design System (Linear/Vercel/GitHub inspired) */

:root {
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

  /* Matte Dark Zinc Color Palette */
  --bg-primary: #09090b;   /* Zinc 950 - pitch black-gray */
  --bg-secondary: #0c0c0e; /* Header and sidebar background */
  --bg-card: #18181b;      /* Zinc 900 - card backgrounds */
  --bg-input: #18181b;
  
  --border-color: #27272a; /* Zinc 800 - crisp, thin borders */
  --border-light: #1f1f23; /* Zinc 850 */

  --text-primary: #fafafa;   /* Zinc 50 */
  --text-secondary: #a1a1aa; /* Zinc 400 */
  --text-muted: #52525b;     /* Zinc 600 */

  --accent-color: #3f3f46;   /* Zinc 700 - clean neutral actions */
  --accent-hover: #52525b;   /* Zinc 600 */
  --accent-blue: #3b82f6;    /* Soft blue for primary highlights */
  --accent-blue-light: rgba(59, 130, 246, 0.1);

  --correct-color: #10b981;  /* Clean Emerald */
  --correct-bg: #064e3b;     /* Dark green */
  --correct-border: #047857;

  --incorrect-color: #ef4444; /* Clean Red */
  --incorrect-bg: #4c0519;    /* Dark red */
  --incorrect-border: #991b1b;

  --bookmark-color: #f59e0b; /* Amber */
  --bookmark-bg: rgba(245, 158, 11, 0.08);

  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;

  --transition: 0.12s ease-out;
}

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

body {
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-family);
  font-size: 14px;
  line-height: 1.5;
  height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Scrollbars */
::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}
::-webkit-scrollbar-track {
  background: var(--bg-primary);
}
::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: var(--radius-sm);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

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

.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
}

/* Headings */
h1, h2, h3, h4 {
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}

/* Crisp Buttons */
.btn {
  font-family: var(--font-family);
  font-weight: 500;
  font-size: 13px;
  padding: 8px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--bg-card);
  color: var(--text-primary);
  transition: all var(--transition);
}

.btn:hover {
  background: #27272a;
  border-color: #3f3f46;
}

.btn-primary {
  background: #ffffff;
  color: #000000;
  border-color: #ffffff;
}
.btn-primary:hover {
  background: #e4e4e7;
  border-color: #e4e4e7;
}

.btn-secondary {
  background: transparent;
  border-color: var(--border-color);
  color: var(--text-secondary);
}
.btn-secondary:hover {
  color: var(--text-primary);
  border-color: var(--accent-hover);
  background: rgba(255, 255, 255, 0.03);
}

.btn-accent {
  background: transparent;
  color: #60a5fa;
  border-color: rgba(96, 165, 250, 0.4);
}
.btn-accent:hover {
  background: var(--accent-blue-light);
  border-color: #60a5fa;
}

.btn-danger {
  background: #7f1d1d;
  color: #fca5a5;
  border-color: #991b1b;
}
.btn-danger:hover {
  background: #991b1b;
  border-color: #b91c1c;
}

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

.btn-icon-only {
  width: 32px;
  height: 32px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Landing Dropzone */
.dropzone-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
  background-color: var(--bg-primary);
}

.dropzone-card {
  width: 100%;
  max-width: 550px;
  text-align: center;
  padding: 48px 36px;
  border: 1px dashed var(--border-color);
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  transition: all var(--transition);
}

.dropzone-card.dragover {
  border-color: var(--accent-blue);
  background: rgba(59, 130, 246, 0.02);
}

.dropzone-icon {
  color: var(--text-secondary);
  margin-bottom: 20px;
}

.dropzone-card h2 {
  font-size: 20px;
  margin-bottom: 8px;
}

.dropzone-card p {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 24px;
}

.file-input-wrapper {
  position: relative;
  display: inline-block;
  margin-bottom: 20px;
}

.file-input-wrapper input[type="file"] {
  position: absolute;
  left: 0;
  top: 0;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

.demo-notice {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
  border-top: 1px solid var(--border-color);
  padding-top: 20px;
  margin-top: 10px;
}

/* App Core Layout */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* Header */
.app-header {
  min-height: 52px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  padding: 8px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  flex-wrap: wrap;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand h1 {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}

.logo-icon {
  color: var(--text-primary);
  display: flex;
  align-items: center;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.mode-selector {
  display: flex;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 2px;
}

.mode-btn {
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  padding: 4px 12px;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all var(--transition);
}

.mode-btn:hover {
  color: var(--text-primary);
}

.mode-btn.active {
  background: var(--border-color);
  color: var(--text-primary);
}

.exam-timer {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  padding: 5px 12px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
}

.timer-label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
}

.timer-val {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
}

/* Simulation Mode Top Banner */
.simulation-banner {
  background: #090d16;
  border-bottom: 1px solid #1e3a8a;
  padding: 8px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: #93c5fd;
  flex-shrink: 0;
}

.simulation-banner .btn-sm {
  padding: 3px 8px;
  font-size: 11px;
  border-radius: var(--radius-sm);
  background: rgba(239, 68, 68, 0.08);
  color: #fca5a5;
  border-color: rgba(239, 68, 68, 0.2);
}

.simulation-banner .btn-sm:hover {
  background: #7f1d1d;
  color: #ffffff;
  border-color: #b91c1c;
}

/* App Main Grid */
.app-layout {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* Sidebar Layout */
.app-sidebar {
  width: 280px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
}

.sidebar-filters {
  padding: 12px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 10px;
  color: var(--text-muted);
  pointer-events: none;
}

.search-box input {
  width: 100%;
  background: var(--bg-primary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 7px 10px 7px 30px;
  font-size: 13px;
  outline: none;
}

.search-box input:focus {
  border-color: var(--text-secondary);
}

.topic-select {
  width: 100%;
  background: var(--bg-primary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 7px 10px;
  font-size: 13px;
  outline: none;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2371717a'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 14px;
}

.filter-toggles {
  display: flex;
  gap: 6px;
}

.filter-toggle-btn {
  flex: 1;
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  padding: 6px;
  font-size: 11px;
  font-weight: 500;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: all var(--transition);
}

.filter-toggle-btn:hover {
  border-color: var(--text-secondary);
  color: var(--text-primary);
}

.filter-toggle-btn.active {
  background: var(--border-color);
  color: var(--text-primary);
}

/* Sidebar mini dashboard stats */
.sidebar-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 10px;
  background: rgba(0, 0, 0, 0.1);
  border-bottom: 1px solid var(--border-color);
  text-align: center;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stat-item:first-child {
  border-right: 1px solid var(--border-color);
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.stat-label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  font-weight: 500;
  letter-spacing: 0.02em;
}

/* Question sidebar list */
.question-list-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.question-list-header {
  padding: 10px 12px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.02em;
  border-bottom: 1px solid var(--border-light);
}

.question-list {
  flex: 1;
  overflow-y: auto;
}

.q-item {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-light);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 3px;
  transition: all var(--transition);
}

.q-item:hover {
  background: #18181b;
}

.q-item.active {
  background: #27272a;
}

.q-item-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.q-item-num {
  font-weight: 500;
  font-size: 12px;
  color: var(--text-primary);
}

.q-item-badges {
  display: flex;
  gap: 4px;
}

.badge {
  font-size: 8px;
  font-weight: 600;
  padding: 1px 4px;
  border-radius: var(--radius-sm);
  text-transform: uppercase;
}

.badge-bookmarked {
  background: var(--bookmark-bg);
  color: var(--bookmark-color);
  border: 1px solid rgba(245, 158, 11, 0.2);
}

.badge-answered {
  background: #27272a;
  color: var(--text-secondary);
}

.badge-answered.correct {
  background: var(--correct-bg);
  color: var(--correct-color);
  border: 1px solid rgba(16, 185, 129, 0.2);
}

.badge-answered.incorrect {
  background: var(--incorrect-bg);
  color: var(--incorrect-color);
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.q-item-snippet {
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Main Content Pane */
.question-viewer {
  flex: 1;
  min-height: 0;
  padding: 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
  background: var(--bg-primary);
}

/* Center question content on wide screens */
.question-viewer > * {
  max-width: 900px;
  width: 100%;
  margin-left: auto;
  margin-right: auto;
}

.viewer-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
}

.question-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 12px;
}

.meta-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.question-number {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.topic-badge {
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  color: var(--text-secondary);
  background: var(--border-color);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}

.btn-bookmark {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  transition: all var(--transition);
  padding: 4px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
}

.btn-bookmark:hover {
  color: var(--text-secondary);
}

.btn-bookmark.active {
  color: var(--bookmark-color);
}

.question-body {
  font-size: 14px;
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.question-text {
  white-space: pre-wrap;
  color: var(--text-primary);
}

.question-images {
  margin-top: 4px;
}

.question-images img {
  max-width: 100%;
  max-height: 380px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  object-fit: contain;
}

/* MCQ Option Cards */
.choices-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 6px;
}

.choice-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  cursor: pointer;
  text-align: left;
  font-family: var(--font-family);
  font-size: 13px;
  color: var(--text-secondary);
  transition: all var(--transition);
  width: 100%;
  white-space: pre-wrap;
}

.choice-card:hover {
  border-color: var(--text-secondary);
  color: var(--text-primary);
  background: #18181b;
}

.choice-letter {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  min-width: 22px;
  min-height: 22px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
  margin-top: 2px;
}

.choice-text {
  flex: 1;
  min-width: 0;
  word-break: break-word;
}

.choice-text img {
  display: block;
  max-width: 100%;
  max-height: 300px;
  margin-top: 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  object-fit: contain;
}

.choice-card.selected {
  border-color: var(--accent-blue);
  background: var(--accent-blue-light);
  color: var(--text-primary);
}

.choice-card.selected .choice-letter {
  background: var(--accent-blue);
  border-color: var(--accent-blue);
  color: #ffffff;
}

/* Study mode feedback results styles */
.choice-card.correct {
  border-color: var(--correct-border) !important;
  background: var(--correct-bg) !important;
  color: #d1fae5 !important;
}

.choice-card.correct .choice-letter {
  background: var(--correct-color) !important;
  border-color: var(--correct-border) !important;
  color: #ffffff !important;
}

.choice-card.incorrect {
  border-color: var(--incorrect-border) !important;
  background: var(--incorrect-bg) !important;
  color: #fee2e2 !important;
}

.choice-card.incorrect .choice-letter {
  background: var(--incorrect-color) !important;
  border-color: var(--incorrect-border) !important;
  color: #ffffff !important;
}

/* Actions Footer Panel */
.question-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid var(--border-color);
  padding-top: 16px;
  margin-top: 8px;
}

.footer-left, .footer-right {
  display: flex;
  gap: 8px;
}

/* Feedback Explanation Cards */
.explanation-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 6px;
}

.explanation-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  font-size: 13px;
}

.explanation-card.correct {
  border-color: var(--correct-border);
  color: var(--correct-color);
}

.explanation-card.incorrect {
  border-color: var(--incorrect-border);
  color: var(--incorrect-color);
}

/* Expandable Discussion Comments Section */
.comments-section {
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
}

.comments-header {
  padding: 14px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  user-select: none;
  background: var(--bg-secondary);
}

.comments-header:hover {
  background: #18181b;
}

.comments-header-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
}

.comments-toggle-indicator {
  color: var(--text-muted);
  transition: transform var(--transition);
  display: flex;
  align-items: center;
}

.comments-body {
  border-top: 1px solid var(--border-color);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-height: 400px;
  overflow-y: auto;
  background: var(--bg-primary);
}

.comments-body.collapsed {
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  border-top-color: transparent;
  overflow: hidden;
}

.comments-section.open .comments-toggle-indicator svg {
  transform: rotate(180deg);
}

.comment-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-light);
}

.comment-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.comment-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.comment-author-info {
  display: flex;
  align-items: center;
  gap: 6px;
}

.comment-author {
  font-weight: 500;
  font-size: 12px;
  color: var(--text-primary);
}

.comment-date {
  font-size: 11px;
  color: var(--text-muted);
}

.comment-likes {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 10px;
  color: var(--text-muted);
}

.comment-content {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: pre-wrap;
}

/* Modals & Backdrop */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 1;
}

.modal-card {
  width: 100%;
  max-width: 460px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
  animation: modalFadeIn 0.15s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalFadeIn {
  from { transform: scale(0.97); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h2 {
  font-size: 15px;
}

.modal-close-btn {
  background: transparent;
  border: none;
  font-size: 20px;
  color: var(--text-secondary);
  cursor: pointer;
  line-height: 1;
}
.modal-close-btn:hover {
  color: var(--text-primary);
}

.modal-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  align-items: center;
}

.results-dashboard {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: 100%;
}

/* Circular Dashboard Score Tracker */
.circular-progress-wrapper {
  position: relative;
  width: 100px;
  height: 100px;
}

.circular-progress {
  width: 100px;
  height: 100px;
  transform: rotate(-90deg);
}

.circular-progress circle {
  fill: none;
  stroke-width: 6px;
}

.circular-progress circle.bg {
  stroke: var(--border-color);
}

.circular-progress circle.fg {
  stroke: var(--accent-blue);
  stroke-linecap: square;
}

.circular-progress-wrapper .percentage {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
}

.results-stats {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--bg-primary);
  padding: 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.res-stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
}

.res-stat-label {
  color: var(--text-secondary);
}

.res-stat-value {
  font-weight: 500;
  font-family: var(--font-mono);
}

.text-red {
  color: var(--incorrect-color);
}

.status-badge {
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
}

.status-badge.pass {
  background: var(--correct-bg);
  color: var(--correct-color);
  border: 1px solid rgba(16, 185, 129, 0.2);
}

.status-badge.fail {
  background: var(--incorrect-bg);
  color: var(--incorrect-color);
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.results-options {
  display: flex;
  gap: 10px;
  width: 100%;
}

.results-options button {
  flex: 1;
}

/* Mobile sidebar toggle button — hidden on desktop */
.sidebar-toggle-btn {
  display: none;
  background: var(--bg-card);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  align-items: center;
  gap: 6px;
  transition: all var(--transition);
  flex-shrink: 0;
}

.sidebar-toggle-btn:hover {
  background: #27272a;
  color: var(--text-primary);
}

/* Mobile sidebar overlay backdrop */
.sidebar-backdrop {
  display: none;
}

/* ======================== */
/* Tablet: <= 900px         */
/* ======================== */
@media (max-width: 900px) {
  .app-layout {
    flex-direction: column;
  }

  /* Sidebar becomes a slide-over drawer on mobile */
  .app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 300px;
    max-width: 85vw;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    border-right: 1px solid var(--border-color);
    box-shadow: none;
  }

  .app-sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.4);
  }

  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 49;
  }

  .sidebar-backdrop.visible {
    display: block;
  }

  .sidebar-toggle-btn {
    display: inline-flex;
  }

  .question-viewer {
    padding: 16px;
  }
}

/* ======================== */
/* Phone: <= 600px          */
/* ======================== */
@media (max-width: 600px) {
  /* Header stacks vertically */
  .app-header {
    padding: 10px 12px;
    gap: 8px;
  }

  /* Controls row: use a single row with proper sizing */
  .header-controls {
    width: 100%;
    gap: 6px;
    flex-wrap: nowrap;
  }

  /* Sidebar toggle: compact, icon-only on narrow screens */
  .sidebar-toggle-btn {
    padding: 6px 8px;
    font-size: 11px;
    flex-shrink: 0;
  }

  .sidebar-toggle-btn .toggle-label {
    display: none;
  }

  /* Mode selector: takes available space but shrinks */
  .mode-selector {
    flex: 1;
    min-width: 0;
  }

  .mode-btn {
    flex: 1;
    justify-content: center;
    padding: 6px 6px;
    font-size: 11px;
    white-space: nowrap;
    overflow: hidden;
  }

  /* Hide SVG icons in mode buttons to save space */
  .mode-btn svg {
    display: none;
  }

  /* Exam Simulator: icon-only on mobile */
  #start-simulation-btn {
    padding: 6px;
    flex-shrink: 0;
  }

  #start-simulation-btn span.sim-label {
    display: none;
  }

  /* Touch-friendly icon buttons */
  .btn-icon-only {
    width: 34px;
    height: 34px;
    flex-shrink: 0;
  }

  /* Question viewer compact */
  .question-viewer {
    padding: 12px;
    gap: 14px;
  }

  .viewer-card {
    padding: 16px;
    gap: 12px;
  }

  .question-number {
    font-size: 14px;
  }

  /* Action footer stacks on phone */
  .question-footer {
    flex-direction: column;
    gap: 10px;
  }

  .footer-left,
  .footer-right {
    width: 100%;
  }

  .footer-left button,
  .footer-right button {
    flex: 1;
    justify-content: center;
    min-height: 40px;
  }

  /* Simulation banner stacks */
  .simulation-banner {
    flex-direction: column;
    text-align: center;
    gap: 8px;
    padding: 10px 12px;
    font-size: 12px;
  }

  /* Dropzone landing */
  .dropzone-card {
    padding: 32px 20px;
  }

  .dropzone-card h2 {
    font-size: 18px;
  }

  .dropzone-icon svg {
    width: 48px;
    height: 48px;
  }

  /* Demo notice wraps */
  .demo-notice {
    flex-direction: column;
    gap: 6px;
  }

  .demo-notice .divider {
    display: none;
  }

  /* Choice cards: bigger tap targets */
  .choice-card {
    padding: 14px 12px;
    font-size: 14px;
  }

  /* Modal responsive */
  .modal-card {
    max-width: calc(100vw - 24px);
    margin: 12px;
  }

  .modal-body {
    padding: 16px;
  }

  .results-options {
    flex-direction: column;
  }

  /* Comments section */
  .comments-section {
    border-radius: var(--radius-md);
  }

  .comments-header {
    padding: 10px 12px;
  }

  .comments-header-title {
    font-size: 12px;
    gap: 6px;
  }

  .comments-header-title svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
  }

  .comments-body {
    padding: 12px;
    gap: 12px;
    max-height: 300px;
  }

  .comment-meta {
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
  }

  .comment-author-info {
    flex-wrap: wrap;
    gap: 4px;
  }

  .comment-author {
    font-size: 11px;
  }

  .comment-date {
    font-size: 10px;
  }

  .comment-likes {
    font-size: 10px;
  }

  .comment-content {
    font-size: 12px;
    word-break: break-word;
  }
}

/* Light Theme Variables and Rules */
:root.light {
  --bg-primary: #ffffff;
  --bg-secondary: #fafafa;
  --bg-card: #ffffff;
  --bg-input: #ffffff;
  
  --border-color: #e4e4e7;
  --border-light: #f4f4f5;

  --text-primary: #09090b;
  --text-secondary: #27272a;
  --text-muted: #52525b;

  --accent-color: #e4e4e7;
  --accent-hover: #d4d4d8;
  --accent-blue: #2563eb;
  --accent-blue-light: rgba(37, 99, 235, 0.05);

  --correct-color: #047857;
  --correct-bg: #ecfdf5;
  --correct-border: #a7f3d0;

  --incorrect-color: #b91c1c;
  --incorrect-bg: #fef2f2;
  --incorrect-border: #fca5a5;

  --bookmark-color: #d97706;
  --bookmark-bg: rgba(217, 119, 6, 0.05);
}

/* Base styling overrides for Light Mode */
:root.light .btn-primary {
  background: #09090b;
  color: #ffffff;
  border-color: #09090b;
}

:root.light .btn-primary:hover {
  background: #27272a;
  border-color: #27272a;
}

:root.light .simulation-banner {
  background: #eff6ff;
  border-bottom: 1px solid #bfdbfe;
  color: #1e40af;
}

:root.light .choice-card:hover {
  background: #f4f4f5;
}

:root.light .q-item:hover {
  background: #f4f4f5;
}

:root.light .q-item.active {
  background: #e4e4e7;
}

:root.light .comments-header:hover {
  background: #f4f4f5;
}

:root.light .modal-card {
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.15);
}

/* Light mode: readable text on correct/incorrect choice cards */
:root.light .choice-card.correct {
  color: #065f46 !important;
}

:root.light .choice-card.incorrect {
  color: #991b1b !important;
}

:root.light .explanation-card.correct {
  color: #065f46;
}

:root.light .explanation-card.incorrect {
  color: #991b1b;
}

/* Media Query default for light preferences */
@media (prefers-color-scheme: light) {
  :root:not(.dark) {
    --bg-primary: #ffffff;
    --bg-secondary: #fafafa;
    --bg-card: #ffffff;
    --bg-input: #ffffff;
    
    --border-color: #e4e4e7;
    --border-light: #f4f4f5;

    --text-primary: #09090b;
    --text-secondary: #27272a;
    --text-muted: #52525b;

    --accent-color: #e4e4e7;
    --accent-hover: #d4d4d8;
    --accent-blue: #2563eb;
    --accent-blue-light: rgba(37, 99, 235, 0.05);

    --correct-color: #047857;
    --correct-bg: #ecfdf5;
    --correct-border: #a7f3d0;

    --incorrect-color: #b91c1c;
    --incorrect-bg: #fef2f2;
    --incorrect-border: #fca5a5;

    --bookmark-color: #d97706;
    --bookmark-bg: rgba(217, 119, 6, 0.05);
  }
  
  :root:not(.dark) .btn-primary {
    background: #09090b;
    color: #ffffff;
    border-color: #09090b;
  }
  
  :root:not(.dark) .btn-primary:hover {
    background: #27272a;
    border-color: #27272a;
  }
  
  :root:not(.dark) .simulation-banner {
    background: #eff6ff;
    border-bottom: 1px solid #bfdbfe;
    color: #1e40af;
  }
  
  :root:not(.dark) .choice-card:hover {
    background: #f4f4f5;
  }

  :root:not(.dark) .q-item:hover {
    background: #f4f4f5;
  }

  :root:not(.dark) .q-item.active {
    background: #e4e4e7;
  }

  :root:not(.dark) .comments-header:hover {
    background: #f4f4f5;
  }
  
  :root:not(.dark) .modal-card {
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.15);
  }

  :root:not(.dark) .choice-card.correct {
    color: #065f46 !important;
  }

  :root:not(.dark) .choice-card.incorrect {
    color: #991b1b !important;
  }

  :root:not(.dark) .explanation-card.correct {
    color: #065f46;
  }

  :root:not(.dark) .explanation-card.incorrect {
    color: #991b1b;
  }
}

/* Style for images inside MCQ choice cards and explanation panels */
.choice-card img,
#correct-answer-text img {
  max-width: 100%;
  max-height: 180px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background-color: #ffffff; /* Ensures black-on-transparent diagrams are visible in dark mode */
  padding: 8px;
  object-fit: contain;
  margin: 6px 0;
  display: block;
}
