/* 
  Calculus Calculator - Main Stylesheet
  Design: Modern Minimalist, Responsive, Dark/Light Mode
*/

:root {
  /* Light Theme Variables */
  --bg-color: #f8fafc;
  --bg-surface: #ffffff;
  --bg-surface-hover: #f1f5f9;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --border-color: #e2e8f0;
  
  --primary-color: #6366f1; /* Indigo */
  --primary-hover: #4f46e5;
  --secondary-color: #8b5cf6; /* Violet */
  --accent-gradient: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
  
  --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);
  
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  
  --success: #10b981;
  --error: #ef4444;
  --warning: #f59e0b;
}

[data-theme="dark"] {
  /* Dark Theme Variables */
  --bg-color: #0f172a;
  --bg-surface: #1e293b;
  --bg-surface-hover: #334155;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --border-color: #334155;
  
  --primary-color: #818cf8;
  --primary-hover: #6366f1;
  --secondary-color: #a78bfa;
  
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.5);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.4);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.4);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-primary);
  line-height: 1.6;
  transition: background-color 0.3s ease, color 0.3s ease;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* --- Layout --- */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.5rem;
  width: 100%;
}

header {
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  padding: 1rem 0;
  position: sticky;
  top: 0;
  z-index: 50;
  transition: background-color 0.3s ease;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo {
  font-size: 1.5rem;
  font-weight: 700;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-decoration: none;
}

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

.nav-links a {
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.2s;
}

.nav-links a:hover, .nav-links a.active {
  color: var(--primary-color);
}

.theme-toggle {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 1.25rem;
  padding: 0.5rem;
  border-radius: var(--radius-md);
  transition: background-color 0.2s;
}

.theme-toggle:hover {
  background-color: var(--bg-surface-hover);
}

main {
  flex: 1;
  padding: 2rem 0;
}

/* --- Calculator Interface --- */
.calculator-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2rem;
}

@media (min-width: 1024px) {
  .calculator-layout {
    grid-template-columns: 400px 1fr;
  }
}

/* Left Panel: Input */
.input-panel {
  background-color: var(--bg-surface);
  border-radius: var(--radius-xl);
  padding: 1.5rem;
  box-shadow: var(--shadow-md);
  height: fit-content;
}

.tabs {
  display: flex;
  background-color: var(--bg-color);
  border-radius: var(--radius-lg);
  padding: 0.25rem;
  margin-bottom: 1.5rem;
}

.tab-btn {
  flex: 1;
  padding: 0.75rem 1rem;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  border-radius: var(--radius-md);
  transition: all 0.2s;
}

.tab-btn.active {
  background-color: var(--bg-surface);
  color: var(--primary-color);
  box-shadow: var(--shadow-sm);
}

.input-group {
  margin-bottom: 1.5rem;
}

.input-group label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
  font-size: 0.95rem;
}

.math-input-wrapper {
  position: relative;
}

.math-input {
  width: 100%;
  padding: 1rem;
  font-size: 1.1rem;
  font-family: monospace;
  border: 2px solid var(--border-color);
  border-radius: var(--radius-lg);
  background-color: var(--bg-color);
  color: var(--text-primary);
  transition: border-color 0.2s;
}

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

.katex-preview {
  margin-top: 0.75rem;
  min-height: 3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background-color: var(--bg-color);
  border-radius: var(--radius-lg);
  color: var(--text-primary);
  font-size: 1.2rem;
  overflow-x: auto;
  border: 1px dashed var(--border-color);
}

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

.options-row > div {
  flex: 1;
}

.select-input, .bounds-input {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background-color: var(--bg-color);
  color: var(--text-primary);
  font-size: 0.95rem;
}

.bounds-input {
  text-align: center;
}

.btn-primary {
  width: 100%;
  padding: 1rem;
  background: var(--accent-gradient);
  color: white;
  border: none;
  border-radius: var(--radius-lg);
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.2s;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.5rem;
}

.btn-primary:hover {
  opacity: 0.9;
}

.btn-primary:active {
  transform: scale(0.98);
}

.btn-primary:disabled {
  opacity: 0.7;
  cursor: not-allowed;
  transform: none;
}

/* Loading Spinner */
.spinner {
  width: 20px;
  height: 20px;
  border: 3px solid rgba(255,255,255,0.3);
  border-radius: 50%;
  border-top-color: white;
  animation: spin 1s linear infinite;
  display: none;
}
@keyframes spin { 100% { transform: rotate(360deg); } }

.examples {
  margin-top: 1.5rem;
  font-size: 0.85rem;
}

.examples p {
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.example-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.example-tag {
  background-color: var(--bg-color);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: 0.3rem 0.6rem;
  border-radius: 1rem;
  cursor: pointer;
  transition: all 0.2s;
}

.example-tag:hover {
  border-color: var(--primary-color);
  color: var(--primary-color);
}

/* Right Panel: Results */
.result-panel {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.result-card {
  background-color: var(--bg-surface);
  border-radius: var(--radius-xl);
  padding: 1.5rem;
  box-shadow: var(--shadow-md);
}

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

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

.copy-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.copy-btn:hover {
  color: var(--primary-color);
}

.final-result {
  font-size: 1.5rem;
  padding: 1.5rem;
  background-color: var(--bg-color);
  border-radius: var(--radius-lg);
  overflow-x: auto;
  text-align: center;
  border: 2px solid var(--primary-color);
}

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

.step-card {
  background-color: var(--bg-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  border-left: 4px solid var(--primary-color);
}

.step-card.nested {
  margin-left: 2rem;
  border-left-color: var(--secondary-color);
  background-color: transparent;
  border: 1px solid var(--border-color);
  border-left: 4px solid var(--secondary-color);
}

.step-rule {
  display: inline-block;
  background-color: var(--bg-surface);
  color: var(--primary-color);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.2rem 0.5rem;
  border-radius: 0.25rem;
  margin-bottom: 0.5rem;
  border: 1px solid var(--border-color);
}

.step-desc {
  color: var(--text-secondary);
  margin-bottom: 0.75rem;
  font-size: 0.95rem;
}

.step-math {
  font-size: 1.1rem;
  overflow-x: auto;
  padding: 0.5rem 0;
}

/* Graph */
.graph-container {
  width: 100%;
  height: 400px;
  background-color: var(--bg-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

/* Alerts & Errors */
.alert {
  padding: 1rem;
  border-radius: var(--radius-md);
  margin-bottom: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.alert-error {
  background-color: rgba(239, 68, 68, 0.1);
  border: 1px solid var(--error);
  color: var(--error);
}

.alert-title {
  font-weight: 700;
}

.alert-suggestion {
  font-size: 0.9rem;
  opacity: 0.9;
}

.hidden {
  display: none !important;
}

/* --- Mobile Symbol Keyboard --- */
.symbol-keyboard {
  background-color: var(--bg-surface);
  border-top: 1px solid var(--border-color);
  padding: 0.5rem;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.25rem;
}

@media (min-width: 1024px) {
  .symbol-keyboard {
    display: none; /* Hide on regular desktop unless activated */
  }
}

.key-btn {
  background-color: var(--bg-color);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  border-radius: 0.25rem;
  padding: 0.5rem 0;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  touch-action: manipulation;
}

.key-btn:active {
  background-color: var(--border-color);
}

.key-btn.action {
  background-color: rgba(99, 102, 241, 0.1);
  color: var(--primary-color);
  font-weight: 700;
}

/* Footer */
footer {
  text-align: center;
  padding: 2rem 0;
  color: var(--text-secondary);
  font-size: 0.9rem;
  border-top: 1px solid var(--border-color);
  background-color: var(--bg-surface);
}

.support-notice {
  font-size: 0.85rem;
  margin-top: 1rem;
  padding: 1rem;
  background-color: var(--bg-color);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
}
