/*
 * CHAIWITHJAI DESIGN SYSTEM
 * Minimal, unified design tokens and base styles
 * Source of truth: Algorithm Blog aesthetic
 *
 * Usage: Include this file FIRST in all pages
 * <link rel="stylesheet" href="design-system.css">
 */

/* === GOOGLE FONTS === */
@import url('https://fonts.googleapis.com/css2?family=Fraunces:ital,opsz,wght@0,9..144,400;0,9..144,600;0,9..144,700;1,9..144,400&family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

/* === DESIGN TOKENS === */
:root {
  /* Brand Colors */
  --cream: #f8f6f3;
  --cream-dark: #f0ede8;
  --navy: #001666;
  --navy-light: #0a2472;
  --orange: #c94400;           /* Darkened from #ff5900 for WCAG AA contrast (4.5:1 on white) */
  --orange-bright: #ff5900;    /* Original orange for decorative use only */
  --orange-light: #e65500;     /* Adjusted for accessibility */
  --slate: #2a3132;
  --light-slate: #9ca3af;      /* Lightened from #5f6566 for better contrast on dark backgrounds */
  --white: #ffffff;

  /* Semantic Colors */
  --bg-primary: var(--cream);
  --bg-secondary: var(--white);
  --bg-elevated: var(--white);
  --text-primary: var(--slate);
  --text-secondary: var(--light-slate);
  --text-heading: var(--navy);
  --accent: var(--orange);

  /* Typography */
  --font-display: 'Fraunces', Georgia, serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  /* Spacing Scale */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;
  --space-3xl: 4rem;

  /* Standard Section Spacing */
  --section-padding: 80px;
  --section-padding-mobile: 60px;

  /* Border Radius */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 22, 102, 0.05);
  --shadow-md: 0 4px 12px rgba(0, 22, 102, 0.08);
  --shadow-lg: 0 8px 24px rgba(0, 22, 102, 0.12);
  --shadow-card: 0 2px 8px rgba(0, 22, 102, 0.06);

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-base: 250ms ease;
  --transition-slow: 400ms ease;
}

/* === BASE RESET === */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
  font-size: 16px;
}

body {
  font-family: var(--font-body);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* === TYPOGRAPHY === */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  font-weight: 700;
  line-height: 1.25;
  color: var(--text-heading);
}

h1 { font-size: clamp(2rem, 5vw, 3rem); }
h2 { font-size: clamp(1.5rem, 4vw, 2.25rem); }
h3 { font-size: clamp(1.25rem, 3vw, 1.5rem); }
h4 { font-size: 1.125rem; }

p {
  margin-bottom: var(--space-md);
  color: var(--text-primary);
  line-height: 1.7;
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--orange-light);
}

strong {
  color: var(--navy);
  font-weight: 600;
}

/* === LAYOUT === */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--space-xl);
}

@media (max-width: 768px) {
  .container {
    padding: 0 var(--space-md);
  }
}

/* === BUTTONS === */
.btn {
  display: inline-block;
  padding: 14px 28px;
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 1rem;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  border: none;
  transition: all var(--transition-fast);
}

.btn:hover {
  transform: translateY(-2px);
}

.btn-primary {
  background: var(--orange);
  color: var(--white);
}

.btn-primary:hover {
  background: #e64f00;
  box-shadow: 0 4px 12px rgba(255, 89, 0, 0.3);
  color: var(--white);
}

.btn-secondary {
  background: transparent;
  color: var(--navy);
  border: 2px solid var(--orange);
}

.btn-secondary:hover {
  background: var(--orange);
  color: var(--white);
}

/* === CARDS === */
.card {
  background: var(--white);
  border: 1px solid rgba(0, 22, 102, 0.1);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  box-shadow: var(--shadow-card);
  transition: box-shadow var(--transition-base), transform var(--transition-base);
}

.card:hover {
  box-shadow: var(--shadow-md);
}

/* === SECTIONS === */
section {
  padding: var(--space-3xl) 0;
}

/* === UTILITY CLASSES === */
.text-center { text-align: center; }
.text-navy { color: var(--navy); }
.text-orange { color: var(--orange); }
.text-slate { color: var(--slate); }
.text-white { color: var(--white); }

.bg-cream { background-color: var(--cream); }
.bg-white { background-color: var(--white); }
.bg-navy { background-color: var(--navy); }

/* === HEADER STYLES === */
.main-header {
  position: sticky;
  top: 0;
  z-index: 1000;
  background: rgba(248, 246, 243, 0.97);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(0, 22, 102, 0.08);
  padding: var(--space-md) 0;
}

.main-header .container {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--navy);
  text-decoration: none;
  transition: color var(--transition-fast);
}

.logo:hover {
  color: var(--accent);
}

.main-nav {
  display: flex;
  align-items: center;
  gap: var(--space-lg);
}

.main-nav a {
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 0.9375rem;
  padding: var(--space-xs) 0;
  position: relative;
  transition: color var(--transition-fast);
}

.main-nav a:hover,
.main-nav a.active-link {
  color: var(--navy);
}

.main-nav a::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 0;
  height: 2px;
  background: var(--accent);
  transition: width var(--transition-base);
}

.main-nav a:hover::after,
.main-nav a.active-link::after {
  width: 100%;
}

.nav-cta {
  background: var(--accent) !important;
  color: var(--white) !important;
  padding: var(--space-sm) var(--space-md) !important;
  border-radius: var(--radius-md);
  font-weight: 600 !important;
  font-size: 0.875rem !important;
  transition: all var(--transition-fast) !important;
}

.nav-cta:hover {
  background: var(--orange-light) !important;
  transform: translateY(-1px);
}

.nav-cta::after {
  display: none !important;
}

/* Mobile Nav Toggle */
.nav-toggle {
  display: none;
  flex-direction: column;
  cursor: pointer;
  padding: var(--space-xs);
}

.nav-toggle span {
  width: 24px;
  height: 2px;
  background: var(--navy);
  margin: 3px 0;
  border-radius: 2px;
  transition: var(--transition-fast);
}

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

  .main-nav {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--cream);
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: var(--space-xl);
  }

  .main-nav.active {
    display: flex;
  }

  .main-nav a {
    font-size: 1.25rem;
  }
}

/* === FOOTER STYLES === */
.main-footer {
  background: var(--navy);
  color: var(--white);
  padding: var(--space-2xl) 0;
}

.footer-grid {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr;
  gap: var(--space-2xl);
}

@media (max-width: 768px) {
  .footer-grid {
    grid-template-columns: 1fr 1fr;
    gap: var(--space-xl);
  }
}

@media (max-width: 480px) {
  .footer-grid {
    grid-template-columns: 1fr;
  }
}

.footer-brand .logo {
  color: var(--white);
  font-size: 1.5rem;
  margin-bottom: var(--space-md);
  display: block;
}

.footer-brand p {
  color: rgba(255, 255, 255, 0.7);
  font-size: 0.9375rem;
  line-height: 1.6;
}

.footer-section {
  min-width: 0;
}

.footer-heading {
  color: var(--accent);
  font-size: 0.8125rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: var(--space-md);
}

.footer-links-column {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.footer-links-column a {
  color: rgba(255, 255, 255, 0.8);
  font-size: 0.9375rem;
  transition: color var(--transition-fast);
  text-decoration: none;
}

.footer-links-column a:hover {
  color: var(--accent);
}

.footer-bottom {
  margin-top: var(--space-2xl);
  padding-top: var(--space-lg);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  text-align: center;
  color: rgba(255, 255, 255, 0.5);
  font-size: 0.875rem;
}

.footer-bottom p {
  color: inherit;
  margin: 0;
}

/* === HERO SECTIONS === */
.hero-section {
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-light) 100%);
  padding: 100px 0 80px;
  color: var(--white);
  position: relative;
  overflow: hidden;
}

.hero-section::before {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  width: 40%;
  height: 100%;
  background: linear-gradient(135deg, transparent 0%, rgba(255, 89, 0, 0.1) 100%);
}

.hero-section h1 {
  color: var(--white);
  margin-bottom: var(--space-lg);
  max-width: 800px;
}

.hero-section .lead {
  font-size: 1.25rem;
  color: rgba(255, 255, 255, 0.9);
  max-width: 700px;
  line-height: 1.7;
}

/* === FORM STYLES === */
.form-group {
  margin-bottom: var(--space-lg);
}

.form-group label {
  display: block;
  font-weight: 500;
  color: var(--navy);
  margin-bottom: var(--space-sm);
  font-size: 0.9375rem;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid rgba(0, 22, 102, 0.15);
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-family: var(--font-body);
  background: var(--cream);
  color: var(--slate);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--orange);
  box-shadow: 0 0 0 3px rgba(255, 89, 0, 0.1);
}

/* === HIGHLIGHT BOXES === */
.highlight-box {
  background: linear-gradient(135deg, #f0f4ff 0%, #e8ecf8 100%);
  border-left: 4px solid var(--navy);
  padding: var(--space-xl) var(--space-xl);
  margin: var(--space-xl) 0;
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
}

.highlight-box p {
  margin-bottom: 0;
  color: var(--navy);
  font-weight: 500;
}

.quote-box {
  background: linear-gradient(135deg, #fff8f0 0%, #fff5eb 100%);
  border-left: 4px solid var(--orange);
  padding: var(--space-xl) var(--space-xl);
  margin: var(--space-xl) 0;
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
}

.quote-box p {
  font-style: italic;
  color: var(--slate);
  margin-bottom: 0;
}

.quote-box .attribution {
  font-style: normal;
  font-size: 0.875rem;
  color: var(--light-slate);
  margin-top: var(--space-sm);
}

/* === VISUAL AUDIT FIXES === */

/* --- Fix XP-001, ABT-005: Prose/Text Readability --- */
.prose {
  max-width: 70ch;
}

.prose p,
.prose li {
  line-height: 1.8;
}

/* --- Fix: Typography on dark backgrounds --- */
.text-on-dark {
  color: var(--white);
}

.text-on-dark-muted {
  color: rgba(255, 255, 255, 0.8);
}

/* --- Fix CS-001: Orange on dark needs to be lighter --- */
.text-orange-on-dark {
  color: #ff6b35;
}

/* --- Fix XP-004: Price display consistency --- */
.price-display {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(2rem, 4vw, 2.5rem);
  color: var(--navy);
  line-height: 1.2;
}

.price-display-dark {
  color: var(--white);
}

/* --- Fix: Card grid alignment (IDX-003, SVC-001, CDX-001, BLG-001) --- */
.card-grid {
  display: grid;
  gap: var(--space-xl);
}

.card-grid-2 {
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}

.card-grid-3 {
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

/* Card with flex column for alignment */
.card-flex {
  display: flex;
  flex-direction: column;
}

.card-flex .card-content {
  flex-grow: 1;
}

.card-flex .card-footer {
  margin-top: auto;
  padding-top: var(--space-lg);
}

/* --- Fix ABT-001: Hero headline line height --- */
.hero-section h1 {
  line-height: 1.15;
}

@media (max-width: 768px) {
  .hero-section h1 {
    line-height: 1.2;
  }
}

/* --- Fix IDX-004: Mobile hero text overflow --- */
@media (max-width: 480px) {
  h1 {
    font-size: clamp(1.5rem, 8vw, 2rem);
  }

  .hero-section {
    padding: 60px 0 50px;
  }

  .hero-section .lead {
    font-size: 1rem;
  }
}

/* --- Fix XP-003: Footer mobile responsive --- */
@media (max-width: 480px) {
  .footer-grid {
    grid-template-columns: 1fr;
    gap: var(--space-lg);
    text-align: center;
  }

  .footer-brand {
    margin-bottom: var(--space-md);
  }

  .footer-links-column {
    align-items: center;
  }
}

/* --- Fix SVC-004: Mobile card padding --- */
@media (max-width: 768px) {
  .card {
    padding: var(--space-lg);
  }
}

@media (max-width: 480px) {
  .card {
    padding: var(--space-md);
  }
}

/* --- Fix CNT-001, CNT-002: Form improvements --- */
.form-grid {
  display: grid;
  gap: var(--space-xl);
}

@media (min-width: 900px) {
  .form-grid-2col {
    grid-template-columns: 1fr 1fr;
  }
}

.form-group {
  margin-bottom: var(--space-lg);
}

/* --- Fix BLG-004: Filter pills horizontal scroll --- */
.filter-pills {
  display: flex;
  gap: var(--space-sm);
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  padding-bottom: var(--space-sm);
  scrollbar-width: thin;
}

.filter-pills::-webkit-scrollbar {
  height: 4px;
}

.filter-pills::-webkit-scrollbar-thumb {
  background: var(--light-slate);
  border-radius: var(--radius-full);
}

.filter-pill {
  scroll-snap-align: start;
  flex-shrink: 0;
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-full);
  font-size: 0.875rem;
  font-weight: 500;
  border: 1px solid rgba(0, 22, 102, 0.15);
  background: var(--white);
  color: var(--slate);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.filter-pill:hover {
  border-color: var(--orange);
  color: var(--orange);
}

.filter-pill.active {
  background: var(--orange);
  border-color: var(--orange);
  color: var(--white);
}

/* --- Fix ALG-001: Code block readability --- */
pre, code {
  font-family: var(--font-mono);
  font-size: 1rem;
}

pre {
  background: #1e1e1e;
  color: #d4d4d4;
  padding: var(--space-lg);
  border-radius: var(--radius-md);
  overflow-x: auto;
  line-height: 1.6;
}

/* Fix ALG-002: Syntax highlighting contrast */
pre .comment {
  color: #6a9955;
}

/* --- Fix ABT-002: Stats section grounding --- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: var(--space-xl);
  text-align: center;
  padding: var(--space-xl);
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
}

.stat-item {
  padding: var(--space-md);
}

.stat-value {
  font-family: var(--font-display);
  font-size: clamp(2rem, 5vw, 2.5rem);
  font-weight: 700;
  color: var(--navy);
  line-height: 1.2;
}

.stat-label {
  font-size: 0.875rem;
  color: var(--light-slate);
  margin-top: var(--space-xs);
}

/* --- Fix SDR-002: Image grid consistency --- */
.image-grid {
  display: grid;
  gap: var(--space-md);
}

.image-grid img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: var(--radius-md);
}

.aspect-square {
  aspect-ratio: 1 / 1;
}

.aspect-video {
  aspect-ratio: 16 / 9;
}

/* --- Fix SDR-005: Touch-friendly buttons --- */
@media (max-width: 768px) {
  .btn {
    min-height: 44px;
    min-width: 44px;
    padding: 12px 24px;
  }
}

/* --- Fix EXC-001: Dark theme text hierarchy --- */
.dark-theme {
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-light) 100%);
  color: var(--white);
}

.dark-theme h1,
.dark-theme h2,
.dark-theme h3 {
  color: var(--white);
}

.dark-theme p {
  color: rgba(255, 255, 255, 0.8);
}

.dark-theme .text-muted {
  color: rgba(255, 255, 255, 0.6);
}

/* --- Fix SDR-004: Brand-consistent gradients --- */
.gradient-navy {
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-light) 100%);
}

.gradient-accent {
  background: linear-gradient(135deg, var(--orange) 0%, #e65500 100%);
}

/* --- Fix: Section spacing consistency (XP-002) --- */
.section-sm {
  padding: var(--space-2xl) 0;
}

.section-md {
  padding: var(--space-3xl) 0;
}

.section-lg {
  padding: calc(var(--space-3xl) * 1.5) 0;
}

@media (max-width: 768px) {
  .section-sm {
    padding: var(--space-xl) 0;
  }

  .section-md {
    padding: var(--space-2xl) 0;
  }

  .section-lg {
    padding: var(--space-3xl) 0;
  }
}

/* --- Fix IDX-002: Logo grid consistency --- */
.logo-grid {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: var(--space-lg);
}

.logo-grid img {
  height: 24px;
  width: auto;
  max-width: 100px;
  object-fit: contain;
  opacity: 0.7;
  transition: opacity var(--transition-fast);
}

.logo-grid img:hover {
  opacity: 1;
}

/* --- Fix SVC-002: Checkmarks on tinted backgrounds --- */
.check-list {
  list-style: none;
}

.check-list li {
  position: relative;
  padding-left: 1.75rem;
  margin-bottom: var(--space-sm);
}

.check-list li::before {
  content: '✓';
  position: absolute;
  left: 0;
  color: var(--navy);
  font-weight: 700;
}

.check-list-orange li::before {
  color: var(--orange);
}

/* --- Fix CNT-003: Clickable link affordance --- */
.link-with-icon {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* --- Fix CDX-002: Difficulty badges --- */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.badge-easy {
  background: #d4edda;
  color: #155724;
}

.badge-medium {
  background: #fff3cd;
  color: #856404;
}

.badge-hard {
  background: #f8d7da;
  color: #721c24;
}
