:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1a202c;
  --text-muted: #64748b;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --practice: #0d9488;
  --practice-dark: #0f766e;
  --exam: #dc2626;
  --exam-dark: #b91c1c;
  --correct: #16a34a;
  --correct-bg: #dcfce7;
  --incorrect: #dc2626;
  --incorrect-bg: #fee2e2;
  --unanswered: #94a3b8;
  --marked: #d97706;
  --marked-bg: #fef3c7;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
}

* { box-sizing: border-box; }

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

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

/* Header */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}
.app-header .header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 24px;
}
.brand {
  font-weight: 700;
  font-size: 1.15rem;
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}
.brand .logo { font-size: 1.4rem; }
.nav-links {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
.nav-links a {
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--text-muted);
}
.nav-links a:hover { background: var(--bg); color: var(--text); }
.nav-links a.active { background: #eef2ff; color: var(--primary); }

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 28px 20px 60px;
}

/* Dashboard mode cards */
.mode-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin: 24px 0 36px;
}
@media (max-width: 720px) {
  .mode-cards { grid-template-columns: 1fr; }
}
.mode-card {
  border-radius: 16px;
  padding: 28px;
  color: #fff;
  box-shadow: var(--shadow-md);
  position: relative;
  overflow: hidden;
}
.mode-card.practice { background: linear-gradient(135deg, #0d9488, #0f766e); }
.mode-card.exam { background: linear-gradient(135deg, #dc2626, #991b1b); }
.mode-card h2 { margin: 4px 0 8px; font-size: 1.5rem; }
.mode-card p.tagline { opacity: 0.92; margin: 0 0 18px; font-size: 0.98rem; }
.mode-card ul { padding-left: 18px; margin: 0 0 20px; font-size: 0.9rem; opacity: 0.95; }
.mode-card ul li { margin-bottom: 4px; }
.mode-card .icon { font-size: 2.2rem; }
.btn-white {
  background: #fff;
  border: none;
  padding: 11px 22px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.95rem;
}
.mode-card.practice .btn-white { color: var(--practice-dark); }
.mode-card.exam .btn-white { color: var(--exam-dark); }

.section-title { font-size: 1.15rem; font-weight: 700; margin: 32px 0 14px; }

/* Paper cards */
.paper-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.paper-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: relative;
  overflow: hidden;
}
.paper-card.solved { border-color: var(--correct); box-shadow: 0 0 0 1px var(--correct), var(--shadow); }
.solved-ribbon {
  position: absolute; top: 12px; right: -30px; transform: rotate(40deg);
  background: var(--correct); color: #fff; font-size: 0.68rem; font-weight: 700;
  padding: 3px 34px; box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.paper-card .tag-row { display: flex; gap: 6px; flex-wrap: wrap; }
.tag {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  background: #eef2ff;
  color: var(--primary);
}
.tag.subject { background: #f1f5f9; color: var(--text-muted); }
.tag.difficulty-easy { background: #dcfce7; color: #166534; }
.tag.difficulty-medium { background: #fef3c7; color: #92400e; }
.tag.difficulty-hard { background: #fee2e2; color: #991b1b; }
.tag.difficulty-mixed { background: #ede9fe; color: #5b21b6; }
.paper-card h3 { margin: 2px 0; font-size: 1.05rem; }
.paper-card p.desc { color: var(--text-muted); font-size: 0.88rem; margin: 0; flex-grow: 1; }
.paper-card .meta-row { font-size: 0.82rem; color: var(--text-muted); display: flex; justify-content: space-between; }
.paper-card .prev-score { font-size: 0.82rem; background: var(--bg); padding: 6px 10px; border-radius: 6px; }
.paper-card .actions { display: flex; gap: 8px; margin-top: 6px; }
.btn { border: none; padding: 9px 16px; border-radius: 7px; font-weight: 600; font-size: 0.88rem; flex: 1; text-align: center; }
.btn-practice { background: var(--practice); color: #fff; }
.btn-practice:hover { background: var(--practice-dark); }
.btn-exam { background: var(--exam); color: #fff; }
.btn-exam:hover { background: var(--exam-dark); }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:disabled { background: #cbd5e1; cursor: not-allowed; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }

/* Practice/Exam layout */
.attempt-layout {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 20px;
  align-items: start;
}
@media (max-width: 900px) {
  .attempt-layout { grid-template-columns: 1fr; }
  .side-panel { order: -1; }
}
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; }

.progress-bar-track { background: var(--border); border-radius: 999px; height: 8px; overflow: hidden; margin: 10px 0 18px; }
.progress-bar-fill { background: var(--primary); height: 100%; transition: width 0.25s ease; }
.progress-bar-fill.exam-fill { background: var(--exam); }

.q-meta { display: flex; justify-content: space-between; align-items: center; font-size: 0.85rem; color: var(--text-muted); margin-bottom: 6px; }
.q-text { font-size: 1.08rem; font-weight: 600; margin: 10px 0 20px; white-space: pre-wrap; }
.options-list { display: flex; flex-direction: column; gap: 10px; }
.option {
  border: 1.5px solid var(--border);
  border-radius: 9px;
  padding: 13px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.98rem;
  transition: border-color .15s, background .15s;
}
.option:not(.locked):hover { border-color: var(--primary); background: #f8faff; cursor: pointer; }
.option .opt-letter {
  width: 26px; height: 26px; border-radius: 50%; background: var(--bg); color: var(--text-muted);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 0.82rem; flex-shrink: 0;
}
.option.selected { border-color: var(--primary); background: #eef2ff; }
.option.selected .opt-letter { background: var(--primary); color: #fff; }
.option.locked.correct-answer { border-color: var(--correct); background: var(--correct-bg); }
.option.locked.correct-answer .opt-letter { background: var(--correct); color: #fff; }
.option.locked.wrong-selected { border-color: var(--incorrect); background: var(--incorrect-bg); }
.option.locked.wrong-selected .opt-letter { background: var(--incorrect); color: #fff; }
.option.locked { cursor: default; }

.feedback-banner { margin-top: 18px; padding: 14px 16px; border-radius: 9px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.feedback-banner.correct { background: var(--correct-bg); color: #166534; }
.feedback-banner.incorrect { background: var(--incorrect-bg); color: #991b1b; }
.explanation-box { margin-top: 14px; padding: 14px 16px; background: #f8fafc; border-left: 4px solid var(--primary); border-radius: 6px; font-size: 0.93rem; }
.explanation-box .source-line { margin-top: 8px; font-size: 0.82rem; color: var(--text-muted); font-style: italic; }

.nav-buttons { display: flex; justify-content: space-between; margin-top: 22px; gap: 10px; }
.nav-buttons .right-group { display: flex; gap: 10px; }

/* Side panel: timer + palette */
.side-panel { display: flex; flex-direction: column; gap: 16px; }
.timer-box { text-align: center; }
.timer-box .label { font-size: 0.8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.timer-box .time { font-size: 2rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.timer-box.warn-15 .time { color: var(--marked); }
.timer-box.warn-5 .time { color: var(--exam); }
.timer-box.warn-1 .time { color: var(--exam); animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.45; } }

.palette-legend { display: flex; flex-wrap: wrap; gap: 8px; font-size: 0.74rem; margin-bottom: 10px; }
.legend-item { display: flex; align-items: center; gap: 4px; color: var(--text-muted); }
.legend-dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.palette-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.palette-cell {
  aspect-ratio: 1;
  border-radius: 6px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  font-size: 0.78rem;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  position: relative;
}
.palette-cell.answered { background: var(--correct-bg); border-color: var(--correct); color: #166534; }
.palette-cell.unanswered { background: var(--surface); border-color: var(--border); color: var(--text-muted); }
.palette-cell.marked { background: var(--marked-bg); border-color: var(--marked); color: #92400e; }
.palette-cell.answered-marked { background: var(--marked-bg); border: 1.5px solid var(--correct); color: #166534; }
.palette-cell.current { outline: 2.5px solid var(--primary); outline-offset: 1px; }
.palette-cell.review-correct { background: var(--correct-bg); border-color: var(--correct); color: #166534; }
.palette-cell.review-incorrect { background: var(--incorrect-bg); border-color: var(--incorrect); color: #991b1b; }

/* Instructions page */
.instructions-list li { margin-bottom: 10px; }
.checkbox-row { display: flex; align-items: center; gap: 10px; margin: 20px 0; padding: 14px; background: var(--bg); border-radius: 8px; }
.checkbox-row input { width: 18px; height: 18px; }
.stat-strip { display: flex; gap: 16px; flex-wrap: wrap; margin: 16px 0; }
.stat-box { background: var(--bg); border-radius: 8px; padding: 14px 18px; min-width: 120px; }
.stat-box .num { font-size: 1.4rem; font-weight: 800; }
.stat-box .lbl { font-size: 0.78rem; color: var(--text-muted); }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,0.55);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.modal-box { background: #fff; border-radius: 12px; padding: 26px; max-width: 440px; width: 100%; box-shadow: var(--shadow-md); }
.modal-box h3 { margin-top: 0; }
.modal-stats { display: flex; gap: 10px; margin: 16px 0; flex-wrap: wrap; }
.modal-stats div { flex: 1; background: var(--bg); border-radius: 8px; padding: 10px; text-align: center; min-width: 90px; }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; }
.modal-actions button { flex: 1; }

/* Results page */
.results-hero { text-align: center; padding: 24px; }
.results-hero .score-num { font-size: 3rem; font-weight: 800; color: var(--primary); }
.results-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin: 20px 0; }
.results-grid .box { background: var(--bg); border-radius: 10px; padding: 16px; text-align: center; }
.results-grid .box .n { font-size: 1.5rem; font-weight: 800; }
.results-grid .box .l { font-size: 0.8rem; color: var(--text-muted); margin-top: 2px; }
table.topic-table { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 0.9rem; }
table.topic-table th, table.topic-table td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); }
table.topic-table th { color: var(--text-muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; }
.callout-row { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 16px; }
.callout { flex: 1; min-width: 220px; padding: 14px; border-radius: 8px; }
.callout.good { background: var(--correct-bg); }
.callout.bad { background: var(--incorrect-bg); }
.callout h4 { margin: 0 0 6px; font-size: 0.88rem; }
.callout ul { margin: 0; padding-left: 18px; font-size: 0.86rem; }

.filter-row { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.filter-chip { padding: 7px 14px; border-radius: 999px; border: 1px solid var(--border); background: #fff; font-size: 0.85rem; font-weight: 600; }
.filter-chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.action-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 20px; }

.history-table-wrap { overflow-x: auto; }
.empty-state { text-align: center; padding: 50px 20px; color: var(--text-muted); }
.empty-state .big-icon { font-size: 2.6rem; margin-bottom: 10px; }

.chart-bars { display: flex; align-items: flex-end; gap: 8px; height: 140px; margin-top: 12px; }
.chart-bars .bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.chart-bars .bar { width: 100%; background: var(--primary); border-radius: 4px 4px 0 0; min-height: 2px; }
.chart-bars .bar-label { font-size: 0.68rem; color: var(--text-muted); margin-top: 4px; }

.mobile-palette-toggle { display: none; }
@media (max-width: 900px) {
  .mobile-palette-toggle { display: block; margin-bottom: 14px; }
}

.settings-row { display: flex; justify-content: space-between; align-items: center; padding: 14px 0; border-bottom: 1px solid var(--border); }
.settings-row:last-child { border-bottom: none; }
.pill-toggle { display: flex; border: 1px solid var(--border); border-radius: 999px; overflow: hidden; }
.pill-toggle button { border: none; padding: 6px 14px; background: #fff; font-size: 0.82rem; font-weight: 600; }
.pill-toggle button.active { background: var(--primary); color: #fff; }

.text-muted { color: var(--text-muted); }
.mt-0 { margin-top: 0; }
