@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  /* Light theme (default) - clean SaaS blue */
  --bg: #FFFFFF;
  --bg-alt: #F6F8FB;
  --panel: #FFFFFF;
  --panel-2: #F3F5F9;
  --border: #E4E8F0;
  --text: #12172A;
  --muted: #6B7488;
  --primary: #2F6FED;
  --primary-hover: #2559C7;
  --primary-tint: #EAF0FE;
  --success: #1BA672;
  --success-tint: #E7F8F1;
  --danger: #E5484D;
  --danger-tint: #FDEBEC;
  --radius: 10px;
  --sans: 'Inter', -apple-system, sans-serif;
  --mono: 'JetBrains Mono', 'Courier New', monospace;
  --shadow: 0 1px 2px rgba(16,24,40,0.04), 0 1px 3px rgba(16,24,40,0.06);
  
  /* American Flag Colors */
  --flag-red: #B22234;
  --flag-white: #FFFFFF;
  --flag-blue: #1A3A6B;
}

[data-theme="dark"] {
  --bg: #0E1220;
  --bg-alt: #0B0E19;
  --panel: #161B2C;
  --panel-2: #1E2438;
  --border: #2A3149;
  --text: #EDEFF7;
  --muted: #8D95AC;
  --primary: #5B8DEF;
  --primary-hover: #7BA3F2;
  --primary-tint: #1B2B4D;
  --success: #3FCF95;
  --success-tint: #123A2D;
  --danger: #F0655F;
  --danger-tint: #3A1A1A;
  --shadow: 0 1px 2px rgba(0,0,0,0.3);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg-alt);
  color: var(--text);
  font-family: var(--sans);
  line-height: 1.55;
  transition: background 0.15s, color 0.15s;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { font-family: var(--sans); font-weight: 700; margin: 0 0 0.5em; letter-spacing: -0.02em; }
code, pre, .mono { font-family: var(--mono); }

.wrap { max-width: 960px; margin: 0 auto; padding: 32px 24px 80px; }
.wrap-narrow { max-width: 440px; margin: 0 auto; padding: 60px 24px; }

/* ===== TOP NAV - ENHANCED ===== */
.topbar {
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  position: sticky; 
  top: 0; 
  z-index: 100;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

/* American Flag Bar - NEW */
.flag-bar {
  height: 4px;
  display: flex;
  width: 100%;
}
.flag-bar span { flex: 1; }
.flag-bar span:nth-child(1) { background: var(--flag-red); }
.flag-bar span:nth-child(2) { background: var(--flag-white); }
.flag-bar span:nth-child(3) { background: var(--flag-blue); }

[data-theme="dark"] .flag-bar span:nth-child(2) { 
  background: rgba(255,255,255,0.15); 
}

.topbar-inner {
  max-width: 960px; 
  margin: 0 auto; 
  padding: 12px 24px;
  display: flex; 
  align-items: center; 
  justify-content: space-between;
  gap: 12px;
}

/* ===== LOGO - BIGGER ===== */
.brand { 
  font-size: 1.05rem; 
  font-weight: 800; 
  color: var(--text); 
  display: flex; 
  align-items: center; 
  gap: 12px;
  flex-shrink: 0;
}
.brand .seal { 
  width: 48px;  /* WAS: 38px - NOW BIGGER */
  height: 48px;
  border-radius: 50%;
  border: 2px solid var(--border);
  transition: all 0.3s;
  object-fit: contain;
}
.brand .seal:hover {
  border-color: var(--primary);
  transform: scale(1.05);
}

/* Brand with flag accent */
.brand .flag-accent {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: 4px;
}
.brand .flag-accent .dot {
  width: 6px;
  height: 6px;
  border-radius: 1px;
  display: inline-block;
}
.brand .flag-accent .dot:nth-child(1) { background: var(--flag-red); }
.brand .flag-accent .dot:nth-child(2) { background: var(--flag-white); }
.brand .flag-accent .dot:nth-child(3) { background: var(--flag-blue); }

[data-theme="dark"] .brand .flag-accent .dot:nth-child(2) {
  background: rgba(255,255,255,0.2);
}

/* ===== NAV LINKS - ENHANCED ===== */
.nav-links { 
  display: flex; 
  gap: 16px; 
  align-items: center; 
  font-size: 0.9rem; 
  color: var(--muted); 
  flex-wrap: wrap;
}
.nav-links a { 
  color: var(--muted);
  padding: 6px 10px;
  border-radius: 6px;
  transition: all 0.2s;
}
.nav-links a:hover { 
  color: var(--text);
  background: var(--panel-2);
}

/* ===== LOGIN BUTTON - BETTER VISIBILITY ON MOBILE ===== */
.nav-links .login-btn {
  background: var(--primary);
  color: #fff !important;
  padding: 8px 20px;
  border-radius: 8px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all 0.3s;
}
.nav-links .login-btn:hover {
  background: var(--primary-hover);
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(47, 111, 237, 0.3);
  text-decoration: none !important;
}

/* Flag-themed login button variant */
.nav-links .login-btn-flag {
  background: linear-gradient(135deg, var(--flag-red), var(--flag-blue));
  color: #fff !important;
  padding: 8px 20px;
  border-radius: 8px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all 0.3s;
  position: relative;
  overflow: hidden;
}
.nav-links .login-btn-flag::before {
  content: '★';
  margin-right: 6px;
  color: #fff;
  opacity: 0.6;
  font-size: 0.7rem;
}
.nav-links .login-btn-flag:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 20px rgba(26, 58, 107, 0.3);
  text-decoration: none !important;
}

.theme-toggle {
  background: var(--panel-2); 
  border: 1px solid var(--border); 
  border-radius: 20px;
  width: 38px; 
  height: 22px; 
  position: relative; 
  cursor: pointer; 
  padding: 0;
  flex-shrink: 0;
}
.theme-toggle::after {
  content: ''; 
  position: absolute; 
  top: 2px; 
  left: 2px; 
  width: 16px; 
  height: 16px;
  border-radius: 50%; 
  background: var(--primary); 
  transition: transform 0.15s;
}
[data-theme="dark"] .theme-toggle::after { transform: translateX(16px); }

/* Cards */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 16px; }

/* ===== GRID - ENHANCED ===== */
.grid { 
  display: grid; 
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); 
  gap: 16px; 
}

/* ===== MOBILE: 2 COLUMN GRID ===== */
@media (max-width: 600px) {
  .grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }
}

@media (max-width: 400px) {
  .grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }
}

/* Buttons */
.btn {
  display: inline-block;
  font-family: var(--sans);
  font-weight: 600;
  font-size: 0.9rem;
  padding: 10px 18px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); text-decoration: none; }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { border-color: var(--primary); text-decoration: none; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-block { display: block; width: 100%; text-align: center; }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }

/* Forms */
label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 6px; font-weight: 500; }
input, select {
  width: 100%; padding: 10px 12px; margin-bottom: 16px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); font-family: var(--sans); font-size: 0.95rem;
}
input:focus, select:focus { outline: 2px solid var(--primary); outline-offset: 1px; }

/* Flash messages */
.flash { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 0.9rem; }
.flash-success { background: var(--success-tint); color: var(--success); border: 1px solid var(--success); }
.flash-error { background: var(--danger-tint); color: var(--danger); border: 1px solid var(--danger); }

/* Progress */
.progress-bar { height: 6px; background: var(--panel-2); border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--primary); }

/* Badges / pills */
.pill {
  display: inline-block; padding: 3px 10px; border-radius: 20px;
  font-size: 0.75rem; font-weight: 600; background: var(--panel-2); color: var(--muted);
  border: 1px solid var(--border);
}
.pill-primary { color: var(--primary); background: var(--primary-tint); border-color: transparent; }
.pill-success { color: var(--success); background: var(--success-tint); border-color: transparent; }
.pill-admin { color: #fff; background: linear-gradient(135deg, #2F6FED, #1BA6E0); border: none; }

/* American Flag Pill */
.pill-flag {
  background: linear-gradient(135deg, var(--flag-red), var(--flag-blue));
  color: #fff;
  border: none;
}

/* Chapter reader */
.lesson-notes { white-space: pre-wrap; font-size: 0.95rem; line-height: 1.7; }
.code-block {
  background: var(--bg-alt); border: 1px solid var(--border); border-radius: 8px;
  padding: 16px; overflow-x: auto; font-family: var(--mono); font-size: 0.85rem;
  color: var(--text); white-space: pre;
}
[data-theme="dark"] .code-block { background: #0A0D16; color: #6FD8C6; }

/* Exam */
.timer { font-family: var(--mono); font-size: 1.3rem; color: var(--primary); }
.timer.timer-low { color: var(--danger); }
.q-nav-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(36px, 1fr)); gap: 6px; }
.q-nav-btn {
  width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--panel); color: var(--muted); font-size: 0.8rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.q-nav-btn.answered { background: var(--primary-tint); color: var(--primary); border-color: var(--primary); }
.q-nav-btn.current { background: var(--primary); color: #fff; border-color: var(--primary); }

.option-row {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; margin-bottom: 8px;
  border: 1px solid var(--border); border-radius: 8px; cursor: pointer;
}
.option-row:hover { border-color: var(--primary); }
.option-row.selected { border-color: var(--primary); background: var(--primary-tint); }
.option-row input { width: auto; margin: 0; }

.correct { color: var(--success); font-weight: 600; }
.incorrect { color: var(--danger); font-weight: 600; }

/* Certificate seal */
.seal-badge {
  width: 64px; height: 64px; border-radius: 50%;
  border: 2px solid var(--success);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.6rem; font-weight: 700; color: var(--success);
  background: var(--success-tint);
}

.muted { color: var(--muted); }
.text-center { text-align: center; }
.mt-24 { margin-top: 24px; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }

/* ===== MOBILE RESPONSIVE ENHANCEMENTS ===== */
@media (max-width: 768px) {
  .topbar-inner {
    padding: 10px 16px;
    flex-wrap: wrap;
    gap: 8px;
  }
  
  .brand {
    font-size: 0.95rem;
    gap: 10px;
  }
  .brand .seal {
    width: 40px;
    height: 40px;
  }
  
  .nav-links {
    gap: 8px;
    font-size: 0.8rem;
    width: 100%;
    justify-content: center;
    padding-top: 8px;
    border-top: 1px solid var(--border);
  }
  
  .nav-links a {
    padding: 4px 8px;
    font-size: 0.8rem;
  }
  
  .nav-links .login-btn,
  .nav-links .login-btn-flag {
    padding: 6px 14px;
    font-size: 0.8rem;
  }
  
  .wrap {
    padding: 20px 16px 60px;
  }
}

@media (max-width: 480px) {
  .topbar-inner {
    padding: 8px 12px;
  }
  
  .brand {
    font-size: 0.85rem;
    gap: 8px;
  }
  .brand .seal {
    width: 36px;
    height: 36px;
  }
  
  .nav-links {
    gap: 4px;
    padding-top: 6px;
  }
  
  .nav-links a {
    padding: 4px 6px;
    font-size: 0.7rem;
  }
  
  .nav-links .login-btn,
  .nav-links .login-btn-flag {
    padding: 4px 10px;
    font-size: 0.7rem;
  }
  
  /* 2 column grid for very small screens */
  .grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }
}

/* ===== AMERICAN FLAG UTILITY CLASSES ===== */
.flag-strip {
  display: flex;
  height: 4px;
  border-radius: 2px;
  overflow: hidden;
  width: 100%;
}
.flag-strip span { flex: 1; }
.flag-strip span:nth-child(1) { background: var(--flag-red); }
.flag-strip span:nth-child(2) { background: var(--flag-white); }
.flag-strip span:nth-child(3) { background: var(--flag-blue); }

[data-theme="dark"] .flag-strip span:nth-child(2) {
  background: rgba(255,255,255,0.1);
}

.flag-dots {
  display: flex;
  gap: 4px;
  align-items: center;
}
.flag-dots span {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  display: inline-block;
}
.flag-dots span:nth-child(1) { background: var(--flag-red); }
.flag-dots span:nth-child(2) { background: var(--flag-white); }
.flag-dots span:nth-child(3) { background: var(--flag-blue); }

[data-theme="dark"] .flag-dots span:nth-child(2) {
  background: rgba(255,255,255,0.15);
}

/* Flag-themed badge */
.flag-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: linear-gradient(135deg, var(--flag-red), var(--flag-blue));
  color: #fff;
  padding: 4px 14px;
  border-radius: 50px;
  font-size: 0.7rem;
  font-weight: 600;
}
.flag-badge .star {
  font-size: 0.6rem;
  opacity: 0.7;
}
