/* ============================================================
   FRACTIONS CALCULATOR — Premium Design System
   ============================================================ */

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

/* ---------- CSS Custom Properties ---------- */
:root {
  /* Background */
  --bg-primary: #0a0f1c;
  --bg-secondary: #0f1528;
  --bg-tertiary: #151d35;
  --bg-card: rgba(255, 255, 255, 0.04);
  --bg-card-hover: rgba(255, 255, 255, 0.07);
  --bg-glass: rgba(255, 255, 255, 0.06);
  --bg-glass-strong: rgba(255, 255, 255, 0.10);
  --bg-input: rgba(255, 255, 255, 0.05);
  --bg-input-focus: rgba(255, 255, 255, 0.08);

  /* Borders */
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-medium: rgba(255, 255, 255, 0.12);
  --border-strong: rgba(255, 255, 255, 0.18);
  --border-accent: rgba(99, 102, 241, 0.4);

  /* Primary Accent: Indigo → Purple */
  --accent-primary: #6366f1;
  --accent-primary-rgb: 99, 102, 241;
  --accent-hover: #818cf8;
  --accent-glow: rgba(99, 102, 241, 0.25);
  --accent-subtle: rgba(99, 102, 241, 0.12);

  /* Secondary Accent: Purple */
  --accent-secondary: #8b5cf6;
  --accent-secondary-rgb: 139, 92, 246;

  /* Tertiary: Cyan */
  --accent-tertiary: #06b6d4;
  --accent-tertiary-rgb: 6, 182, 212;

  /* Success/Result */
  --success: #10b981;
  --success-rgb: 16, 185, 129;
  --success-glow: rgba(16, 185, 129, 0.2);

  /* Error */
  --error: #ef4444;
  --error-rgb: 239, 68, 68;
  --error-glow: rgba(239, 68, 68, 0.2);

  /* Warning */
  --warning: #f59e0b;
  --warning-rgb: 245, 158, 11;

  /* Text */
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-tertiary: #64748b;
  --text-accent: #a5b4fc;
  --text-math: #c4b5fd;

  /* Typography */
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;

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

  /* Radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-2xl: 24px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
  --shadow-xl: 0 16px 48px rgba(0, 0, 0, 0.6);
  --shadow-glow: 0 0 30px var(--accent-glow);
  --shadow-glow-success: 0 0 30px var(--success-glow);

  /* Transitions */
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-spring: 500ms cubic-bezier(0.34, 1.56, 0.64, 1);

  /* Layout */
  --max-width: 1200px;
  --header-height: 72px;
}

/* ---------- Reset & Base ---------- */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-body);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

/* Animated Background */
body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background:
    radial-gradient(ellipse 800px 600px at 20% 20%, rgba(99, 102, 241, 0.08) 0%, transparent 70%),
    radial-gradient(ellipse 600px 800px at 80% 80%, rgba(139, 92, 246, 0.06) 0%, transparent 70%),
    radial-gradient(ellipse 400px 400px at 50% 50%, rgba(6, 182, 212, 0.04) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

/* ---------- Selection ---------- */
::selection {
  background: rgba(99, 102, 241, 0.3);
  color: var(--text-primary);
}

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar {
  width: 8px;
}
::-webkit-scrollbar-track {
  background: var(--bg-primary);
}
::-webkit-scrollbar-thumb {
  background: var(--border-medium);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--border-strong);
}

/* ---------- Typography ---------- */
h1, h2, h3, h4, h5, h6 {
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.02em;
}

h1 { font-size: clamp(2rem, 5vw, 3.5rem); }
h2 { font-size: clamp(1.5rem, 3.5vw, 2.5rem); }
h3 { font-size: clamp(1.2rem, 2.5vw, 1.75rem); }
h4 { font-size: 1.25rem; }

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

/* ---------- Layout ---------- */
.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 var(--space-lg);
}

section {
  position: relative;
  z-index: 1;
  padding: var(--space-4xl) 0;
}

/* ---------- Header / Navbar ---------- */
.navbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: rgba(10, 15, 28, 0.8);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-subtle);
  z-index: 1000;
  display: flex;
  align-items: center;
}

.navbar .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

.navbar-brand {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-weight: 800;
  font-size: 1.25rem;
  color: var(--text-primary);
  text-decoration: none;
}

.navbar-brand .brand-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
}

.navbar-brand .brand-icon .frac-line {
  width: 16px;
  height: 2px;
  background: white;
  margin: 1px 0;
  border-radius: 1px;
}

.navbar-nav {
  display: flex;
  align-items: center;
  gap: var(--space-xl);
  list-style: none;
}

.navbar-nav a {
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
  transition: color var(--transition-fast);
  position: relative;
}

.navbar-nav a::after {
  content: '';
  position: absolute;
  bottom: -4px;
  left: 0;
  width: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary));
  border-radius: 1px;
  transition: width var(--transition-base);
}

.navbar-nav a:hover {
  color: var(--text-primary);
}

.navbar-nav a:hover::after {
  width: 100%;
}

.mobile-menu-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 1.5rem;
  cursor: pointer;
  padding: var(--space-sm);
}

/* ---------- Hero Section ---------- */
.hero {
  padding-top: calc(var(--header-height) + var(--space-4xl));
  padding-bottom: var(--space-4xl);
  text-align: center;
  position: relative;
  overflow: hidden;
}

.hero::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 800px;
  height: 800px;
  background: radial-gradient(circle, rgba(99, 102, 241, 0.1) 0%, transparent 70%);
  pointer-events: none;
}

.hero-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-xs) var(--space-md);
  background: var(--accent-subtle);
  border: 1px solid var(--border-accent);
  border-radius: var(--radius-full);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-accent);
  margin-bottom: var(--space-xl);
  animation: fadeInUp 0.6s ease-out;
}

.hero-badge .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
  animation: pulse-dot 2s infinite;
}

.hero h1 {
  background: linear-gradient(135deg, var(--text-primary) 0%, var(--accent-hover) 50%, var(--accent-secondary) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: var(--space-lg);
  animation: fadeInUp 0.6s ease-out 0.1s both;
}

.hero-subtitle {
  font-size: clamp(1rem, 2vw, 1.25rem);
  color: var(--text-secondary);
  max-width: 640px;
  margin: 0 auto var(--space-2xl);
  animation: fadeInUp 0.6s ease-out 0.2s both;
}

.hero-cta {
  display: flex;
  gap: var(--space-md);
  justify-content: center;
  flex-wrap: wrap;
  animation: fadeInUp 0.6s ease-out 0.3s both;
}

/* Floating fraction elements in hero */
.hero-float {
  position: absolute;
  font-family: var(--font-mono);
  font-size: 1.5rem;
  color: rgba(99, 102, 241, 0.15);
  font-weight: 700;
  animation: float 6s ease-in-out infinite;
  pointer-events: none;
}

.hero-float:nth-child(1) { top: 20%; left: 10%; animation-delay: 0s; }
.hero-float:nth-child(2) { top: 30%; right: 12%; animation-delay: 1s; }
.hero-float:nth-child(3) { bottom: 25%; left: 15%; animation-delay: 2s; }
.hero-float:nth-child(4) { bottom: 30%; right: 10%; animation-delay: 3s; }
.hero-float:nth-child(5) { top: 50%; left: 5%; animation-delay: 4s; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: 0.75rem 1.75rem;
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all var(--transition-base);
  white-space: nowrap;
  position: relative;
  overflow: hidden;
}

.btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.1), transparent);
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.btn:hover::before {
  opacity: 1;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  color: white;
  box-shadow: 0 4px 16px rgba(var(--accent-primary-rgb), 0.3);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(var(--accent-primary-rgb), 0.4);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-secondary {
  background: var(--bg-glass);
  color: var(--text-primary);
  border: 1px solid var(--border-medium);
}

.btn-secondary:hover {
  background: var(--bg-glass-strong);
  border-color: var(--border-strong);
  transform: translateY(-2px);
}

.btn-success {
  background: linear-gradient(135deg, var(--success), #059669);
  color: white;
  box-shadow: 0 4px 16px rgba(var(--success-rgb), 0.3);
}

.btn-success:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(var(--success-rgb), 0.4);
}

.btn-sm {
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  border-radius: var(--radius-sm);
}

.btn-lg {
  padding: 1rem 2.5rem;
  font-size: 1.05rem;
  border-radius: var(--radius-lg);
}

.btn-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: var(--radius-sm);
  font-size: 1.1rem;
}

/* ---------- Glass Card ---------- */
.glass-card {
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  padding: var(--space-2xl);
  transition: all var(--transition-base);
}

.glass-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-medium);
}

.glass-card-accent {
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border-accent);
  border-radius: var(--radius-xl);
  padding: var(--space-2xl);
  box-shadow: var(--shadow-glow);
}

/* ---------- Section Headers ---------- */
.section-header {
  text-align: center;
  margin-bottom: var(--space-3xl);
}

.section-label {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent-primary);
  margin-bottom: var(--space-md);
}

.section-label .icon {
  font-size: 1rem;
}

.section-title {
  margin-bottom: var(--space-md);
}

.section-desc {
  color: var(--text-secondary);
  font-size: 1.05rem;
  max-width: 640px;
  margin: 0 auto;
}

/* ============================================================
   CALCULATOR SECTION
   ============================================================ */

#calculator {
  padding-top: var(--space-2xl);
}

.calculator-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2xl);
  align-items: start;
}

.calculator-main {
  display: flex;
  flex-direction: column;
  gap: var(--space-xl);
}

.calculator-sidebar {
  display: flex;
  flex-direction: column;
  gap: var(--space-xl);
  position: sticky;
  top: calc(var(--header-height) + var(--space-xl));
}

/* ---------- Mode Selector ---------- */
.mode-selector {
  position: relative;
}

.mode-selector label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: var(--space-sm);
}

.mode-dropdown {
  position: relative;
}

.mode-dropdown-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md) var(--space-lg);
  background: var(--bg-input);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-base);
}

.mode-dropdown-btn:hover,
.mode-dropdown-btn.active {
  background: var(--bg-input-focus);
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

.mode-dropdown-btn .mode-icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  font-size: 1.1rem;
  flex-shrink: 0;
}

.mode-dropdown-btn .chevron {
  margin-left: auto;
  font-size: 0.75rem;
  transition: transform var(--transition-fast);
  color: var(--text-tertiary);
}

.mode-dropdown-btn.active .chevron {
  transform: rotate(180deg);
}

.mode-dropdown-menu {
  position: absolute;
  top: calc(100% + var(--space-sm));
  left: 0;
  right: 0;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  padding: var(--space-sm);
  z-index: 100;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition: all var(--transition-base);
  box-shadow: var(--shadow-xl);
  max-height: 400px;
  overflow-y: auto;
}

.mode-dropdown-menu.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.mode-dropdown-menu .mode-option {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  color: var(--text-secondary);
  font-weight: 500;
}

.mode-dropdown-menu .mode-option:hover {
  background: var(--accent-subtle);
  color: var(--text-primary);
}

.mode-dropdown-menu .mode-option.selected {
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  color: white;
}

.mode-dropdown-menu .mode-option .mode-icon {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}

.mode-dropdown-menu .divider {
  height: 1px;
  background: var(--border-subtle);
  margin: var(--space-sm) 0;
}

/* ---------- Form Type Toggle ---------- */
.form-type-toggle {
  display: flex;
  gap: var(--space-sm);
  padding: 4px;
  background: var(--bg-input);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

.form-type-btn {
  flex: 1;
  padding: var(--space-sm) var(--space-md);
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.form-type-btn.active {
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  color: white;
  box-shadow: var(--shadow-sm);
}

.form-type-btn:hover:not(.active) {
  color: var(--text-primary);
  background: var(--bg-glass);
}

/* ---------- Fraction Formula Display ---------- */
.formula-display {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-lg);
  padding: var(--space-xl);
  background: var(--bg-glass);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-subtle);
  font-family: var(--font-mono);
  font-size: 1.4rem;
  color: var(--text-math);
  min-height: 100px;
}

.formula-fraction {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.formula-fraction .num,
.formula-fraction .den {
  padding: 2px 8px;
  min-width: 28px;
  text-align: center;
}

.formula-fraction .frac-bar {
  width: 100%;
  height: 2px;
  background: var(--text-math);
  border-radius: 1px;
  min-width: 28px;
}

.formula-operator {
  font-size: 1.5rem;
  color: var(--accent-primary);
  font-weight: 700;
}

.formula-equals {
  font-size: 1.5rem;
  color: var(--text-tertiary);
}

.formula-result {
  color: var(--success);
}

/* ---------- Fraction Input Groups ---------- */
.fraction-inputs {
  display: flex;
  flex-direction: column;
  gap: var(--space-xl);
}

.fraction-group {
  background: var(--bg-glass);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  transition: border-color var(--transition-fast);
}

.fraction-group:focus-within {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

.fraction-group-label {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-accent);
  margin-bottom: var(--space-md);
}

.fraction-group-label .ordinal {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--accent-subtle);
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent-primary);
}

.fraction-input-row {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.fraction-field {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex: 1;
}

.fraction-field label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.fraction-field input {
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 1.2rem;
  font-weight: 600;
  text-align: center;
  transition: all var(--transition-fast);
  outline: none;
}

.fraction-field input:focus {
  background: var(--bg-input-focus);
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

.fraction-field input::placeholder {
  color: var(--text-tertiary);
  font-weight: 400;
}

.fraction-field input.error {
  border-color: var(--error);
  box-shadow: 0 0 0 3px var(--error-glow);
}

.fraction-divider {
  width: 100%;
  height: 2px;
  background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary));
  border-radius: 1px;
  margin: 2px 0;
}

.mixed-number-field {
  flex: 0.7;
}

.single-input-field {
  max-width: 300px;
}

.single-input-field input {
  font-size: 1.1rem;
  padding: var(--space-md);
}

/* Operator between fractions */
.fraction-operator {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  color: white;
  font-size: 1.25rem;
  font-weight: 700;
  flex-shrink: 0;
  box-shadow: 0 4px 16px rgba(var(--accent-primary-rgb), 0.3);
}

/* ---------- Calculate Button ---------- */
.calc-actions {
  display: flex;
  gap: var(--space-md);
}

.calc-actions .btn-primary {
  flex: 1;
  padding: var(--space-md) var(--space-xl);
  font-size: 1.05rem;
}

.calc-actions .btn-secondary {
  padding: var(--space-md);
  min-width: 48px;
}

/* ---------- Results Section ---------- */
.results-panel {
  opacity: 0;
  transform: translateY(16px);
  transition: all var(--transition-slow);
}

.results-panel.visible {
  opacity: 1;
  transform: translateY(0);
}

.result-display {
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
}

.result-main {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-xl);
  padding: var(--space-xl);
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.08), rgba(6, 182, 212, 0.05));
  border: 1px solid rgba(16, 185, 129, 0.2);
  border-radius: var(--radius-lg);
}

.result-label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.result-value {
  font-family: var(--font-mono);
  font-size: 2rem;
  font-weight: 700;
  color: var(--success);
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.result-fraction {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.result-fraction .num {
  font-size: 1.8rem;
}

.result-fraction .frac-bar {
  width: 100%;
  height: 3px;
  background: var(--success);
  border-radius: 2px;
  min-width: 40px;
}

.result-fraction .den {
  font-size: 1.8rem;
}

.result-mixed {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.result-decimal {
  font-family: var(--font-mono);
  font-size: 1.2rem;
  color: var(--text-secondary);
  padding: var(--space-sm) var(--space-md);
  background: var(--bg-glass);
  border-radius: var(--radius-sm);
}

.result-forms {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-md);
  justify-content: center;
}

.result-form-chip {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  background: var(--bg-glass);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.result-form-chip strong {
  color: var(--text-primary);
  font-family: var(--font-mono);
}

/* ---------- Steps Section ---------- */
.steps-panel {
  margin-top: var(--space-xl);
}

.steps-toggle {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-md);
  background: none;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-accent);
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  transition: all var(--transition-fast);
}

.steps-toggle:hover {
  background: var(--bg-glass);
  border-color: var(--accent-primary);
}

.steps-toggle .chevron {
  margin-left: auto;
  transition: transform var(--transition-fast);
}

.steps-toggle.expanded .chevron {
  transform: rotate(180deg);
}

.steps-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.5s ease-in-out;
}

.steps-content.expanded {
  max-height: 5000px;
}

.step-item {
  display: flex;
  gap: var(--space-md);
  padding: var(--space-lg) 0;
  border-bottom: 1px solid var(--border-subtle);
  opacity: 0;
  transform: translateX(-16px);
  animation: stepReveal 0.4s ease-out forwards;
}

.step-item:last-child {
  border-bottom: none;
}

.step-number {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--accent-subtle);
  color: var(--accent-primary);
  font-size: 0.75rem;
  font-weight: 700;
  flex-shrink: 0;
  margin-top: 2px;
}

.step-body {
  flex: 1;
}

.step-title {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-primary);
  margin-bottom: var(--space-xs);
}

.step-description {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: var(--space-sm);
  line-height: 1.5;
}

.step-math {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  background: var(--bg-glass);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.95rem;
  color: var(--text-math);
  flex-wrap: wrap;
}

/* ============================================================
   VISUAL DIAGRAM
   ============================================================ */
.diagram-panel {
  min-height: 250px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-lg);
}

.diagram-panel .diagram-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  text-align: center;
}

.diagram-container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2xl);
  flex-wrap: wrap;
  width: 100%;
}

.diagram-fraction-visual {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-sm);
}

.diagram-fraction-label {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-accent);
}

.diagram-operator {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent-primary);
}

.diagram-equals {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-tertiary);
}

/* Pie chart styles */
.pie-chart-svg {
  transition: all var(--transition-base);
}

.pie-chart-svg .slice {
  transition: all var(--transition-base);
}

.pie-chart-svg .slice:hover {
  filter: brightness(1.2);
}

/* Bar chart styles */
.bar-visual {
  width: 120px;
  height: 24px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  display: flex;
  border: 1px solid var(--border-medium);
}

.bar-filled {
  height: 100%;
  transition: width var(--transition-slow);
}

.bar-empty {
  height: 100%;
  background: var(--bg-glass);
  flex: 1;
}

/* ---------- Diagram Type Toggle ---------- */
.diagram-type-toggle {
  display: flex;
  gap: 4px;
  padding: 3px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
}

.diagram-type-btn {
  padding: 4px 12px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text-tertiary);
  font-family: var(--font-body);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.diagram-type-btn.active {
  background: var(--accent-primary);
  color: white;
}

/* ============================================================
   HISTORY PANEL
   ============================================================ */
.history-panel {
  max-height: 300px;
  overflow-y: auto;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition-fast);
  font-size: 0.85rem;
}

.history-item:hover {
  background: var(--bg-glass);
}

.history-item .history-expr {
  font-family: var(--font-mono);
  color: var(--text-secondary);
}

.history-item .history-result {
  font-family: var(--font-mono);
  color: var(--success);
  font-weight: 600;
}

/* ============================================================
   QUICK REFERENCE SECTION
   ============================================================ */
.reference-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-lg);
}

.reference-card {
  padding: var(--space-lg);
}

.reference-card h4 {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
  color: var(--text-accent);
  font-size: 1rem;
}

.reference-table {
  width: 100%;
  border-collapse: collapse;
}

.reference-table th,
.reference-table td {
  padding: var(--space-sm);
  text-align: center;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border-subtle);
}

.reference-table th {
  color: var(--text-tertiary);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.05em;
}

.reference-table td {
  font-family: var(--font-mono);
  color: var(--text-secondary);
}

.reference-table td:last-child {
  color: var(--text-accent);
}

/* ============================================================
   HOW IT WORKS SECTION
   ============================================================ */
.how-it-works-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: var(--space-xl);
}

.how-card {
  padding: var(--space-xl);
  transition: all var(--transition-base);
}

.how-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-glow);
  border-color: var(--border-accent);
}

.how-card .how-icon {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  background: var(--accent-subtle);
  color: var(--accent-primary);
  font-size: 1.25rem;
  margin-bottom: var(--space-md);
}

.how-card h4 {
  margin-bottom: var(--space-sm);
  color: var(--text-primary);
}

.how-card p {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

.how-card .formula-example {
  margin-top: var(--space-md);
  padding: var(--space-md);
  background: var(--bg-glass);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--text-math);
  text-align: center;
}

/* ============================================================
   FAQ SECTION
   ============================================================ */
.faq-list {
  max-width: 800px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.faq-item {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  overflow: hidden;
  transition: border-color var(--transition-fast);
}

.faq-item.open {
  border-color: var(--border-accent);
}

.faq-question {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  width: 100%;
  padding: var(--space-lg);
  background: none;
  border: none;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.faq-question:hover {
  background: var(--bg-glass);
}

.faq-question .faq-icon {
  margin-left: auto;
  font-size: 0.75rem;
  color: var(--text-tertiary);
  transition: transform var(--transition-fast);
  flex-shrink: 0;
}

.faq-item.open .faq-icon {
  transform: rotate(180deg);
}

.faq-answer {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease-in-out, padding 0.3s ease;
}

.faq-item.open .faq-answer {
  max-height: 500px;
}

.faq-answer-inner {
  padding: 0 var(--space-lg) var(--space-lg);
  color: var(--text-secondary);
  font-size: 0.9rem;
  line-height: 1.7;
}

/* ============================================================
   FOOTER
   ============================================================ */
.site-footer {
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-subtle);
  padding: var(--space-3xl) 0 var(--space-xl);
}

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

.footer-brand p {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-top: var(--space-md);
  max-width: 320px;
  line-height: 1.6;
}

.footer-col h4 {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-tertiary);
  margin-bottom: var(--space-md);
}

.footer-col ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.footer-col ul a {
  color: var(--text-secondary);
  font-size: 0.9rem;
  transition: color var(--transition-fast);
}

.footer-col ul a:hover {
  color: var(--text-primary);
}

.footer-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: var(--space-xl);
  border-top: 1px solid var(--border-subtle);
  font-size: 0.85rem;
  color: var(--text-tertiary);
}

/* ============================================================
   ANIMATIONS
   ============================================================ */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes stepReveal {
  from {
    opacity: 0;
    transform: translateX(-16px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes float {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-20px) rotate(5deg); }
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(1.5); }
}

@keyframes glowPulse {
  0%, 100% { box-shadow: 0 0 20px rgba(var(--accent-primary-rgb), 0.2); }
  50% { box-shadow: 0 0 40px rgba(var(--accent-primary-rgb), 0.4); }
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.animate-in {
  animation: fadeInUp 0.5s ease-out forwards;
}

/* Staggered animation delays */
.delay-1 { animation-delay: 0.1s; }
.delay-2 { animation-delay: 0.2s; }
.delay-3 { animation-delay: 0.3s; }
.delay-4 { animation-delay: 0.4s; }
.delay-5 { animation-delay: 0.5s; }

/* ---------- Loading Spinner ---------- */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

/* ---------- Toast Notification ---------- */
.toast {
  position: fixed;
  bottom: var(--space-xl);
  right: var(--space-xl);
  padding: var(--space-md) var(--space-lg);
  background: var(--bg-tertiary);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.9rem;
  box-shadow: var(--shadow-lg);
  z-index: 9999;
  animation: slideInRight 0.3s ease-out;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.toast.success {
  border-color: rgba(var(--success-rgb), 0.3);
}

.toast.error {
  border-color: rgba(var(--error-rgb), 0.3);
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1024px) {
  .calculator-layout {
    grid-template-columns: 1fr;
  }

  .calculator-sidebar {
    position: static;
  }

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

@media (max-width: 768px) {
  :root {
    --space-4xl: 3rem;
    --space-3xl: 2.5rem;
  }

  .navbar-nav {
    display: none;
  }

  .navbar-nav.mobile-open {
    display: flex;
    flex-direction: column;
    position: absolute;
    top: var(--header-height);
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-subtle);
    padding: var(--space-lg);
    gap: var(--space-md);
  }

  .mobile-menu-btn {
    display: block;
  }

  .hero-cta {
    flex-direction: column;
    align-items: center;
  }

  .fraction-input-row {
    flex-direction: column;
  }

  .fraction-operator {
    width: 36px;
    height: 36px;
    font-size: 1rem;
  }

  .formula-display {
    font-size: 1.1rem;
    padding: var(--space-md);
  }

  .result-value {
    font-size: 1.5rem;
  }

  .glass-card {
    padding: var(--space-lg);
  }

  .footer-grid {
    grid-template-columns: 1fr;
  }

  .footer-bottom {
    flex-direction: column;
    gap: var(--space-sm);
    text-align: center;
  }

  .diagram-container {
    gap: var(--space-md);
  }

  .how-it-works-grid {
    grid-template-columns: 1fr;
  }

  .reference-grid {
    grid-template-columns: 1fr;
  }
}

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

  .glass-card {
    padding: var(--space-md);
    border-radius: var(--radius-lg);
  }

  .hero h1 {
    font-size: 1.75rem;
  }

  .result-main {
    flex-direction: column;
    text-align: center;
  }
}

/* ---------- Print Styles ---------- */
@media print {
  body {
    background: white;
    color: black;
  }

  .navbar, .hero, .site-footer, .hero-float,
  .calc-actions, .mode-selector, .form-type-toggle,
  .diagram-type-toggle, .history-panel {
    display: none !important;
  }

  .glass-card {
    background: white;
    border: 1px solid #ddd;
    box-shadow: none;
  }

  .result-value {
    color: #059669;
  }

  .step-math {
    background: #f5f5f5;
    border: 1px solid #ddd;
    color: #333;
  }
}
