/* CLS FIX: Global Defaults */
html {
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  font-synthesis-weight: none;
  -webkit-font-smoothing: antialiased;
}
img, svg {
  max-width: 100%;
  height: auto;
  display: block;
}

:root {
  --bg-body: #f8fafc;
  --bg-card: rgba(255, 255, 255, 0.9);
  --text-main: #0f172a;
  --text-muted: #334155;
  --border: #cbd5e1;
  
  /* MODERN SAAS PURPLE/INDIGO THEME */
  --primary: #4338ca;
  --primary-hover: #3730a3;
  --primary-bg: #e0e7ff;
  --primary-light: #6366f1;
  
  --radius: 12px;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;

  /* VISUAL ACCENTS */
  --accent-1: #818cf8;
  --accent-2: #38bdf8;
  --accent-3: #a78bfa;
  --accent-4: #34d399;
  --accent-5: #fbbf24;
  --accent-6: #f472b6;
  
  /* SHADOWS */
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body { 
  font-family: var(--font-sans); 
  background: var(--bg-body); 
  background-image: 
      radial-gradient(at 0% 0%, rgba(67, 56, 202, 0.03) 0px, transparent 50%),
      radial-gradient(at 100% 0%, rgba(3, 105, 161, 0.03) 0px, transparent 50%);
  background-attachment: fixed;
  color: var(--text-main); 
  line-height: 1.4; 
  font-size: 13px; 
  display: flex; 
  flex-direction: column; 
  min-height: 100vh; 
}

/* Ad Placeholder Styles */
.ad-slot {
  width: 100%;
  max-width: 1140px;
  display: none; /* Preserved display:none as per original, change via JS or CSS if needed */
  min-height: 80px;
  overflow: hidden; 
  background: transparent;
  border: none;
  border-radius: var(--radius);
  align-items: center;
  justify-content: center;
  color: var(--text-muted); 
  font-size: 0.8rem;
}
.ad-slot.top { margin-bottom: 0; }
.ad-slot.bottom { margin-top: 0.5rem; }

header { 
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 3px solid var(--primary); /* Primary blue accent */
  padding: 0.5rem 0;
  margin-bottom: 0.35rem; /* Tightened spacing */
  margin-top: 0;
  box-shadow: var(--shadow-md); /* Increased shadow to complement the bold border */
  position: relative;
  z-index: 1;
  min-height: 52px;
}
.container { 
  max-width: 1140px; 
  margin: 0 auto; 
  padding: 0 1rem; 
}

.header-top-row {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  margin-bottom: 0.2rem;
}

.brand-wrapper {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.brand-icon {
  width: 32px; 
  height: 32px;
  color: white;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  padding: 6px; 
  border-radius: 8px; 
  box-shadow: 0 2px 4px rgba(67, 56, 202, 0.25);
  flex-shrink: 0;
}

/* Header Branding - Not H1 anymore */
.site-title {
  font-size: 1.25rem; 
  font-weight: 800; 
  letter-spacing: -0.02em;
  margin: 0;
  line-height: 1.1;
  background: linear-gradient(to right, var(--text-main), #334155);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* =========================================
   UNIFIED H2 HEADING SYSTEM
   Applies unified typography & accents cleanly
   ========================================= */
.card-header h2,
.related-title,
.educational-content h2,
.example-keywords h2 {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text-main);
  position: relative;
  padding-bottom: 0.35rem;
}

.card-header h2::after,
.related-title::after,
.educational-content h2::after,
.example-keywords h2::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: 0;
  width: 32px;
  height: 2px;
  border-radius: 2px;
  background: var(--primary);
  opacity: 0.35;
}

/* Center-aligned headings get center-aligned underlines */
.related-title::after,
.formulas-section h2::after,
.about-section h2::after,
.example-keywords h2::after {
  left: 50%;
  transform: translateX(-50%);
}

@media (max-width: 640px) {
  .card-header h2,
  .related-title,
  .educational-content h2,
  .example-keywords h2 {
    font-size: 0.95rem;
  }
  
  .card-header h2::after,
  .related-title::after,
  .educational-content h2::after,
  .example-keywords h2::after {
    width: 24px;
  }
}

main { padding-bottom: 1.5rem; flex: 1; }

/* Grid Layout */
#grid {
  margin-top: 0; /* Remove artificial separation */
  padding-top: 0;
}

.grid { 
  display: grid; 
  grid-template-columns: 1fr; 
  gap: 0.75rem; 
  min-height: 480px; 
  align-items: start; /* Ensure grid items align to top (no stretch) */
}
@media (min-width: 640px) { 
  .grid { grid-template-columns: 1fr 1fr; } 
}
@media (min-width: 1024px) { 
  .grid { grid-template-columns: repeat(3, 1fr); } 
}

/* Align Card Top Edge Optically */
.card:first-child {
  margin-top: -1px;
}

/* Card Component */
.card { 
  background: var(--bg-card);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(226, 232, 240, 0.8);
  border-top: 3px solid var(--card-accent, var(--primary)); 
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  display: flex; 
  flex-direction: column; 
  height: fit-content;
}

/* Static Accents based on ID for reliability */
#percentage-of-number { --card-accent: var(--accent-1); }
#percent-of-total { --card-accent: var(--accent-2); }
#reverse-percentage { --card-accent: var(--accent-3); }
#percentage-increase { --card-accent: var(--accent-4); }
#percentage-decrease { --card-accent: var(--accent-5); }
#percentage-difference { --card-accent: var(--accent-6); }

.card-header { 
  display: flex; 
  justify-content: space-between; 
  align-items: center; 
  padding: 0.6rem 0.85rem; 
  border-bottom: 1px solid rgba(0, 0, 0, 0.06); 
  background: rgba(241, 245, 249, 0.7); 
  border-top-left-radius: var(--radius);
  border-top-right-radius: var(--radius);
}
.card-header h2 { 
  margin: 0;
}

.reset-btn { 
  background: transparent; 
  border: none; 
  cursor: pointer; 
  color: #64748b; 
  padding: 4px; 
  border-radius: 4px; 
  display: flex; 
  align-items: center; 
  transition: all 0.2s; 
}
.reset-btn:hover { 
  color: var(--text-main); 
  background: #e2e8f0; 
}
.reset-btn svg { width: 13px; height: 13px; }

/* Card Body */
.card-body { 
  padding: 0.85rem; 
  display: grid; 
  grid-template-columns: 1fr; 
  gap: 0.5rem; 
  align-content: start;
}
@media (min-width: 640px) {
  .card-body { 
      grid-template-columns: 1fr 1fr; 
  }
  .result-wrapper, .try-example, details.history, .explain-section { grid-column: 1 / -1; }
}

.field label { 
  display: block; 
  font-size: 0.7rem; 
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted); 
  margin-bottom: 0.2rem; 
  font-weight: 700; 
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.field input { 
  width: 100%; 
  height: 32px; 
  padding: 0 0.5rem; 
  border: 1px solid var(--border); 
  border-radius: 6px; 
  font-size: 0.85rem; 
  background: #fff; 
  outline: none; 
  transition: border-color 0.15s, box-shadow 0.15s;
  -moz-appearance: textfield;
  color: var(--text-main);
  font-weight: 500;
}
.field input::-webkit-outer-spin-button,
.field input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.field input:focus { 
  border-color: var(--primary); 
  box-shadow: 0 0 0 2px rgba(67, 56, 202, 0.15); 
}
.field input::placeholder { color: #94a3b8; opacity: 1; }

/* Mobile Input Optimization */
@media (max-width: 640px) {
  .field input {
    height: 40px; 
    font-size: 16px; 
  }
}

.result-wrapper {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
  margin-top: 0.25rem;
}

.result { 
  flex: 1;
  padding: 0.25rem 0.5rem;
  border-radius: 6px; 
  text-align: center; 
  font-size: 13.4px; 
  font-weight: 700; 
  min-height: 32px; 
  display: flex;
  align-items: center;
  justify-content: center;
  word-break: break-word;
  transition: all 0.3s ease;
  background: #f1f5f9; 
  color: var(--text-muted); 
  border: 1px dashed var(--border);
}

.result.filled { 
  background: var(--primary-bg); 
  color: var(--primary); 
  border: 1px solid rgba(67, 56, 202, 0.2);
}

@media (max-width: 640px) { .result { min-height: 40px; } }

@keyframes highlight-pulse {
  0% { background-color: #c7d2fe; transform: scale(1.02); }
  100% { background-color: var(--primary-bg); transform: scale(1); }
}
.result.updated { animation: highlight-pulse 0.4s cubic-bezier(0.4, 0, 0.2, 1); }

.copy-btn {
  width: 32px; 
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.2s;
}
.copy-btn:hover { 
  background: #f8fafc; 
  color: var(--primary); 
  border-color: var(--primary); 
}
.copy-btn:active { transform: translateY(1px); }
.copy-btn svg { width: 14px; height: 14px; }

@media (max-width: 640px) { .copy-btn { width: 40px; } }

/* Explanation Styles */
.explain-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.75rem;
  text-decoration: underline;
  cursor: pointer;
  margin-top: 0.25rem;
  padding: 0;
  display: none; 
  width: fit-content;
}
.explain-btn:hover { color: var(--primary); }

.explanation-box {
    display: none;
    margin-top: 0.5rem;
    padding: 0.75rem;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.75rem;
    font-family: 'Inter', monospace;
    color: var(--text-main);
    white-space: pre-wrap;
    line-height: 1.5;
}
.explanation-box.visible { display: block; }

/* Try Example Section */
.try-example {
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 8px; 
  border: 1px dashed var(--border);
  border-radius: 6px;
  font-size: 0.7rem;
  background: rgba(248, 250, 252, 0.9);
  color: var(--text-muted);
  margin-top: 0.15rem;
}
.try-example button {
  border: none;
  background: none;
  color: var(--primary);
  cursor: pointer;
  font-size: 0.7rem;
  font-weight: 700; 
  padding: 2px 4px;
  border-radius: 4px;
}
.try-example button:hover { text-decoration: underline; }

/* History Section */
details.history {
  font-size: 0.7rem; 
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  padding-top: 0.35rem; 
  margin-top: 0.15rem;
}
summary {
  cursor: pointer;
  list-style: none;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.2rem;
  user-select: none;
  color: var(--text-muted);
  transition: color 0.2s;
}
summary:hover { color: var(--primary); }
summary::-webkit-details-marker { display: none; }
summary::before {
  content: '';
  display: inline-block;
  width: 0; 
  height: 0; 
  border-top: 3px solid transparent; 
  border-bottom: 3px solid transparent;
  border-left: 4px solid currentColor;
  margin-right: 3px;
  transition: transform 0.2s;
}
details[open] summary::before { transform: rotate(90deg); }

.history-list {
  list-style: none;
  padding-top: 0.25rem;
}
.history-list li {
  padding: 0.2rem 0; 
  border-bottom: 1px dashed var(--border);
  display: flex;
  justify-content: space-between;
}
.history-list li:last-child { border-bottom: none; }
.history-val { 
  color: var(--text-main); 
  font-family: monospace; 
  font-weight: 500; 
  background: rgba(0,0,0,0.03);
  padding: 0 4px;
  border-radius: 4px;
}

/* Footer & Educational Content Styles */
footer { 
  border-top: 4px solid var(--primary); /* Primary blue accent separation */
  margin-top: auto; 
  background: #1e293b; /* Dark distinct footer background */
  contain: content;
  color: #e2e8f0; /* Lighter base text color for better contrast */
}
footer .container { 
  padding-top: 1.25rem; 
  padding-bottom: 1.25rem; 
}
.footer-bottom-section {
  background-color: transparent; /* Remove inner bg since footer has it */
  padding: 0; 
  width: 100%;
}

.footer-content-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  text-align: center;
}

/* Desktop layout: Side-by-side */
@media (min-width: 640px) {
  .footer-content-wrapper {
    flex-direction: row;
    justify-content: space-between;
    text-align: left;
  }
  .footer-info {
    text-align: left;
  }
  .footer-end-actions {
    margin-top: 0 !important; /* Override inline style from JS template */
  }
}

.evergreen-note {
  font-size: 0.7rem;
  color: #ffffff; /* Increased to pure white for maximum contrast */
  margin-bottom: 4px;
}
.trust-bar {
  font-size: 0.7rem;
  color: #f1f5f9; /* Increased to Slate 100 (almost white) */
  margin-bottom: 0.5rem;
  font-weight: 500;
  opacity: 1; /* Removed opacity reduction */
}
footer p.copyright { 
  font-size: 0.7rem; 
  color: #ffffff !important; /* Force Pure White for maximum readability */
  margin-bottom: 0.25rem;
}
footer a {
  color: #ffffff !important; /* Force Pure White for links */
  transition: color 0.2s;
  text-decoration-color: rgba(255,255,255,0.5);
}
footer a:hover {
  color: #6366f1 !important; /* Primary accent on hover */
  text-decoration-color: #6366f1;
}

.share-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #f1f5f9;
  padding: 0 14px; 
  border-radius: 20px; 
  font-size: 0.75rem; 
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  height: 32px; 
  margin: 0 auto;
  box-shadow: none;
}
.share-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  color: white;
  border-color: rgba(255, 255, 255, 0.3);
  transform: translateY(-1px);
}
.share-btn:active { transform: translateY(0); }
.share-btn svg { width: 13px; height: 13px; }

/* Compact Educational Sections for Fraction Page & General Use */
.formulas-section {
  margin: 1rem auto;
  padding: 1rem;
  max-width: 1000px;
  background: #fff;
  border-radius: 12px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.formulas-section h2 {
  text-align: center;
  margin-bottom: 0.75rem;
}

.formula-grid {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(3, 1fr);
}

@media (max-width: 1024px) {
  .formula-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 640px) {
  .formula-grid {
    grid-template-columns: 1fr;
  }
  .fraction-page .formula-grid,
  .decimal-page .formula-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
  }
}

.formula-item {
  background: #f8fafc;
  padding: 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
}
.formula-item h3 {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 0.25rem;
}
.formula-item p {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
  line-height: 1.35;
}
.formula-box {
  background: #fff;
  padding: 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  margin-top: 0.35rem;
  font-size: 0.75rem;
  line-height: 1.5;
  color: var(--text-main);
  font-family: monospace;
  display: block;
}

.about-section {
  max-width: 900px;
  margin: 0 auto 2rem auto; 
  padding: 1.5rem;
  background: #fff;
  border-radius: 12px;
  border: 1px solid var(--border);
  text-align: center;
  box-shadow: var(--shadow-sm);
}

.about-section h2 {
  margin-bottom: 0.5rem; 
}
.about-section p {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 0.75rem;
}

.instant-note {
  font-weight: 600;
  color: var(--primary);
  font-size: 0.9rem;
  margin-bottom: 0.75rem;
  display: block;
}

.feature-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.5rem;
  max-width: 600px; 
  margin: 0 auto;
  padding: 0;
  list-style: none;
}
.feature-list li {
  background-color: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px; 
  padding: 0.5rem 0.75rem;
  text-align: center;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  transition: all 0.2s;
}
.feature-list li:hover {
  background: #fff;
  border-color: var(--primary);
  color: var(--primary);
}
@media (min-width: 640px) {
  .feature-list { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
}

.faq-section {
  margin-bottom: 2rem;
  max-width: 900px; 
  margin-left: auto;
  margin-right: auto;
  background: #fff;
  padding: 1.5rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.faq-section h2 {
  margin-bottom: 1rem; 
}
.faq-item { margin-bottom: 1rem; }
.faq-item h3 { font-size: 0.9rem; font-weight: 700; color: var(--text-main); margin-bottom: 0.35rem; }
.faq-item p { font-size: 0.85rem; line-height: 1.5; color: var(--text-muted); margin: 0; }

/* Example Keywords Section */
.example-keywords {
  margin: 1rem auto;
  padding: 1rem;
  max-width: 1000px;
  background: #fff;
  border-radius: 12px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.example-keywords h2 {
  margin-bottom: 0.5rem;
  text-align: center; 
}

.example-keywords > p {
  color: var(--text-muted);
  margin-bottom: 0.75rem;
  font-size: 0.8rem;
  text-align: center;
}

.example-list {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: 1fr;
}

@media (min-width: 640px) {
  .example-list { grid-template-columns: 1fr 1fr; }
}

.example-item {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
}

.example-item h3 {
  font-size: 0.85rem;
  font-weight: 700;
  margin-bottom: 0.2rem;
  color: var(--text-main);
}

.example-item p {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.35;
}

/* Related Calculators Section */
.related-tools {
  margin: 2rem 0 1.5rem 0;
  text-align: center;
}

.related-title {
  margin-bottom: 0.75rem;
}

.related-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
}

/* Homepage Tools Hub Overlay */
.tools-hub {
  margin-top: 2rem;
  padding: 1.25rem 1.25rem;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid rgba(226, 232, 240, 0.8);
  box-shadow: var(--shadow-sm);
}

.tools-hub .related-title {
  margin-bottom: 1rem;
}

.tools-hub .related-grid {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}

@media (min-width: 1200px) {
  .tools-hub .related-grid {
    grid-template-columns: repeat(5, 1fr);
  }
}

.related-card {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.45rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-main);
  text-decoration: none;

  border-radius: 999px;
  border: 1px solid var(--border);

  background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
  box-shadow: var(--shadow-sm);

  transition: all 0.2s ease;
}

.related-card:hover {
  color: white;
  border-color: transparent;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  transform: translateY(-1px);
  box-shadow: 0 6px 14px rgba(67,56,202,0.25);
}

.related-card span {
  pointer-events: none;
}

/* Breadcrumb Styling */
.breadcrumb {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-bottom: 0.2rem;
  display: flex;
  justify-content: center;
  align-items: center;
}

.breadcrumb a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
}

.breadcrumb a:hover {
  text-decoration: underline;
}

.breadcrumb span {
  margin: 0 5px;
}

/* Page Heading Section (H1 & Description) */
.page-heading {
  max-width: 1108px;
  width: calc(100% - 2rem);
  margin: 0 auto 1rem auto;
  padding: 0.65rem 1rem;
  border-radius: var(--radius);
  background: linear-gradient(135deg, rgba(67, 56, 202, 0.05), rgba(99, 102, 241, 0.03));
  border: 1px solid rgba(226, 232, 240, 0.8);
  box-shadow: 0 4px 10px rgba(15, 23, 42, 0.03);
  text-align: center;
}

.page-heading .container {
  padding: 0; /* Prevent double-padding inside the constrained heading */
}

.page-heading h1 {
  font-size: 1.9rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.15;
  margin: 0;
  color: var(--text-main);
}

.page-description {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-muted);
  margin: 0.2rem auto 0 auto;
  line-height: 1.45;
  max-width: 760px;
}

@media (max-width: 640px) {
  .page-heading {
    padding: 0.45rem 0.85rem;
    border-radius: 10px;
    box-shadow: 0 3px 8px rgba(15, 23, 42, 0.05);
  }
  .page-heading h1 {
    font-size: 1.45rem;
    line-height: 1.12;
    letter-spacing: -0.02em;
    margin: 0;
  }
  .page-description {
    font-size: 0.88rem;
    margin-top: 0.12rem;
    line-height: 1.38;
  }
}