/* Dermato Anki — Clean Clinical Flashcard Trainer */
:root {
  --bg: #0c1117;
  --bg-elev: #141b24;
  --bg-card: #18212c;
  --bg-subtle: #1e2937;
  --border: #2a3748;
  --border-strong: #3a4c63;
  --text: #edf2f7;
  --text-muted: #94a3b8;
  --accent: #38bdf8;
  --accent-strong: #0284c7;
  --accent-soft: rgba(56, 189, 248, 0.14);
  --good: #22c55e;
  --good-soft: rgba(34, 197, 94, 0.15);
  --warn: #f59e0b;
  --warn-soft: rgba(245, 158, 11, 0.15);
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.15);
  --easy: #a855f7;
  --easy-soft: rgba(168, 85, 247, 0.15);
  --shadow: 0 14px 36px rgba(0, 0, 0, 0.35);
  --radius: 14px;
  --radius-sm: 9px;
}

[data-theme="light"] {
  --bg: #f1f5f9;
  --bg-elev: #ffffff;
  --bg-card: #ffffff;
  --bg-subtle: #f8fafc;
  --border: #dbe3ec;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #64748b;
  --accent: #0284c7;
  --accent-strong: #0369a1;
  --accent-soft: rgba(2, 132, 199, 0.11);
  --good: #16a34a;
  --good-soft: rgba(22, 163, 74, 0.12);
  --warn: #d97706;
  --warn-soft: rgba(217, 119, 6, 0.12);
  --danger: #dc2626;
  --danger-soft: rgba(220, 38, 38, 0.12);
  --easy: #7c3aed;
  --easy-soft: rgba(124, 58, 237, 0.12);
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* App Shell */
.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Top Header */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 20px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
}

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

.brand-logo {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #0ea5e9, #14b8a6);
  font-size: 1.25rem;
  box-shadow: 0 4px 12px rgba(14, 165, 233, 0.3);
}

.brand-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-sub {
  margin: 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.mode-tabs {
  display: flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 3px;
  gap: 3px;
}

.mode-tab {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 7px 14px;
  border-radius: 8px;
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.16s ease;
}

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

.mode-tab.active {
  background: var(--accent);
  color: #04131c;
}

[data-theme="light"] .mode-tab.active {
  color: #ffffff;
}

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

/* Workspace Layout */
.workspace {
  display: grid;
  grid-template-columns: 295px 1fr;
  flex: 1;
  max-width: 1520px;
  width: 100%;
  margin: 0 auto;
}

/* Sidebar */
.sidebar {
  border-right: 1px solid var(--border);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--bg-elev);
  height: calc(100vh - 61px);
  position: sticky;
  top: 61px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.sidebar::-webkit-scrollbar {
  width: 6px;
}

.sidebar::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 99px;
}

.panel {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 13px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.panel-header h2 {
  margin: 0;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

/* Anki Counts */
.anki-counts {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 12px;
}

.count-chip {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 7px 4px;
  text-align: center;
}

.count-num {
  display: block;
  font-size: 1.08rem;
  font-weight: 700;
  line-height: 1.2;
}

.count-lbl {
  font-size: 0.68rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

.count-new .count-num { color: var(--accent); }
.count-learn .count-num { color: var(--warn); }
.count-due .count-num { color: var(--good); }
.count-mastered .count-num { color: var(--easy); }

.mastery-bar-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 5px;
}

.mastery-bar {
  height: 7px;
  background: var(--bg);
  border-radius: 99px;
  overflow: hidden;
}

.mastery-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--good));
  border-radius: 99px;
  transition: width 0.3s ease;
}

/* Toggle Rows */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 0;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}

.toggle-row:last-child {
  border-bottom: none;
  padding-bottom: 2px;
}

.toggle-row strong {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
}

.toggle-row small {
  display: block;
  font-size: 0.74rem;
  color: var(--text-muted);
}

.toggle-row input {
  display: none;
}

.switch {
  width: 38px;
  height: 22px;
  border-radius: 99px;
  background: var(--border-strong);
  position: relative;
  flex-shrink: 0;
  transition: background 0.18s ease;
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.18s ease;
}

.toggle-row input:checked + .switch {
  background: var(--accent);
}

.toggle-row input:checked + .switch::after {
  transform: translateX(16px);
}

/* Topic List */
.topic-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.topic-item {
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  border-radius: 9px;
  padding: 7px 9px;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.82rem;
  transition: all 0.15s ease;
}

.topic-item:hover {
  background: var(--bg-card);
  border-color: var(--border);
}

.topic-item.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

.topic-count {
  font-size: 0.74rem;
  padding: 2px 7px;
  border-radius: 99px;
  background: var(--bg-card);
  color: var(--text-muted);
  flex-shrink: 0;
}

.topic-item.active .topic-count {
  background: var(--accent);
  color: #04131c;
}

[data-theme="light"] .topic-item.active .topic-count {
  color: #fff;
}

.data-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* Main Stage */
.main-stage {
  padding: 22px 28px 48px;
  min-width: 0;
}

.study-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.session-meta, .toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Buttons & Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 0.76rem;
  font-weight: 600;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  color: var(--text);
}

.badge-accent {
  background: var(--accent-soft);
  border-color: rgba(56, 189, 248, 0.35);
  color: var(--accent);
}

.badge-subtle {
  color: var(--text-muted);
}

.badge-good {
  background: var(--good-soft);
  border-color: rgba(34, 197, 94, 0.35);
  color: var(--good);
}

.badge-warn {
  background: var(--warn-soft);
  border-color: rgba(245, 158, 11, 0.35);
  color: var(--warn);
}

.badge-danger {
  background: var(--danger-soft);
  border-color: rgba(239, 68, 68, 0.35);
  color: var(--danger);
}

.btn, .pill-btn, .icon-btn, .link-btn {
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-sm {
  padding: 6px 11px;
  font-size: 0.8rem;
}

.btn-lg {
  padding: 12px 24px;
  font-size: 0.98rem;
  border-radius: 11px;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #04131c;
}

[data-theme="light"] .btn-primary {
  color: #ffffff;
}

.btn-primary:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

.btn-ghost {
  background: var(--bg-subtle);
  color: var(--text);
}

.btn-ghost:hover {
  border-color: var(--border-strong);
  background: var(--bg-card);
}

.btn-good {
  background: var(--good);
  border-color: var(--good);
  color: #03150a;
}

.btn-warn {
  background: var(--warn);
  border-color: var(--warn);
  color: #1f1202;
}

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.btn-danger-ghost {
  background: transparent;
  border-color: rgba(239, 68, 68, 0.35);
  color: var(--danger);
}

.btn-danger-ghost:hover {
  background: var(--danger-soft);
}

.pill-btn {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 99px;
  padding: 5px 12px;
  font-size: 0.8rem;
  font-weight: 600;
}

.pill-btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.pill-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.pill-btn.flagged {
  background: var(--warn-soft);
  border-color: var(--warn);
  color: var(--warn);
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--bg-subtle);
  color: var(--text);
  display: grid;
  place-items: center;
  font-size: 1rem;
}

.icon-btn:hover {
  border-color: var(--accent);
}

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 2px 4px;
}

.link-btn:hover {
  text-decoration: underline;
}

kbd {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 5px;
  font-size: 0.72rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.16);
}

[data-theme="light"] kbd {
  background: rgba(15, 23, 42, 0.08);
  border-color: rgba(15, 23, 42, 0.16);
}

/* Flashcard */
.flashcard {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 20px 24px 24px;
  max-width: 980px;
  margin: 0 auto;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.card-badges {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.card-prompt {
  margin: 0 0 14px;
  font-size: 0.96rem;
  color: var(--text-muted);
  text-align: center;
}

/* Crop Gallery (Front Images) */
.crop-gallery {
  display: grid;
  gap: 12px;
  margin-bottom: 18px;
  justify-items: center;
  align-items: center;
}

.crop-gallery.cols-1 {
  grid-template-columns: 1fr;
}

.crop-gallery.cols-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.crop-gallery.cols-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.crop-tile {
  position: relative;
  width: 100%;
  background: #090d12;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-in;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.crop-tile:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.crop-tile img {
  width: 100%;
  max-height: 410px;
  object-fit: contain;
  display: block;
}

.crop-gallery.cols-2 .crop-tile img {
  max-height: 330px;
}

.crop-gallery.cols-2.compact-grid .crop-tile img {
  max-height: 215px;
}

.crop-gallery.cols-3 .crop-tile img {
  max-height: 215px;
}

.crop-tile .zoom-pill {
  position: absolute;
  right: 8px;
  bottom: 8px;
  background: rgba(0, 0, 0, 0.68);
  color: #fff;
  font-size: 0.7rem;
  padding: 2px 7px;
  border-radius: 99px;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.crop-tile:hover .zoom-pill {
  opacity: 1;
}

/* Compact gallery when answer is revealed */
.flashcard.revealed .crop-gallery {
  margin-bottom: 16px;
}
.flashcard.revealed .crop-tile img {
  max-height: 230px;
}

/* Text-Only Front Box */
.text-front-box {
  background: linear-gradient(145deg, var(--bg-subtle), var(--bg-elev));
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  padding: 36px 26px;
  text-align: center;
  margin-bottom: 18px;
}

.text-front-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  font-weight: 700;
  margin-bottom: 8px;
}

.text-front-title {
  margin: 0;
  font-size: 1.5rem;
  line-height: 1.3;
}

.text-front-sub {
  margin: 8px 0 0;
  color: var(--text-muted);
}

/* Recall Input & Hint */
.recall-box {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  align-items: stretch;
}

.recall-box .btn {
  white-space: nowrap;
  flex-shrink: 0;
}

.recall-input, .search-input, .select-input, textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 10px 13px;
  font-family: inherit;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.15s ease;
}

.recall-input:focus, .search-input:focus, .select-input:focus, textarea:focus {
  border-color: var(--accent);
}

.hint-box {
  background: var(--warn-soft);
  border: 1px solid rgba(245, 158, 11, 0.35);
  color: var(--warn);
  border-radius: var(--radius-sm);
  padding: 9px 13px;
  font-size: 0.86rem;
  margin-bottom: 12px;
}

.flip-bar {
  display: flex;
  justify-content: center;
  margin-top: 8px;
}

/* Back / Answer Area */
.card-back {
  border-top: 1px solid var(--border);
  padding-top: 18px;
  margin-top: 14px;
  animation: fadeSlide 0.18s ease-out;
}

@keyframes fadeSlide {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.recall-check {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  margin-bottom: 14px;
  border: 1px solid var(--border);
}

.recall-check.match-good {
  background: var(--good-soft);
  border-color: rgba(34, 197, 94, 0.4);
  color: var(--good);
}

.recall-check.match-partial {
  background: var(--warn-soft);
  border-color: rgba(245, 158, 11, 0.4);
  color: var(--warn);
}

.recall-check.match-miss {
  background: var(--bg-subtle);
  color: var(--text-muted);
}

.answer-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.answer-topic {
  display: inline-block;
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  font-weight: 700;
  margin-bottom: 3px;
}

.answer-title {
  margin: 0;
  font-size: 1.48rem;
  line-height: 1.25;
  letter-spacing: -0.015em;
}

.answer-subtitle {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.section-label {
  display: block;
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 700;
  margin-bottom: 8px;
}

.answer-points-card {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 18px;
  margin-bottom: 16px;
}

.answer-bullets {
  margin: 0;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.answer-bullets li {
  font-size: 0.96rem;
  line-height: 1.5;
}

.answer-bullets li strong.lead {
  color: var(--accent);
}

/* Personal Notes */
.note-editor {
  margin-bottom: 14px;
}

.saved-note {
  background: var(--accent-soft);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 9px 13px;
  font-size: 0.88rem;
  margin-bottom: 14px;
}

/* Original Full Slide */
.original-slide-section {
  margin-bottom: 18px;
}

.original-slide-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.original-slide-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 10px;
}

.orig-slide-card {
  background: #080b10;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  cursor: zoom-in;
}

.orig-slide-card img {
  width: 100%;
  max-height: 360px;
  object-fit: contain;
  display: block;
}

.orig-slide-cap {
  padding: 5px 10px;
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--bg-subtle);
  border-top: 1px solid var(--border);
}

/* Anki Rating Buttons */
.rating-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: 8px;
}

.rate-btn {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  background: var(--bg-subtle);
  color: var(--text);
  transition: transform 0.14s ease, border-color 0.14s ease, background 0.14s ease;
}

.rate-btn:hover {
  transform: translateY(-2px);
}

.rate-title {
  font-weight: 700;
  font-size: 0.92rem;
  display: flex;
  align-items: center;
  gap: 5px;
}

.rate-int {
  font-size: 0.76rem;
  color: var(--text-muted);
}

.rate-again { border-color: rgba(239, 68, 68, 0.45); background: var(--danger-soft); }
.rate-again .rate-title { color: var(--danger); }

.rate-hard { border-color: rgba(245, 158, 11, 0.45); background: var(--warn-soft); }
.rate-hard .rate-title { color: var(--warn); }

.rate-good { border-color: rgba(34, 197, 94, 0.45); background: var(--good-soft); }
.rate-good .rate-title { color: var(--good); }

.rate-easy { border-color: rgba(168, 85, 247, 0.45); background: var(--easy-soft); }
.rate-easy .rate-title { color: var(--easy); }

.cram-bar, .exam-grade-bar {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
}

/* Empty State */
.empty-state {
  max-width: 560px;
  margin: 48px auto;
  text-align: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 40px 28px;
}

.empty-icon {
  font-size: 2.8rem;
  margin-bottom: 8px;
}

.empty-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 20px;
  flex-wrap: wrap;
}

/* Exam Setup & Summary */
.exam-setup-card {
  max-width: 760px;
  margin: 12px auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 28px;
  box-shadow: var(--shadow);
}

.exam-setup-head h2 {
  margin: 10px 0 6px;
  font-size: 1.5rem;
}

.exam-options-grid {
  display: grid;
  gap: 16px;
  margin: 22px 0;
}

.option-group label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 7px;
}

.seg-control {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.seg-btn {
  border: 1px solid var(--border);
  background: var(--bg-subtle);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 9px;
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
}

.seg-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #04131c;
}

[data-theme="light"] .seg-btn.active {
  color: #fff;
}

.exam-start-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}

.exam-progress-track {
  height: 6px;
  background: var(--bg-subtle);
  border-radius: 99px;
  overflow: hidden;
  max-width: 980px;
  margin: 0 auto 14px;
}

.exam-progress-fill {
  height: 100%;
  background: var(--accent);
  transition: width 0.25s ease;
}

.exam-input-wrap {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.user-answer-echo {
  background: var(--bg-subtle);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 10px 13px;
  margin-bottom: 14px;
  font-size: 0.9rem;
}

.summary-score-ring {
  text-align: center;
  margin-bottom: 14px;
}

.summary-pct {
  font-size: 3rem;
  font-weight: 800;
  color: var(--accent);
  line-height: 1.1;
}

.summary-stats-row {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 12px 0 20px;
}

.missed-review-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 18px;
}

.missed-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
}

.missed-row img {
  width: 72px;
  height: 54px;
  object-fit: cover;
  border-radius: 6px;
  background: #000;
}

/* Browse Deck */
.browse-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.browse-controls .search-input {
  flex: 1;
  min-width: 240px;
}

.browse-controls .select-input {
  width: auto;
  min-width: 200px;
}

.browse-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 14px;
}

.browse-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 13px;
  overflow: hidden;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.browse-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
}

.browse-thumb {
  height: 148px;
  background: #090d12;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}

.browse-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.browse-thumb-text {
  padding: 14px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.84rem;
}

.browse-card-body {
  padding: 11px 13px 13px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.browse-card-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.browse-card-title {
  margin: 0;
  font-size: 0.92rem;
  font-weight: 700;
  line-height: 1.3;
}

.browse-card-snip {
  margin: 0;
  font-size: 0.78rem;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Modals & Lightbox */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(5, 9, 14, 0.84);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.lightbox-close {
  position: fixed;
  top: 18px;
  right: 22px;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  font-size: 1.2rem;
  cursor: pointer;
}

.lightbox-content {
  max-width: 94vw;
  max-height: 90vh;
  text-align: center;
}

.lightbox-content img {
  max-width: 92vw;
  max-height: 82vh;
  object-fit: contain;
  border-radius: 10px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.65);
}

.lightbox-caption {
  color: #e2e8f0;
  margin-top: 10px;
  font-size: 0.9rem;
}

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 100%;
  max-width: 440px;
  max-height: 88vh;
  overflow-y: auto;
  padding: 20px;
  box-shadow: var(--shadow);
}

.modal-card-wide {
  max-width: 780px;
}

.modal-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.modal-card-header h3 {
  margin: 0;
  font-size: 1.15rem;
}

.shortcut-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.shortcut-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
}

.shortcut-row:last-child {
  border-bottom: none;
}

.preview-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 120;
  background: var(--bg-elev);
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 9px 18px;
  border-radius: 99px;
  font-size: 0.86rem;
  font-weight: 600;
  box-shadow: var(--shadow);
}

/* Mobile Responsive */
.mobile-only {
  display: none;
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: 55;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(3px);
}

@media (hover: none) {
  kbd {
    display: none;
  }
}

@media (max-width: 960px) {
  .mobile-only {
    display: grid;
  }
  .workspace {
    grid-template-columns: minmax(0, 1fr);
    overflow-x: clip;
  }
  .sidebar {
    position: fixed;
    left: -320px;
    top: 0;
    height: 100dvh;
    padding-top: max(18px, env(safe-area-inset-top));
    padding-bottom: max(24px, env(safe-area-inset-bottom));
    width: 300px;
    z-index: 60;
    transition: left 0.22s ease;
    box-shadow: var(--shadow);
  }
  .sidebar.open {
    left: 0;
  }
  .main-stage {
    padding: 12px 10px max(36px, env(safe-area-inset-bottom));
    width: 100%;
    max-width: 100vw;
  }
  .rating-bar {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }
  .rate-btn {
    padding: 14px 10px;
    min-height: 58px;
  }
  .crop-gallery.cols-3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .brand-sub {
    display: none;
  }
}

@media (max-width: 600px) {
  .topbar {
    flex-wrap: wrap;
    padding: max(10px, env(safe-area-inset-top)) 10px 10px;
    gap: 8px;
    width: 100%;
  }
  .topbar-actions #shortcutsBtn {
    display: none;
  }
  .mode-tabs {
    order: 3;
    width: 100%;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 2px;
  }
  .mode-tab {
    padding: 7px 2px;
    font-size: 0.72rem;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .flashcard {
    padding: 12px 12px 16px;
    border-radius: 14px;
    width: 100%;
  }
  .card-header {
    flex-wrap: wrap;
    gap: 6px;
  }
  .crop-gallery.cols-2, .crop-gallery.cols-3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }
  .crop-tile img {
    max-height: 270px;
  }
  .crop-gallery.cols-2 .crop-tile img,
  .crop-gallery.cols-3 .crop-tile img {
    max-height: 195px;
  }
  .recall-input, .search-input, .select-input, textarea {
    font-size: 16px;
    min-width: 0;
  }
  .browse-controls .search-input,
  .browse-controls .select-input {
    min-width: 0;
    width: 100%;
  }
  .btn-lg {
    width: 100%;
    padding: 14px 18px;
  }
  .answer-title {
    font-size: 1.24rem;
  }
  .exam-setup-card {
    padding: 18px 14px;
  }
}
