@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Lexend:wght@400;500;600;700&display=swap');

:root {
  --primary: #2563eb;
  --primary-glow: rgba(37, 99, 235, 0.4);
  --secondary: #10b981;
  --accent: #f59e0b;
  --danger: #ef4444;
  --success: #22c55e;
  
  --bg-color: #f8fafc;
  --card-bg: #ffffff;
  --border-color: #e2e8f0;
  --text-main: #0f172a;
  --text-muted: #64748b;
  
  --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  --radius: 1.5rem;
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dark Mode Support */
body.dark-mode {
  --bg-color: #020617;
  --card-bg: #1e293b;
  --border-color: #334155;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
}

[data-theme='dark'] {
  --bg-color: #020617;
  --card-bg: #1e293b;
  --border-color: #334155;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: 'Inter', sans-serif;
  background-color: var(--bg-color);
  color: var(--text-main);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
header {
  padding: 1.25rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 1000;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
}

.brand-icon {
  width: 2.5rem;
  height: 2.5rem;
  background: var(--primary);
  color: white;
  border-radius: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.25rem;
  box-shadow: 0 4px 6px var(--primary-glow);
}

.brand-name {
  font-family: 'Lexend', sans-serif;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary);
}

/* Hero Section */
.hero {
  padding: 4rem 2rem 2rem;
  text-align: center;
  max-width: 800px;
  margin: 0 auto;
}

.hero h1 {
  font-family: 'Lexend', sans-serif;
  font-size: 3rem;
  font-weight: 800;
  margin-bottom: 1.5rem;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.02em;
}

.hero p {
  font-size: 1.25rem;
  color: var(--text-muted);
}

/* Calculator Container */
main {
  flex: 1;
  padding: 2rem;
  max-width: 1000px;
  margin: 0 auto;
  width: 100%;
}

.calculator-card {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 3rem;
  box-shadow: var(--shadow-lg);
  margin-bottom: 4rem;
}

/* Fraction Inputs */
.fraction-grid {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2.5rem;
  margin-bottom: 3rem;
  flex-wrap: wrap;
}

.fraction-group {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.input-box {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

input[type="number"] {
  width: 4.5rem;
  height: 4rem;
  border: 2px solid var(--border-color);
  border-radius: 1rem;
  text-align: center;
  font-size: 1.5rem;
  font-weight: 600;
  font-family: 'Lexend', sans-serif;
  transition: all 0.2s;
  background: transparent;
  color: var(--text-main);
}

input[type="number"]:focus {
  border-color: var(--primary);
  outline: none;
  box-shadow: 0 0 0 4px var(--primary-glow);
  transform: translateY(-2px);
}

.whole-part {
  width: 4rem;
  border-color: var(--border-color);
}

.fraction-line {
  width: 5rem;
  height: 3px;
  background: var(--text-main);
  border-radius: 2px;
}

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

/* Button & Actions */
.actions {
  text-align: center;
  display: flex;
  gap: 1rem;
  justify-content: center;
}

.btn {
  padding: 1.1rem 2.8rem;
  border-radius: 1.25rem;
  border: none;
  font-size: 1.15rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

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

.btn-primary:hover {
  background: #1d4ed8;
  transform: translateY(-3px);
  box-shadow: 0 8px 15px var(--primary-glow);
}

.btn-outline {
  background: transparent;
  border: 2px solid var(--border-color);
  color: var(--text-muted);
}

.btn-outline:hover {
  border-color: var(--text-muted);
  background: var(--border-color);
}

/* Result Area */
.result-section {
  display: none;
  margin-top: 3.5rem;
  padding-top: 3.5rem;
  border-top: 2px dashed var(--border-color);
  animation: slideUp 0.5s ease-out;
}

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

.result-header {
  font-family: 'Lexend', sans-serif;
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 2rem;
  text-align: center;
  color: var(--secondary);
}

.step-card {
  background: var(--bg-color);
  border-radius: 1.25rem;
  padding: 2.5rem;
  margin-bottom: 1.5rem;
  position: relative;
  border: 1px solid var(--border-color);
}

.step-label {
  position: absolute;
  top: -1rem;
  left: 2rem;
  background: var(--primary);
  color: white;
  padding: 0.4rem 1rem;
  border-radius: 0.75rem;
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.step-content {
  font-size: 1.25rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
}

/* FAQ & Knowledge Section */
.seo-content {
  margin-top: 4rem;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 2rem;
  margin-bottom: 4rem;
}

.info-card {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 1.25rem;
  padding: 2rem;
}

.info-card h2 {
  color: var(--primary);
  margin-bottom: 1.5rem;
  font-size: 1.5rem;
}

.faq-item {
  margin-bottom: 1.5rem;
}

.faq-item h3 {
  font-size: 1.15rem;
  margin-bottom: 0.5rem;
  color: var(--text-main);
}

.faq-item p {
  color: var(--text-muted);
}

/* Footer */
footer {
  padding: 4rem 2rem;
  background: var(--text-main);
  color: white;
  text-align: center;
}

.footer-nav {
  display: flex;
  justify-content: center;
  gap: 2rem;
  margin-bottom: 2rem;
}

.footer-nav a {
  color: #94a3b8;
  text-decoration: none;
  font-weight: 500;
  transition: color 0.2s;
}

.footer-nav a:hover {
  color: white;
}

/* Advanced: History Bar */
.history-section {
    margin-top: 3rem;
    display: none;
}

.history-section.active { display: block; }

.history-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.history-item {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    padding: 1.25rem;
    border-radius: 1rem;
    cursor: pointer;
    transition: var(--transition);
    text-align: center;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.history-item:hover {
    transform: translateY(-5px);
    border-color: var(--primary);
    box-shadow: var(--shadow-lg);
}

/* Advanced: Quiz Mode */
.quiz-container {
    background: var(--card-bg);
    border: 2px solid var(--primary);
    border-radius: var(--radius);
    padding: 3rem;
    margin: 4rem 0;
    text-align: center;
}

.quiz-problem {
    font-size: 2.5rem;
    font-family: 'Lexend', sans-serif;
    margin-bottom: 2rem;
    color: var(--text-main);
}

.quiz-feedback {
    margin-top: 1.5rem;
    font-weight: 700;
    min-height: 1.5rem;
}

/* Advanced: Visualizer */
.visualizer-area {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    margin: 2rem 0;
}

.vis-row {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.bar-container {
    flex: 1;
    height: 30px;
    background: var(--bg-color);
    border-radius: 15px;
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.bar-fill {
    height: 100%;
    background: var(--primary);
    transition: width 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* UI Utilities */
.lang-toggle {
    background: var(--primary-light);
    color: var(--primary);
    padding: 0.5rem 1rem;
    border-radius: 2rem;
    font-weight: 700;
    cursor: pointer;
    font-size: 0.85rem;
}

/* Print Styles */
@media print {
    header, footer, .actions, .hero, .seo-content, .quiz-container { display: none !important; }
    main { padding: 0; }
    .calculator-card { box-shadow: none; border: none; padding: 0; }
    .result-section { display: block !important; padding: 0; border: none; }
    .step-card { background: white; border: 1px solid #ddd; margin-bottom: 20px; page-break-inside: avoid; }
}

/* Quiz Difficulty Tabs */
.quiz-tabs {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 2rem;
}

.tab-btn {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    padding: 0.6rem 1.2rem;
    border-radius: 0.75rem;
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition);
}

.tab-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* Math Glossary */
.glossary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
    margin-top: 3rem;
}

.glossary-item {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    padding: 1.5rem;
    border-radius: 1rem;
}

.glossary-term {
    font-weight: 800;
    color: var(--primary);
    display: block;
    margin-bottom: 0.5rem;
    font-family: 'Lexend', sans-serif;
}

/* Word Problems Section */
.word-problem {
    background: linear-gradient(to right, var(--primary-light), transparent);
    border-left: 5px solid var(--primary);
    padding: 2rem;
    border-radius: 0 1rem 1rem 0;
    margin: 2rem 0;
}

.problem-header {
    font-weight: 700;
    margin-bottom: 1rem;
    color: var(--text-main);
}

@media (max-width: 600px) {
  .hero h1 { font-size: 2.25rem; }
  .calculator-card { padding: 1.5rem; }
  .fraction-grid { gap: 1.5rem; }
}
