:root {
  --blue: #1A56DB;
  --blue-dark: #1E40AF;
  --blue-light: #EFF6FF;
  --blue-mid: #BFDBFE;
  --green: #10B981;
  --red: #EF4444;
  --purple: #7C3AED;
  --orange: #F59E0B;
  --text: #111827;
  --muted: #6B7280;
  --border: #E5E7EB;
  --bg: #F3F4F6;
  --white: #FFFFFF;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Segoe UI', system-ui, sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; }
button { cursor: pointer; font-family: inherit; }
a { color: var(--blue); text-decoration: none; }

/* ========= HEADER ========= */
#app-header {
  background: var(--blue-dark);
  color: white;
  padding: 0 20px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}
#app-header h1 { font-size: 1.1rem; font-weight: 700; letter-spacing: 0.5px; }
#header-right { display: flex; align-items: center; gap: 10px; }
#header-timer-badge {
  background: rgba(255,255,255,0.15);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 0.85rem;
  font-weight: 600;
  display: none;
}
#header-timer-badge.urgent { background: rgba(239,68,68,0.8); animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { opacity:1; } 50% { opacity:0.7; } }

/* ========= SCREENS ========= */
.screen { display: none; min-height: calc(100vh - 52px); }
.screen.active { display: block; }

/* ========= UPLOAD SCREEN ========= */
#screen-upload { display: none; align-items: center; justify-content: center; padding: 40px 20px; }
#screen-upload.active { display: flex; }
.upload-card {
  background: white;
  border-radius: 16px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.08);
  padding: 48px 40px;
  max-width: 480px;
  width: 100%;
  text-align: center;
}
.upload-card h2 { font-size: 1.5rem; margin-bottom: 8px; }
.upload-card p { color: var(--muted); margin-bottom: 32px; font-size: 0.95rem; line-height: 1.6; }
.drop-zone {
  border: 2px dashed var(--blue-mid);
  border-radius: 12px;
  padding: 40px 20px;
  cursor: pointer;
  transition: all 0.2s;
  background: var(--blue-light);
  margin-bottom: 20px;
}
.drop-zone:hover, .drop-zone.drag-over { border-color: var(--blue); background: #DBEAFE; }
.drop-zone-icon { font-size: 2.5rem; margin-bottom: 12px; }
.drop-zone p { color: var(--blue); font-weight: 600; margin-bottom: 4px; }
.drop-zone small { color: var(--muted); font-size: 0.8rem; }
#file-input { display: none; }
.btn-primary {
  background: var(--blue); color: white; border: none;
  border-radius: 8px; padding: 10px 24px;
  font-size: 0.95rem; font-weight: 600; transition: background 0.2s;
}
.btn-primary:hover { background: var(--blue-dark); }
.btn-secondary {
  background: white; color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 24px;
  font-size: 0.95rem; font-weight: 600; transition: all 0.2s;
}
.btn-secondary:hover { background: var(--bg); }
#upload-progress { display: none; margin-top: 20px; }
.progress-bar-wrap { background: var(--border); border-radius: 99px; height: 8px; overflow: hidden; margin-bottom: 8px; }
.progress-bar-fill { height: 100%; background: var(--blue); border-radius: 99px; transition: width 0.3s; }
#upload-status { font-size: 0.85rem; color: var(--muted); }

/* ========= SELECT SCREEN ========= */
#screen-select { padding: 32px 24px; max-width: 900px; margin: 0 auto; }

#select-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  min-height: 36px;
}
.btn-home-nav {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 16px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.2s;
}
.btn-home-nav:hover { background: var(--bg); color: var(--text); border-color: var(--text); }
.btn-back {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 14px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  display: none;
  align-items: center;
  gap: 4px;
  transition: all 0.2s;
}
.btn-back:hover { background: var(--bg); color: var(--text); border-color: var(--text); }
.breadcrumb { display: flex; align-items: center; gap: 0; font-size: 0.8rem; color: var(--muted); }
.bc-item { display: flex; align-items: center; cursor: pointer; }
.bc-item:hover { color: var(--blue); text-decoration: underline; }
.bc-sep { margin: 0 6px; color: var(--border); font-size: 1rem; }
.bc-label { font-weight: 600; color: var(--blue-dark); }

.select-header { margin-bottom: 28px; }
.select-header h2 { font-size: 1.6rem; font-weight: 700; margin-bottom: 5px; }
.select-subtitle { color: var(--muted); font-size: 0.92rem; }

/* Stream cards — Step 1 */
.stream-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 20px;
  max-width: 620px;
}
.stream-card {
  background: white;
  border: 2px solid var(--border);
  border-radius: 16px;
  padding: 32px 28px;
  cursor: pointer;
  transition: all 0.25s;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: relative;
  overflow: hidden;
}
.stream-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: var(--blue);
  transform: scaleX(0);
  transition: transform 0.25s;
}
.stream-card:hover {
  border-color: var(--blue);
  box-shadow: 0 8px 28px rgba(26,86,219,0.14);
  transform: translateY(-4px);
}
.stream-card:hover::before { transform: scaleX(1); }
.stream-icon { font-size: 2.6rem; margin-bottom: 4px; }
.stream-card h3 { font-size: 1.2rem; font-weight: 700; }
.stream-short { color: var(--muted); font-size: 0.88rem; margin-bottom: 4px; }
.stream-meta { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 6px; }
.stream-meta span {
  font-size: 0.78rem; color: var(--blue-dark);
  background: var(--blue-light); padding: 3px 10px;
  border-radius: 99px; font-weight: 500;
}
.stream-arrow {
  position: absolute; right: 22px; top: 50%;
  transform: translateY(-50%);
  font-size: 1.5rem; color: var(--blue-mid);
  transition: all 0.25s;
}
.stream-card:hover .stream-arrow { color: var(--blue); transform: translateY(-50%) translateX(5px); }

/* Type cards — Step 2 */
.type-cards { display: flex; flex-direction: column; gap: 12px; }
.type-card {
  background: white;
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 18px 22px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.type-card:hover {
  border-color: var(--type-color, var(--blue));
  box-shadow: 0 4px 16px rgba(0,0,0,0.08);
  transform: translateX(4px);
}
.type-card-left { display: flex; align-items: center; gap: 16px; flex: 1; min-width: 0; }
.type-icon { font-size: 2rem; flex-shrink: 0; }
.type-info h3 { font-size: 1rem; font-weight: 700; margin-bottom: 3px; }
.type-info p { font-size: 0.82rem; color: var(--muted); line-height: 1.4; }
.type-card-right { display: flex; align-items: center; gap: 18px; flex-shrink: 0; }
.type-stats { text-align: center; }
.type-count { display: block; font-size: 1.05rem; font-weight: 700; color: var(--blue-dark); }
.type-count-label { display: block; font-size: 0.7rem; color: var(--muted); }
.type-arrow { font-size: 1.6rem; color: var(--border); transition: all 0.2s; }
.type-card:hover .type-arrow { color: var(--type-color, var(--blue)); transform: translateX(4px); }

/* Subject grid — Step 3 (weekly/topic/subject) */
.subject-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}
.subject-chip {
  background: white;
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 18px 16px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.subject-chip:hover {
  border-color: var(--blue);
  box-shadow: 0 4px 14px rgba(26,86,219,0.12);
  transform: translateY(-2px);
}
.subject-chip-name {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
}
.subject-chip-count {
  font-size: 0.76rem;
  color: var(--muted);
}

/* Test grid — Step 4 */
.test-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
}
.test-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 16px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.test-card:hover { box-shadow: 0 4px 16px rgba(26,86,219,0.1); border-color: var(--blue-mid); transform: translateY(-2px); }
.test-card h3 { font-size: 0.95rem; font-weight: 600; line-height: 1.3; }
.test-card-stats { display: flex; gap: 10px; flex-wrap: wrap; }
.stat-chip { display: flex; align-items: center; gap: 4px; font-size: 0.78rem; color: var(--muted); }
.stat-chip span:first-child { font-size: 0.72rem; }
#no-tests-msg { text-align: center; color: var(--muted); padding: 60px; grid-column: 1/-1; }

/* ========= TEST SCREEN ========= */
#screen-test { display: none; }
#screen-test.active { display: flex; flex-direction: column; }
.test-top-bar {
  background: var(--blue-dark); color: white;
  padding: 8px 20px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; font-size: 0.85rem;
}
.test-top-bar-left { display: flex; align-items: center; gap: 12px; }
#test-title { font-weight: 600; font-size: 0.9rem; }
#section-tabs {
  display: flex; gap: 4px;
  background: rgba(255,255,255,0.1);
  border-radius: 8px; padding: 4px;
}
.section-tab {
  background: transparent; border: none;
  color: rgba(255,255,255,0.7);
  padding: 4px 14px; border-radius: 6px;
  font-size: 0.8rem; font-weight: 600; transition: all 0.2s;
}
.section-tab.active { background: white; color: var(--blue-dark); }
#submit-test-btn {
  background: var(--red); color: white; border: none;
  border-radius: 8px; padding: 6px 16px;
  font-size: 0.85rem; font-weight: 600;
}
#submit-test-btn:hover { background: #DC2626; }

.test-layout {
  display: flex; flex: 1; min-height: 0;
  height: calc(100vh - 52px - 46px);
}

/* Question column (panel + action bar) */
.question-col {
  flex: 1; display: flex; flex-direction: column; min-width: 0; overflow: hidden;
}

/* Question panel */
.question-panel {
  flex: 1; overflow-y: auto; padding: 20px;
  display: flex; flex-direction: column; gap: 16px;
}
.question-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.meta-badge { font-size: 0.75rem; font-weight: 600; padding: 3px 10px; border-radius: 99px; }
.meta-badge.mcq { background: #DBEAFE; color: #1E40AF; }
.meta-badge.msq { background: #EDE9FE; color: #5B21B6; }
.meta-badge.nat { background: #FEF3C7; color: #92400E; }
.meta-badge.marks { background: #DCFCE7; color: #166534; }
.meta-badge.subject { background: var(--bg); color: var(--muted); }
.meta-badge.correct { background: #DCFCE7; color: #166534; }
.meta-badge.wrong { background: #FEE2E2; color: #991B1B; }
.meta-badge.partial { background: #FEF3C7; color: #92400E; }
.question-body {
  background: white; border-radius: 12px;
  border: 1px solid var(--border); padding: 20px;
}
.question-number { font-size: 0.8rem; color: var(--muted); font-weight: 600; margin-bottom: 10px; }
.question-text { font-size: 0.95rem; line-height: 1.7; }
.question-text .q-img { max-width: 100%; height: auto; display: block; margin: 8px 0; border-radius: 4px; }
.question-text .code-block {
  background: #1E293B; color: #E2E8F0; border-radius: 8px;
  padding: 14px 16px; overflow-x: auto;
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 0.85rem; line-height: 1.6; margin: 10px 0; white-space: pre;
}
.options-area {
  background: white; border-radius: 12px;
  border: 1px solid var(--border); padding: 16px;
}
.options-area h4 {
  font-size: 0.8rem; color: var(--muted); font-weight: 600;
  margin-bottom: 14px; text-transform: uppercase; letter-spacing: 0.5px;
}
.option-row {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 10px 12px; border-radius: 8px; margin-bottom: 8px;
  border: 2px solid transparent; cursor: pointer;
  transition: all 0.15s; font-size: 0.92rem; line-height: 1.6;
}
.option-row:hover { background: var(--blue-light); border-color: var(--blue-mid); }
.option-row.selected-draft { background: var(--blue-light); border-color: var(--blue); }
.option-row.selected-saved { background: #EFF6FF; border-color: var(--blue-dark); }
.option-key {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--bg); border: 2px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.8rem; flex-shrink: 0; margin-top: 1px;
  transition: all 0.15s;
}
.option-row.selected-draft .option-key { background: var(--blue); border-color: var(--blue); color: white; }
.option-row.selected-saved .option-key { background: var(--blue-dark); border-color: var(--blue-dark); color: white; }
.option-content { flex: 1; }
.option-content .q-img { max-width: 100%; height: auto; max-height: 200px; border-radius: 4px; }
.option-content .code-block {
  background: #1E293B; color: #E2E8F0; border-radius: 6px;
  padding: 10px 12px; overflow-x: auto; font-family: monospace;
  font-size: 0.82rem; line-height: 1.5; margin: 4px 0; white-space: pre;
}

/* Combined image options */
.combined-img-wrap { text-align: center; margin-bottom: 16px; }
.combined-img-wrap img { max-width: 100%; height: auto; border-radius: 6px; }
.selector-btns { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.selector-btn {
  width: 44px; height: 44px; border-radius: 8px;
  border: 2px solid var(--border); background: white;
  font-weight: 700; font-size: 0.9rem; transition: all 0.15s;
}
.selector-btn:hover { border-color: var(--blue); color: var(--blue); }
.selector-btn.selected { background: var(--blue); border-color: var(--blue); color: white; }
.selector-btn.selected-saved { background: var(--blue-dark); border-color: var(--blue-dark); color: white; }

/* NAT keypad */
.nat-keypad { max-width: 280px; }
.nat-display {
  background: #1E293B; color: #E2E8F0;
  border-radius: 8px; padding: 12px 16px;
  font-size: 1.4rem; font-weight: 600; font-family: monospace;
  text-align: right; margin-bottom: 12px; min-height: 52px;
  display: flex; align-items: center; justify-content: flex-end;
  letter-spacing: 1px;
}
.nat-keys { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 10px; }
.nat-keys button, .nat-keys div {
  height: 44px; border-radius: 6px;
  border: 1px solid var(--border); background: white;
  font-size: 1rem; font-weight: 600; color: var(--text); transition: all 0.1s;
}
.nat-keys button:hover { background: var(--bg); }
.nat-keys button:active { background: var(--border); transform: scale(0.96); }
.nat-actions { display: flex; gap: 8px; }
.nat-actions button { flex: 1; padding: 10px; font-size: 0.85rem; font-weight: 600; }

/* Answer display */
.answer-display {
  background: var(--blue-light); border: 1px solid var(--blue-mid);
  border-radius: 8px; padding: 10px 16px;
  font-size: 0.85rem; display: flex; align-items: center; gap: 8px;
}
.answer-display strong { color: var(--blue-dark); }

/* Action bar */
.action-bar {
  background: white; border-top: 1px solid var(--border);
  padding: 12px 20px; display: flex; gap: 8px; flex-wrap: wrap;
}
.action-bar .btn-action {
  border: none; border-radius: 8px; padding: 9px 16px;
  font-size: 0.82rem; font-weight: 600; transition: all 0.15s;
}
.btn-save-next { background: var(--blue); color: white; }
.btn-save-next:hover { background: var(--blue-dark); }
.btn-mark-review { background: var(--purple); color: white; }
.btn-mark-review:hover { background: #6D28D9; }
.btn-clear { background: white; color: var(--red); border: 1px solid var(--red) !important; }
.btn-clear:hover { background: #FEF2F2; }
.btn-next-q { background: var(--bg); color: var(--text); border: 1px solid var(--border) !important; }
.btn-next-q:hover { background: var(--border); }

/* Sidebar */
.sidebar {
  width: 300px; background: white;
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden;
}
.timer-box {
  background: var(--blue-dark); color: white;
  padding: 14px 16px; text-align: center;
}
.timer-label { font-size: 0.7rem; opacity: 0.7; text-transform: uppercase; letter-spacing: 0.5px; }
.timer-value { font-size: 1.8rem; font-weight: 700; font-family: monospace; letter-spacing: 2px; }
.timer-box.urgent { background: var(--red); }
.palette-wrap { flex: 1; overflow-y: auto; padding: 12px; }
.palette-header { font-size: 0.78rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 10px; }
.palette-grid { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.palette-btn {
  width: 34px; height: 34px; border-radius: 6px;
  border: 1px solid var(--border); background: #E5E7EB;
  color: #6B7280; font-size: 0.8rem; font-weight: 600;
  transition: all 0.15s; position: relative;
}
.palette-btn:hover { transform: scale(1.1); }
.palette-btn.visited { border-color: var(--red); color: var(--red); background: #FEF2F2; }
.palette-btn.answered { background: var(--green); border-color: var(--green); color: white; }
.palette-btn.marked { background: var(--purple); border-color: var(--purple); color: white; }
.palette-btn.answered-marked { background: var(--green); border-color: var(--green); color: white; }
.palette-btn.answered-marked::after {
  content: ''; position: absolute; top: 2px; right: 2px;
  width: 6px; height: 6px; border-radius: 50%; background: var(--purple);
}
.palette-btn.current { box-shadow: 0 0 0 2px var(--orange); }
.legend { padding: 0 4px 12px; }
.legend h4 { font-size: 0.72rem; color: var(--muted); font-weight: 600; text-transform: uppercase; margin-bottom: 8px; }
.legend-items { display: flex; flex-direction: column; gap: 5px; }
.legend-item { display: flex; align-items: center; gap: 7px; font-size: 0.75rem; color: var(--muted); }
.legend-dot { width: 16px; height: 16px; border-radius: 3px; flex-shrink: 0; }
.legend-dot.not-visited { background: #E5E7EB; border: 1px solid #D1D5DB; }
.legend-dot.visited { background: #FEF2F2; border: 1px solid var(--red); }
.legend-dot.answered { background: var(--green); }
.legend-dot.marked { background: var(--purple); }
.sidebar-submit { padding: 12px; border-top: 1px solid var(--border); }
.sidebar-submit button {
  width: 100%; background: var(--red); color: white; border: none;
  border-radius: 8px; padding: 10px; font-size: 0.9rem; font-weight: 600;
}
.sidebar-submit button:hover { background: #DC2626; }

/* Mobile test layout */
@media (max-width: 767px) {
  .test-layout { flex-direction: column; height: auto; }
  .sidebar { display: none; }
  .question-panel { padding: 12px; padding-bottom: 140px; }
  .action-bar {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
    display: grid; grid-template-columns: 1fr 1fr; gap: 6px;
    padding: 10px; background: white; box-shadow: 0 -2px 12px rgba(0,0,0,0.1);
  }
  #btn-palette-mobile {
    position: fixed; bottom: 100px; right: 16px; z-index: 60;
    background: var(--blue); color: white; border: none;
    border-radius: 99px; padding: 8px 16px; font-size: 0.8rem; font-weight: 600;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  }
  #header-timer-badge { display: flex !important; }
  .test-top-bar { flex-wrap: wrap; gap: 6px; }
  #section-tabs { flex-wrap: wrap; }
  .section-tab { padding: 3px 10px; font-size: 0.75rem; }
  .stream-cards { grid-template-columns: 1fr; max-width: 100%; }
  .stream-arrow { display: none; }
  .type-card-right { gap: 10px; }
  .type-stats:last-of-type { display: none; }
}
@media (min-width: 768px) {
  #btn-palette-mobile { display: none !important; }
  #header-timer-badge { display: none !important; }
}

/* Mobile palette overlay */
#palette-overlay { display: none; position: fixed; inset: 0; z-index: 200; background: rgba(0,0,0,0.5); }
#palette-overlay.open { display: flex; align-items: flex-end; }
.palette-drawer {
  background: white; width: 100%; max-height: 80vh;
  border-radius: 16px 16px 0 0; padding: 20px; overflow-y: auto;
}
.palette-drawer-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.palette-drawer-header h3 { font-size: 1rem; font-weight: 700; }
#close-palette-btn {
  background: var(--bg); border: none; border-radius: 8px;
  padding: 6px 14px; font-size: 0.85rem; font-weight: 600;
}

/* ========= RESULTS SCREEN ========= */
#screen-results { padding: 24px 20px; max-width: 1100px; margin: 0 auto; }
.results-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 24px; flex-wrap: wrap; gap: 12px;
}
.results-header h2 { font-size: 1.3rem; font-weight: 700; }
.results-actions { display: flex; gap: 8px; }
.scorecard {
  background: linear-gradient(135deg, var(--blue-dark), var(--blue));
  color: white; border-radius: 16px; padding: 32px; text-align: center; margin-bottom: 20px;
}
.score-big { font-size: 3rem; font-weight: 800; font-family: monospace; }
.score-denom { font-size: 1.2rem; opacity: 0.8; }
.score-pct { font-size: 1.1rem; margin-top: 6px; opacity: 0.9; }
.score-sections { margin-top: 12px; font-size: 0.9rem; opacity: 0.9; display: flex; justify-content: center; align-items: center; gap: 12px; flex-wrap: wrap; }
.score-sections strong { font-weight: 700; }
.score-sec-sep { opacity: 0.4; }
.pass-badge {
  display: inline-block; margin-top: 10px; padding: 4px 16px;
  border-radius: 99px; font-size: 0.85rem; font-weight: 700;
  background: rgba(255,255,255,0.2);
}
.stats-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px; margin-bottom: 20px;
}
.stat-card {
  background: white; border-radius: 12px; border: 1px solid var(--border);
  padding: 16px; text-align: center;
}
.stat-card .val { font-size: 1.4rem; font-weight: 700; color: var(--blue-dark); }
.stat-card .lbl { font-size: 0.75rem; color: var(--muted); margin-top: 4px; }
.results-section {
  background: white; border-radius: 12px; border: 1px solid var(--border);
  padding: 20px; margin-bottom: 16px;
}
.results-section h3 { font-size: 1rem; font-weight: 700; margin-bottom: 16px; padding-bottom: 10px; border-bottom: 1px solid var(--border); }
.breakdown-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.breakdown-table th { background: var(--bg); padding: 8px 12px; text-align: left; font-weight: 600; color: var(--muted); border-bottom: 1px solid var(--border); }
.breakdown-table td { padding: 8px 12px; border-bottom: 1px solid var(--border); }
.breakdown-table tr:last-child td { font-weight: 700; border-bottom: none; }
.subject-bar-row { margin-bottom: 12px; }
.subject-bar-label { display: flex; justify-content: space-between; font-size: 0.82rem; margin-bottom: 4px; }
.subject-bar-label span:first-child { font-weight: 500; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.subject-bar-label span:last-child { color: var(--muted); }
.subject-bar-track { background: var(--bg); border-radius: 99px; height: 8px; overflow: hidden; }
.subject-bar-fill { height: 100%; border-radius: 99px; background: var(--green); transition: width 0.5s; }
.time-stats { display: flex; flex-direction: column; gap: 8px; }
.time-stat-row { display: flex; justify-content: space-between; align-items: center; font-size: 0.88rem; padding: 8px 0; border-bottom: 1px solid var(--bg); }
.time-stat-row .tlabel { color: var(--muted); }
.time-stat-row .tval { font-weight: 600; }
.review-table-wrap { overflow-x: auto; }
.review-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
.review-table th { background: var(--bg); padding: 8px 10px; text-align: left; font-weight: 600; color: var(--muted); border-bottom: 1px solid var(--border); white-space: nowrap; }
.review-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); }
.review-table tr:hover td { background: #FAFAFA; }
.result-chip { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 0.75rem; font-weight: 600; }
.result-chip.correct { background: #DCFCE7; color: #166534; }
.result-chip.wrong { background: #FEE2E2; color: #991B1B; }
.result-chip.unattempted { background: var(--bg); color: var(--muted); }
.result-chip.partial { background: #FEF3C7; color: #92400E; }

/* Modals */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 300; align-items: center; justify-content: center; }
.modal-overlay.open { display: flex; }
.modal-box { background: white; border-radius: 16px; padding: 32px; max-width: 440px; width: 90%; box-shadow: 0 8px 32px rgba(0,0,0,0.2); }
.modal-box h3 { font-size: 1.1rem; margin-bottom: 12px; }
.modal-box p { color: var(--muted); font-size: 0.9rem; line-height: 1.6; margin-bottom: 20px; }
.modal-stats { background: var(--bg); border-radius: 8px; padding: 14px; margin-bottom: 20px; }
.modal-stat-row { display: flex; justify-content: space-between; font-size: 0.88rem; padding: 3px 0; }
.modal-stat-row .ms-label { color: var(--muted); }
.modal-stat-row .ms-val { font-weight: 600; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }
.modal-actions button { padding: 9px 20px; border-radius: 8px; font-size: 0.9rem; font-weight: 600; border: none; }
.modal-btn-confirm { background: var(--red); color: white; }
.modal-btn-confirm:hover { background: #DC2626; }
.modal-btn-cancel { background: var(--bg); color: var(--text); }
.modal-btn-cancel:hover { background: var(--border); }

/* Browse / Answer Key Screen */
.browse-nav-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 20px; background: white; border-top: 1px solid var(--border);
  flex-shrink: 0; gap: 10px;
}
.browse-nav-bar .btn-action {
  border: none; border-radius: 8px; padding: 9px 20px;
  font-size: 0.85rem; font-weight: 600; cursor: pointer; transition: all 0.15s;
}
.btn-prev-q { background: var(--bg); color: var(--text); border: 1px solid var(--border) !important; }
.btn-prev-q:hover { background: var(--border); }
.browse-nav-center { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.browse-progress { font-size: 0.9rem; color: var(--muted); font-weight: 600; }
.browse-live-timer { font-size: 0.8rem; color: var(--blue); font-weight: 700; letter-spacing: 0.03em; min-height: 1em; }
.solve-time-taken { display: block; margin-top: 6px; font-size: 0.82rem; font-weight: 600; opacity: 0.75; }
.palette-section-label {
  font-size: 0.75rem; font-weight: 700; text-transform: uppercase;
  color: var(--muted); letter-spacing: 0.04em; margin: 8px 0 4px;
}
.browse-answer-box {
  margin-top: 18px; padding: 12px 16px;
  border-radius: 10px; font-size: 0.95rem;
}
.browse-answer-box.solve-correct {
  background: #f0fdf4; border: 2px solid var(--green); color: #166534;
}
.browse-answer-box.solve-wrong {
  background: #fef2f2; border: 2px solid var(--red); color: #991b1b;
}
.option-row.browse-correct {
  background: #f0fdf4; border-color: var(--green);
}
.option-row.browse-correct .option-key {
  background: var(--green); color: white;
}
.option-row.browse-wrong {
  background: #fef2f2; border-color: var(--red);
}
.option-row.browse-wrong .option-key {
  background: var(--red); color: white;
}
.selector-btn.browse-correct {
  background: var(--green) !important; color: white !important;
  border-color: var(--green) !important;
}
.selector-btn.browse-wrong {
  background: var(--red) !important; color: white !important;
  border-color: var(--red) !important;
}
.solve-check-btn {
  display: block; margin-top: 18px; width: 100%;
  background: var(--blue); color: white; border: none;
  border-radius: 10px; padding: 12px; font-size: 0.95rem;
  font-weight: 700; cursor: pointer; transition: background 0.15s;
}
.solve-check-btn:hover { background: var(--blue-dark); }
#btn-palette-browse {
  display: none; position: fixed; bottom: 80px; right: 16px;
  background: var(--blue); color: white; border: none;
  border-radius: 24px; padding: 10px 18px; font-size: 0.85rem;
  font-weight: 600; box-shadow: 0 2px 8px rgba(0,0,0,.18); cursor: pointer; z-index: 100;
}
#browse-palette-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4);
  z-index: 200; align-items: flex-end;
}
#browse-palette-overlay.open { display: flex; }
#btn-palette-response {
  display: none; position: fixed; bottom: 80px; right: 16px;
  background: var(--blue); color: white; border: none;
  border-radius: 24px; padding: 10px 18px; font-size: 0.85rem;
  font-weight: 600; box-shadow: 0 2px 8px rgba(0,0,0,.18); cursor: pointer; z-index: 100;
}
#response-palette-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4);
  z-index: 200; align-items: flex-end;
}
#response-palette-overlay.open { display: flex; }
@media (max-width: 767px) {
  #btn-palette-browse { display: block; }
  #browse-sidebar { display: none; }
  #btn-palette-response { display: block; }
  #response-sidebar { display: none; }
}

/* Print */
@media print {
  #app-header, #screen-upload, #screen-select, #screen-test, #screen-response, #screen-browse,
  .results-header .results-actions, #btn-back-select { display: none !important; }
  #screen-results { display: block !important; padding: 0; }
  .results-section { page-break-inside: avoid; }
}

/* Misc */
.spinner { width: 40px; height: 40px; border: 4px solid var(--border); border-top-color: var(--blue); border-radius: 50%; animation: spin 0.7s linear infinite; margin: 0 auto; }
@keyframes spin { to { transform: rotate(360deg); } }
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }
.screen { transition: opacity 0.2s; }
.screen:not(.active) { opacity: 0; pointer-events: none; }
.screen.active { opacity: 1; pointer-events: all; }
.empty-msg { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty-msg .empty-icon { font-size: 3rem; margin-bottom: 12px; }
