/* ── Reset & Variables ─────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --sidebar-w: 260px;
  --sidebar-bg: #0f172a;
  --sidebar-border: rgba(255,255,255,0.08);
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: rgba(99,102,241,0.12);
  --correct: #22c55e;
  --correct-bg: rgba(34,197,94,0.1);
  --correct-border: rgba(34,197,94,0.35);
  --wrong: #ef4444;
  --wrong-bg: rgba(239,68,68,0.1);
  --wrong-border: rgba(239,68,68,0.35);
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --text-2: #475569;
  --text-3: #94a3b8;
  --border: #e2e8f0;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,0.07), 0 1px 2px rgba(0,0,0,0.05);
}

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

/* ── Layout ────────────────────────────────────────── */
.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ───────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 30;
}

.sidebar-header {
  padding: 18px 16px 14px;
  border-bottom: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.2px;
  color: #f8fafc;
}

.btn-new-paper {
  margin: 14px 12px 6px;
  padding: 10px 14px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.84rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 7px;
  transition: background 0.18s;
  flex-shrink: 0;
}
.btn-new-paper:hover { background: var(--primary-dark); }

.paper-list-label {
  padding: 14px 16px 6px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #64748b;
  flex-shrink: 0;
}

.paper-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px 12px;
}

.paper-list::-webkit-scrollbar { width: 4px; }
.paper-list::-webkit-scrollbar-track { background: transparent; }
.paper-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 4px; }

.paper-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 7px;
  cursor: pointer;
  margin-bottom: 2px;
  transition: background 0.15s;
  font-size: 0.855rem;
  color: #cbd5e1;
}
.paper-item:hover { background: rgba(255,255,255,0.07); }
.paper-item.active { background: var(--primary); color: #fff; }

.paper-item-icon {
  flex-shrink: 0;
  opacity: 0.6;
}
.paper-item.active .paper-item-icon { opacity: 1; }

.paper-item-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.paper-item-count {
  font-size: 0.72rem;
  font-weight: 600;
  background: rgba(255,255,255,0.12);
  padding: 1px 6px;
  border-radius: 10px;
  flex-shrink: 0;
  white-space: nowrap;
}
.paper-item.active .paper-item-count { background: rgba(255,255,255,0.22); }

.paper-item-del {
  background: none;
  border: none;
  color: rgba(255,255,255,0.3);
  cursor: pointer;
  padding: 2px 5px;
  border-radius: 4px;
  font-size: 0.78rem;
  flex-shrink: 0;
  line-height: 1;
  display: none;
}
.paper-item:hover .paper-item-del { display: block; }
.paper-item-del:hover { color: var(--wrong); background: rgba(239,68,68,0.15); }

.paper-list-empty {
  text-align: center;
  padding: 28px 16px;
  color: #475569;
  font-size: 0.82rem;
  line-height: 1.8;
}

/* Sidebar toggle (mobile) */
.sidebar-toggle {
  display: none;
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 50;
  background: var(--sidebar-bg);
  color: #e2e8f0;
  border: none;
  border-radius: 8px;
  width: 40px;
  height: 40px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 20;
}

/* ── Main ──────────────────────────────────────────── */
.main {
  flex: 1;
  overflow-y: auto;
  min-width: 0;
}

.view {
  padding: 36px 32px;
  max-width: 820px;
  margin: 0 auto;
}

.hidden { display: none !important; }

/* ── Landing ───────────────────────────────────────── */
.landing { margin-bottom: 28px; }
.landing-title { font-size: 1.85rem; font-weight: 800; margin-bottom: 8px; letter-spacing: -0.4px; }
.landing-sub { color: var(--text-2); font-size: 0.95rem; line-height: 1.65; max-width: 560px; }

/* ── Upload Card ───────────────────────────────────── */
.upload-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  overflow: hidden;
  margin-bottom: 28px;
}

.upload-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  padding: 0 4px;
  background: #f8fafc;
}

.utab {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 13px 16px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-3);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.15s;
}
.utab:hover { color: var(--text-2); }
.utab.active { color: var(--primary); border-bottom-color: var(--primary); }

.upanel { padding: 24px; }

/* Drop zone */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 44px 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}
.drop-zone:hover, .drop-zone.dragover {
  border-color: var(--primary);
  background: var(--primary-light);
}
.drop-icon { color: var(--text-3); margin-bottom: 14px; }
.drop-text { font-size: 0.94rem; color: var(--text-2); margin-bottom: 4px; }
.drop-or { font-size: 0.82rem; color: var(--text-3); margin-bottom: 12px; }

.btn-browse {
  display: inline-block;
  padding: 9px 22px;
  background: var(--primary);
  color: white;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 600;
  transition: background 0.18s;
}
.btn-browse:hover { background: var(--primary-dark); }

textarea#jsonPaste {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.82rem;
  line-height: 1.6;
  resize: vertical;
  outline: none;
  color: var(--text);
  background: #fafafa;
  transition: border-color 0.2s;
  margin-bottom: 14px;
}
textarea#jsonPaste:focus { border-color: var(--primary); background: #fff; }

.paste-footer { display: flex; }

.btn-primary {
  padding: 10px 22px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  transition: background 0.18s;
}
.btn-primary:hover { background: var(--primary-dark); }

/* ── Example Card ──────────────────────────────────── */
.example-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  overflow: hidden;
}

.example-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: #f8fafc;
}
.example-header h3 { font-size: 0.9rem; font-weight: 700; color: var(--text-2); }

.btn-copy {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  background: white;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-2);
  transition: all 0.18s;
}
.btn-copy:hover { border-color: var(--primary); color: var(--primary); }
.btn-copy.copied { border-color: var(--correct); color: var(--correct); }

.code-pre {
  background: var(--sidebar-bg);
  color: #94a3b8;
  padding: 20px 22px;
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.8rem;
  line-height: 1.7;
  overflow-x: auto;
  white-space: pre;
}
.code-pre .key { color: #7dd3fc; }
.code-pre .str { color: #86efac; }
.code-pre .num { color: #fda4af; }
.code-pre .bool { color: #fcd34d; }
.code-pre .punc { color: #64748b; }

/* ── Exam Header ───────────────────────────────────── */
.exam-header {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 18px 22px;
  margin-bottom: 20px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.exam-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  gap: 12px;
}
#examTitle {
  font-size: 1.15rem;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-reset {
  padding: 6px 13px;
  border: 1px solid var(--border);
  background: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-3);
  white-space: nowrap;
  transition: all 0.18s;
  flex-shrink: 0;
}
.btn-reset:hover { border-color: var(--wrong); color: var(--wrong); }

.score-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.score-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 0.83rem;
  font-weight: 700;
  border: 1px solid transparent;
}
.chip-icon { font-size: 0.85rem; }
.chip-label { font-weight: 500; color: inherit; opacity: 0.75; font-size: 0.78rem; }
.chip-sep { opacity: 0.4; margin: 0 1px; }

.chip-correct { background: var(--correct-bg); border-color: var(--correct-border); color: #16a34a; }
.chip-wrong   { background: var(--wrong-bg);   border-color: var(--wrong-border);   color: #dc2626; }
.chip-neutral { background: #f1f5f9; border-color: var(--border); color: var(--text-2); }

/* ── Question Cards ────────────────────────────────── */
.question-card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 22px 24px;
  margin-bottom: 14px;
  transition: border-color 0.2s;
}
.question-card.answered-correct { border-color: var(--correct-border); }
.question-card.answered-wrong   { border-color: var(--wrong-border); }

.q-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.q-num {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.q-badge {
  font-size: 0.67rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.badge-mcq         { background: var(--primary-light); color: var(--primary); }
.badge-descriptive { background: rgba(245,158,11,0.12); color: #b45309; }

.q-text {
  font-size: 0.97rem;
  font-weight: 500;
  line-height: 1.65;
  margin-bottom: 18px;
  color: var(--text);
}

/* ── MCQ Options ───────────────────────────────────── */
.options-list { display: flex; flex-direction: column; gap: 9px; }

.option-btn {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 11px 15px;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: #fafafa;
  cursor: pointer;
  text-align: left;
  font-size: 0.9rem;
  color: var(--text);
  transition: border-color 0.18s, background 0.18s;
  line-height: 1.4;
}
.option-btn:hover:not(:disabled) {
  border-color: var(--primary);
  background: var(--primary-light);
}
.option-btn:disabled { cursor: default; }

.opt-label {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--border);
  color: var(--text-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.78rem;
  flex-shrink: 0;
  transition: background 0.18s, color 0.18s;
}

.option-btn.opt-correct {
  border-color: var(--correct);
  background: var(--correct-bg);
  color: #14532d;
}
.option-btn.opt-correct .opt-label {
  background: var(--correct);
  color: white;
}

.option-btn.opt-wrong {
  border-color: var(--wrong);
  background: var(--wrong-bg);
  color: #7f1d1d;
}
.option-btn.opt-wrong .opt-label {
  background: var(--wrong);
  color: white;
}

/* ── Descriptive ───────────────────────────────────── */
.btn-show-answer {
  padding: 9px 18px;
  border: 2px solid var(--primary);
  background: none;
  color: var(--primary);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 600;
  transition: background 0.18s, color 0.18s;
}
.btn-show-answer:hover { background: var(--primary); color: white; }

.answer-box {
  margin-top: 16px;
  padding: 14px 16px;
  background: var(--correct-bg);
  border: 1px solid var(--correct-border);
  border-radius: 8px;
  font-size: 0.9rem;
  line-height: 1.7;
  color: #14532d;
  white-space: pre-wrap;
  word-break: break-word;
}
.answer-box-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--correct);
  margin-bottom: 7px;
}

/* ── Toast ─────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 22px;
  right: 22px;
  padding: 11px 18px;
  background: #1e293b;
  color: #f8fafc;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: 0 4px 14px rgba(0,0,0,0.22);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
  z-index: 100;
  max-width: 340px;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.toast-error { background: var(--wrong); }

/* ── Responsive / Mobile ───────────────────────────── */
@media (max-width: 680px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    transform: translateX(-100%);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.open { display: block; }
  .sidebar-toggle { display: flex; }
  .main { width: 100%; }
  .view { padding: 20px 16px 20px 16px; }
  .exam-header { top: 0; }
  .landing-title { font-size: 1.4rem; }
}

@media (max-width: 400px) {
  .score-bar { gap: 7px; }
  .score-chip { padding: 5px 9px; font-size: 0.78rem; }
}
