/* ====================
   CORE STYLES
   ==================== */

:root {
  --primary-bg: #f7fafd;
  --panel-bg: rgba(30, 41, 59, 0.92);
  --accent: #4299e1;
  --danger: #e74444;
  --success: #2ecc71;
  --text-main: #222;
  --text-light: #f1f1f1;
  --primary-gradient: linear-gradient(135deg, #66cbea 0%, rgb(221, 207, 207) 100%);
  --header-bg: rgba(26, 46, 36, 0.8);
  --border-light: rgba(255, 255, 255, 0.1);
  --border-medium: rgba(255, 255, 255, 0.2);
  --code-bg: rgba(0, 0, 0, 0.3);
}

/* ====================
   BASE STYLES
   ==================== */

body {
  font-family: "Inter", "Segoe UI", -apple-system, BlinkMacSystemFont, Arial, sans-serif;
  margin: 0;
  padding: 0;
  background: var(--primary-gradient);
  color: #f1f1f1;
  min-height: 100vh;
}

/* ====================
   GUIDANCE BANNER (Persistent, Dismissible)
   ==================== */

.mathlab-guidance-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: linear-gradient(135deg, rgba(26, 46, 59, 0.95) 0%, rgba(30, 41, 59, 0.95) 100%);
  border-bottom: 2px solid rgba(66, 153, 225, 0.5);
  backdrop-filter: blur(10px);
  z-index: 999;
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s ease;
  padding: 0;
  max-height: 0;
  overflow: hidden;
}

.mathlab-guidance-banner.visible {
  opacity: 1;
  pointer-events: auto;
  max-height: 80px;
  padding: 12px 20px;
}

.guidance-banner-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  max-width: 1400px;
  margin: 0 auto;
}

.guidance-banner-steps {
  display: flex;
  gap: 24px;
  align-items: center;
  flex-wrap: wrap;
  flex: 1;
}

.guidance-step {
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.8);
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 4px;
}

.guidance-step strong {
  color: #4299e1;
  font-weight: 600;
  font-size: 0.95rem;
}

.guidance-banner-close {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: rgba(255, 255, 255, 0.7);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
  transition: all 0.2s ease;
  padding: 0;
}

.guidance-banner-close:hover {
  background: rgba(255, 255, 255, 0.15);
  color: rgba(255, 255, 255, 0.9);
  transform: scale(1.05);
}

.guidance-banner-close:focus-visible {
  outline: 2px solid #4299e1;
  outline-offset: 2px;
}

@media (max-width: 768px) {
  .mathlab-guidance-banner.visible {
    max-height: 120px;
    padding: 10px 16px;
  }

  .guidance-banner-steps {
    gap: 16px;
  }

  .guidance-step {
    font-size: 0.8rem;
  }

  .guidance-banner-content {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* ====================
   LAYOUT
   ==================== */

header {
  background: var(--header-bg);
  backdrop-filter: blur(8px);
  padding: 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-light);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.2);
  transition: top 0.3s ease;
}

/* When banner is visible, header moves down */
.mathlab-guidance-banner.visible ~ header {
  top: 80px;
}

@media (max-width: 768px) {
  .mathlab-guidance-banner.visible ~ header {
    top: 120px;
  }
}

header h1 {
  margin: 0;
  font-size: 1.6rem;
  font-weight: 600;
}

.main-container {
  max-width: none;
  width: 100vw;
  margin: 0;
  padding: 1rem;
  display: grid;
  grid-template-columns: minmax(400px, 1fr) minmax(600px, 2fr);
  gap: 1rem;
  overflow: auto;
  background: var(--panel-bg);
}

.left-column {
  min-width: 400px;
  max-width: 600px;
  width: 100%;
  margin: 0;
  padding: 0;
  background: none;
}

.right-column {
  min-width: 600px;
  max-width: none;
  margin: 0;
  padding: 0 1rem;
  background: var(--panel-bg);
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
}

/* ====================
   PANELS
   ==================== */

.panel {
  background: var(--panel-bg);
  border-radius: 14px;
  padding: 1.5rem;
  margin-bottom: 1rem;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
  border: 1px solid var(--border-light);
  backdrop-filter: blur(10px);
  max-width: 100%;
  min-width: 0;
  font-size: 1.08rem;
  word-break: break-word;
  width: 100%;
  box-sizing: border-box;
  transition: all 0.2s ease;
  overflow: hidden;
}

.panel:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}

.panel h2 {
  margin-top: 0;
  font-size: 1.1rem;
  border-bottom: 1px solid var(--border-light);
  padding-bottom: 0.6rem;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  color: rgb(224, 226, 240);
  font-weight: 600;
}

/* ====================
   TABS
   ==================== */

.tab-buttons {
  display: grid;
  grid-template-rows: auto auto;
  gap: 0.6rem;
  margin-bottom: 1rem;
  padding: 0.75rem;
  z-index: 10;
  position: relative;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.10);
  border: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(12px);
}

.tab-row {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  flex-wrap: wrap;
  padding: 0.25rem;
  align-items: center;
}

.tab-buttons-inline {
  z-index: 10;
  position: relative;
  background: linear-gradient(to right, rgb(108, 116, 108), #ffffff);
  display: flex;
  align-items: center;
}

.tab-button {
  background: white;
  border: 1px solid #e2e8f0;
  color: #1a365d;
  padding: 0.6rem 1rem;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 500;
  border-radius: 10px;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  white-space: nowrap;
  flex: 0 0 auto;
  min-width: 112px;
  min-height: 40px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  letter-spacing: 0.2px;
  position: relative;
  overflow: hidden;
}

.tab-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  background: linear-gradient(to bottom, #ffffff, #f8fafc);
  border-color: #93c5fd;
}

.special-func-btn {
  background: white;
  border: 1px solid #e2e8f0;
  color: #1a365d;
  padding: 0.6rem 1rem;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 500;
  border-radius: 10px;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  white-space: nowrap;
  min-width: 112px;
  min-height: 40px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  letter-spacing: 0.2px;
  position: relative;
  overflow: hidden;
}

.special-func-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  background: linear-gradient(to bottom, #ffffff, #f8fafc);
  border-color: #93c5fd;
}

.tab-button[aria-selected="true"] {
  color: #222;
  background: #fff;
  border-bottom: 2px solid var(--accent);
}

.tab-button:hover {
  background: rgba(255, 255, 255, 0.15);
}

.tab-button.active-compare {
  background: #007bff !important;
  color: white !important;
}

.tab-compare-custom {
  margin-left: 12px;
  background: #e0e0ff;
  border: 2px solid #007bff;
  color: #007bff;
}

.tab-panel {
  max-width: 100%;
  overflow-x: auto;
  padding: 0.5rem 0.2rem 0.5rem 0.2rem;
  font-size: 1.08rem;
  width: 100%;
  box-sizing: border-box;
  word-break: break-word;
  display: none;
}

.tab-panel[aria-hidden="false"] {
  display: block;
}

/* ====================
   FORM ELEMENTS
   ==================== */

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.4rem;
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.9);
  font-weight: 500;
}

.control-input,
.form-control {
  width: 100%;
  padding: 0.8rem;
  border-radius: 6px;
  border: 1px solid var(--border-medium);
  background: rgba(0, 0, 0, 0.2);
  color: #fff;
  font-size: 1rem;
  transition: all 0.2s ease;
  box-sizing: border-box;
}

.control-input:focus,
.form-control:focus {
  outline: none;
  border-color: rgba(255, 255, 255, 0.5);
  background: rgba(0, 0, 0, 0.3);
  box-shadow: 0 0 0 3px rgba(79, 168, 251, 0.25);
}

.control-input::placeholder,
.form-control::placeholder {
  color: rgba(255, 255, 255, 0.4);
}

.control-input:hover,
.form-control:hover {
  border-color: rgba(255, 255, 255, 0.3);
}

.compact-form {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.7rem;
  align-items: start;
}

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

.form-row .form-group {
  flex: 1;
  margin-bottom: 0;
}

/* ====================
   BUTTONS
   ==================== */

.primary-btn,
.btn-primary {
  background: linear-gradient(135deg, #4fa8fb, #6a75ca);
  color: #fff;
  border: none;
  cursor: pointer;
  font-weight: 500;
  font-size: 0.9rem;
  padding: 0.7rem 1.5rem;
  border-radius: 6px;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  line-height: 1.2;
  border: 1px solid transparent;
  white-space: nowrap;
}

.primary-btn:hover,
.btn-primary:hover {
  background: linear-gradient(135deg, #3a97ea, #5964b9);
  transform: translateY(-1px);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.2);
}

.secondary-btn,
.btn-secondary {
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--border-medium);
  cursor: pointer;
  font-weight: 500;
  font-size: 0.85rem;
  padding: 0.4rem 0.75rem;
  border-radius: 4px;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  line-height: 1.2;
  white-space: nowrap;
  min-height: 32px;
}

.secondary-btn:hover,
.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: translateY(-1px);
}

.header-btn {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  text-decoration: none;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  font-size: 0.9rem;
  transition: all 0.2s ease;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.header-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: translateY(-1px);
}

/* Custom color for Plot Results button */
#plot-equation-btn {
  background: #e6d9e0 !important;
  color: #e74444 !important;
  border: none;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(229, 62, 62, 0.12);
}

#plot-equation-btn:hover {
  background: #c53030 !important;
}

.btn-group {
  display: flex;
  gap: 0.8rem;
  margin-top: 1rem;
}

.btn-width-60 {
  width: 60%;
}

.btn-width-100 {
  width: 100%;
}

/* Special function buttons */
.special-func-btn {
  background: white;
  border: 1px solid #e2e8f0;
  color: #1a365d;
  padding: 0.7rem 1.2rem;
  border-radius: 6px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s ease;
  margin: 0.5rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.special-func-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.2);
  background: linear-gradient(to bottom, #ffffff, #f8fafc);
  border-color: #93c5fd;
}

/* ====================
   RESULTS & DISPLAY
   ==================== */

.result-panel {
  position: relative;
  padding-top: 35px;  /* Space for buttons */
  min-height: 80px;
  display: flex;
  flex-direction: column;
  transition: none;
}

.action-buttons {
  position: absolute;
  top: 0;
  left: 0;
  display: flex;
  gap: 0.35rem;
  padding: 0.5rem;
}

.result-display {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 4px;
  font-family: "Courier New", monospace;
  line-height: 1.3;
  color: #a0aec0;
  padding: 0.5rem;
  text-align: center;
}

.math-expression {
  font-size: 1rem;
  color: #f1f1f1;
  width: 100%;
  max-width: 100%;
  margin: 0;
}

.math-expression .solution {
  font-family: 'Consolas', 'Monaco', monospace;
  color: #fff;
  white-space: normal;
  line-height: 1.3;
  text-align: center;
  padding: 0.3rem;
}

#result-placeholder {
  color: rgba(255, 255, 255, 0.5);
  font-style: italic;
}

.latex-expression {
  background: rgba(213, 230, 218, 0.05);
  padding: 1rem;
  border-radius: 6px;
  margin: 0.8rem 0;
  overflow-x: auto;
  background-color: #ede9f1;
}

.result-card {
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 1rem;
  transition: all 0.2s ease;
}

.result-card:hover {
  transform: translateY(-2px);
  border-color: rgba(255, 255, 255, 0.2);
}

.result-card .equation {
  font-family: 'Courier New', monospace;
  background: rgba(0, 0, 0, 0.15);
  padding: 0.6rem;
  border-radius: 4px;
  margin-bottom: 0.8rem;
  white-space: pre-wrap;
  word-break: break-all;
}

.result-card .solution {
  display: flex;
  flex-direction: column;
  margin-bottom: 0.8rem;
}

.result-card .label {
  font-weight: 500;
  color: rgba(255, 255, 255, 0.7);
  margin-bottom: 0.3rem;
}

.result-card .value {
  font-family: 'Courier New', monospace;
  word-break: break-word;
}

.solution {
  margin-top: 0.5rem;
}

.solution .label {
  color: var(--accent);
  margin-right: 0.5rem;
  font-weight: 500;
}

.solution .value {
  color: #f1f1f1;
}

.plottable-message {
  margin-top: 1rem;
  padding: 0.5rem;
  background: rgba(66, 153, 225, 0.1);
  border-left: 3px solid var(--accent);
  font-style: italic;
}

/* ====================
   DERIVATIVE ANALYSIS
   ==================== */

.derivative-analysis-results {
  margin-top: 0.3rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 0.3rem;
}

.analysis-section {
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  padding: 0.4rem;
  margin-bottom: 0; /* Remove bottom margin for grid layout */
}

.analysis-section h3 {
  color: var(--accent);
  margin-top: 0;
  margin-bottom: 0.3rem;
  font-size: 0.85rem;
  font-weight: 600;
}

.analysis-item {
  margin-bottom: 0.2rem;
  padding: 0.2rem 0.3rem;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 3px;
  font-family: 'Courier New', monospace;
  font-size: 0.8rem;
  line-height: 1.2;
}

.analysis-item .label {
  font-weight: 500;
  color: rgba(255, 255, 255, 0.8);
  margin-right: 0.5rem;
}

.analysis-item .value {
  font-family: 'Courier New', monospace;
  color: #f1f1f1;
  word-break: break-word;
  background: rgba(0, 0, 0, 0.15);
  padding: 0.2rem 0.4rem;
  border-radius: 3px;
  font-size: 0.85rem;
}

.tangent-line-result {
  background: rgba(46, 204, 113, 0.1);
  border-left: 2px solid var(--success);
  padding: 0.3rem;
  border-radius: 3px;
  margin-bottom: 0.3rem;
}

.tangent-line-result .equation {
  font-family: 'Courier New', monospace;
  color: #f1f1f1;
  background: rgba(0, 0, 0, 0.15);
  padding: 0.2rem 0.3rem;
  border-radius: 3px;
  margin-top: 0.2rem;
  font-size: 0.8rem;
}

/* ====================
   FORM HELP TEXT
   ==================== */

.form-help {
  display: block;
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.7);
  margin-top: 0.25rem;
  font-style: italic;
}

/* ====================
   PLOT SECTION
   ==================== */

.plot-container {
  width: 100%;
  max-width: 100%;
  height: 600px;
  border-radius: 12px;
  overflow: hidden;
  background: #fff;
  margin: 0;
  padding: 1rem;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  position: relative;
}

#math-plot.panel,
.panel #math-plot {
  padding: 0 !important;
  margin: 0 !important;
  background: none !important;
  box-shadow: none !important;
  border: none !important;
  position: relative !important;
  width: 100% !important;
  max-width: 100% !important;
}

#math-plot {
  z-index: 2;
  position: relative;
}

.plot-canvas {
  width: 100%;
  height: 100%;
}

.plot-controls {
  margin-bottom: 1rem;
  padding-bottom: 0.8rem;
  border-bottom: 1px solid var(--border-light);
}

.plot-type-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  margin-bottom: 0.5rem;
}

#plot-dimension-controls {
  margin-top: 0.5rem;
}

.plot-title {
  text-align: center;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
  color: #a0d0ff;
}

.plot-subtitle {
  text-align: center;
  margin-bottom: 1rem;
  font-size: 0.8rem;
  color: #e2e8f0;
}

.family-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
  padding: 0.5rem;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 4px;
}

.family-legend-item {
  display: flex;
  align-items: center;
  margin-right: 1rem;
}

.family-legend-color {
  width: 1rem;
  height: 1rem;
  border-radius: 3px;
  margin-right: 0.3rem;
}

/* ====================
   INFO BOXES & HELP
   ==================== */

.info-box {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 6px;
  padding: 0.8rem;
  border: 1px solid var(--border-light);
  margin-bottom: 0.8rem;
}

.info-box h4 {
  margin-top: 0;
  margin-bottom: 0.5rem;
  color: var(--accent);
  font-size: 0.9rem;
}

.info-box ul {
  margin: 0;
  padding-left: 1.2rem;
  font-size: 0.85rem;
}

.info-box li {
  margin-bottom: 0.3rem;
}

.info-box code {
  background: var(--code-bg);
  padding: 0.1rem 0.3rem;
  border-radius: 3px;
  color: #a0d0ff;
  font-family: 'Consolas', 'Monaco', monospace;
}

.warning-box {
  margin-top: 0.8rem;
  padding: 0.6rem;
  background: rgba(235, 153, 27, 0.1);
  border-left: 3px solid rgba(235, 153, 27, 0.6);
  border-radius: 3px;
}

.warning-box h5 {
  margin-top: 0;
  margin-bottom: 0.4rem;
  color: rgba(235, 153, 27, 0.9);
  font-size: 0.85rem;
  font-weight: 600;
}

.warning-box ul {
  margin: 0;
  padding-left: 1.2rem;
  font-size: 0.8rem;
}

.warning-box li {
  margin-bottom: 0.25rem;
  color: rgba(255, 255, 255, 0.8);
}

.syntax-help {
  margin-top: 0.25rem;
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.7);
  line-height: 1.2;
}

.syntax-help code {
  background: var(--code-bg);
  padding: 0.1rem 0.3rem;
  border-radius: 3px;
  color: #a0d0ff;
  font-family: 'Consolas', 'Monaco', monospace;
}

.input-guide,
.complexity-note {
  font-size: 0.98rem;
  margin-top: 0.5em;
  margin-bottom: 0.5em;
}

.input-guide {
  background: rgba(46, 204, 113, 0.1);
  border-left: 4px solid #2ecc71;
  padding: 10px;
  margin: 10px 0;
  border-radius: 4px;
  font-size: 0.9em;
}

.complexity-note,
.complexity-warning {
  margin: 0.8rem 0;
  padding: 0.7rem;
  border-radius: 4px;
  font-size: 0.9rem;
  display: flex;
  align-items: flex-start;
}

.complexity-note {
  background-color: rgba(66, 153, 225, 0.1);
  border-left: 3px solid rgba(66, 153, 225, 0.5);
  color: rgba(255, 255, 255, 0.9);
}

.complexity-warning {
  background: rgba(230, 126, 34, 0.2);
  border-left: 4px solid #e67e22;
  padding: 10px;
  margin: 10px 0;
  border-radius: 4px;
  font-size: 0.9em;
}

.complexity-note .icon,
.complexity-warning .icon {
  margin-right: 0.5rem;
  font-size: 1rem;
}

.complexity-note .message,
.complexity-warning .message {
  flex: 1;
  line-height: 1.4;
}

.suggestion-list {
  margin: 0.4em 0 0.4em 1.2em;
  padding: 0;
  font-size: 0.98rem;
}

.suggestion-list {
  margin-top: 8px;
  padding-left: 20px;
  list-style-type: disc;
}

.suggestion-list li {
  margin-bottom: 5px;
}

.input-syntax-guide {
  margin-top: 1rem;
  margin-bottom: 1rem;
}

/* ====================
   SPECIAL COMPONENTS
   ==================== */

.constants-container {
  margin: 1rem 0;
  padding: 0.8rem;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 6px;
  border: 1px solid var(--border-light);
}

.constants-inputs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
  margin-bottom: 0.5rem;
}

.constant-group {
  display: flex;
  align-items: center;
  margin-bottom: 0.5rem;
}

.constant-group label {
  margin-right: 0.5rem;
  font-family: 'Consolas', 'Monaco', monospace;
  color: #a0d0ff;
}

.constant-group input {
  width: 5rem;
  padding: 0.3rem;
  border-radius: 4px;
  border: 1px solid var(--border-medium);
  background: rgba(0, 0, 0, 0.3);
  color: white;
}

.family-inputs {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.family-inputs .input-group {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.family-inputs label {
  width: 40%;
}

.family-inputs input,
.family-inputs select {
  width: 55%;
}

.info-note {
  font-size: 0.9rem;
  color: #a0d0ff;
}

.info-note p {
  margin: 0.3rem 0;
}

.diff-constants-control {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.family-control {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.constant-range {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.constant-range label {
  font-size: 0.8rem;
  white-space: nowrap;
  margin-bottom: 0;
}

.constant-range input {
  width: 60px;
  padding: 0.3rem 0.5rem;
}

/* ====================
   LOADING & ERROR STATES
   ==================== */

.loading {
  background: rgba(52, 152, 219, 0.1);
  border-left: 4px solid #3498db;
  padding: 15px;
  margin: 10px 0;
  border-radius: 4px;
  text-align: center;
  font-size: 1em;
  min-height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
}

@keyframes pulse {
  0% { opacity: 0.6; }
  50% { opacity: 1; }
  100% { opacity: 0.6; }
}

.error {
  background: rgba(231, 76, 60, 0.1);
  border-left: 4px solid #e74c3c;
  padding: 15px;
  margin: 10px 0;
  border-radius: 4px;
  color: #c0392b;
}

.math-error {
  background-color: rgba(255, 50, 50, 0.1);
  border: 1px solid rgba(255, 50, 50, 0.3);
  color: #ff6b6b;
  padding: 0.7rem;
  border-radius: 4px;
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 0.9rem;
  margin: 0.5rem 0;
  line-height: 1.4;
}

.error + .syntax-help {
  margin-top: 0.8rem;
  padding: 0.8rem;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 6px;
  border-left: 3px solid var(--accent);
}

.error + .syntax-help strong {
  display: block;
  margin-bottom: 0.5rem;
  color: var(--accent);
}

.error + .syntax-help ul {
  margin: 0;
  padding-left: 1.2rem;
}

.error + .syntax-help li {
  margin-bottom: 0.4rem;
}

/* ====================
   SPECIAL STYLING
   ==================== */

.complex-note {
  margin-top: 0.5rem;
  padding: 0.5rem;
  background: rgba(0, 0, 0, 0.15);
  border-radius: 4px;
  text-align: center;
  color: rgba(255, 255, 255, 0.8);
  font-style: italic;
}

.complex-note small {
  font-size: 0.85rem;
}

.crootof-explanation {
  background: rgba(241, 196, 15, 0.1);
  border-left: 4px solid #f1c40f;
  padding: 10px 15px;
  margin: 10px 0;
  border-radius: 4px;
  font-size: 0.9em;
  line-height: 1.5;
}

.crootof-explanation .title {
  font-weight: 600;
  margin-bottom: 5px;
  color: #7d6608;
}

.numerical-approximation {
  margin-top: 8px;
  background: rgba(241, 241, 241, 0.5);
  padding: 8px;
  border-radius: 4px;
}

.numerical-approximation .label {
  font-weight: 600;
  color: #2c3e50;
}

.latex-render .note {
  font-size: 0.85rem;
  color: #a0a0a0;
  margin-top: 0.3rem;
  font-style: italic;
}

/* ====================
   TOGGLE SWITCHES
   ==================== */

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 60px;
  height: 30px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.2);
  transition: .4s;
  border-radius: 34px;
}

.toggle-slider:before {
  position: absolute;
  content: "";
  height: 22px;
  width: 22px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  transition: .4s;
  border-radius: 50%;
}

input:checked + .toggle-slider {
  background-color: #4fa8fb;
}

input:focus + .toggle-slider {
  box-shadow: 0 0 1px #4fa8fb;
}

input:checked + .toggle-slider:before {
  transform: translateX(30px);
}

.toggle-container {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  cursor: pointer;
}

.toggle-container input {
  display: none;
}

.toggle-slider {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 20px;
  background-color: rgba(255, 255, 255, 0.2);
  border-radius: 20px;
  transition: all 0.3s;
}

.toggle-slider:before {
  position: absolute;
  content: "";
  height: 16px;
  width: 16px;
  left: 2px;
  bottom: 2px;
  background-color: white;
  border-radius: 50%;
  transition: all 0.3s;
}

input:checked + .toggle-slider {
  background-color: var(--accent);
}

input:checked + .toggle-slider:before {
  transform: translateX(20px);
}

/* ====================
   EXAMPLES & HISTORY
   ==================== */

.examples-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.example-eq {
  background: rgba(0, 0, 0, 0.15);
  padding: 0.4rem 0.8rem;
  border-radius: 20px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.example-eq:hover {
  background: rgba(0, 0, 0, 0.25);
}

.history-item {
  background: rgba(0, 0, 0, 0.15);
  border-radius: 6px;
  padding: 0.8rem;
  margin-bottom: 0.8rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.history-item:hover {
  background: rgba(0, 0, 0, 0.25);
  transform: translateY(-1px);
}

.history-equation {
  font-family: 'Courier New', monospace;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 0.4rem;
}

.history-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.5);
}

/* ====================
   COMPLEX PLANE
   ==================== */

.complex-legend {
  margin-top: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  font-size: 0.9rem;
}

.complex-legend .legend-item {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.complex-legend .color-dot {
  width: 100%;
  min-width: 350px;
  max-width: 900px;
  height: 500px;
  border-radius: 8px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.98);
  margin: 0 auto;
  box-sizing: border-box;
}

.complex-legend .real-dot {
  background-color: #3498db;
}

.complex-legend .imag-dot {
  background-color: #e74c3c;
}

.complex-legend .mag-dot {
  background-color: #2ecc71;
}

/* ====================
   AREA CONTROLS
   ==================== */

.area-controls {
  display: flex;
  gap: 1rem;
  align-items: center;
  margin-bottom: 1rem;
}

.area-controls label {
  color: var(--accent);
  font-size: 0.95em;
  margin-right: 0.3rem;
}

.area-controls input[type="number"] {
  width: 80px;
  padding: 0.4rem 0.6rem;
  border-radius: 4px;
  border: 1px solid var(--accent);
  background: rgba(0, 0, 0, 0.15);
  color: #fff;
  font-size: 1em;
}

.area-result {
  margin-top: 0.7rem;
  padding: 0.7rem 1rem;
  background: rgba(46, 204, 113, 0.08);
  border-left: 4px solid #2ecc71;
  border-radius: 4px;
  color: #2ecc71;
  font-size: 1.05em;
  font-weight: 500;
}

/* ====================
   COORDINATE DISPLAY
   ==================== */

#coordinateDisplay {
  position: absolute;
  bottom: 10px;
  right: 10px;
  background: rgba(0, 0, 0, 0.7);
  color: white;
  padding: 5px 10px;
  border-radius: 4px;
  font-family: monospace;
  font-size: 12px;
  pointer-events: none;
  z-index: 10;
}

/* ====================
   PANEL CUSTOM STYLES
   ==================== */

#panel-algebraic {
  max-width: 100%;
  min-width: 0;
  word-break: break-word;
  overflow-x: auto;
  font-size: 1.08rem;
  padding: 1.2rem 0.8rem;
  width: 100%;
  box-sizing: border-box;
}

.panel-algebraic-custom {
  background: rgba(23, 21, 24, 0.98);
  max-width: 340px;
  min-width: 0;
  word-break: break-word;
  overflow-x: auto;
}

/* #integral-limits display controlled by .hidden class */

/* ====================
   RESPONSIVE DESIGN
   ==================== */

@media (max-width: 1200px) {
  .main-container {
    grid-template-columns: minmax(500px, 1.5fr) minmax(250px, 1fr);
    padding: 0 2vw;
  }
  
  .left-column {
    min-width: 500px;
    max-width: 800px;
  }
  
  .right-column {
    min-width: 250px;
    max-width: 350px;
  }
}

@media (max-width: 900px) {
  .main-container {
    grid-template-columns: 1fr;
    padding: 0 4vw;
  }
  
  .left-column,
  .right-column {
    width: 100%;
    min-width: 420px;
    max-width: 600px;
    margin: 0 auto;
    padding: 0;
  }
  
  .panel,
  #panel-algebraic {
    max-width: 100vw;
    min-width: 0;
    padding: 1rem 0.5rem;
  }
  
  .panel h2 {
    font-size: 1rem;
  }
  
  .plot-container {
    height: 300px;
    min-width: 0;
    width: 100%;
  }
  
  .tab-buttons {
    grid-template-rows: auto;
  }
  
  .tab-row {
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.25rem;
  }
  
  .tab-button {
    font-size: 0.85rem;
    padding: 0.4rem 0.8rem;
  }
}

@media (max-width: 768px) {
  .main-container {
    grid-template-columns: 1fr;
  }
  
  .form-row {
    flex-direction: column;
    gap: 0.5rem;
  }
  
  .btn-group {
    flex-direction: column;
  }
}

@media (max-width: 600px) {
  .main-container {
    padding: 0 2vw;
  }
  
  .panel,
  #panel-algebraic {
    padding: 0.5rem 0.2rem;
  }
  
  .panel h2 {
    font-size: 0.95rem;
  }
  
  .plot-container {
    height: 180px;
  }
  
  .tab-buttons {
    font-size: 0.85rem;
  }
  
  .primary-btn,
  .secondary-btn {
    font-size: 0.8rem;
    padding: 0.4rem 0.7rem;
  }
}

/* ====================
   UTILITY CLASSES
   ==================== */

.hidden {
  display: none !important;
}

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

.mt-1 {
  margin-top: 1rem;
}

.mb-1 {
  margin-bottom: 1rem;
}

.flex {
  display: flex;
}

.flex-wrap {
  flex-wrap: wrap;
}

.gap-1 {
  gap: 1rem;
}

.items-center {
  align-items: center;
}

.justify-between {
  justify-content: space-between;
}

.w-full {
  width: 100%;
}

.cursor-pointer {
  cursor: pointer;
}

/* ====================
   ORGANIZED UI LAYOUT
   ==================== */

/* Tab container with groups */
.tab-buttons {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.4rem !important;
  margin-bottom: 0.5rem !important;
  padding: 0.5rem !important;
  border-radius: 8px !important;
  background: rgba(255,255,255,0.03) !important;
}

/* Tab groups */
.tab-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.tab-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: 0.35rem !important;
  align-items: stretch;
}

/* Primary operations group */
.primary-ops {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.35rem;
}

/* Special operations group */
.special-ops {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.35rem;
}

/* Compare action */
.compare-action {
  display: flex;
  justify-content: flex-end;
  margin-top: 0.25rem;
}

/* Compare button specific */
.tab-button-compare {
  width: auto !important;
  min-width: 100px !important;
}

/* Compact button styles */
.tab-button,
.special-func-btn {
  padding: 0.4rem 0.6rem !important;
  font-size: 0.85rem !important;
  min-width: 90px !important;
  min-height: 32px !important;
  border-radius: 4px !important;
  margin: 0 !important;
  transition: all 0.2s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Special styling for Compare button */
.tab-button-compare {
  background: linear-gradient(to bottom right, #3c4f8c, #2c3a66) !important;
  border: 1px solid rgba(255,255,255,0.1) !important;
}

/* Smaller icons */
.tab-button i,
.special-func-btn i {
  font-size: 0.9em !important;
}

/* Slightly reduce header spacing */
.panel h2 {
  margin-bottom: 0.75rem !important;
}

/* ====================
   BUTTON POLISH (subtle, modern) 
   ==================== */

/* Shared glossy overlay */
.tab-button::after,
.special-func-btn::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(120% 60% at 0% 0%, rgba(255,255,255,0.35) 0%, rgba(255,255,255,0) 55%);
  opacity: 0.06;
  pointer-events: none;
  border-radius: inherit;
  transition: opacity 0.25s ease;
}

.tab-button:hover::after,
.special-func-btn:hover::after {
  opacity: 0.12;
}

/* Focus-visible rings for accessibility */
.tab-button:focus-visible,
.special-func-btn:focus-visible {
  outline: 2px solid #93c5fd;
  outline-offset: 2px;
}

/* Pressed state */
.tab-button:active,
.special-func-btn:active {
  transform: translateY(0);
  box-shadow: 0 2px 6px rgba(0,0,0,0.12);
}

/* Slightly larger radius and smoother edges */
.tab-button,
.special-func-btn {
  border-radius: 12px;
}

/* Selected tab: richer gradient and subtle glow */
.tab-button[aria-selected="true"] {
  color: #fff;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  border-color: #3b82f6;
  box-shadow: 0 6px 18px rgba(59, 130, 246, 0.25);
}

.tab-button[aria-selected="true"]:hover {
  background: linear-gradient(135deg, #2563eb, #1e40af);
  box-shadow: 0 8px 22px rgba(59, 130, 246, 0.3);
}

/* Special buttons: brighter hover and subtle inner highlight */
.special-func-btn {
  background: white;
  border: 1px solid #e2e8f0;
  color: #1a365d;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.special-func-btn:hover {
  background: linear-gradient(to bottom, #ffffff, #f8fafc);
  border-color: #93c5fd;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}