*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

:root {
  --bg: #080b10;
  --bg-elevated: #0e1219;
  --surface: #141a24;
  --surface-raised: #1a2230;
  --surface-hover: #212b3c;
  --border: #2b3648;
  --border-light: #3a475c;
  --text: #f2f5fa;
  --text-muted: #b0bccf;
  --text-dim: #8493a8;
  --accent: #4d8ef7;
  --accent-hover: #6ba0ff;
  --accent-soft: rgba(77, 142, 247, 0.14);
  --success: #3dd68c;
  --success-soft: rgba(61, 214, 140, 0.12);
  --warning: #f0ad4e;
  --warning-soft: rgba(240, 173, 78, 0.12);
  --radius: 10px;
  --radius-lg: 14px;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.28);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.38);
  --header-h: auto;
  --feed-max: 820px;
  --input-bg: #0c1018;
  --sidebar-w: 260px;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  direction: rtl;
  text-align: right;
  font-family: "Rubik", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── Header ── */

.header {
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(12px);
}

.header-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 1.25rem 1.5rem 1rem;
}

.header-top h1 {
  margin: 0 0 0.2rem;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.header-title-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
}

.subject-group {
  min-width: 9rem;
}

.subject-select {
  min-width: 8rem;
  max-width: 14rem;
}

.subject-form-row {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.subject-form-field {
  flex: 1;
  min-width: 0;
}

.modal-select {
  width: 100%;
  margin-bottom: 0.5rem;
}

.subject-topics-list {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  margin-bottom: 0.75rem;
  max-height: 14rem;
  overflow-y: auto;
}

.subject-topic-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.subject-topic-num {
  font-size: 0.75rem;
  color: var(--text-dim);
  width: 1.25rem;
  flex-shrink: 0;
  text-align: center;
}

.subject-topic-row .search {
  flex: 1;
  margin-bottom: 0;
}

.modal-wide {
  max-width: 640px;
}

.modal-textarea {
  width: 100%;
  margin-bottom: 0.75rem;
  padding: 0.65rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: inherit;
  font-size: 0.82rem;
  line-height: 1.45;
  resize: vertical;
  min-height: 12rem;
}

.modal-desc code {
  background: var(--bg);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  font-size: 0.8rem;
}

.subtitle {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr) 2fr;
  gap: 0.65rem;
  margin-top: 1rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.stat-card-wide {
  justify-content: center;
}

.stat-card-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.35rem;
}

.stat-value {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.2;
}

.stat-value-success {
  color: var(--success);
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.stat-pct {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--success);
}

.progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.progress-bar-lg {
  height: 8px;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--success));
  border-radius: 999px;
  transition: width 0.4s ease;
}

/* ── Main layout ── */

.main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 1rem 1.5rem 2rem;
}

/* ── Toolbar ── */

.toolbar-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 0.85rem 1rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow);
  position: sticky;
  top: calc(var(--header-h, 120px) + 0.5rem);
  z-index: 50;
}

.toolbar-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: center;
}

.toolbar-main {
  margin-bottom: 0.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.toolbar-group-start {
  flex-shrink: 0;
}

.search-wrap {
  flex: 1;
  min-width: 10rem;
}

.search {
  width: 100%;
  padding: 0.55rem 0.85rem;
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  background: var(--input-bg);
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.search::placeholder {
  color: var(--text-dim);
}

.search:focus,
.select:focus,
.view-toggle-btn:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.toolbar-filters {
  gap: 0.75rem;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 0;
}

.filter-group .select {
  min-width: 9rem;
}

.filter-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.filter-actions {
  margin-right: auto;
  flex-direction: row;
  align-items: flex-end;
  gap: 0.4rem;
}

.select {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  background: var(--input-bg);
  color: var(--text);
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
}

.select option {
  background: var(--surface-raised);
  color: var(--text);
}

.results-bar {
  margin-top: 0.65rem;
  padding-top: 0.65rem;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ── View toggle ── */

.view-toggle {
  display: inline-flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 3px;
  gap: 2px;
}

.view-toggle-btn {
  padding: 0.4rem 0.85rem;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}

.view-toggle-btn:hover {
  color: var(--text);
}

.view-toggle-btn.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 1px 4px rgba(91, 141, 239, 0.35);
}

/* ── Buttons ── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.5rem 0.9rem;
  border: none;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
  white-space: nowrap;
}

.btn:active {
  transform: scale(0.98);
}

.btn-sm {
  padding: 0.45rem 0.7rem;
  font-size: 0.8rem;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border: 1px solid transparent;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.btn-primary:hover {
  background: var(--accent-hover);
  box-shadow: 0 4px 14px rgba(77, 142, 247, 0.28);
}

.btn-xs {
  padding: 0.28rem 0.55rem;
  font-size: 0.72rem;
}

.btn-ghost {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  background: var(--surface-hover);
  border-color: var(--border-light);
}

.btn-lg {
  padding: 0.75rem 1.5rem;
  font-size: 0.95rem;
}

.btn-icon {
  font-size: 1rem;
  line-height: 1;
}

.upload-btn,
.import-btn {
  cursor: pointer;
}

/* ── Empty state ── */

.empty-state {
  text-align: center;
  padding: 3.5rem 2rem;
  background: var(--surface);
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  max-width: 520px;
  margin: 2rem auto;
}

.empty-icon {
  font-size: 2.75rem;
  margin-bottom: 0.75rem;
}

.empty-state h2 {
  margin: 0 0 0.5rem;
  font-size: 1.35rem;
}

.empty-state p {
  color: var(--text-muted);
  margin: 0 0 1.25rem;
  font-size: 0.9rem;
  line-height: 1.6;
}

.empty-tips {
  list-style: none;
  padding: 0;
  margin: 0 0 1.5rem;
  text-align: right;
  display: inline-block;
}

.empty-tips li {
  font-size: 0.85rem;
  color: var(--text-muted);
  padding: 0.3rem 0;
  padding-right: 1.25rem;
  position: relative;
}

.empty-tips li::before {
  content: "✓";
  position: absolute;
  right: 0;
  color: var(--success);
  font-size: 0.75rem;
}

/* ── Exam grid ── */

.exam-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 0.85rem;
  align-items: start;
}

.exam-grid.topics-view {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(400px, 1fr));
  align-items: start;
  gap: 0.85rem;
  width: 100%;
  max-width: 100%;
  margin: 0;
}

.exam-grid.theorems-view,
.exam-grid[data-page="theorems"] {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(500px, 1fr));
  align-items: stretch;
  gap: 1rem;
  width: 100%;
  max-width: 100%;
  margin: 0;
}

/* ── Exam card ── */

.exam-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 0;
  box-shadow: var(--shadow);
  transition: border-color 0.2s, box-shadow 0.2s;
  display: flex;
  flex-direction: column;
  gap: 0;
  overflow: hidden;
  min-width: 0;
}

.exam-card-compact {
  padding: 0.85rem 0.95rem 0.65rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.exam-card:hover {
  border-color: var(--border-light);
  box-shadow: var(--shadow-lg);
}

.exam-card.complete {
  border-color: rgba(61, 214, 140, 0.4);
}

.exam-card.partial {
  border-color: rgba(240, 173, 78, 0.4);
}

.exam-card.unpaired {
  border-color: rgba(240, 173, 78, 0.35);
}

.exam-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  margin-bottom: 0.65rem;
}

.exam-dates {
  flex: 1;
  min-width: 0;
}

.exam-title {
  font-weight: 700;
  font-size: 0.95rem;
  line-height: 1.4;
  margin-bottom: 0.15rem;
}

.exam-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.exam-badge {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  background: var(--bg);
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.exam-badge.complete {
  background: var(--success-soft);
  color: var(--success);
}

.exam-badge.partial {
  background: var(--warning-soft);
  color: var(--warning);
}

.exam-progress-wrap {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.exam-progress-bar {
  flex: 1;
}

.exam-progress-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.exam-progress-dots {
  display: flex;
  gap: 4px;
  margin-bottom: 0.75rem;
}

.exam-progress-dot {
  flex: 1;
  height: 4px;
  border-radius: 999px;
  background: var(--border);
  transition: background 0.2s;
}

.exam-progress-dot.solved {
  background: var(--success);
}

.exam-progress-dot.has-topic:not(.solved) {
  background: var(--accent);
  opacity: 0.5;
}

.exam-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
}

.exam-actions-primary {
  margin-bottom: 0;
}

.exam-toggle-questions {
  width: 100%;
  padding: 0.5rem 0.95rem;
  border: none;
  border-top: 1px solid var(--border);
  background: rgba(99, 102, 241, 0.06);
  color: var(--accent);
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: background 0.15s;
}

.exam-toggle-questions:hover {
  background: rgba(99, 102, 241, 0.12);
}

.exam-card.expanded .exam-toggle-questions {
  background: rgba(99, 102, 241, 0.1);
}

.exam-questions-panel {
  border-top: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.12);
  padding: 0.65rem 0.75rem 0.85rem;
}

.exam-questions-panel[hidden] {
  display: none !important;
}

.exam-questions-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  margin-bottom: 0.55rem;
  padding-bottom: 0.55rem;
  border-bottom: 1px solid var(--border);
}

.exam-questions-toolbar .btn-sm {
  padding: 0.3rem 0.55rem;
  font-size: 0.72rem;
}

.exam-files-inline {
  margin: 0;
}

.exam-files-inline summary {
  font-size: 0.72rem;
}

.file-action-group {
  display: flex;
  gap: 0.3rem;
  min-width: 0;
}

.file-action-group .btn-open {
  flex: 1;
  min-width: 0;
}

.btn-copy {
  padding: 0.45rem 0.55rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.btn-copy:hover {
  background: var(--surface-hover);
  border-color: var(--border-light);
  color: var(--text);
}

.btn-copy.btn-solution:hover {
  background: var(--success-soft);
  border-color: var(--success);
  color: var(--success);
}

.btn-copy.btn-compact {
  padding: 0.3rem 0.4rem;
  font-size: 0.68rem;
}

.btn-open {
  padding: 0.45rem 0.5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.btn-open:hover:not(:disabled) {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.btn-open.btn-solution {
  color: var(--success);
}

.btn-open.btn-solution:hover:not(:disabled) {
  background: var(--success-soft);
  border-color: var(--success);
}

.btn-open.btn-missing {
  opacity: 0.4;
  cursor: not-allowed;
  color: var(--text-dim);
}

.exam-files {
  margin-bottom: 0.65rem;
}

.exam-files summary {
  font-size: 0.72rem;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.exam-files summary::-webkit-details-marker {
  display: none;
}

.exam-files summary::before {
  content: "▸";
  font-size: 0.65rem;
  transition: transform 0.15s;
}

.exam-files[open] summary::before {
  transform: rotate(90deg);
}

.exam-filename {
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-top: 0.35rem;
  word-break: break-all;
  direction: ltr;
  text-align: right;
  line-height: 1.5;
}

.questions-header {
  display: none;
}

.questions {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.question-row {
  display: flex;
  align-items: flex-start;
  gap: 0.45rem;
  padding: 0.4rem 0.45rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-elevated);
  direction: rtl;
  text-align: right;
}

.question-row-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.question-row-inline {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.3rem 0.4rem;
  min-width: 0;
}

.question-row-extra {
  min-width: 0;
}

.question-row-extra .accordion-section {
  margin-top: 0;
}

.question-btn-sm {
  width: 1.85rem;
  height: 1.85rem;
  min-width: 1.85rem;
  padding: 0;
  flex-shrink: 0;
}

.question-btn-sm .question-num {
  font-size: 0.78rem;
}

.btn-notes-toggle {
  width: 1.65rem;
  height: 1.65rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text-dim);
  font-size: 0.85rem;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.btn-notes-toggle:hover,
.btn-notes-toggle.active {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

.btn-notes-toggle.has-notes {
  color: var(--warning);
  border-color: rgba(240, 173, 78, 0.45);
}

.question-notes-panel {
  width: 100%;
}

.question-notes-panel[hidden] {
  display: none !important;
}

.question-notes-panel .question-notes {
  font-size: 0.72rem;
  min-height: 2.25rem;
  max-height: 4.5rem;
}

.question-body {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 0;
}

.question-meta {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.difficulty-rating {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.difficulty-label {
  font-size: 0.68rem;
  color: var(--text-dim);
  font-weight: 600;
  margin-left: 0.15rem;
}

.difficulty-btn {
  width: 1.55rem;
  height: 1.55rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text-muted);
  font-size: 0.68rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
}

.difficulty-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

.difficulty-btn.active {
  color: #fff;
  border-color: transparent;
}

.difficulty-btn.diff-1.active { background: #22c55e; }
.difficulty-btn.diff-2.active { background: #84cc16; }
.difficulty-btn.diff-3.active { background: #eab308; }
.difficulty-btn.diff-4.active { background: #f97316; }
.difficulty-btn.diff-5.active { background: #ef4444; }

.question-notes {
  width: 100%;
  min-height: 1.75rem;
  max-height: 5rem;
  resize: vertical;
  padding: 0.35rem 0.5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.75rem;
  line-height: 1.4;
}

.question-notes:focus {
  outline: none;
  border-color: var(--accent);
}

.question-notes::placeholder {
  color: var(--text-dim);
}

.exam-progress-dot.diff-1 { box-shadow: inset 0 0 0 2px #22c55e; }
.exam-progress-dot.diff-2 { box-shadow: inset 0 0 0 2px #84cc16; }
.exam-progress-dot.diff-3 { box-shadow: inset 0 0 0 2px #eab308; }
.exam-progress-dot.diff-4 { box-shadow: inset 0 0 0 2px #f97316; }
.exam-progress-dot.diff-5 { box-shadow: inset 0 0 0 2px #ef4444; }

.topic-item-notes {
  margin-top: 0.2rem;
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.35;
  white-space: pre-wrap;
}

.difficulty-rating-compact .difficulty-btn {
  width: 1.35rem;
  height: 1.35rem;
  font-size: 0.62rem;
  border-radius: 5px;
}

.topic-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem;
  min-width: 0;
}

.question-row-inline .topic-chips {
  flex: 1 1 auto;
}

.question-row-inline .topic-chip {
  padding: 0.12rem 0.35rem;
  font-size: 0.62rem;
}

.topic-chip {
  padding: 0.25rem 0.45rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text-muted);
  font-size: 0.68rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.topic-chip:hover {
  border-color: var(--accent);
  color: var(--text);
}

.topic-chip.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.btn-theorem-extract-exam {
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(99, 102, 241, 0.08);
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-theorem-extract-exam:hover:not(:disabled) {
  background: rgba(99, 102, 241, 0.15);
  border-color: var(--accent);
}

.btn-theorem-extract-exam:disabled,
.btn-theorem-extract:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-theorem-extract {
  align-self: flex-start;
  margin-top: 0.15rem;
  padding: 0.2rem 0.45rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--accent);
  font-size: 0.68rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}

.btn-theorem-extract:hover:not(:disabled) {
  border-color: var(--accent);
}

.theorem-list {
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  direction: rtl;
  text-align: right;
}

.theorem-item {
  padding: 1rem 1.15rem;
  border: 1px solid rgba(99, 102, 241, 0.18);
  border-radius: 12px;
  background: rgba(99, 102, 241, 0.06);
  direction: rtl;
  text-align: right;
}

.theorem-name {
  display: block;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 0.45rem;
  line-height: 1.6;
  text-align: right;
}

.theorem-context {
  display: block;
  font-size: 1rem;
  color: var(--text-muted);
  line-height: 1.75;
  text-align: right;
}

.math-inline {
  display: inline-block;
  direction: ltr;
  unicode-bidi: isolate;
  margin: 0 0.2em;
  vertical-align: middle;
}

.math-display {
  display: block;
  direction: ltr;
  unicode-bidi: isolate;
  margin: 0.65rem 0;
  padding: 0.55rem 0.75rem;
  overflow-x: auto;
  text-align: center;
  background: rgba(0, 0, 0, 0.15);
  border-radius: 8px;
}

.theorem-name .katex,
.theorem-context .katex,
.theorem-section-title .katex,
.theorem-map-item-context .katex,
.theorem-map-item-title .katex {
  font-size: 1.05em;
  vertical-align: middle;
}

.theorem-name .katex {
  color: var(--accent);
}

.theorem-map-item-context .math-inline,
.theorem-context .math-inline,
.theorem-name .math-inline {
  vertical-align: middle;
}

.katex {
  color: var(--text);
}

.katex .mord,
.katex .mop,
.katex .mbin,
.katex .mrel,
.katex .mopen,
.katex .mclose,
.katex .mpunct {
  color: inherit;
}

.exam-grid.theorems-view {
  width: 100%;
  max-width: 100%;
}

.page-filters--theorems .page-filters-inner {
  max-width: 100%;
}

.theorems-control-bar {
  align-items: flex-end;
}

.theorem-mastery-card {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  direction: rtl;
  text-align: right;
  background: linear-gradient(165deg, rgba(99, 102, 241, 0.07) 0%, var(--surface) 42%);
  border: 1px solid rgba(99, 102, 241, 0.2);
  border-radius: var(--radius-lg);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.18);
  overflow: hidden;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.theorem-mastery-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.28);
  border-color: rgba(99, 102, 241, 0.38);
}

.theorem-mastery-card--mastered {
  background: linear-gradient(155deg, rgba(34, 197, 94, 0.14) 0%, rgba(99, 102, 241, 0.08) 38%, var(--surface) 72%);
  border-color: rgba(34, 197, 94, 0.45);
  box-shadow:
    0 4px 22px rgba(34, 197, 94, 0.12),
    0 0 0 1px rgba(34, 197, 94, 0.18) inset;
}

.theorem-mastery-card--mastered:hover {
  border-color: rgba(34, 197, 94, 0.62);
  box-shadow:
    0 12px 36px rgba(34, 197, 94, 0.18),
    0 0 0 1px rgba(34, 197, 94, 0.24) inset;
}

.theorem-mastery-card-body {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1.25rem;
  flex: 1;
}

.theorem-mastery-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.85rem;
}

.theorem-mastery-title {
  margin: 0;
  flex: 1;
  min-width: 0;
  font-size: 1.3rem;
  font-weight: 700;
  line-height: 1.5;
  color: var(--accent);
  text-align: right;
}

.theorem-category-badge {
  flex-shrink: 0;
  max-width: 9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
  color: hsl(var(--theorem-cat-hue, 250) 82% 90%);
  background: hsl(var(--theorem-cat-hue, 250) 62% 48% / 0.22);
  border: 1px solid hsl(var(--theorem-cat-hue, 250) 58% 58% / 0.38);
}

.theorem-category-badge--muted {
  --theorem-cat-hue: 220;
  color: var(--text-muted);
  background: rgba(148, 163, 184, 0.12);
  border-color: rgba(148, 163, 184, 0.22);
}

.theorem-mastery-progress {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.theorem-mastery-progress-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  font-size: 0.84rem;
}

.theorem-mastery-progress-label {
  color: var(--text-muted);
  font-weight: 600;
}

.theorem-mastery-progress-pct {
  color: var(--accent);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.theorem-mastery-card--mastered .theorem-mastery-progress-pct {
  color: #4ade80;
}

.theorem-mastery-bar {
  height: 0.45rem;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.18);
  overflow: hidden;
}

.theorem-mastery-bar-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #6366f1, #8b5cf6);
  transition: width 0.35s ease;
}

.theorem-mastery-card--mastered .theorem-mastery-bar-fill {
  background: linear-gradient(90deg, #22c55e, #4ade80);
  box-shadow: 0 0 12px rgba(34, 197, 94, 0.45);
}

.theorem-mastery-actions {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.65rem;
  margin-top: auto;
}

.theorem-mastery-formula-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
}

.theorem-formula-btn {
  width: 100%;
  justify-content: flex-start;
  text-align: right;
}

.theorem-formula-panel {
  display: none;
  margin-top: 0.55rem;
  padding: 0.85rem 0.95rem;
  border-radius: 12px;
  background: rgba(8, 12, 22, 0.72);
  border: 1px solid rgba(99, 102, 241, 0.28);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
  direction: rtl;
  text-align: right;
  z-index: 2;
}

.theorem-mastery-formula-wrap.is-open .theorem-formula-panel {
  display: block;
}

@media (hover: hover) {
  .theorem-mastery-formula-wrap:hover .theorem-formula-panel {
    display: block;
  }
}

.theorem-formula-panel-label {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--text-dim);
  margin-bottom: 0.45rem;
}

.theorem-formula-panel-body {
  font-size: 0.95rem;
  line-height: 1.75;
  color: var(--text);
  overflow: visible;
}

.theorem-formula-conditions {
  list-style: none;
  margin: 0 0 0.65rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  direction: rtl;
  text-align: right;
}

.theorem-formula-condition {
  position: relative;
  padding-right: 0.95rem;
}

.theorem-formula-condition::before {
  content: "•";
  position: absolute;
  right: 0;
  color: var(--accent);
  font-weight: 700;
}

.theorem-formula-conclusion {
  padding-top: 0.55rem;
  border-top: 1px solid rgba(99, 102, 241, 0.22);
}

.theorem-formula-conclusion--solo {
  padding-top: 0;
  border-top: none;
}

.academic-content--formula {
  direction: rtl;
  text-align: right;
  unicode-bidi: plaintext;
  overflow: visible;
  white-space: normal;
  word-wrap: break-word;
}

.academic-content--formula .math-inline {
  display: inline-block;
  direction: ltr;
  unicode-bidi: isolate;
  margin: 0 0.2em;
  vertical-align: middle;
}

.academic-content--formula .math-display {
  display: block;
  direction: ltr;
  unicode-bidi: isolate;
  margin: 0.55rem 0;
  padding: 0.55rem 0.75rem;
  overflow-x: auto;
  text-align: center;
  background: rgba(0, 0, 0, 0.22);
  border-radius: 8px;
}

.theorem-formula-panel--empty {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.theorem-practice-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  flex-shrink: 0;
  white-space: nowrap;
}

.theorem-practice-btn .accordion-chevron {
  width: 0.45rem;
  height: 0.45rem;
}

.theorem-practice-btn.expanded .accordion-chevron {
  transform: rotate(135deg);
}

.theorem-map-card {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.theorem-section {
  direction: rtl;
  text-align: right;
}

.theorem-map-panel-wrap {
  flex: 1 1 auto;
  min-height: 0;
}

.theorem-map-panel {
  background: rgba(0, 0, 0, 0.2);
  border-top: 1px solid var(--border);
  direction: rtl;
  text-align: right;
}

.theorem-map-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  direction: rtl;
  text-align: right;
}

.theorem-map-item {
  padding: 1rem 1.15rem;
  border: 1px solid rgba(99, 102, 241, 0.14);
  border-radius: 12px;
  background: var(--surface-raised);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.03);
  direction: rtl;
  text-align: right;
}

.theorem-map-item-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.55rem;
  direction: rtl;
  text-align: right;
}

.theorem-map-item-title {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.5;
  text-align: right;
  flex: 1;
  min-width: 0;
}

.theorem-map-item-question {
  flex-shrink: 0;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--accent);
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  background: var(--accent-soft);
  white-space: nowrap;
}

.theorem-map-item-context {
  font-size: 1rem;
  color: var(--text-muted);
  line-height: 1.75;
  text-align: right;
  direction: rtl;
}

.btn-classify {
  width: 100%;
  margin-top: 0.5rem;
  margin-bottom: 0;
  padding: 0.45rem 0.75rem;
  background: transparent;
  border: 1px dashed var(--accent);
  border-radius: 8px;
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-classify:hover:not(:disabled) {
  background: var(--accent-soft);
}

.btn-classify:disabled {
  opacity: 0.6;
  cursor: wait;
}

.exam-card.classifying {
  border-color: var(--accent);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 1rem;
}

.modal-overlay[hidden] {
  display: none;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  max-width: 420px;
  width: 100%;
  box-shadow: var(--shadow-lg);
}

.modal h2 {
  margin: 0 0 0.5rem;
  font-size: 1.1rem;
}

.modal-desc {
  margin: 0 0 1rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.modal-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 0.35rem;
}

.modal-input {
  margin-bottom: 0.5rem;
}

.modal-hint {
  margin: 0 0 1rem;
  font-size: 0.8rem;
}

.modal-hint a {
  color: var(--accent);
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}

.question-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
  font-size: 0.75rem;
  font-family: inherit;
  flex-shrink: 0;
}

.question-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

.question-btn.solved {
  background: var(--success-soft);
  border-color: var(--success);
  color: var(--success);
}

.question-num {
  font-weight: 700;
  font-size: 0.9rem;
  line-height: 1;
}

/* ── Question bank (Topics view) ── */

.question-bank-card {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
  direction: rtl;
  text-align: right;
  min-width: 0;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.question-bank-card:hover {
  border-color: var(--border-light);
  box-shadow: var(--shadow-lg);
}

.question-bank-card.solved {
  border-color: rgba(61, 214, 140, 0.35);
  background: rgba(61, 214, 140, 0.04);
}

.question-bank-card.has-diff-1 { border-right: 3px solid #22c55e; }
.question-bank-card.has-diff-2 { border-right: 3px solid #84cc16; }
.question-bank-card.has-diff-3 { border-right: 3px solid #eab308; }
.question-bank-card.has-diff-4 { border-right: 3px solid #f97316; }
.question-bank-card.has-diff-5 { border-right: 3px solid #ef4444; }

.question-bank-head {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  min-width: 0;
}

.question-bank-info {
  flex: 1;
  min-width: 0;
}

.question-bank-exam {
  font-size: 0.88rem;
  font-weight: 700;
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.question-bank-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.5rem;
  margin-top: 0.15rem;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.question-bank-q {
  font-weight: 600;
  color: var(--accent);
}

.question-bank-date {
  color: var(--text-dim);
}

.question-bank-head .difficulty-badge {
  flex-shrink: 0;
  font-size: 0.65rem;
  padding: 0.12rem 0.4rem;
}

.question-bank-topics .topic-chips {
  gap: 0.25rem;
}

.question-bank-topics .topic-chip {
  padding: 0.15rem 0.4rem;
  font-size: 0.65rem;
}

.question-bank-actions {
  display: flex;
  gap: 0.35rem;
  padding-top: 0.15rem;
  border-top: 1px solid var(--border);
}

.question-bank-actions .file-action-group {
  flex: 1;
  min-width: 0;
}

.question-bank-actions .btn-open {
  width: 100%;
  font-size: 0.72rem;
  padding: 0.38rem 0.45rem;
}

/* ── Topic sections (legacy) ── */

.topic-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 0;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.topic-section.accordion-section {
  padding: 0;
}

.topic-section-header.accordion-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.75rem 1rem;
  border: none;
  background: transparent;
  cursor: pointer;
  text-align: right;
  direction: rtl;
  margin: 0;
}

.topic-section-header .topic-section-title {
  font-weight: 700;
  font-size: 0.9rem;
  line-height: 1.45;
  flex: 1;
  min-width: 0;
  text-align: right;
  margin: 0;
}

.topic-section-stats {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.topic-section-count {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.topic-section-pct {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
}

.topic-section-progress {
  padding: 0 1rem 0.65rem;
  margin: 0;
}

.topic-items-panel .accordion-panel-inner {
  padding: 0 0.75rem 0.75rem;
}

.topic-items {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.topic-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.35rem 0.45rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  direction: rtl;
  text-align: right;
  min-width: 0;
}

.topic-row.has-diff-1 { border-right: 3px solid #22c55e; }
.topic-row.has-diff-2 { border-right: 3px solid #84cc16; }
.topic-row.has-diff-3 { border-right: 3px solid #eab308; }
.topic-row.has-diff-4 { border-right: 3px solid #f97316; }
.topic-row.has-diff-5 { border-right: 3px solid #ef4444; }

.topic-row.solved {
  border-color: rgba(61, 214, 140, 0.35);
  background: rgba(61, 214, 140, 0.04);
}

.topic-row-main {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.35rem 0.5rem;
}

.topic-row-exam {
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 14rem;
}

.topic-row-q {
  font-size: 0.68rem;
  color: var(--text-dim);
  white-space: nowrap;
}

.topic-row-actions {
  display: flex;
  gap: 0.25rem;
  flex-shrink: 0;
}

.topic-row-actions .file-action-group {
  gap: 0.2rem;
}

.topic-row .difficulty-badge {
  font-size: 0.62rem;
  padding: 0.1rem 0.35rem;
}

.topic-item {
  display: grid;
  grid-template-columns: 2.75rem 1fr auto;
  gap: 0.6rem;
  align-items: start;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  transition: border-color 0.15s;
}

.topic-item.has-diff-1 { border-right: 3px solid #22c55e; }
.topic-item.has-diff-2 { border-right: 3px solid #84cc16; }
.topic-item.has-diff-3 { border-right: 3px solid #eab308; }
.topic-item.has-diff-4 { border-right: 3px solid #f97316; }
.topic-item.has-diff-5 { border-right: 3px solid #ef4444; }

.topic-item:hover {
  border-color: var(--border-light);
}

.topic-item.solved {
  border-color: rgba(61, 214, 140, 0.35);
  background: rgba(61, 214, 140, 0.04);
}

.question-btn-compact {
  width: 2.75rem;
  height: 2.75rem;
}

.topic-item-info {
  min-width: 0;
}

.topic-item-title-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  min-width: 0;
  margin-bottom: 0.1rem;
}

.topic-item-title-row .topic-item-title {
  flex: 1;
  min-width: 0;
}

.difficulty-badge {
  flex-shrink: 0;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.15rem 0.4rem;
  border-radius: 5px;
  white-space: nowrap;
  line-height: 1.3;
}

.difficulty-badge.unset {
  background: var(--surface);
  color: var(--text-dim);
  border: 1px dashed var(--border);
}

.difficulty-badge.diff-1 { background: rgba(34, 197, 94, 0.18); color: #22c55e; }
.difficulty-badge.diff-2 { background: rgba(132, 204, 22, 0.18); color: #84cc16; }
.difficulty-badge.diff-3 { background: rgba(234, 179, 8, 0.18); color: #eab308; }
.difficulty-badge.diff-4 { background: rgba(249, 115, 22, 0.18); color: #f97316; }
.difficulty-badge.diff-5 { background: rgba(239, 68, 68, 0.18); color: #ef4444; }

.difficulty-rating-compact {
  margin-top: 0.2rem;
}

.difficulty-rating-compact .difficulty-btn {
  width: 1.35rem;
  height: 1.35rem;
  font-size: 0.62rem;
}

.topic-item-title {
  font-weight: 600;
  font-size: 0.85rem;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topic-item-meta {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 0.05rem;
}

.topic-item-actions {
  display: flex;
  gap: 0.3rem;
  flex-shrink: 0;
}

.btn-open.btn-compact {
  padding: 0.3rem 0.5rem;
  font-size: 0.72rem;
}

/* ── Warnings ── */

.parse-warning {
  padding: 0.75rem 1rem;
  background: var(--warning-soft);
  border: 1px solid rgba(240, 173, 78, 0.35);
  border-radius: var(--radius);
  color: var(--warning);
  font-size: 0.85rem;
  line-height: 1.5;
}

.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(1rem);
  background: var(--surface);
  border: 1px solid var(--border-light);
  color: var(--text);
  padding: 0.65rem 1.1rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 1000;
  max-width: calc(100vw - 2rem);
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Responsive ── */

@media (max-width: 900px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .stat-card-wide {
    grid-column: 1 / -1;
  }

  .exam-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 600px) {
  .header-inner,
  .main {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .toolbar-panel {
    position: static;
  }

  .toolbar-main {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar-group-start {
    flex-wrap: wrap;
  }

  .toolbar-filters {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .filter-actions {
    grid-column: 1 / -1;
    justify-content: flex-start;
  }

  .topic-item {
    grid-template-columns: 2.75rem 1fr;
  }

  .topic-item-actions {
    grid-column: 2;
  }

  .topic-item-title {
    white-space: normal;
  }
}

/* ── Redesign: action bar + filter bar + feed ── */

.content-feed {
  max-width: var(--feed-max);
  margin: 0 auto;
}

.action-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 0.75rem;
  box-shadow: var(--shadow);
}

.action-bar-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
}

.action-bar-cluster {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.5rem;
}

.action-bar-utilities {
  justify-content: flex-end;
}

.action-divider {
  width: 1px;
  height: 1.5rem;
  background: var(--border);
  align-self: center;
}

.filter-bar {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  position: sticky;
  top: calc(var(--header-h, 100px) + 0.35rem);
  z-index: 40;
}

.filter-bar-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem;
}

.filter-bar-row + .filter-bar-row {
  margin-top: 0.65rem;
  padding-top: 0.65rem;
  border-top: 1px solid var(--border);
}

.filter-bar-filters {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.65rem;
}

.filter-bar .search-wrap {
  flex: 1;
  min-width: 12rem;
}

.filter-bar .results-bar {
  margin-top: 0.6rem;
  padding-top: 0.6rem;
  border-top: 1px solid var(--border);
}

/* ── Accordion ── */

.accordion {
  margin-top: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-elevated);
  overflow: hidden;
}

.accordion-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.35rem 0.45rem 0.35rem 0.35rem;
}

.accordion-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  flex: 1;
  padding: 0.4rem 0.55rem;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  text-align: right;
  transition: background 0.15s, color 0.15s;
}

.accordion-toggle:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.accordion-toggle.expanded {
  color: var(--text);
}

.accordion-chevron {
  width: 0.45rem;
  height: 0.45rem;
  border-left: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
  transition: transform 0.25s ease;
  flex-shrink: 0;
}

.accordion-toggle.expanded .accordion-chevron {
  transform: rotate(135deg);
}

.badge-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.25rem;
  height: 1.25rem;
  padding: 0 0.35rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.68rem;
  font-weight: 700;
}

.accordion-panel {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.28s ease, opacity 0.22s ease;
  opacity: 0;
}

.accordion-panel.open {
  grid-template-rows: 1fr;
  opacity: 1;
}

.accordion-panel-inner {
  overflow: hidden;
  padding: 0 0.55rem;
}

.accordion-panel.open .accordion-panel-inner {
  padding: 0 0.55rem 0.55rem;
}

.accordion-empty {
  margin: 0;
  padding: 0.35rem 0.15rem;
  font-size: 0.74rem;
  color: var(--text-dim);
}

/* ── Question cards (exam view) ── */

.question-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-elevated);
  padding: 0.55rem 0.65rem;
}

.question-card-head {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.55rem;
  align-items: start;
}

.question-card-meta {
  min-width: 0;
}

.question-meta-row {
  margin-top: 0.35rem;
}

.question-card-body {
  margin-top: 0.45rem;
  padding-top: 0.45rem;
  border-top: 1px solid var(--border);
}

.questions {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

/* ── Academic / math content direction ── */

.academic-content {
  direction: ltr;
  text-align: left;
  line-height: 1.65;
  unicode-bidi: isolate;
}

.academic-content--rtl {
  direction: rtl;
  text-align: right;
}

.academic-content .math-inline {
  display: inline-block;
  direction: ltr;
  unicode-bidi: isolate;
  margin: 0 0.15em;
  vertical-align: middle;
}

.academic-content .math-display {
  display: block;
  direction: ltr;
  margin: 0.4rem 0;
  padding: 0.35rem 0.5rem;
  overflow-x: auto;
  text-align: center;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 6px;
}

.theorem-item {
  direction: rtl;
  text-align: right;
}

.theorem-name .academic-content,
.theorem-context .academic-content {
  display: block;
}

.theorem-section.accordion-section,
.theorem-section:has(.accordion-panel) {
  padding: 0;
  overflow: hidden;
}

.theorem-section.accordion-section .theorem-map-panel.accordion-panel-inner {
  padding: 0 1.25rem 1.25rem;
}

.theorem-section.accordion-section .accordion-panel.open .theorem-map-panel.accordion-panel-inner {
  padding: 0 1.25rem 1.35rem;
}

.exam-card {
  background: var(--surface-raised);
  overflow: hidden;
  min-width: 0;
}

.exam-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
}

.btn-classify,
.btn-theorem-extract-exam {
  margin: 0;
}

.exam-questions-toolbar .btn-classify,
.exam-questions-toolbar .btn-theorem-extract-exam {
  width: auto;
}

@media (max-width: 720px) {
  .filter-bar-filters {
    grid-template-columns: 1fr 1fr;
  }

  .action-bar-inner {
    flex-direction: column;
    align-items: stretch;
  }

  .action-bar-utilities {
    justify-content: flex-start;
  }

  .action-divider {
    display: none;
  }
}

/* ══════════════════════════════════════════
   APP SHELL — sidebar layout
   ══════════════════════════════════════════ */

.app-shell {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  min-height: 100vh;
  width: 100%;
}

/* Sidebar — first flex child sits on the right in RTL */
.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--bg-elevated);
  border-inline-start: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 1rem 0.85rem;
  position: sticky;
  top: 0;
  align-self: flex-start;
  height: 100vh;
  max-height: 100vh;
  overflow-x: hidden;
  overflow-y: auto;
  z-index: 200;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.35rem 0.5rem 0.85rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.35rem;
}

.sidebar-logo {
  font-size: 1.5rem;
  line-height: 1;
}

.sidebar-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

.sidebar-tagline {
  font-size: 0.72rem;
  color: var(--text-dim);
  margin-top: 0.1rem;
}

.sidebar-block {
  padding: 0.5rem 0.35rem;
}

.sidebar-label {
  display: block;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  margin-bottom: 0.4rem;
}

.sidebar-select {
  width: 100%;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.25rem 0;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  padding: 0.55rem 0.65rem;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.88rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  text-align: right;
  transition: background 0.15s, color 0.15s;
}

.sidebar-link:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.sidebar-link.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.sidebar-link-icon {
  width: 1.1rem;
  text-align: center;
  font-size: 0.85rem;
  opacity: 0.85;
}

.sidebar-actions {
  margin-top: auto;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.sidebar-upload-btn {
  width: 100%;
  justify-content: center;
  text-align: center;
}

.sidebar-action-btn,
.sidebar-tool-btn {
  width: 100%;
  justify-content: flex-start;
  text-align: right;
}

.sidebar-tools {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 150;
  border: none;
  margin: 0;
  padding: 0;
}

body.sidebar-open .sidebar-backdrop {
  display: block;
}

/* Main area */
.app-main {
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  text-align: right;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.85rem 1.5rem;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.sidebar-toggle {
  display: none;
  width: 2.25rem;
  height: 2.25rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
  flex-shrink: 0;
}

.topbar-titles {
  flex: 1;
  min-width: 0;
  text-align: right;
}

.page-title {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.page-subtitle {
  margin: 0.15rem 0 0;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.topbar-progress {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 8rem;
}

.topbar-progress-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--success);
  white-space: nowrap;
}

.progress-bar-top {
  width: 6rem;
  flex-shrink: 0;
}

.topic-chip.readonly {
  cursor: default;
  pointer-events: none;
  opacity: 0.95;
}

.topic-chips-empty {
  font-size: 0.78rem;
  color: var(--text-dim);
}

/* Page filters */
.page-filters {
  padding: 0.75rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.page-filters-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.65rem;
  width: 100%;
  max-width: var(--feed-max);
  margin: 0 auto;
}

.page-filters .search-wrap {
  flex: 1 1 12rem;
  min-width: 0;
}

.page-filters .filter-group {
  flex: 0 1 auto;
  min-width: 7rem;
}

.page-filters .filter-group .select {
  width: 100%;
  min-width: 7rem;
}

.page-filters .results-bar {
  margin-top: 0.55rem;
  font-size: 0.78rem;
  color: var(--text-dim);
}

/* Page content */
.page-content {
  flex: 1 1 auto;
  width: 100%;
  padding: 1.25rem 1.5rem 2.5rem;
  overflow-x: hidden;
  overflow-y: auto;
}

.page-panel {
  width: 100%;
  max-width: var(--feed-max);
  margin: 0 auto;
}

.page-panel.page-dashboard,
#page-dashboard.page-dashboard {
  max-width: 100%;
  width: 100%;
  margin: 0;
}

.page-content .exam-grid {
  width: 100%;
  max-width: 100%;
  margin: 0;
}

.page-content .empty-state {
  width: 100%;
  max-width: 520px;
  margin: 2rem auto;
}

.page-dashboard .stats-grid {
  margin-top: 0;
  width: 100%;
  max-width: 100%;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}

@media (min-width: 768px) {
  .page-dashboard .stats-grid {
    grid-template-columns: repeat(3, 1fr) minmax(220px, 2fr);
  }
}

.page-dashboard .stat-card {
  background: radial-gradient(ellipse 120% 80% at 50% -20%, rgba(99, 102, 241, 0.18) 0%, var(--surface) 55%);
  border: 1px solid var(--border);
  border-top: 2px solid rgba(99, 102, 241, 0.45);
  border-radius: var(--radius-lg);
  padding: 1rem 1.1rem;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.18);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.page-dashboard .stat-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.22);
}

.page-dashboard .stat-card-wide {
  grid-column: 1 / -1;
}

@media (min-width: 768px) {
  .page-dashboard .stat-card-wide {
    grid-column: auto;
  }
}

.page-dashboard .stat-card-wide .progress-bar-lg {
  height: 12px;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 999px;
}

.page-dashboard .stat-card-wide .progress-fill {
  background: linear-gradient(90deg, var(--accent) 0%, #38bdf8 50%, var(--success) 100%);
  box-shadow: 0 0 14px rgba(99, 102, 241, 0.55);
  border-radius: 999px;
}

.page-dashboard .stat-value {
  font-size: 1.65rem;
}

/* Dashboard — Bento layout */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
  margin-top: 1.5rem;
  width: 100%;
  max-width: 100%;
}

@media (min-width: 1024px) {
  .dashboard-grid {
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "topics exams"
      "leaderboard leaderboard";
    align-items: start;
  }

  .dashboard-card--topics {
    grid-area: topics;
  }

  .dashboard-card--exams {
    grid-area: exams;
  }

  .dashboard-leaderboard {
    grid-area: leaderboard;
  }
}

.dashboard-leaderboard {
  grid-column: 1 / -1;
  background: linear-gradient(145deg, rgba(99, 102, 241, 0.08) 0%, var(--surface-raised) 45%);
  border-color: rgba(99, 102, 241, 0.22);
}

.leaderboard-list {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.leaderboard-row {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.75rem 0.9rem;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.06);
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.leaderboard-row:hover {
  transform: translateY(-2px);
  background: rgba(99, 102, 241, 0.1);
  border-color: rgba(99, 102, 241, 0.25);
}

.leaderboard-rank {
  flex-shrink: 0;
  width: 2.25rem;
  height: 2.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  font-size: 0.95rem;
  font-weight: 800;
  line-height: 1;
}

.leaderboard-rank--gold {
  background: linear-gradient(135deg, #fcd34d, #f59e0b);
  color: #422006;
  box-shadow: 0 0 16px rgba(245, 158, 11, 0.45);
}

.leaderboard-rank--silver {
  background: linear-gradient(135deg, #e2e8f0, #94a3b8);
  color: #1e293b;
  box-shadow: 0 0 12px rgba(148, 163, 184, 0.35);
}

.leaderboard-rank--bronze {
  background: linear-gradient(135deg, #fdba74, #c2410c);
  color: #431407;
  box-shadow: 0 0 12px rgba(194, 65, 12, 0.35);
}

.leaderboard-rank--default {
  background: rgba(99, 102, 241, 0.18);
  color: var(--accent);
  border: 1px solid rgba(99, 102, 241, 0.35);
}

.leaderboard-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.leaderboard-row-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
}

.leaderboard-name {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.4;
  flex: 1;
  min-width: 0;
}

.leaderboard-name .academic-content {
  font-size: inherit;
  direction: rtl;
  text-align: right;
}

.leaderboard-count {
  flex-shrink: 0;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
}

.leaderboard-bar-track {
  height: 8px;
  width: 100%;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.35);
  overflow: hidden;
}

.leaderboard-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), #818cf8);
  transition: width 0.45s ease;
}

.leaderboard-bar-fill--1 {
  background: linear-gradient(90deg, #f59e0b, #fcd34d);
  box-shadow: 0 0 10px rgba(245, 158, 11, 0.5);
}

.leaderboard-bar-fill--2 {
  background: linear-gradient(90deg, #94a3b8, #e2e8f0);
}

.leaderboard-bar-fill--3 {
  background: linear-gradient(90deg, #c2410c, #fdba74);
}

.leaderboard-bar-fill--4,
.leaderboard-bar-fill--5,
.leaderboard-bar-fill--6 {
  background: linear-gradient(90deg, #6366f1, #a855f7, #38bdf8);
}

.dashboard-card {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.15rem 1.25rem;
  box-shadow: 0 2px 14px rgba(0, 0, 0, 0.16);
  min-width: 0;
}

.dashboard-card-title {
  margin: 0 0 1rem;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.01em;
}

.dashboard-empty {
  margin: 0;
  padding: 0.5rem 0;
  font-size: 0.82rem;
  color: var(--text-dim);
  grid-column: 1 / -1;
}

/* Topic donut charts */
.dashboard-topic-charts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem 0.75rem;
}

.topic-chart-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.45rem;
  padding: 0.65rem 0.5rem;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.05);
  transition: transform 0.15s ease, background 0.15s ease;
}

.topic-chart-card:hover {
  transform: translateY(-2px);
  background: rgba(255, 255, 255, 0.04);
}

.circular-chart {
  --progress: 0;
  --chart-color: #6366f1;
  position: relative;
  width: 92px;
  height: 92px;
  flex-shrink: 0;
}

.circular-chart-ring {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: conic-gradient(
    var(--chart-color) calc(var(--progress) * 1%),
    rgba(255, 255, 255, 0.08) 0
  );
  box-shadow: 0 0 18px color-mix(in srgb, var(--chart-color) 35%, transparent);
}

.circular-chart-hole {
  position: absolute;
  inset: 13%;
  border-radius: 50%;
  background: var(--surface-raised);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
}

.circular-chart-pct {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1;
}

.topic-chart-name {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  text-align: center;
  line-height: 1.35;
  max-width: 100%;
  word-break: break-word;
}

.topic-chart-fraction {
  font-size: 0.72rem;
  color: var(--text-dim);
  text-align: center;
}

.dashboard-exam-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 0.65rem;
}

.dashboard-exam-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  background: rgba(99, 102, 241, 0.05);
  border: 1px solid rgba(99, 102, 241, 0.14);
  border-radius: 12px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.dashboard-exam-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.22);
  background: rgba(99, 102, 241, 0.1);
  border-color: rgba(99, 102, 241, 0.28);
}

.dashboard-exam-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.dashboard-exam-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.dashboard-exam-title {
  font-weight: 600;
  font-size: 0.88rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}

.dashboard-exam-meta {
  font-size: 0.72rem;
  color: var(--text-dim);
}

.dashboard-progress-pill {
  flex-shrink: 0;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 700;
  white-space: nowrap;
}

.dashboard-exam-go {
  flex-shrink: 0;
  padding: 0.4rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 600;
}

/* Settings page */
.page-settings {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.settings-card {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.1rem 1.25rem;
  overflow: hidden;
}

.settings-card .modal-input,
.settings-card .search {
  width: 100%;
  max-width: 100%;
}

.settings-card-title {
  margin: 0 0 0.35rem;
  font-size: 1rem;
  font-weight: 600;
}

.settings-card-desc {
  margin: 0 0 0.85rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.settings-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* Legacy layout overrides (old header/main removed from HTML) */
.header {
  display: none !important;
}

.main {
  max-width: none;
  padding: 0;
  margin: 0;
}

/* Mobile sidebar */
@media (max-width: 860px) {
  .sidebar {
    position: fixed;
    inset-inline-end: 0;
    top: 0;
    bottom: 0;
    height: 100vh;
    max-height: none;
    transform: translateX(100%);
    transition: transform 0.25s ease;
    box-shadow: var(--shadow-lg);
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .topbar {
    padding: 0.75rem 1rem;
  }

  .page-content {
    padding: 1rem;
  }

  .page-filters {
    padding: 0.65rem 1rem;
  }

  .page-filters-inner {
    flex-direction: column;
    align-items: stretch;
  }

  .page-filters .filter-group {
    min-width: 0;
    width: 100%;
  }

  .page-filters .filter-group .select {
    min-width: 0;
  }

  .topbar-progress {
    display: none;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .stat-card-wide {
    grid-column: 1 / -1;
  }
}

/* ══ Theorems study view — enforced typography (must load last) ══ */

.exam-grid.theorems-view,
.exam-grid[data-page="theorems"] {
  font-family: "Rubik", sans-serif;
  align-items: stretch;
}

.exam-grid.theorems-view .theorem-mastery-card,
.exam-grid[data-page="theorems"] .theorem-mastery-card {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.exam-grid.theorems-view .theorem-mastery-title,
.exam-grid[data-page="theorems"] .theorem-mastery-title {
  font-size: 1.32rem;
  font-weight: 700;
  line-height: 1.5;
  color: var(--accent);
  text-align: right;
  direction: rtl;
}

.exam-grid.theorems-view .theorem-mastery-title .academic-content,
.exam-grid.theorems-view .theorem-mastery-title .academic-content--rtl,
.exam-grid[data-page="theorems"] .theorem-mastery-title .academic-content,
.exam-grid[data-page="theorems"] .theorem-mastery-title .academic-content--rtl {
  font-size: inherit;
  line-height: inherit;
  font-family: inherit;
  direction: rtl;
  text-align: right;
  display: block;
  width: 100%;
}

.exam-grid.theorems-view .theorem-formula-panel-body .academic-content,
.exam-grid.theorems-view .theorem-formula-panel-body .academic-content--formula,
.exam-grid[data-page="theorems"] .theorem-formula-panel-body .academic-content,
.exam-grid[data-page="theorems"] .theorem-formula-panel-body .academic-content--formula {
  direction: rtl;
  text-align: right;
  unicode-bidi: plaintext;
  overflow: visible;
}

.exam-grid.theorems-view .theorem-map-panel,
.exam-grid[data-page="theorems"] .theorem-map-panel {
  background: rgba(8, 12, 22, 0.55);
  border-top: 1px solid rgba(99, 102, 241, 0.2);
  direction: rtl;
  text-align: right;
}

.exam-grid.theorems-view .theorem-map-panel.accordion-panel-inner,
.exam-grid[data-page="theorems"] .theorem-map-panel.accordion-panel-inner {
  padding: 0 1.25rem 1.35rem;
}

.exam-grid.theorems-view .theorem-map-list,
.exam-grid[data-page="theorems"] .theorem-map-list {
  gap: 1rem;
}

.exam-grid.theorems-view .theorem-map-item,
.exam-grid[data-page="theorems"] .theorem-map-item {
  padding: 1.1rem 1.25rem;
  border-radius: 14px;
  border: 1px solid rgba(99, 102, 241, 0.18);
  background: var(--surface-raised);
  direction: rtl;
  text-align: right;
}

.exam-grid.theorems-view .theorem-map-item.solved,
.exam-grid[data-page="theorems"] .theorem-map-item.solved {
  border-color: rgba(34, 197, 94, 0.28);
  background: linear-gradient(135deg, rgba(34, 197, 94, 0.06), var(--surface-raised));
}

.exam-grid.theorems-view .theorem-map-item-head,
.exam-grid[data-page="theorems"] .theorem-map-item-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

.exam-grid.theorems-view .theorem-map-item-meta,
.exam-grid[data-page="theorems"] .theorem-map-item-meta {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  flex-shrink: 0;
}

.exam-grid.theorems-view .theorem-map-item-status,
.exam-grid[data-page="theorems"] .theorem-map-item-status {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-dim);
}

.exam-grid.theorems-view .theorem-map-item.solved .theorem-map-item-status,
.exam-grid[data-page="theorems"] .theorem-map-item.solved .theorem-map-item-status {
  color: #4ade80;
}

.exam-grid.theorems-view .theorem-map-item-title,
.exam-grid[data-page="theorems"] .theorem-map-item-title {
  font-size: 1.1rem;
  font-weight: 600;
  line-height: 1.55;
  color: var(--text);
  text-align: right;
  flex: 1;
  min-width: 0;
}

.exam-grid.theorems-view .theorem-map-item-question,
.exam-grid[data-page="theorems"] .theorem-map-item-question {
  font-size: 0.92rem;
  font-weight: 600;
}

.exam-grid.theorems-view .theorem-map-item-context,
.exam-grid[data-page="theorems"] .theorem-map-item-context {
  font-size: 1.05rem;
  line-height: 1.8;
  color: var(--text-muted);
  direction: rtl;
  text-align: right;
}

.exam-grid.theorems-view .theorem-map-item-context .academic-content,
.exam-grid.theorems-view .theorem-map-item-context .academic-content--rtl,
.exam-grid[data-page="theorems"] .theorem-map-item-context .academic-content,
.exam-grid[data-page="theorems"] .theorem-map-item-context .academic-content--rtl {
  font-size: inherit;
  line-height: inherit;
  font-family: inherit;
  direction: rtl;
  text-align: right;
}

.exam-grid.theorems-view .theorem-map-item-context .math-inline,
.exam-grid.theorems-view .theorem-mastery-title .math-inline,
.exam-grid.theorems-view .theorem-formula-panel-body .math-inline,
.exam-grid[data-page="theorems"] .theorem-map-item-context .math-inline,
.exam-grid[data-page="theorems"] .theorem-mastery-title .math-inline,
.exam-grid[data-page="theorems"] .theorem-formula-panel-body .math-inline {
  direction: ltr;
  unicode-bidi: isolate;
  vertical-align: middle;
}

.exam-grid.theorems-view .theorem-map-item-context .math-display,
.exam-grid.theorems-view .theorem-mastery-title .math-display,
.exam-grid.theorems-view .theorem-formula-panel-body .math-display,
.exam-grid[data-page="theorems"] .theorem-map-item-context .math-display,
.exam-grid[data-page="theorems"] .theorem-mastery-title .math-display,
.exam-grid[data-page="theorems"] .theorem-formula-panel-body .math-display {
  direction: ltr;
  unicode-bidi: isolate;
  margin: 0.75rem 0;
  padding: 0.65rem 0.85rem;
  font-size: 1.05rem;
  text-align: center;
}

.exam-grid.theorems-view .theorem-map-item-context .katex,
.exam-grid.theorems-view .theorem-mastery-title .katex,
.exam-grid.theorems-view .theorem-formula-panel-body .katex,
.exam-grid[data-page="theorems"] .theorem-map-item-context .katex,
.exam-grid[data-page="theorems"] .theorem-mastery-title .katex,
.exam-grid[data-page="theorems"] .theorem-formula-panel-body .katex {
  font-size: 1.08em;
  vertical-align: middle;
}
