/* Base Variables & Theming */
:root {
  --primary: #667eea;
  --primary-hover: #5a6fe0;
  --secondary: #e2e8f0;
  --secondary-hover: #cbd5e1;
  --bg: #f8fafc;
  --card-bg: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --success: #10b981;
  --error: #ef4444;
  --warning: #f59e0b;
  --info: #3b82f6;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --radius: 0.5rem;
  --transition: all 0.2s ease-in-out;
}

body.dark-mode {
  --primary: #818cf8;
  --primary-hover: #6366f1;
  --secondary: #334155;
  --secondary-hover: #475569;
  --bg: #0f172a;
  --card-bg: #1e293b;
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --border: #334155;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.5), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5), 0 4px 6px -2px rgba(0, 0, 0, 0.3);
}

/* Reset and Base */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.6;
  transition: var(--transition);
}

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

ul {
  list-style: none;
}

/* Layout */
.platform-nav {
  position: sticky;
  top: 0;
  z-index: 50;
  background-color: var(--card-bg);
  border-bottom: 1px solid var(--border);
  padding: 1rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow);
}

.nav-brand {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--primary);
}

.nav-links {
  display: flex;
  gap: 1rem;
  align-items: center;
}

.solver-container {
  max-width: 900px;
  margin: 2rem auto;
  padding: 0 1rem;
}

.solver-header {
  text-align: center;
  margin-bottom: 2rem;
}

.solver-header h1 {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
  color: var(--text);
}

.solver-header p {
  color: var(--text-muted);
  font-size: 1.1rem;
}

/* Buttons */
.primary-btn, .secondary-btn, .nav-link-btn, .dark-mode-btn, .modal-close-btn, .preset-btn {
  font-family: inherit;
  cursor: pointer;
  border-radius: var(--radius);
  transition: var(--transition);
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.primary-btn {
  background-color: var(--primary);
  color: #fff;
  border: none;
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
}

.primary-btn:hover {
  background-color: var(--primary-hover);
  transform: translateY(-1px);
}

.secondary-btn {
  background-color: var(--secondary);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
}

.secondary-btn:hover {
  background-color: var(--secondary-hover);
}

.nav-link-btn {
  background: transparent;
  color: var(--text);
  border: none;
  padding: 0.5rem 1rem;
}

.nav-link-btn:hover {
  color: var(--primary);
  background-color: var(--secondary);
}

.dark-mode-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.5rem;
  border-radius: 50%;
  width: 40px;
  height: 40px;
}

.dark-mode-btn:hover {
  background-color: var(--secondary);
}

/* Input Section */
.input-card {
  background-color: var(--card-bg);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow);
  margin-bottom: 2rem;
  border: 1px solid var(--border);
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.input-group textarea {
  width: 100%;
  min-height: 150px;
  padding: 1rem;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background-color: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
  resize: vertical;
  transition: var(--transition);
}

.input-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
}

.presets-wrapper {
  margin-bottom: 1rem;
}

.presets-label {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
  display: block;
  font-weight: 600;
}

.presets-scroll {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  padding-bottom: 0.5rem;
  scrollbar-width: thin;
}

.preset-btn {
  white-space: nowrap;
  background-color: var(--secondary);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.4rem 1rem;
  font-size: 0.875rem;
  border-radius: 9999px; /* Pill shape */
}

.preset-btn:hover {
  background-color: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.options-bar {
  display: flex;
  gap: 1.5rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.option-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.option-item input[type="checkbox"] {
  accent-color: var(--primary);
  width: 1rem;
  height: 1rem;
}

.controls-bar {
  display: flex;
  justify-content: flex-end;
  gap: 1rem;
  margin-top: 1.5rem;
}

/* Solution Area */
.solution-card {
  background-color: var(--card-bg);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  margin-bottom: 2rem;
}

.solution-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.solution-header h2 {
  font-size: 1.5rem;
  color: var(--text);
}

.action-buttons {
  display: flex;
  gap: 0.5rem;
}

.solution-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

/* Badges */
.badge {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.concept-badge {
  background-color: rgba(102, 126, 234, 0.1);
  color: var(--primary);
  border: 1px solid rgba(102, 126, 234, 0.2);
}

.difficulty-badge {
  background-color: rgba(245, 158, 11, 0.1);
  color: var(--warning);
  border: 1px solid rgba(245, 158, 11, 0.2);
}

.type-badge {
  background-color: rgba(16, 185, 129, 0.1);
  color: var(--success);
  border: 1px solid rgba(16, 185, 129, 0.2);
}

/* Steps */
.steps-container {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.step-card {
  display: flex;
  background-color: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  border-left: 4px solid var(--primary);
  transition: var(--transition);
}

.step-card:hover {
  box-shadow: var(--shadow);
}

.step-number {
  background-color: rgba(102, 126, 234, 0.1);
  color: var(--primary);
  width: 3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.25rem;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
}

.step-body {
  padding: 1.25rem;
  flex-grow: 1;
}

.step-title {
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--text);
  font-size: 1.1rem;
}

.step-content {
  color: var(--text-muted);
}

.math-block {
  background-color: var(--card-bg);
  padding: 1rem;
  border-radius: var(--radius);
  margin: 1rem 0;
  border: 1px solid var(--border);
  overflow-x: auto;
  text-align: center;
}

/* Result Cards */
.final-answer-card, .verification-card, .warning-card, .error-card, .ambiguous-card {
  padding: 1.5rem;
  border-radius: var(--radius);
  margin-top: 1.5rem;
  border: 1px solid var(--border);
}

.final-answer-card {
  background-color: rgba(16, 185, 129, 0.05);
  border-left: 4px solid var(--success);
}

.final-answer-card h3 {
  color: var(--success);
  margin-bottom: 0.5rem;
}

.final-answer-text {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text);
}

.verification-card {
  background-color: rgba(59, 130, 246, 0.05);
  border-left: 4px solid var(--info);
}

.verification-card h3 {
  color: var(--info);
  margin-bottom: 0.5rem;
}

.warning-card, .ambiguous-card {
  background-color: rgba(245, 158, 11, 0.05);
  border-left: 4px solid var(--warning);
}

.warning-card h3, .ambiguous-card h3 {
  color: var(--warning);
  margin-bottom: 0.5rem;
}

.error-card {
  background-color: rgba(239, 68, 68, 0.05);
  border-left: 4px solid var(--error);
}

.error-card h3 {
  color: var(--error);
  margin-bottom: 0.5rem;
}

/* Modals */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  visibility: hidden;
  transition: var(--transition);
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal-content {
  background-color: var(--card-bg);
  border-radius: var(--radius);
  width: 90%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  transform: translateY(20px);
  transition: var(--transition);
}

.modal-overlay.active .modal-content {
  transform: translateY(0);
}

.modal-header {
  padding: 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  background-color: var(--card-bg);
  z-index: 10;
}

.modal-header h2 {
  font-size: 1.25rem;
  color: var(--text);
}

.modal-close-btn {
  background: transparent;
  border: none;
  font-size: 1.5rem;
  color: var(--text-muted);
  line-height: 1;
  padding: 0.25rem;
}

.modal-close-btn:hover {
  color: var(--error);
}

/* History */
.history-list {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.history-item {
  background-color: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  cursor: pointer;
  transition: var(--transition);
}

.history-item:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow);
}

.history-problem {
  font-weight: 500;
  margin-bottom: 0.5rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.history-answer {
  color: var(--success);
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.history-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.history-type, .history-time {
  /* optional specific styling */
}

/* Practice Quiz Mode */
.practice-container {
  padding: 1.5rem;
}

.quiz-problem {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 1.5rem;
  padding: 1rem;
  background-color: var(--bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.quiz-input-row {
  display: flex;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.quiz-input {
  flex-grow: 1;
  padding: 0.75rem;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background-color: var(--bg);
  color: var(--text);
  font-size: 1rem;
  transition: var(--transition);
}

.quiz-input:focus {
  outline: none;
  border-color: var(--primary);
}

.quiz-score {
  text-align: right;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 1rem;
}

#quiz-feedback {
  margin-top: 1rem;
  padding: 1rem;
  border-radius: var(--radius);
  font-weight: 500;
}

#quiz-feedback.correct {
  background-color: rgba(16, 185, 129, 0.1);
  color: var(--success);
  border: 1px solid rgba(16, 185, 129, 0.2);
}

#quiz-feedback.incorrect {
  background-color: rgba(239, 68, 68, 0.1);
  color: var(--error);
  border: 1px solid rgba(239, 68, 68, 0.2);
}

/* FAQ Section */
.seo-faq-section {
  max-width: 900px;
  margin: 4rem auto;
  padding: 0 1rem;
}

.seo-faq-section h2 {
  text-align: center;
  margin-bottom: 2rem;
  font-size: 2rem;
}

.faq-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.5rem;
}

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

.faq-item h3 {
  font-size: 1.1rem;
  margin-bottom: 0.75rem;
  color: var(--text);
}

.faq-item p {
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* Utilities */
.hidden {
  display: none !important;
}

.clarification {
  font-style: italic;
  color: var(--info);
  margin-top: 0.5rem;
  font-size: 0.9rem;
}

/* KaTeX Overrides */
.katex {
  font-size: 1.1em;
}

.katex-display {
  margin: 1em 0;
  padding: 0.5em;
  overflow-x: auto;
  overflow-y: hidden;
}

/* Media Queries */
@media (max-width: 768px) {
  .platform-nav {
    padding: 1rem;
    flex-wrap: wrap;
    gap: 1rem;
  }
  
  .solver-container {
    margin: 1rem auto;
  }
  
  .input-card, .solution-card {
    padding: 1.5rem;
  }
  
  .controls-bar {
    flex-direction: column;
  }
  
  .controls-bar button {
    width: 100%;
  }
  
  .solution-header {
    flex-direction: column;
    gap: 1rem;
  }
  
  .action-buttons {
    width: 100%;
    justify-content: space-between;
  }
  
  .step-card {
    flex-direction: column;
  }
  
  .step-number {
    width: 100%;
    height: 3rem;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  
  .faq-grid {
    grid-template-columns: 1fr;
  }
  
  .quiz-input-row {
    flex-direction: column;
  }
}

/* Print Styles */
@media print {
  body {
    background: white;
    color: black;
  }
  
  .platform-nav, .input-card, .action-buttons, .seo-faq-section, .modal-overlay {
    display: none !important;
  }
  
  .solver-container {
    max-width: 100%;
    margin: 0;
    padding: 0;
  }
  
  .solution-card {
    box-shadow: none;
    border: none;
    padding: 0;
  }
  
  .step-card {
    border: 1px solid #ccc;
    break-inside: avoid;
    margin-bottom: 1rem;
  }
  
  .step-number {
    background: transparent;
    color: black;
    border-right: 1px solid #ccc;
  }
  
  .final-answer-card, .verification-card {
    border: 1px solid #ccc;
    break-inside: avoid;
  }
}
