:root {
  --primary: #2b57d9;
  --primary-dark: #1c3f9e;
  --accent: #ff7a00;
  --success: #1aa053;
  --success-bg: #e6f7ee;
  --danger: #e0333f;
  --danger-bg: #fdeaec;
  --muted: #6b7280;
  --bg: #f4f6fb;
  --card-bg: #ffffff;
  --text: #1f2937;
  --border: #e5e9f2;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { text-decoration: none; color: inherit; }

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 16px;
}

/* Top nav */
.navbar {
  background: var(--primary);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 2px 6px rgba(0,0,0,0.12);
}
.navbar .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
}
.navbar .brand {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.3px;
}
.navbar .brand span { color: var(--accent); }
.navbar .nav-links {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 14px;
}
.navbar .nav-links a {
  opacity: 0.92;
  padding: 6px 10px;
  border-radius: 6px;
  white-space: nowrap;
}
.navbar .nav-links a:hover { background: rgba(255,255,255,0.12); }
.navbar .user-pill {
  background: rgba(255,255,255,0.15);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 13px;
  white-space: nowrap;
}

/* Hamburger toggle (hidden on desktop) */
.nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 34px;
  height: 34px;
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 0;
}
.nav-toggle span {
  display: block;
  width: 22px;
  height: 2.5px;
  background: #fff;
  border-radius: 2px;
  transition: transform 0.2s ease, opacity 0.2s ease;
}
.nav-toggle.open span:nth-child(1) { transform: translateY(7.5px) rotate(45deg); }
.nav-toggle.open span:nth-child(2) { opacity: 0; }
.nav-toggle.open span:nth-child(3) { transform: translateY(-7.5px) rotate(-45deg); }

@media (max-width: 640px) {
  .nav-toggle { display: flex; }

  .navbar .nav-links {
    position: absolute;
    top: 56px;
    left: 0;
    right: 0;
    background: var(--primary-dark);
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.25s ease;
  }
  .navbar .nav-links.open {
    max-height: 260px;
    box-shadow: 0 8px 12px rgba(0,0,0,0.15);
  }
  .navbar .nav-links a,
  .navbar .nav-links .user-pill {
    width: 100%;
    padding: 14px 16px;
    border-radius: 0;
    border-bottom: 1px solid rgba(255,255,255,0.12);
    text-align: left;
    background: transparent;
  }
  .navbar .nav-links .user-pill {
    border-radius: 0;
    font-weight: 600;
  }
}

.page { padding: 24px 0 60px; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 8px;
  padding: 11px 20px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.05s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-outline { background: transparent; color: var(--primary); border: 1.5px solid var(--primary); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-muted { background: #eef0f5; color: var(--text); }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Cards */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

/* Auth */
.auth-wrap {
  min-height: calc(100vh - 56px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.auth-card {
  width: 100%;
  max-width: 380px;
  padding: 32px 28px;
  text-align: center;
}
.auth-card h1 {
  font-size: 22px;
  margin-bottom: 4px;
}
.auth-card p.sub { color: var(--muted); font-size: 14px; margin-bottom: 24px; }
.field { text-align: left; margin-bottom: 16px; }
.field label { font-size: 13px; font-weight: 600; display: block; margin-bottom: 6px; }
.field input {
  width: 100%;
  padding: 11px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
}
.field input:focus { outline: none; border-color: var(--primary); }
.error-box {
  background: var(--danger-bg);
  color: var(--danger);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 16px;
}

/* Dashboard */
.page-title { font-size: 22px; margin: 4px 0 20px; }
.quiz-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}
@media (min-width: 640px) {
  .quiz-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 992px) {
  .quiz-grid { grid-template-columns: repeat(3, 1fr); }
}
.quiz-card { padding: 18px; display: flex; flex-direction: column; gap: 10px; }
.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 3px 9px;
  border-radius: 20px;
  background: #eaf0ff;
  color: var(--primary);
  width: fit-content;
}
.badge.status-progress { background: #fff3e0; color: var(--accent); }
.badge.status-paused { background: #fdeaec; color: var(--danger); }
.badge.status-done { background: var(--success-bg); color: var(--success); }
.quiz-card h3 { margin: 0; font-size: 17px; }
.quiz-meta { display: flex; gap: 14px; font-size: 12.5px; color: var(--muted); flex-wrap: wrap; }
.quiz-meta span { display: flex; align-items: center; gap: 4px; }
.quiz-card .score-line { font-size: 13px; color: var(--text); }
.empty-state { text-align: center; padding: 60px 20px; color: var(--muted); }

/* Quiz intro */
.intro-card { max-width: 620px; margin: 0 auto; padding: 28px; }
.intro-card h2 { margin-top: 0; }
.intro-list { list-style: none; padding: 0; margin: 18px 0; }
.intro-list li {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px dashed var(--border);
  font-size: 14px;
}
.intro-list li:last-child { border-bottom: none; }
.intro-list .label { color: var(--muted); }
.intro-actions { margin-top: 20px; display: flex; gap: 10px; flex-wrap: wrap; }

/* Attempt page */
.attempt-wrap { padding-bottom: 90px; }
.attempt-topbar {
  position: sticky;
  top: 56px;
  z-index: 40;
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.attempt-topbar .quiz-title { font-weight: 700; font-size: 14.5px; }
.timer {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 16px;
  background: #eaf0ff;
  color: var(--primary);
  padding: 6px 14px;
  border-radius: 20px;
}
.timer.timer-warning { background: var(--danger-bg); color: var(--danger); animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.55; } }

.attempt-body {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  margin-top: 16px;
}
@media (min-width: 900px) {
  .attempt-body { grid-template-columns: 2.3fr 1fr; align-items: start; }
}

.question-card { padding: 20px; }
.question-number-tag { font-size: 12.5px; color: var(--muted); font-weight: 600; margin-bottom: 8px; }
.question-text { font-size: 16px; line-height: 1.5; margin-bottom: 20px; }
.options { display: flex; flex-direction: column; gap: 10px; }
.option {
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  cursor: pointer;
  font-size: 14.5px;
  transition: border-color .12s, background .12s;
}
.option:hover { border-color: var(--primary); }
.option.selected { border-color: var(--primary); background: #eaf0ff; }
.option .opt-letter {
  width: 26px; height: 26px; flex: 0 0 26px;
  border-radius: 50%;
  background: #eef0f5;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 12.5px; color: var(--text);
}
.option.selected .opt-letter { background: var(--primary); color: #fff; }

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

/* Palette */
.palette-card { padding: 16px; }
.palette-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.palette-header h4 { margin: 0; font-size: 14px; }
.legend { display: flex; gap: 10px; font-size: 11px; color: var(--muted); flex-wrap: wrap; margin-bottom: 12px; }
.legend .dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: 4px; }
.palette-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}
@media (min-width: 900px) {
  .palette-grid { grid-template-columns: repeat(5, 1fr); }
}
.palette-cell {
  aspect-ratio: 1;
  border-radius: 6px;
  border: none;
  background: #eef0f5;
  color: var(--text);
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
}
.palette-cell.answered { background: var(--success); color: #fff; }
.palette-cell.current { outline: 2.5px solid var(--primary); outline-offset: 1px; }
.palette-submit { margin-top: 14px; }

/* Mobile palette drawer */
.palette-toggle {
  display: none;
  position: fixed;
  right: 16px;
  bottom: 84px;
  z-index: 45;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 50px;
  padding: 12px 16px;
  font-size: 13px;
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
}
@media (max-width: 899px) {
  .palette-toggle { display: inline-flex; align-items: center; gap: 6px; }
  .palette-card { display: none; position: fixed; left: 0; right: 0; bottom: 0; z-index: 60; border-radius: 16px 16px 0 0; max-height: 70vh; overflow-y: auto; }
  .palette-card.open { display: block; }
  .palette-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 55; }
  .palette-overlay.open { display: block; }
}

/* Bottom nav on attempt page */
.attempt-bottombar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: #fff;
  border-top: 1px solid var(--border);
  padding: 10px 16px;
  display: flex;
  gap: 10px;
  z-index: 40;
}
.attempt-bottombar .btn { flex: 1; }

/* Pause overlay */
.pause-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.92);
  color: #fff;
  z-index: 100;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px;
}
.pause-overlay.open { display: flex; }
.pause-overlay .pause-box h2 { font-size: 24px; margin-bottom: 8px; }
.pause-overlay .pause-box p { color: #cbd5e1; margin-bottom: 24px; }

/* Result page */
.result-summary { padding: 24px; text-align: center; }
.score-big { font-size: 42px; font-weight: 800; color: var(--primary); }
.score-big span { font-size: 18px; color: var(--muted); font-weight: 500; }
.stat-row { display: flex; justify-content: center; gap: 22px; margin-top: 18px; flex-wrap: wrap; }
.stat { text-align: center; }
.stat .num { font-size: 20px; font-weight: 700; }
.stat .lbl { font-size: 12px; color: var(--muted); }
.stat.correct .num { color: var(--success); }
.stat.wrong .num { color: var(--danger); }

.review-item { padding: 16px 18px; margin-top: 12px; }
.review-item .q-head { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--muted); margin-bottom: 8px; }
.review-opt {
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.review-opt.correct-answer { border-color: var(--success); background: var(--success-bg); }
.review-opt.wrong-answer { border-color: var(--danger); background: var(--danger-bg); }
.tag-pill { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 12px; }
.tag-pill.correct { background: var(--success); color: #fff; }
.tag-pill.wrong { background: var(--danger); color: #fff; }
.tag-pill.unattempted { background: #d1d5db; color: #374151; }

/* History */
.history-item {
  padding: 16px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  flex-wrap: wrap;
  gap: 10px;
}
.history-item .left h4 { margin: 0 0 4px; font-size: 15px; }
.history-item .left .meta { font-size: 12.5px; color: var(--muted); }
.history-item .right { text-align: right; }
.history-item .right .score { font-weight: 700; font-size: 16px; }

/* Error page */
.error-wrap { text-align: center; padding: 80px 20px; }
.error-wrap h1 { font-size: 60px; margin: 0; color: var(--primary); }

/* PWA install banner */
.pwa-banner {
  display: none;
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: 12px;
  z-index: 80;
  background: #16213e;
  color: #fff;
  border-radius: 10px;
  padding: 12px 14px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: 0 8px 20px rgba(0,0,0,0.25);
  font-size: 13.5px;
}
.pwa-banner.show { display: flex; }
.pwa-banner-actions { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }
.pwa-banner .btn { padding: 8px 14px; font-size: 13px; white-space: nowrap; }
.pwa-banner-close {
  background: transparent;
  border: none;
  color: #fff;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 4px;
  opacity: 0.75;
}
.pwa-banner-close:hover { opacity: 1; }
@media (max-width: 480px) {
  .pwa-banner { flex-direction: column; align-items: stretch; text-align: center; }
  .pwa-banner-actions { justify-content: center; }
}
