:root {
  --amcq-primary: #0d6efd;
  --amcq-primary-dark: #0a58ca;
  --amcq-accent: #ffc107;
  --amcq-accent-dark: #e0a800;
  --amcq-success: #198754;
  --amcq-success-bg: #d1e7dd;
  --amcq-success-border: #a3cfbb;
  --amcq-danger: #dc3545;
  --amcq-danger-bg: #f8d7da;
  --amcq-danger-border: #f1aeb5;
  --amcq-bg: #f0f4f8;
  --amcq-card-shadow: 0 2px 12px rgba(13, 110, 253, 0.08);
  --amcq-card-shadow-hover: 0 8px 24px rgba(13, 110, 253, 0.15);
  --amcq-radius: 1rem;
  --amcq-radius-sm: 0.6rem;
}

* { -webkit-tap-highlight-color: transparent; }

body {
  background: linear-gradient(180deg, #f0f4f8 0%, #e9eef5 100%);
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: #1a2233;
}

/* ---------- Navbar ---------- */
.navbar {
  backdrop-filter: blur(10px);
  background: linear-gradient(135deg, #0d6efd 0%, #0a58ca 100%) !important;
}
.navbar-brand { letter-spacing: .3px; font-size: 1.15rem; }
.navbar .nav-link {
  border-radius: var(--amcq-radius-sm);
  padding: .5rem .85rem !important;
  transition: background .2s;
}
.navbar .nav-link:hover { background: rgba(255,255,255,.12); }
.navbar .dropdown-menu {
  border: none;
  border-radius: var(--amcq-radius-sm);
  box-shadow: 0 8px 30px rgba(0,0,0,.15);
  padding: .5rem;
}
.navbar .dropdown-item {
  border-radius: .4rem;
  padding: .55rem .85rem;
  transition: background .15s;
}
.navbar .dropdown-item:hover { background: #f0f4f8; }

/* ---------- Cards ---------- */
.card {
  border-radius: var(--amcq-radius) !important;
  border: none;
  box-shadow: var(--amcq-card-shadow);
  transition: box-shadow .25s ease, transform .25s ease;
}
.card:hover { box-shadow: var(--amcq-card-shadow-hover); }
.topic-card:hover { transform: translateY(-3px); }
.card-header {
  border-radius: var(--amcq-radius) var(--amcq-radius) 0 0 !important;
  border-bottom: none;
  font-weight: 600;
}

/* ---------- Buttons ---------- */
.btn {
  border-radius: var(--amcq-radius-sm);
  font-weight: 500;
  transition: all .2s ease;
  position: relative;
}
.btn-primary { background: linear-gradient(135deg, #0d6efd, #0a58ca); border: none; }
.btn-primary:hover { background: linear-gradient(135deg, #0a58ca, #084298); transform: translateY(-1px); }
.btn-warning { background: linear-gradient(135deg, #ffc107, #e0a800); border: none; }
.btn-warning:hover { background: linear-gradient(135deg, #e0a800, #c69500); }

.btn.loading {
  color: transparent !important;
  pointer-events: none;
  position: relative;
}
.btn.loading::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  top: 50%;
  left: 50%;
  margin: -9px 0 0 -9px;
  border: 2.5px solid rgba(255,255,255,.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: btn-spin .65s linear infinite;
}
.btn-outline-primary.loading::after,
.btn-outline-secondary.loading::after {
  border-color: rgba(13,110,253,.3);
  border-top-color: #0d6efd;
}
@keyframes btn-spin { to { transform: rotate(360deg); } }

/* ---------- Option Buttons (quiz) ---------- */
.opt-btn {
  text-align: left;
  border-radius: var(--amcq-radius-sm) !important;
  margin-bottom: .5rem;
  border: 1.5px solid #e2e8f0;
  background: #fff;
  color: #1a2233;
  font-weight: 500;
  padding: .85rem 1rem;
  transition: all .18s ease;
  display: block;
  width: 100%;
}
.opt-btn:hover:not(:disabled) {
  border-color: var(--amcq-primary);
  background: #f0f7ff;
  transform: translateX(3px);
}
.opt-btn:disabled { opacity: 1; cursor: default; }

.opt-btn.list-group-item-success,
.opt-btn.correct-answer {
  background: var(--amcq-success-bg) !important;
  border-color: var(--amcq-success-border) !important;
  color: #0a3622 !important;
}
.opt-btn.list-group-item-success strong,
.opt-btn.correct-answer strong {
  color: #0a3622 !important;
  text-decoration: none;
}

.opt-btn.list-group-item-danger,
.opt-btn.wrong-answer {
  background: var(--amcq-danger-bg) !important;
  border-color: var(--amcq-danger-border) !important;
  color: #58151c !important;
}
.opt-btn.list-group-item-danger strong,
.opt-btn.wrong-answer strong {
  color: #58151c !important;
  text-decoration: none;
}

.list-group-item-success {
  background: var(--amcq-success-bg) !important;
  color: #0a3622 !important;
  border-color: var(--amcq-success-border) !important;
}
.list-group-item-success strong { color: #0a3622 !important; }
.list-group-item-danger {
  background: var(--amcq-danger-bg) !important;
  color: #58151c !important;
  border-color: var(--amcq-danger-border) !important;
}
.list-group-item-danger strong { color: #58151c !important; }

.opt-btn .pct { font-weight: 600; font-size: .85rem; opacity: .9; }

/* ---------- Alerts ---------- */
.alert { border-radius: var(--amcq-radius-sm); border: none; }
.alert-success { background: var(--amcq-success-bg); color: #0a3622; }
.alert-danger { background: var(--amcq-danger-bg); color: #58151c; }

/* ---------- Note button ---------- */
.note-btn.active {
  background-color: var(--amcq-accent) !important;
  border-color: var(--amcq-accent-dark) !important;
  color: #000 !important;
}

/* ---------- Progress ---------- */
.progress {
  height: 0.65rem;
  border-radius: 99px;
  background: #e2e8f0;
  overflow: hidden;
}
.progress-bar { border-radius: 99px; transition: width .4s ease; }

/* ---------- Palette ---------- */
#paletteBody { transition: max-height .3s ease, opacity .3s ease; }
.q-palette-btn { transition: all .15s ease; font-weight: 600; border-radius: .5rem !important; }
.q-palette-btn:hover { transform: scale(1.1); }
.q-palette-btn.active { box-shadow: 0 0 0 3px rgba(13,110,253,.35); transform: scale(1.08); }

/* ---------- Breadcrumb ---------- */
.breadcrumb { background: transparent; padding: .75rem 0; font-size: .9rem; }
.breadcrumb-item a { color: var(--amcq-primary); text-decoration: none; font-weight: 500; }
.breadcrumb-item a:hover { text-decoration: underline; }

/* ---------- Footer ---------- */
.site-footer {
  background: linear-gradient(135deg, #1a2233 0%, #0f1729 100%);
  color: #b8c2d1;
  padding: 3rem 0 1.5rem;
  margin-top: 4rem;
}
.site-footer h5, .site-footer h6 { color: #fff; font-weight: 600; }
.site-footer a { color: #b8c2d1; text-decoration: none; transition: color .15s; }
.site-footer a:hover { color: var(--amcq-accent) !important; }
.footer-topic-pill {
  display: inline-block;
  padding: .35rem .75rem;
  margin: .2rem .25rem .2rem 0;
  background: rgba(255,255,255,.08);
  border-radius: 99px;
  font-size: .82rem;
  transition: all .2s;
}
.footer-topic-pill:hover {
  background: var(--amcq-primary);
  color: #fff !important;
  transform: translateY(-1px);
}

/* ---------- Utilities ---------- */
.stat-card {
  border-radius: var(--amcq-radius);
  padding: 1.25rem;
  text-align: center;
  background: #fff;
  box-shadow: var(--amcq-card-shadow);
}
.stat-card .stat-value { font-size: 1.75rem; font-weight: 700; }
.stat-card .stat-label { color: #6b7a90; font-size: .85rem; }

.badge { font-weight: 500; padding: .4em .7em; border-radius: .5rem; }

/* ---------- Mobile ---------- */
@media (max-width: 576px) {
  .display-6 { font-size: 1.6rem; }
  .card-body { padding: 1rem !important; }
  .opt-btn { padding: .7rem .85rem; font-size: .95rem; }
  .q-palette-btn { width: 32px !important; height: 32px !important; font-size: .8rem; }
  .stat-card .stat-value { font-size: 1.4rem; }
}

:focus-visible {
  outline: 3px solid rgba(13,110,253,.5);
  outline-offset: 2px;
}

/* ==========================================================
   PWA INSTALL MODAL & TOASTS
   ========================================================== */
.amcq-modal-backdrop {
  position: fixed !important;
  inset: 0;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(15, 23, 41, 0.65);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 99999;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity .25s ease, visibility .25s ease;
  padding: 1rem;
  margin: 0;
}
.amcq-modal-backdrop.active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}
.amcq-modal {
  background: #fff;
  border-radius: 1.25rem;
  max-width: 440px;
  width: 100%;
  padding: 2rem 1.75rem 1.5rem;
  text-align: center;
  box-shadow: 0 24px 60px rgba(0,0,0,.3);
  position: relative;
  transform: translateY(20px) scale(.96);
  transition: transform .3s cubic-bezier(.2,.9,.3,1.2);
}
.amcq-modal-backdrop.active .amcq-modal {
  transform: translateY(0) scale(1);
}
.amcq-modal-close {
  position: absolute;
  top: .5rem;
  right: .75rem;
  background: transparent;
  border: none;
  font-size: 1.75rem;
  line-height: 1;
  color: #6b7a90;
  cursor: pointer;
  padding: .25rem .5rem;
  border-radius: .5rem;
  transition: background .15s;
}
.amcq-modal-close:hover { background: #f0f4f8; color: #1a2233; }
.amcq-modal-icon {
  width: 96px;
  height: 96px;
  margin: 0 auto 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #e7f1ff, #d1e7dd);
  border-radius: 24px;
  box-shadow: 0 8px 24px rgba(13,110,253,.18);
}
.amcq-modal-icon img { border-radius: 16px; display: block; }
.amcq-modal-title { font-size: 1.35rem; font-weight: 700; color: #0a2540; margin-bottom: .5rem; }
.amcq-modal-text { color: #5a6b82; font-size: .95rem; line-height: 1.55; margin-bottom: 1.1rem; }
.amcq-modal-benefits {
  list-style: none;
  padding: 0;
  margin: 0 0 1.35rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .55rem .75rem;
  text-align: left;
}
.amcq-modal-benefits li {
  font-size: .86rem;
  color: #334155;
  display: flex;
  align-items: center;
  gap: .4rem;
}
.amcq-modal-benefits li i { color: #0d6efd; font-size: 1rem; }
.amcq-modal-actions { display: flex; gap: .6rem; margin-bottom: .85rem; }
.amcq-modal-actions .btn { flex: 1; padding: .7rem 1rem; font-size: .95rem; }
.amcq-modal-footnote { font-size: .75rem; color: #94a3b8; margin: 0; }

.amcq-toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translate(-50%, 30px);
  background: #1a2233;
  color: #fff;
  padding: .85rem 1.25rem;
  border-radius: 99px;
  font-size: .9rem;
  box-shadow: 0 12px 30px rgba(0,0,0,.28);
  opacity: 0;
  transition: all .35s cubic-bezier(.2,.9,.3,1.2);
  z-index: 100000;
  display: flex;
  align-items: center;
  gap: .75rem;
  max-width: calc(100vw - 2rem);
}
.amcq-toast.show { opacity: 1; transform: translate(-50%, 0); }
.amcq-toast-success { background: #198754; }
.amcq-toast-info    { background: #0d6efd; }
.amcq-toast-update  { background: #1a2233; }
.amcq-toast-btn {
  background: #ffc107;
  color: #1a2233;
  border: none;
  border-radius: 99px;
  padding: .35rem .85rem;
  font-weight: 700;
  font-size: .82rem;
  cursor: pointer;
}
.amcq-toast-btn:hover { background: #ffb300; }

@media (max-width: 480px) {
  .amcq-modal { padding: 1.75rem 1.25rem 1.25rem; }
  .amcq-modal-benefits { grid-template-columns: 1fr; }
  .amcq-modal-actions { flex-direction: column-reverse; }
}