:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --bg-body: #f8fafc;
  --bg-card: #ffffff;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --radius: 0.75rem;
}

body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background-color: var(--bg-body);
  color: var(--text-main);
  line-height: 1.5;
}

* {
  box-sizing: border-box;
}

/* Layout */
.app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.main-content {
  flex: 1;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 1rem;
}

/* Header */
.site-header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1rem;
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--primary);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.nav-desktop {
  display: none;
}

@media(min-width: 768px) {
  .nav-desktop {
    display: flex;
    gap: 2rem;
    /* More space */
    align-items: center;
    height: 100%;
  }
}

.nav-link {
  color: var(--text-main);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.95rem;
  padding: 0.5rem 0;
  /* Add vertical target area */
  white-space: nowrap;
}

.nav-link:hover {
  color: var(--primary);
}

/* Navigation Dropdown */
.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  height: 100%;
}

.nav-item>a {
  display: flex;
  align-items: center;
  height: 100%;
  padding: 0.5rem 0;
}

.dropdown-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  /* Centered drop */
  background-color: var(--bg-card);
  min-width: 220px;
  box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  z-index: 100;
  padding: 0.5rem 0;
  flex-direction: column;
  margin-top: 0.25rem;
  /* Tiny gap */
}

/* Add a bridge so mouse doesn't lose hover over gap */
.dropdown-menu::before {
  content: '';
  position: absolute;
  top: -10px;
  left: 0;
  width: 100%;
  height: 10px;
}

.nav-item:hover .dropdown-menu {
  display: flex;
}

.dropdown-item {
  padding: 0.5rem 1rem;
  color: var(--text-main);
  text-decoration: none;
  font-size: 0.9rem;
  display: block;
}

.dropdown-item:hover {
  background-color: var(--bg-body);
  color: var(--primary);
}

/* Math Input Section */
.solver-area {
  margin-top: 1rem;
  max-width: 800px;
  margin-left: auto;
  margin-right: auto;
}

.math-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  margin-bottom: 2rem;
}

math-field {
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 0.5rem;
  font-size: 1.5rem;
  width: 100%;
  margin-bottom: 1rem;
  background: #fff;
}

math-field:focus-within {
  outline: 2px solid var(--primary);
  border-color: transparent;
}

.toolbar {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.btn {
  background: var(--bg-body);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 0.4rem 0.8rem;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s;
}

.btn:hover {
  background: var(--border);
}

.btn-primary {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.btn-primary:hover {
  background: var(--primary-hover);
}

/* Results */
.result-section {
  display: none;
  /* Hidden by default */
  animation: fadeIn 0.3s ease;
}

.result-section.active {
  display: block;
}

.result-tabs {
  display: flex;
  gap: 1rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
  overflow-x: auto;
}

.tab-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 0.5rem 1rem;
  cursor: pointer;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

.step-card {
  border-left: 3px solid var(--primary);
  background: #f1f5f9;
  padding: 1rem;
  margin-bottom: 0.5rem;
  border-radius: 0 0.5rem 0.5rem 0;
}

/* Footer & Topic Grid */
.footer {
  text-align: center;
  padding: 2rem;
  color: var(--text-muted);
  font-size: 0.9rem;
  border-top: 1px solid var(--border);
  background: #fff;
}

.grid-topics {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 1rem;
  padding: 1rem 0;
}

.topic-card {
  background: var(--bg-card);
  padding: 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  text-decoration: none;
  color: var(--text-main);
  transition: transform 0.2s;
}

.topic-card:hover {
  transform: translateY(-2px);
  border-color: var(--primary);
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(5px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* SEO Content */
.seo-content {
  margin-top: 3rem;
  line-height: 1.7;
}

.seo-content h2,
.seo-content h3 {
  margin-top: 2rem;
}

/* Mobile First Logic */

/* Default (Mobile): Show Menu Button, Hide Desktop Nav */
.menu-btn {
  display: flex;
}

.nav-desktop {
  display: none;
}

/* Desktop Media Query (900px+) */
@media(min-width: 900px) {

  /* Hide Hamburger, Show Top Bar */
  .menu-btn {
    display: none;
  }

  .nav-desktop {
    display: flex !important;
    margin-left: auto;
  }

  /* Ensure Side Nav is hidden/irrelevant on desktop */
  .side-nav {
    display: none;
  }
}

/* Side Nav Styling */
.side-nav {
  position: fixed;
  top: 0;
  left: 0;
  width: 280px;
  height: 100vh;
  background-color: var(--bg-card);
  border-right: 1px solid var(--border);
  transform: translateX(-100%);
  transition: transform 0.3s ease;
  z-index: 1000;
  overflow-y: auto;
  padding: 1rem 0;
  display: flex;
  flex-direction: column;
}

.side-nav.open {
  transform: translateX(0);
  box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
}

.side-nav-header {
  padding: 0 1.5rem 1rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.nav-group {
  margin-bottom: 1rem;
}

.nav-group-title {
  padding: 0.5rem 1.5rem;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 600;
}

.nav-item-link {
  display: block;
  padding: 0.75rem 1.5rem;
  color: var(--text-main);
  text-decoration: none;
  font-weight: 500;
  transition: background 0.2s;
}

.nav-item-link:hover {
  background-color: var(--bg-body);
  color: var(--primary);
  border-right: 3px solid var(--primary);
}

/* Menu Toggle Button Style */
.menu-btn {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0.5rem;
  margin-right: 0.5rem;
  color: var(--text-main);
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  width: 40px;
  height: 40px;
}

.menu-btn:hover {
  background-color: var(--bg-body);
}

/* Overlay */
.nav-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 990;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

.nav-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

/* Breadcrumbs */
.breadcrumbs {
  margin: 1rem 0;
  font-size: 0.95rem;
  color: var(--text-muted);
  display: flex !important;
  /* Force flex */
  flex-direction: row !important;
  /* Force row */
  flex-wrap: wrap;
  /* Allow wrapping on very small screens */
  align-items: center;
  gap: 0.6rem;
  list-style: none !important;
  /* Remove bullets */
  padding: 0.85rem 1.25rem;
  background: white;
  /* Fallback */
  background: rgba(255, 255, 255, 0.9);
  /* Glass effect base */
  backdrop-filter: blur(8px);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02);
  /* Subtle lift */
}

/* Ensure list items don't behave like blocks */
.breadcrumbs li {
  display: inline-flex !important;
  align-items: center;
  margin: 0;
  padding: 0;
}

/* Remove any default list markers */
.breadcrumbs li::before {
  content: none !important;
}

.breadcrumbs a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
  transition: all 0.2s ease;
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  background: transparent;
}

.breadcrumbs a:hover {
  background: #eff6ff;
  /* Light blue bg on hover */
  color: var(--primary-hover);
  text-decoration: none;
  transform: translateY(-1px);
}

.breadcrumbs .separator {
  margin: 0;
  color: #94a3b8;
  /* Lighter gray */
  font-size: 0.85em;
  font-weight: 400;
  user-select: none;
}

.breadcrumbs .current {
  color: var(--text-main);
  font-weight: 600;
  padding: 0.2rem 0.5rem;
  cursor: default;
}

/* Mobile Breadcrumbs */
@media (max-width: 600px) {
  .breadcrumbs {
    font-size: 0.85rem;
    padding: 0.75rem;
    gap: 0.4rem;
  }
}

/* External Links Mobile Menu Logic */
.external-links.open {
  display: block !important;
  animation: fadeIn 0.2s;
}