:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #1e293b;
  --text: #0f172a;
  --text-muted: #64748b;
  --text-subtle: #94a3b8;
  --primary: #1e293b;
  --primary-hover: #0f172a;
  --blue: #2563eb;
  --blue-soft: #eff6ff;
  --blue-border: #bfdbfe;
  --green: #15803d;
  --green-bg: #dcfce7;
  --green-solid: #16a34a;
  --amber: #b45309;
  --amber-bg: #fef3c7;
  --amber-solid: #d97706;
  --red: #b91c1c;
  --red-bg: #fee2e2;
  --red-solid: #dc2626;
  --radius-lg: 14px;
  --radius-md: 10px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.05), 0 1px 2px rgba(15, 23, 42, 0.03);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'IBM Plex Sans Thai', 'Sarabun', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.app-shell {
  max-width: 1240px;
  margin: 0 auto;
  padding: 24px 20px 56px;
}

.hidden {
  display: none !important;
}

/* Header */
.app-header {
  margin-bottom: 18px;
}

.app-header h1 {
  margin: 0 0 4px;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.app-header .subtitle {
  margin: 0;
  font-size: 14px;
  color: var(--text-muted);
}

/* 4 Subject Cards */
.subject-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.subject-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px 12px;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.12s ease;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-family: inherit;
}

.subject-card:hover {
  border-color: #94a3b8;
  transform: translateY(-1px);
}

.subject-card.active {
  border: 2px solid var(--border-strong);
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.08);
}

.subject-card-top {
  display: flex;
  align-items: baseline;
  gap: 7px;
}

.subject-short {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}

.subject-code {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.subject-name {
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.subject-progress-text {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-muted);
  margin-top: 2px;
  display: flex;
  justify-content: space-between;
}

.progress-track {
  height: 5px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
  margin-top: 6px;
  display: flex;
}

.progress-seg-correct { background: var(--green-solid); height: 100%; }
.progress-seg-partial { background: var(--amber-solid); height: 100%; }
.progress-seg-wrong   { background: var(--red-solid); height: 100%; }
.progress-seg-pending { background: var(--blue); height: 100%; }

/* Main View Tabs (Exam vs Summary) */
.view-tabs-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.view-tabs {
  display: inline-flex;
  background: #e8edf4;
  padding: 4px;
  border-radius: 12px;
  gap: 4px;
}

.view-tab {
  border: none;
  background: transparent;
  padding: 8px 16px;
  border-radius: 9px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all 0.15s ease;
}

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

.view-tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

.tab-pill {
  font-size: 12px;
  font-weight: 600;
  padding: 1px 8px;
  border-radius: 999px;
  background: #f1f5f9;
  color: var(--text-muted);
}

.view-tab.active .tab-pill {
  background: #e2e8f0;
  color: var(--text);
}

/* Toolbar */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

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

.segmented {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.seg-btn {
  border: none;
  background: transparent;
  padding: 8px 14px;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.seg-btn.active {
  background: var(--primary);
  color: #ffffff;
}

.select-control {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  box-shadow: var(--shadow);
}

.select-control:focus {
  outline: 2px solid var(--blue);
  outline-offset: 1px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: var(--radius-md);
  padding: 8px 14px;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s ease;
  border: 1px solid transparent;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12.5px;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-outline {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
  box-shadow: var(--shadow);
}

.btn-outline:hover {
  border-color: #94a3b8;
  background: #f8fafc;
}

.btn-outline.active {
  background: var(--blue-soft);
  border-color: var(--blue);
  color: var(--blue);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border);
}

.btn-ghost:hover {
  background: var(--surface);
  color: var(--text);
}

.btn-danger-outline {
  background: var(--surface);
  color: var(--red-solid);
  border: 1.5px solid #ef4444;
  box-shadow: var(--shadow);
}

.btn-danger-outline:hover {
  background: #fef2f2;
}

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

/* Card */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

/* Exam 2-Column Workspace */
.exam-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 310px;
  gap: 16px;
  align-items: start;
}

.question-card {
  padding: 24px 26px;
  min-height: 440px;
  display: flex;
  flex-direction: column;
}

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

.q-badges {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.q-num {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  margin-right: 4px;
  line-height: 1;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface-soft);
  color: var(--text-muted);
}

.badge-old {
  background: #f1f5f9;
  color: #334155;
}

.badge-new {
  background: #eff6ff;
  border-color: #bfdbfe;
  color: #1d4ed8;
}

.btn-scratch {
  padding: 3px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  border: 1.5px solid #93c5fd;
  background: #ffffff;
  color: #1d4ed8;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s ease;
}

.btn-scratch:hover,
.btn-scratch.open {
  background: #eff6ff;
  border-color: #2563eb;
}

.q-counter {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-muted);
}

/* Scratchpad (Handwriting Canvas + Text Mode) */
.scratchpad-box {
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: var(--radius-md);
  padding: 12px;
  margin-bottom: 16px;
}

.scratchpad-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
  font-size: 12.5px;
  font-weight: 600;
  color: #92400e;
}

.scratch-tabs {
  display: inline-flex;
  background: #fef3c7;
  padding: 3px;
  border-radius: 8px;
  gap: 3px;
}

.scratch-tab {
  border: none;
  background: transparent;
  padding: 4px 10px;
  border-radius: 6px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  color: #92400e;
  cursor: pointer;
}

.scratch-tab.active {
  background: #ffffff;
  color: #0f172a;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
}

.scratch-right-tools {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.pen-color {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
}

.pen-color.active {
  border-color: #ffffff;
  box-shadow: 0 0 0 2px #0f172a;
}

.btn-ghost.active-tool {
  background: #fef3c7;
  border-color: #d97706;
  color: #92400e;
}

.scratch-canvas-wrap {
  position: relative;
}

.scratch-canvas {
  display: block;
  width: 100%;
  height: 260px;
  border: 1px solid #fcd34d;
  border-radius: 8px;
  background-color: #ffffff;
  background-image: radial-gradient(#cbd5e1 1px, transparent 1px);
  background-size: 18px 18px;
  cursor: crosshair;
  touch-action: none;
}

.scratch-canvas-hint {
  margin-top: 5px;
  font-size: 11.5px;
  color: #92400e;
  opacity: 0.85;
}

/* Stacked Vertical Math Fractions */
.frac {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  vertical-align: middle;
  margin: 0 3px;
  line-height: 1.15;
  font-size: 0.92em;
}

.frac-num {
  padding: 0 4px 2px;
  border-bottom: 1.5px solid currentColor;
  text-align: center;
}

.frac-den {
  padding: 2px 4px 0;
  text-align: center;
}

.sum-formula-eq {
  line-height: 2.1;
}

.scratchpad-box textarea {
  width: 100%;
  min-height: 84px;
  border: 1px solid #fcd34d;
  border-radius: 8px;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 13.5px;
  background: #ffffff;
  resize: vertical;
  color: var(--text);
}

/* Shared Context Box (like screenshot "▼ โจทย์ร่วม") */
.context-box {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-left: 3.5px solid #2563eb;
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 18px;
}

.context-toggle {
  border: none;
  background: transparent;
  padding: 0;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  color: #1d4ed8;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
}

.context-body {
  margin-top: 8px;
  font-size: 13px;
  color: #334155;
  white-space: pre-wrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;
  overflow-x: auto;
}

/* Question Prompt */
.q-text {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.65;
  margin: 0 0 20px;
  white-space: pre-line;
}

/* Options List (MCQ) */
.options-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 18px;
}

.option-btn {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 13px 15px;
  border-radius: 11px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-family: inherit;
  font-size: 15px;
  color: var(--text);
  transition: all 0.14s ease;
}

.option-btn:hover:not(:disabled) {
  border-color: #94a3b8;
  background: #f8fafc;
}

.option-key {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1.5px solid #cbd5e1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  color: var(--text-muted);
  background: #ffffff;
}

.option-btn.selected {
  border-color: var(--blue);
  background: var(--blue-soft);
}

.option-btn.selected .option-key {
  background: var(--blue);
  border-color: var(--blue);
  color: #ffffff;
}

.option-btn.correct {
  border-color: var(--green-solid);
  background: #f0fdf4;
}

.option-btn.correct .option-key {
  background: var(--green-solid);
  border-color: var(--green-solid);
  color: #ffffff;
}

.option-btn.wrong {
  border-color: var(--red-solid);
  background: #fef2f2;
}

.option-btn.wrong .option-key {
  background: var(--red-solid);
  border-color: var(--red-solid);
  color: #ffffff;
}

/* T/F Grid */
.tf-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 18px;
}

.tf-btn {
  justify-content: center;
  align-items: center;
  padding: 16px;
  font-weight: 700;
  font-size: 16px;
}

/* Written Answer Box (Handwriting Canvas) */
.written-area {
  margin-bottom: 16px;
}

.written-pad-box {
  background: #f8fafc;
  border: 1.5px solid #cbd5e1;
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 12px;
}

.written-pad-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 700;
  color: #1e293b;
}

.written-canvas {
  display: block;
  width: 100%;
  height: 340px;
  border: 1px solid #cbd5e1;
  border-radius: 9px;
  background-color: #ffffff;
  background-image:
    linear-gradient(to bottom, transparent 31px, #e2e8f0 32px);
  background-size: 100% 32px;
  cursor: crosshair;
  touch-action: none;
}

.written-pad-hint {
  margin-top: 6px;
  font-size: 11.5px;
  color: var(--text-muted);
}

.written-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* Explanation / Model Answer Box */
.explanation-box {
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  border-left: 4px solid var(--primary);
  border-radius: 11px;
  padding: 15px 18px;
  margin-bottom: 18px;
}

.explanation-box.is-correct {
  background: #f0fdf4;
  border-color: #bbf7d0;
  border-left-color: var(--green-solid);
}

.explanation-box.is-wrong {
  background: #fef2f2;
  border-color: #fecaca;
  border-left-color: var(--red-solid);
}

.exp-title {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.exp-body {
  font-size: 14.5px;
  color: #1e293b;
  white-space: pre-line;
  line-height: 1.65;
}

/* Self-Grade Row for Written Questions */
.self-grade-row {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px dashed #cbd5e1;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.self-grade-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-right: 4px;
}

.grade-btn {
  border-radius: 999px;
  padding: 5px 13px;
  font-size: 13px;
  font-weight: 600;
  border: 1.5px solid var(--border);
  background: #ffffff;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.14s ease;
}

.grade-btn.g-correct:hover, .grade-btn.g-correct.active {
  background: var(--green-solid);
  border-color: var(--green-solid);
  color: #ffffff;
}

.grade-btn.g-partial:hover, .grade-btn.g-partial.active {
  background: var(--amber-solid);
  border-color: var(--amber-solid);
  color: #ffffff;
}

.grade-btn.g-wrong:hover, .grade-btn.g-wrong.active {
  background: var(--red-solid);
  border-color: var(--red-solid);
  color: #ffffff;
}

/* Question Navigation Footer */
.q-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid #f1f5f9;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.kbd-hint {
  font-size: 12px;
  color: var(--text-subtle);
}

/* Right Answer Sheet */
.sheet-card {
  padding: 18px 18px 20px;
  position: sticky;
  top: 16px;
}

.sheet-header h2 {
  margin: 0 0 6px;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.sheet-score-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.score-big {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  line-height: 1.1;
}

.score-label {
  font-size: 12.5px;
  color: var(--text-muted);
}

.sheet-substats {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-top: 4px;
}

.sim-bar {
  margin-top: 12px;
  padding: 10px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sim-timer {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  text-align: center;
}

.sheet-legend {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 11.5px;
  color: var(--text-muted);
  margin: 12px 0;
  flex-wrap: wrap;
}

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 3px;
}

.dot-correct { background: var(--green-solid); }
.dot-partial { background: var(--amber-solid); }
.dot-wrong   { background: var(--red-solid); }

.sheet-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 7px;
  max-height: 440px;
  overflow-y: auto;
  padding: 3px 2px;
}

.bubble {
  aspect-ratio: 1;
  border-radius: 50%;
  border: 1.5px solid #e2e8f0;
  background: #ffffff;
  color: #475569;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s ease, border-color 0.12s ease;
}

.bubble:hover {
  border-color: #64748b;
  transform: scale(1.06);
}

.bubble.correct {
  background: var(--green-solid);
  border-color: var(--green-solid);
  color: #ffffff;
}

.bubble.partial {
  background: var(--amber-solid);
  border-color: var(--amber-solid);
  color: #ffffff;
}

.bubble.wrong {
  background: var(--red-solid);
  border-color: var(--red-solid);
  color: #ffffff;
}

.bubble.pending {
  background: #dbeafe;
  border-color: #60a5fa;
  color: #1e40af;
}

.bubble.current {
  border: 2.5px solid var(--border-strong);
  box-shadow: 0 0 0 2px rgba(15, 23, 42, 0.12);
}

/* ==================== SUMMARY VIEW ==================== */
.summary-toolbar {
  margin-bottom: 14px;
}

.subdoc-pills {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.subdoc-pill {
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
}

.subdoc-pill.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

.search-box input {
  width: 280px;
  max-width: 100%;
  padding: 8px 13px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  font-family: inherit;
  font-size: 13.5px;
  color: var(--text);
}

.search-box input:focus {
  outline: none;
  border-color: var(--blue);
}

.summary-workspace {
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.summary-toc {
  padding: 14px;
  position: sticky;
  top: 16px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
}

.toc-title {
  font-size: 12.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin: 0 0 10px 6px;
}

.toc-item {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  padding: 8px 10px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  color: #334155;
  cursor: pointer;
  line-height: 1.4;
  margin-bottom: 2px;
}

.toc-item:hover {
  background: #f1f5f9;
  color: var(--text);
}

.summary-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.summary-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.summary-section-head {
  width: 100%;
  border: none;
  background: #f8fafc;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.summary-section-head h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.summary-section-head .chev {
  font-size: 12px;
  color: var(--text-muted);
  transition: transform 0.15s ease;
}

.summary-section.collapsed .summary-section-head {
  border-bottom: none;
}

.summary-section.collapsed .chev {
  transform: rotate(-90deg);
}

.summary-section.collapsed .summary-section-content {
  display: none;
}

.summary-section-content {
  padding: 18px 22px 22px;
  font-size: 14.5px;
  line-height: 1.72;
  color: #1e293b;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.toc-cta {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.sum-lead {
  background: #f8fafc;
  border-left: 3.5px solid #1e293b;
  padding: 11px 15px;
  border-radius: 8px;
  font-size: 14.5px;
  color: #0f172a;
}

.sum-subhead {
  margin: 4px 0 -4px;
  font-size: 15px;
  font-weight: 700;
  color: #0f172a;
}

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

.sum-list li {
  line-height: 1.68;
}

.sum-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.sum-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  line-height: 1.55;
}

.sum-table th {
  background: #f1f5f9;
  color: #0f172a;
  font-weight: 700;
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.sum-table td {
  padding: 9px 12px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: top;
}

.sum-table tbody tr:last-child td {
  border-bottom: none;
}

.sum-table tbody tr:hover {
  background: #fafcff;
}

.sum-formula-card {
  background: #fefce8;
  border: 1px solid #fde047;
  border-left: 4px solid #ca8a04;
  border-radius: 10px;
  padding: 13px 16px;
}

.sum-formula-title {
  font-size: 13.5px;
  font-weight: 700;
  color: #854d0e;
  margin-bottom: 6px;
}

.sum-formula-eq {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;
  font-size: 14px;
  font-weight: 700;
  color: #0f172a;
  background: #ffffff;
  padding: 8px 12px;
  border-radius: 7px;
  border: 1px solid #fef08a;
  overflow-x: auto;
}

.sum-formula-note {
  margin-top: 8px;
  font-size: 13.5px;
  color: #422006;
  white-space: pre-line;
}

.sum-je-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sum-je-title {
  font-size: 14px;
  font-weight: 700;
  color: #1d4ed8;
}

.je-table .je-dr {
  color: #0f172a;
  font-weight: 600;
}

.je-table .je-cr {
  color: #1e40af;
  font-weight: 600;
}

.je-table .je-note {
  color: #475569;
  font-size: 13px;
}

.sum-tip {
  border-radius: 10px;
  padding: 13px 16px;
  border: 1px solid var(--border);
}

.sum-tip.tip-exam {
  background: #eff6ff;
  border-color: #bfdbfe;
  border-left: 4px solid #2563eb;
}

.sum-tip.tip-trap {
  background: #fef2f2;
  border-color: #fecaca;
  border-left: 4px solid #dc2626;
}

.sum-tip.tip-case {
  background: #ecfdf5;
  border-color: #a7f3d0;
  border-left: 4px solid #059669;
}

.sum-tip-title {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 5px;
  color: #0f172a;
}

.sum-tip-body {
  font-size: 13.8px;
  color: #1e293b;
  line-height: 1.65;
}

.sum-line {
  margin: 0;
}

/* Economics SVG Diagram Cards */
.sum-diagram-card {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sum-diagram-title {
  font-size: 14.5px;
  font-weight: 700;
  color: #0f172a;
}

.sum-diagram-svg {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 10px;
  display: flex;
  justify-content: center;
  overflow-x: auto;
}

.sum-diagram-svg svg {
  width: 100%;
  max-width: 540px;
  height: auto;
  display: block;
}

.sum-diagram-steps {
  margin-top: 2px;
  font-size: 13.8px;
}

.sum-image-card {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sum-image-link {
  display: block;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid #e2e8f0;
  background: #ffffff;
}

.sum-image-link img {
  display: block;
  width: 100%;
  height: auto;
}

.sum-image-caption {
  font-size: 12.5px;
  color: var(--text-muted);
  text-align: center;
}

mark {
  background: #fde047;
  color: #0f172a;
  padding: 0 2px;
  border-radius: 3px;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
}

.empty-state p {
  margin: 8px 0 16px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--primary);
  color: #ffffff;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.22);
  z-index: 100;
}

/* Responsive */
@media (max-width: 980px) {
  .subject-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .exam-workspace,
  .summary-workspace {
    grid-template-columns: 1fr;
  }
  .sheet-card,
  .summary-toc {
    position: static;
  }
}

@media (max-width: 560px) {
  .subject-grid {
    grid-template-columns: 1fr;
  }
  .tf-grid {
    grid-template-columns: 1fr;
  }
  .app-header h1 {
    font-size: 22px;
  }
}
