/* =========================================================
   GATE EC · Answer Key Quiz — Mobile-First Redesign
   Made by Yeshwanth Engadoss
   ========================================================= */

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --bg: #f4f6fb;
  --bg-soft: #eef2f9;
  --card: #ffffff;
  --border: #e5e9f2;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --muted: #64748b;
  --muted-2: #94a3b8;

  --primary: #4f46e5;
  --primary-soft: #eef2ff;
  --primary-dark: #4338ca;

  --success: #10b981;
  --success-soft: #ecfdf5;
  --danger: #ef4444;
  --danger-soft: #fef2f2;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 6px 16px -6px rgba(15, 23, 42, 0.1);
  --shadow-lg: 0 12px 32px -12px rgba(15, 23, 42, 0.2);

  --radius-xs: 8px;
  --radius-sm: 10px;
  --radius: 14px;
  --radius-lg: 20px;

  /* Mobile fixed heights */
  --m-topbar: 56px;
  --m-progress: 3px;
  --m-stats: 44px;
  --m-tabs: 60px;
  --m-action: 62px;
  --m-safe-top: env(safe-area-inset-top, 0px);
  --m-safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body { height: 100%; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* =========================================================
   TOP BAR
   ========================================================= */
.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  gap: 12px;
  box-shadow: var(--shadow-sm);
  z-index: 100;
}

.top-bar-left { display: flex; align-items: center; gap: 10px; }

.brand {
  display: flex; align-items: center; gap: 7px;
  font-weight: 800; font-size: 1.05rem;
  letter-spacing: -0.3px;
}

.brand-icon {
  display: inline-flex;
  align-items: center; justify-content: center;
  width: 26px; height: 26px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  border-radius: 8px;
  font-size: 0.85rem;
  box-shadow: 0 4px 10px -3px rgba(99, 102, 241, 0.5);
}

.brand-tag {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--primary);
  background: var(--primary-soft);
  padding: 3px 9px;
  border-radius: 100px;
}

.top-bar-right { display: flex; align-items: center; gap: 10px; }

.year-picker {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.year-picker select {
  appearance: none;
  -webkit-appearance: none;
  padding: 8px 30px 8px 14px;
  border-radius: 100px;
  border: 1.5px solid var(--border);
  background: #fafbfc;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text);
  cursor: pointer;
  outline: none;
  transition: all 0.15s ease;
}

.year-picker select:focus { border-color: var(--primary); background: #fff; }

.year-caret {
  position: absolute;
  right: 12px;
  pointer-events: none;
  color: var(--muted);
  font-size: 0.7rem;
}

.score-badge {
  display: inline-flex;
  align-items: baseline;
  gap: 3px;
  padding: 7px 14px;
  background: linear-gradient(135deg, var(--primary), #6366f1);
  color: white;
  font-weight: 700;
  border-radius: 100px;
  box-shadow: 0 6px 14px -6px rgba(79, 70, 229, 0.6);
}

.score-num { font-size: 1rem; }
.score-sep { font-size: 0.8rem; opacity: 0.7; }
.score-max { font-size: 0.72rem; opacity: 0.85; }

/* =========================================================
   PROGRESS
   ========================================================= */
.progress-track {
  height: 6px;
  background: var(--border);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #6366f1, #a78bfa);
  border-radius: 0 100px 100px 0;
  transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* =========================================================
   STATS RAIL
   ========================================================= */
.stats-rail {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.stats-rail::-webkit-scrollbar { display: none; }

.stat-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 100px;
  font-size: 0.78rem;
  white-space: nowrap;
  flex-shrink: 0;
}

.stat-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot-attempted { background: #8b5cf6; }
.dot-correct { background: var(--success); }
.dot-wrong { background: var(--danger); }

.stat-lbl { color: var(--muted); font-weight: 600; }
.stat-num { font-weight: 800; color: var(--text); }
.stat-num.stat-correct { color: var(--success); }
.stat-num.stat-wrong { color: var(--danger); }

/* =========================================================
   APP WRAPPER
   ========================================================= */
.app {
  max-width: 1500px;
  margin: 0 auto;
  padding: 20px 16px 100px;
}

.main-layout {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 20px;
  align-items: start;
}

/* =========================================================
   PDF PANEL
   ========================================================= */
.pdf-panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 16px;
  height: calc(100vh - 220px);
  max-height: calc(100vh - 220px);
}

.pdf-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: linear-gradient(180deg, #f8fafc, #f1f5f9);
  border-bottom: 1px solid var(--border);
  gap: 8px;
  flex-shrink: 0;
}

.pdf-file {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.pdf-file-icon { font-size: 1rem; }

.pdf-file-name {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pdf-tool-btn {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--primary);
  text-decoration: none;
  padding: 6px 12px;
  border-radius: 100px;
  background: var(--primary-soft);
  white-space: nowrap;
  transition: background 0.15s ease;
  border: 1px solid transparent;
}

.pdf-tool-btn:hover { background: #e0e7ff; }

.pdf-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  background: #e2e8f0;
  -webkit-overflow-scrolling: touch;
  padding: 10px;
  text-align: center;
  scroll-behavior: smooth;
}

.pdf-scroll canvas {
  display: block;
  margin: 0 auto 10px auto;
  max-width: 100%;
  height: auto;
  background: white;
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.15);
  border-radius: 6px;
}

/* PDF loading */
.pdf-loading {
  padding: 40px 16px;
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 600;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.pdf-loading::before {
  content: "";
  width: 22px; height: 22px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.pdf-error {
  padding: 30px 20px;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
}

.pdf-error a {
  display: inline-block;
  margin-top: 12px;
  padding: 10px 22px;
  background: var(--primary);
  color: white;
  text-decoration: none;
  border-radius: 100px;
  font-weight: 700;
  font-size: 0.82rem;
  box-shadow: 0 6px 14px -6px rgba(79, 70, 229, 0.6);
}

/* =========================================================
   QUIZ PANEL
   ========================================================= */
.quiz-panel { min-width: 0; }

.quiz-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

/* Question card */
.q-card {
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: all 0.18s ease;
}

.q-card:hover { border-color: var(--border-strong); }

.q-card.correct {
  border-color: var(--success);
  background: linear-gradient(180deg, #ffffff, #f0fdf9);
}

.q-card.wrong {
  border-color: var(--danger);
  background: linear-gradient(180deg, #ffffff, #fef5f5);
}

.q-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.q-num {
  font-size: 0.92rem;
  font-weight: 800;
  color: var(--text);
  background: #f1f5f9;
  padding: 5px 12px;
  border-radius: 100px;
  letter-spacing: 0.2px;
}

.q-card.correct .q-num { background: #d1fae5; color: #065f46; }
.q-card.wrong .q-num { background: #fee2e2; color: #991b1b; }

.q-type {
  font-size: 0.62rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  padding: 5px 10px;
  border-radius: 100px;
}

.q-type.mcq { background: #eef2ff; color: #4338ca; }
.q-type.msq { background: #dbeafe; color: #1d4ed8; }
.q-type.nat { background: #dcfce7; color: #15803d; }

/* Options */
.options { display: flex; flex-direction: column; gap: 8px; }

.option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fafbfc;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text);
  transition: all 0.14s ease;
  user-select: none;
  position: relative;
  overflow: hidden;
}

.option::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at var(--x, 50%) var(--y, 50%), rgba(99, 102, 241, 0.08), transparent 60%);
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}

.option:active::before { opacity: 1; }
.option:active { transform: scale(0.985); }

.option:hover { background: #f1f5f9; border-color: var(--border-strong); }

.option.selected {
  border-color: var(--primary);
  background: var(--primary-soft);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.option.correct {
  border-color: var(--success);
  background: var(--success-soft);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);
}

.option.wrong {
  border-color: var(--danger);
  background: var(--danger-soft);
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

.option .letter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #e2e8f0;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  flex-shrink: 0;
  transition: all 0.14s ease;
}

.option.selected .letter { background: var(--primary); color: white; }
.option.correct .letter { background: var(--success); color: white; }
.option.wrong .letter { background: var(--danger); color: white; }

.option .opt-text { flex: 1; }

/* NAT input */
.nat-input-wrap { display: flex; flex-direction: column; gap: 8px; }

.nat-input {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: inherit;
  background: #fafbfc;
  color: var(--text);
  font-weight: 600;
  transition: all 0.15s ease;
  outline: none;
}

.nat-input:focus {
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.nat-input.correct {
  border-color: var(--success);
  background: var(--success-soft);
  color: #065f46;
}

.nat-input.wrong {
  border-color: var(--danger);
  background: var(--danger-soft);
  color: #991b1b;
}

.nat-hint {
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 600;
  padding-left: 2px;
}

/* =========================================================
   CREDIT
   ========================================================= */
.page-credit {
  margin-top: 28px;
  padding: 18px 16px 4px;
  text-align: center;
  font-size: 0.78rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
}

.page-credit strong { color: var(--primary); font-weight: 800; }

.credit-pop {
  position: fixed;
  bottom: 84px;
  right: 16px;
  z-index: 90;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 280px;
  padding: 8px 8px 8px 14px;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 100px;
  box-shadow: var(--shadow-lg);
  font-size: 0.68rem;
  color: var(--muted);
  animation: slideUp 0.5s ease;
}

.credit-pop strong { color: var(--primary); font-weight: 800; }

.credit-x {
  width: 22px; height: 22px;
  border: none;
  border-radius: 50%;
  background: #f1f5f9;
  color: var(--muted);
  font-size: 0.9rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.credit-x:hover { background: var(--danger-soft); color: var(--danger); }
.credit-pop.hidden { display: none; }

@keyframes slideUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* =========================================================
   ACTION BAR (bottom on desktop)
   ========================================================= */
.action-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 80;
  display: flex;
  justify-content: center;
  gap: 10px;
  padding: 12px 20px;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
}

.btn-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  padding: 12px 26px;
  border-radius: 100px;
  border: 1.5px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  letter-spacing: 0.2px;
}

.btn-icon { font-size: 0.9rem; }

.btn-primary {
  background: linear-gradient(135deg, var(--primary), #6366f1);
  color: white;
  box-shadow: 0 8px 20px -8px rgba(79, 70, 229, 0.7);
}

.btn-primary:active { transform: scale(0.97); }
.btn-primary:hover { background: linear-gradient(135deg, var(--primary-dark), #4f46e5); }

.btn-ghost {
  background: #fff;
  color: var(--muted);
  border-color: var(--border);
}

.btn-ghost:hover { background: #f8fafc; color: var(--text); }

/* =========================================================
   MOBILE TABS (hidden on desktop)
   ========================================================= */
.mobile-tabs { display: none; }

/* =========================================================
   RESPONSIVE — TABLET
   ========================================================= */
@media (max-width: 1100px) {
  .main-layout { grid-template-columns: 1fr 1fr; gap: 14px; }
  .pdf-panel { height: calc(100vh - 240px); max-height: calc(100vh - 240px); }
}

/* =========================================================
   RESPONSIVE — MOBILE
   ========================================================= */
@media (max-width: 900px) {
  html, body { overflow: hidden; height: 100%; }

  /* Top bar — fixed */
  .top-bar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: calc(var(--m-topbar) + var(--m-safe-top));
    padding: calc(var(--m-safe-top) + 8px) 14px 8px;
    z-index: 100;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
  }

  .brand { font-size: 0.98rem; gap: 6px; }
  .brand-icon { width: 24px; height: 24px; font-size: 0.78rem; border-radius: 7px; }
  .brand-tag { font-size: 0.6rem; padding: 2px 7px; }

  .year-picker select { padding: 6px 26px 6px 11px; font-size: 0.8rem; border-radius: 10px; }
  .year-caret { right: 10px; font-size: 0.62rem; }

  .score-badge { padding: 5px 11px; gap: 2px; }
  .score-num { font-size: 0.9rem; }
  .score-max { font-size: 0.65rem; }

  /* Progress — fixed under top bar */
  .progress-track {
    position: fixed;
    top: calc(var(--m-topbar) + var(--m-safe-top));
    left: 0; right: 0;
    height: var(--m-progress);
    z-index: 100;
  }

  /* Stats rail — fixed under progress */
  .stats-rail {
    position: fixed;
    top: calc(var(--m-topbar) + var(--m-progress) + var(--m-safe-top));
    left: 0; right: 0;
    height: var(--m-stats);
    z-index: 100;
    padding: 6px 12px;
    gap: 6px;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--border);
  }

  .stat-pill { padding: 4px 10px; font-size: 0.72rem; gap: 5px; }
  .stat-dot { width: 7px; height: 7px; }
  .stat-lbl { font-size: 0.68rem; }
  .stat-num { font-size: 0.78rem; }

  /* App wrapper */
  .app {
    max-width: 100%;
    height: 100vh;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    padding-top: calc(var(--m-topbar) + var(--m-progress) + var(--m-stats) + var(--m-safe-top));
    padding-bottom: calc(var(--m-tabs) + var(--m-action) + var(--m-safe-bottom));
  }

  /* Main layout — single column, tabbed */
  .main-layout {
    display: block;
    flex: 1;
    min-height: 0;
    position: relative;
    padding: 0;
    gap: 0;
  }

  /* Both panels toggle visibility */
  .pdf-panel,
  .quiz-panel {
    display: none;
    height: 100%;
    max-height: none;
    border-radius: 0;
    border: none;
    box-shadow: none;
    position: static;
    top: auto;
    width: 100%;
  }

  .pdf-panel.active,
  .quiz-panel.active { display: flex; flex-direction: column; }

  /* PDF panel */
  .pdf-toolbar {
    padding: 8px 12px;
    background: linear-gradient(180deg, #f8fafc, #eef2ff);
    border-bottom: 1px solid var(--border);
  }

  .pdf-file-icon { font-size: 0.9rem; }
  .pdf-file-name { font-size: 0.78rem; }
  .pdf-tool-btn { font-size: 0.68rem; padding: 5px 10px; }

  .pdf-scroll { padding: 6px; }
  .pdf-scroll canvas { margin-bottom: 8px; border-radius: 4px; }

  /* Quiz panel */
  .quiz-panel { padding: 10px; overflow-y: auto; -webkit-overflow-scrolling: touch; }

  .quiz-grid { gap: 10px; }

  .q-card {
    padding: 14px;
    gap: 10px;
    border-radius: 12px;
  }

  .q-num { font-size: 0.85rem; padding: 4px 10px; }
  .q-type { font-size: 0.58rem; padding: 4px 8px; }

  .option {
    padding: 11px 12px;
    font-size: 0.85rem;
    gap: 10px;
    border-radius: 9px;
  }

  .option .letter { width: 22px; height: 22px; font-size: 0.68rem; }

  .nat-input { padding: 11px 12px; font-size: 0.88rem; border-radius: 9px; }
  .nat-hint { font-size: 0.68rem; }

  .page-credit { font-size: 0.68rem; padding: 14px 8px 4px; margin-top: 16px; }

  /* Bottom tab bar */
  .mobile-tabs {
    display: flex;
    position: fixed;
    left: 0; right: 0;
    bottom: calc(var(--m-action) + var(--m-safe-bottom));
    height: var(--m-tabs);
    z-index: 95;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid var(--border);
    padding: 0 8px;
    gap: 6px;
  }

  .tab-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--muted);
    padding: 6px;
    border-radius: 10px;
    transition: all 0.15s ease;
    position: relative;
  }

  .tab-btn.active {
    color: var(--primary);
    background: var(--primary-soft);
  }

  .tab-btn.active::before {
    content: "";
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 22px;
    height: 3px;
    background: var(--primary);
    border-radius: 0 0 4px 4px;
  }

  .tab-icon { font-size: 1.05rem; line-height: 1; }
  .tab-lbl { font-size: 0.66rem; letter-spacing: 0.2px; }

  /* Action bar */
  .action-bar {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: calc(var(--m-action) + var(--m-safe-bottom));
    padding: 8px 12px calc(var(--m-safe-bottom) + 8px);
    z-index: 100;
    gap: 8px;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
  }

  .btn-action {
    flex: 1;
    padding: 11px 14px;
    font-size: 0.82rem;
    border-radius: 100px;
    max-width: none;
  }

  .btn-icon { font-size: 0.85rem; }

  /* Credit pop — above tabs */
  .credit-pop {
    bottom: calc(var(--m-tabs) + var(--m-action) + var(--m-safe-bottom) + 8px);
    left: 10px;
    right: 10px;
    max-width: none;
    font-size: 0.65rem;
    padding: 6px 8px 6px 12px;
    z-index: 105;
  }
}

/* Tiny phones */
@media (max-width: 420px) {
  :root {
    --m-topbar: 50px;
    --m-stats: 40px;
    --m-tabs: 56px;
    --m-action: 58px;
  }

  .brand { font-size: 0.9rem; }
  .brand-tag { display: none; }
  .year-picker select { padding: 5px 22px 5px 9px; font-size: 0.75rem; }
  .score-badge { padding: 4px 9px; }
  .score-num { font-size: 0.82rem; }

  .q-card { padding: 12px; }
  .option { padding: 10px 11px; font-size: 0.82rem; }
  .btn-action { padding: 10px 12px; font-size: 0.78rem; }
}