/* --- 1. CORE VARIABLES & THEMES --- */
:root {
  /* Semantic color variables - named by purpose, not appearance */
  --bg-primary: #FAF9F6;      /* Main page background */
  --bg-secondary: #FFFFFF;    /* Cards, header, footer */
  --bg-tertiary: #F9FAFB;     /* Vault headers, subtle backgrounds */
  --text-primary: #2D2D2D;    /* Main text color */
  --text-muted: #6B7280;      /* Secondary text */
  --border: #E5E7EB;
  --accent: #D97706;
  --accent-glow: rgba(217, 119, 6, 0.4);
  --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);

  /* Spacing scale for consistency */
  --space-xs: 0.5rem;    /* 8px */
  --space-sm: 1rem;      /* 16px */
  --space-md: 1.5rem;    /* 24px */
  --space-lg: 2rem;      /* 32px */
  --space-xl: 3rem;      /* 48px */
  --space-2xl: 4rem;     /* 64px */
}

.dark-mode {
  --bg-primary: #121212;      /* Dark page background */
  --bg-secondary: #1E1E1E;    /* Dark cards */
  --bg-tertiary: #252525;     /* Dark vault headers */
  --text-primary: #F3F4F6;    /* Light text */
  --text-muted: #9CA3AF;
  --border: #333333;
  --accent-glow: rgba(245, 158, 11, 0.6);
  /* --accent stays the same */
}

/* Dark mode legend box backgrounds */
.dark-mode .legend-box.grail { 
  background: rgba(42, 157, 143, 0.1); 
}

.dark-mode .legend-box.dud { 
  background: rgba(231, 111, 81, 0.1); 
}

/* --- 2. GLOBAL FOUNDATION --- */
body {
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: 'Lora', serif !important; /* Override lithium theme */
  font-size: 1.1rem;
  line-height: 1.7;
  margin: 0;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.3s ease;
}

h1, h2, h3, h4, .post-title, .post-title a, .nav-title a, .archive-item-link, .article-title {
  font-family: 'Lora', serif !important; /* Override lithium theme */
  font-weight: 700;
  color: var(--text-primary);
  text-decoration: none;
}

/* --- MATHJAX MOBILE FIX --- */
.MathJax_Display,
.MJXc-display,
mjx-container {
  overflow-x: auto;
  overflow-y: hidden;
  max-width: 100%;
}

@media (max-width: 600px) {
  .MathJax_Display,
  .MJXc-display,
  mjx-container {
    font-size: 0.9rem;
  }
}

/* --- 3. GLOBAL LINK BEHAVIOR --- */
/* Exclude nav links from global hover styles */
a:not(.nav a):not(.nav-logo):not(.nav-title a) {
  color: var(--text-primary);
  text-decoration: none;
  transition: var(--transition-smooth);
  border-bottom: 1px solid transparent;
}

/* Exclude nav links and info icons from global hover styles */
a:not(.nav a):not(.nav-logo):not(.nav-title a):not(.info-link):not(.methodology-link):not(.mini-info-link):hover,
a:not(.nav a):not(.nav-logo):not(.nav-title a):not(.info-link):not(.methodology-link):not(.mini-info-link):focus-visible {
  color: var(--accent);
  border-bottom: 1px solid var(--accent-glow);
}

a:visited {
  color: var(--text-primary);
}

/* Article/Post Specific Links */
.article-content a, .post-content a {
  color: var(--accent);
  border-bottom: 1px solid var(--accent-glow);
}

/* Article content link hover - excludes read-more and info links */
.article-content a:not(.read-more):not(.info-link):not(.methodology-link):not(.mini-info-link):hover, 
.article-content a:not(.read-more):not(.info-link):not(.methodology-link):not(.mini-info-link):focus-visible,
.post-content a:not(.read-more):not(.info-link):not(.methodology-link):not(.mini-info-link):hover,
.post-content a:not(.read-more):not(.info-link):not(.methodology-link):not(.mini-info-link):focus-visible {
  color: var(--text-accent);
  border-bottom: 1px solid var(--accent);
}

/* Post title, archive link, and Read More hover states */
.post-title a:hover,
.post-title a:focus-visible,
.archive-item-link:hover,
.archive-item-link:focus-visible,
.article-title a:hover,
.article-title a:focus-visible,
.archive-item-summary .read-more:hover,
.archive-item-summary .read-more:focus-visible,
.read-more:hover,
.read-more:focus-visible {
  background-color: transparent;
  color: var(--accent);
  border-bottom: 1px solid var(--accent-glow);
}

/* --- 4. INFO ICON LINKS --- */
/* More specific selectors to override global link styles without !important */
a.info-link, 
a.methodology-link, 
a.mini-info-link,
.mini-header .info-link,
.brand-specs-strip .info-link,
.candle-specs-strip .info-link {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-style: normal;
  font-weight: 400;
  font-size: 0.95rem;
  color: var(--text-muted);
  margin-left: 5px;
  padding: 1px 4px;
  border-radius: 3px;
  opacity: 0.8;
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  border: none;
  border-bottom: none !important;
  background: transparent;
  transition: var(--transition-smooth);
  -webkit-tap-highlight-color: transparent;
}

a.info-link:hover:hover, 
a.methodology-link:hover:hover, 
a.mini-info-link:hover:hover,
.mini-header .info-link:hover,
.brand-specs-strip .info-link:hover,
.candle-specs-strip .info-link:hover {
  opacity: 1 !important;
  color: var(--accent) !important;
  text-shadow: 0 0 10px var(--accent-glow) !important;
  background: rgba(217, 119, 6, 0.05) !important;
  cursor: pointer;
  border-bottom: none !important;
}

/* Mobile info links */
@media (max-width: 600px) {
  .info-link, .methodology-link, .mini-info-link { 
    font-size: 0.8rem; 
    margin-left: 3px; 
  }
}

/* --- 5. ACCESSIBILITY - FOCUS STATES --- */
a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

.candle-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
  border-radius: 4px;
}

/* Respect user motion preferences */
@media (prefers-reduced-motion: reduce) {
  .dark-mode .flame {
    animation: none;
  }
  
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important; /* Override all animations */
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* --- 6. HEADER & NAVIGATION --- */
.header {
  background-color: var(--bg-secondary) !important; /* Override lithium theme */
  border-bottom: 1px solid var(--border) !important;
  width: 100%;
  padding-top: 10px;
  padding-bottom: 10px;
  overflow: visible !important; /* Prevent clipping */
}

.nav {
  display: flex !important; /* Override lithium theme */
  justify-content: flex-start !important; /* Left-aligned layout */
  align-items: center;
  gap: 12px !important;
  max-width: 1100px;
  margin: 0 auto;
  height: 75px;
  padding: 0 1.5rem;
  overflow: visible !important; /* Prevent clipping */
}

/* Logo - no absolute positioning */
.nav-logo {
  display: block;
  flex-shrink: 0;
}

/* Remove underlines from logo and title */
.nav-logo:hover,
.nav-logo:focus-visible,
.nav-title a:hover,
.nav-title a:focus-visible {
  border-bottom: none;
}

/* Title - sits next to logo */
.nav-title {
  margin: 0 0 0 12px;
  text-align: left;
}

.nav-title a { 
  font-size: 1.9rem;
  color: var(--text-primary); /* Syncs with dark mode */
}

.nav-title a:hover,
.nav-title a:focus-visible { 
  color: var(--accent);
  text-shadow: 0 0 12px var(--accent-glow); 
}

/* Nav items - pushed to the right */
.nav-links {
  display: flex;
  list-style: none;
  align-items: center;
  padding: 0;
  margin: 0 0 0 auto; /* Push to right */
  gap: 12px;
}

.nav-links li {
  line-height: 1;
  padding: 4px 0;
}

.nav-links a {
  color: var(--text-muted);
  font-size: 0.95rem;
  border-bottom: none;
  padding-bottom: 2px;
}

@media (min-width: 851px) {
  .nav-links a { 
    margin-left: -10px;
    display: inline-block; 
  }
}

/* Special Terryology link styling */
.nav-links .terry-link {
  color: var(--accent);
  font-weight: 700;
  padding: 0;
  background: none;
  border: none;
  border-bottom: none;
  vertical-align: baseline;
}

.nav-links .terry-link:hover,
.nav-links .terry-link:focus-visible {
  color: var(--accent);
  border-bottom: none;
  opacity: 0.8;
}

/* --- 7. THE CANDLE --- */
.candle-toggle {
  background: none; 
  border: none; 
  padding: 0; 
  cursor: pointer;
  width: 30px; 
  height: 30px;
  display: flex; 
  flex-direction: column; 
  align-items: center; 
  justify-content: flex-end;
  position: relative;
  transform: translateY(-6px);
}

.candle-body {
  width: 11px; 
  height: 14px;
  background: var(--text-muted);
  border-radius: 2px;
  transition: var(--transition-smooth);
}

.wick { 
  width: 1.5px; 
  height: 4px; 
  background: #444; 
  position: relative; 
}

.flame {
  width: 8px; 
  height: 12px;
  background: var(--accent);
  border-radius: 50% 50% 35% 35%;
  position: absolute; 
  top: -11px; 
  left: -3.2px;
  opacity: 0; 
  transform: scale(0.5);
  transition: var(--transition-smooth);
  filter: blur(0.3px);
}

.dark-mode .candle-body { 
  background: var(--bg-primary); 
  box-shadow: 0 0 8px var(--accent-glow); 
}

.dark-mode .flame {
  opacity: 1; 
  transform: scale(1.1);
  box-shadow: 0 0 10px var(--accent), 0 0 20px var(--accent-glow);
  animation: flicker 2s infinite ease-in-out;
}

@keyframes flicker {
  0%, 100% { transform: scale(1.1) rotate(-1deg); opacity: 0.9; }
  50% { transform: scale(1) rotate(1.5deg); opacity: 1; }
}

/* --- 8. CARDS & POSTS --- */
.intro.article { 
  max-width: 750px; 
  margin: 0 auto 3.5rem auto; 
  text-align: center; 
}

.intro .article-content { 
  font-style: italic; 
  color: var(--text-muted); 
  font-size: 1.2rem; 
}

.archive-item, .content .article:not(.intro) {
  background-color: var(--bg-secondary) !important; /* Override lithium theme */
  border: 1px solid var(--border) !important;
  border-radius: 12px;
  transition: background-color 0.3s ease;
}

.archive-item { 
  padding: 1.8rem; 
  margin-bottom: 1.5rem; 
}

.content .article:not(.intro) { 
  padding: 3rem; 
  max-width: 800px; 
  margin: 0 auto 4rem auto; 
}

.archive-item-meta, .article-meta {
  color: var(--accent);
  font-size: 0.95rem;
  font-weight: 500;
  margin-bottom: 0.6rem;
}

.dark-mode .article-content, 
.dark-mode .article-content p, 
.dark-mode .archive-item-summary,
.dark-mode .article-title {
  color: var(--text-primary);
}

/* --- 9. PAGINATION --- */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  margin: var(--space-xl) 0;
  flex-wrap: wrap;
}

.pagination-btn {
  color: var(--text-muted);
  font-size: 0.95rem;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 4px;
  transition: var(--transition-smooth);
}

.pagination-btn:hover,
.pagination-btn:focus-visible {
  color: var(--accent);
  border-color: var(--accent);
  border-bottom: 1px solid var(--accent);
  background: rgba(217, 119, 6, 0.05);
}

.pagination-disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.pagination-numbers {
  display: flex;
  gap: var(--space-xs);
  align-items: center;
}

.pagination-number {
  color: var(--text-muted);
  font-size: 0.95rem;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 4px;
  transition: var(--transition-smooth);
}

.pagination-number:hover,
.pagination-number:focus-visible {
  color: var(--accent);
  border-color: var(--accent);
  border-bottom: 1px solid var(--accent);
  background: rgba(217, 119, 6, 0.05);
}

.pagination-current {
  color: var(--bg-secondary);
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 700;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  font-size: 0.95rem;
}

/* Mobile pagination */
@media (max-width: 600px) {
  .pagination {
    gap: var(--space-xs);
  }
  .pagination-btn {
    font-size: 0.85rem;
    padding: 5px 10px;
  }
}

/* --- 10. FOOTER --- */
.footer {
  background-color: var(--bg-secondary) !important; /* Override lithium theme */
  border-top: 1px solid var(--border) !important;
  padding: 1.2rem 0 !important; /* Override lithium theme */
  margin-top: 3rem; 
  text-align: center;
  transition: var(--transition-smooth);
}

.footer-links { 
  list-style: none; 
  display: flex; 
  justify-content: center; 
  flex-wrap: wrap; 
  gap: 1.2rem; 
  padding: 0; 
  margin: 0; 
}

.footer p, .footer-links a { 
  color: var(--text-muted); 
  font-size: 0.85rem; 
}

.footer-links a:hover,
.footer-links a:focus-visible { 
  color: var(--accent); 
  border: none; 
}

.footer-links-kudos img {
  height: 18px !important; /* Override lithium theme */
  width: auto !important; 
  margin-left: 6px !important; 
  display: inline-block !important; 
  transform: translateY(-2px) !important; 
  transition: var(--transition-smooth);
}

.dark-mode .footer-links-kudos img { 
  filter: invert(0.8) brightness(1.2); 
}

/* --- 11. MOBILE --- */
@media (max-width: 850px) {
  .nav { 
    height: auto; 
    padding: 1rem !important; /* Override desktop padding */
    flex-direction: column; 
    gap: 10px; 
  }
  
  .nav-title { 
    margin: 0 !important; /* Override left margin */
  }
  
  .nav-links { 
    margin: 0 !important; /* Override auto margin */
    width: 100%; 
    justify-content: center; 
  }
  
  .archive-item-meta, .article-meta { 
    margin-top: 4px;
    display: block; 
  }
  
  .footer-links li::after, .footer-links li::before { 
    content: "" !important; /* Remove separators */
    display: none !important; 
  }
  
  .footer-links { 
    gap: 0.8rem; 
  }
}

/* --- 12. DATA VAULT --- */
.terryology-vault {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin: 2.5rem 0;
  overflow: hidden;
  box-shadow: 0 4px 15px rgba(0,0,0,0.05);
}

.vault-accent {
  height: 4px;
  background: linear-gradient(90deg, #2D5A27, #D97706);
}

.vault-header {
  display: flex;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border);
  font-size: 0.75rem;
  letter-spacing: 0.05em;
  font-weight: bold;
}

.vault-status { 
  color: #2D5A27; 
  display: flex; 
  align-items: center; 
}

.pulse {
  height: 8px; 
  width: 8px; 
  background: #2D5A27; 
  border-radius: 50%;
  margin-right: 10px; 
  animation: vault-blink 2s infinite;
}

@keyframes vault-blink { 
  0%, 100% { opacity: 1; } 
  50% { opacity: 0.4; } 
}

.vault-body { 
  padding: 20px; 
  overflow-x: auto; 
}

.vault-body img, .vault-body svg { 
  width: 100% !important; /* Override any img defaults */
  height: auto !important; 
}

.vault-footer {
  background: var(--bg-tertiary);
  padding: 10px 20px;
  font-size: 0.7rem;
  color: var(--text-muted);
  text-align: center;
  border-top: 1px solid var(--border);
}

/* Vault methodology link */
.vault-methodology-link {
  color: #967E5D;
  text-decoration: underline;
  transition: var(--transition-smooth);
}

.vault-methodology-link:hover,
.vault-methodology-link:focus-visible {
  color: var(--accent);
  border-bottom: none;
}

/* --- 13. BRAND SPECS (MINI-VAULT) --- */
.mini-vault {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin: 1.5rem auto;
  max-width: 420px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}

.mini-header {
  background: var(--bg-tertiary);
  padding: 10px 15px;
  font-size: 0.75rem;
  font-weight: bold;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.mini-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
}

.mini-item {
  padding: 15px 10px;
  text-align: center;
  border-right: 1px solid var(--border);
}

.mini-item:last-child { border-right: none; }

.mini-label {
  display: block;
  font-size: 0.6rem;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.mini-value {
  font-weight: bold;
  font-size: 1rem;
}

/* Tier color coding - semantic colors that remain consistent across themes */
.tier-grail { color: #2D5A27; }
.tier-workhorse { color: #967E5D; }
.tier-overachiever { color: var(--accent); }
.tier-dud { color: #d63031; }

/* --- 14. CANDLE SPECS STRIP --- */
.candle-specs-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--bg-tertiary);
  border-left: 4px solid var(--accent);
  padding: var(--space-sm);
  margin: var(--space-md) 0;
  border-radius: 0 4px 4px 0;
}

.spec-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  border-right: 1px solid var(--border);
  padding: 12px 0;
  gap: 0.5rem;
}

.spec-item:last-child { border-right: none; }

.spec-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  min-height: 2.4rem;
  margin-bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  text-align: center;
}

/* Nudge "Efficiency" label to center visually with its icon */
.spec-item:nth-child(3) .spec-label {
  padding-left: 12px;
}

.spec-data {
  font-family: 'Lora', serif;
  font-weight: bold;
  font-size: 1.15rem;
  color: var(--text-primary);
  line-height: 1;
}

/* Mobile candle specs */
@media (max-width: 600px) {
  .candle-specs-strip { 
    padding: var(--space-xs); 
  }
  .spec-data { 
    font-size: 1rem; 
    white-space: nowrap; 
  }
  .spec-label { 
    font-size: 0.6rem; 
  }
}

/* --- 15. BLOG TAGS --- */
.blog-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: var(--space-sm);
}

.blog-tags a {
  color: var(--text-muted);
  font-size: 0.85rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 8px;
  transition: var(--transition-smooth);
}

.blog-tags a:hover,
.blog-tags a:focus-visible {
  color: var(--accent);
  border-color: var(--accent);
  border-bottom: 1px solid var(--accent);
  background: rgba(217, 119, 6, 0.05);
}

/* --- 16. VAULT AUDIT --- */
.vault-audit {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin: 3rem auto 0 auto;
  padding: 1.5rem;
  font-family: 'serif';
  max-width: 600px;
  box-shadow: 0 3px 10px rgba(0,0,0,0.05);
}

.audit-line {
  font-size: 0.7rem;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 1rem;
  text-align: center;
}

.audit-grid {
  display: flex;
  gap: 2rem;
  margin-bottom: 1rem;
  justify-content: center;
}

.audit-cell {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.audit-label {
  display: block;
  font-size: 0.6rem;
  text-transform: uppercase;
  color: var(--text-muted);
}

.audit-data {
  font-weight: bold;
  font-size: 0.9rem;
  color: var(--text-primary);
}

.audit-disclaimer {
  font-size: 0.6rem;
  font-style: italic;
  color: var(--text-muted);
  text-align: center;
}

/* Mobile stacking for audit grid */
@media (max-width: 600px) {
  .audit-grid { 
    flex-direction: column; 
    gap: 0.8rem; 
  }
}

/* --- 17. VAULT BASELINES --- */
.methodology-baselines {
  display: flex;
  gap: var(--space-lg);
  flex-wrap: wrap;
  padding: var(--space-sm) 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  margin: var(--space-md) 0;
}

.baseline-item {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.baseline-label {
  display: block;
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.baseline-value {
  font-family: 'Lora', serif;
  font-weight: bold;
  font-size: 1.1rem;
  color: var(--text-primary);
}

/* Mobile stacking for baselines */
@media (max-width: 600px) {
  .methodology-baselines {
    flex-direction: column;
    gap: var(--space-sm);
  }
}

/* --- 18. QUADRANT LEGEND --- */
.quadrant-legend {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 15px;
  margin: 2rem 0;
}

.legend-box {
  padding: 15px;
  border-radius: 4px;
  border: 1px solid var(--border);
}

/* Semantic colors for data visualization - remain consistent across themes */
.legend-box.grail { 
  border-left: 5px solid #2a9d8f; 
  background: #f0f9f8; 
}

.legend-box.dud { 
  border-left: 5px solid #e76f51; 
  background: #fef4f2; 
}