/* === CSS Custom Properties (Dark Theme) === */
:root {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-panel: #1e2a47;
  --bg-input: #0f1729;
  --border: #2a3a5c;
  --border-focus: #4a6fa5;
  --text-primary: #e0e0e0;
  --text-secondary: #a0a8b8;
  --text-muted: #6b7280;
  --accent-a: #f59e0b;
  --accent-b: #3b82f6;
  --accent-hover: #fbbf24;
  --danger: #ef4444;
  --success: #10b981;
  --radius: 6px;
  --shadow: 0 2px 8px rgba(0,0,0,0.3);
}

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

html {
  font-size: 14px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
}

/* === Header === */
.header {
  text-align: center;
  padding: 1.2rem 1rem 0.8rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
}

.header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.header p {
  color: var(--text-secondary);
  font-size: 0.85rem;
  margin-top: 0.2rem;
}

/* === Main Layout === */
.app-container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1rem;
}

.panels-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1rem;
}

/* === Setup Panel === */
.setup-panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
  /* Reserve space before JS populates panels — prevents CLS on graph-controls / chart below */
  min-height: 780px;
}

.setup-panel[data-setup="A"] {
  border-top: 3px solid var(--accent-a);
}

.setup-panel[data-setup="B"] {
  border-top: 3px solid var(--accent-b);
}

.panel-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.8rem;
}

.panel-label {
  font-size: 1.1rem;
  font-weight: 700;
}

.panel-label-a { color: var(--accent-a); }
.panel-label-b { color: var(--accent-b); }

.panel-reset {
  margin-left: auto;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.75rem;
}

.panel-reset:hover {
  border-color: var(--danger);
  color: var(--danger);
}

/* === Form Elements === */
.field-group {
  margin-bottom: 0.75rem;
}

.field-group label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 0.25rem;
  font-weight: 500;
}

select, input[type="number"], input[type="text"] {
  width: 100%;
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.45rem 0.5rem;
  font-size: 0.85rem;
  font-family: inherit;
  transition: border-color 0.15s;
}

select:focus, input:focus {
  outline: none;
  border-color: var(--border-focus);
}

select {
  cursor: pointer;
}

/* === Gear Ratios Grid === */
.gear-ratios-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
}

.gear-ratio-field {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.gear-ratio-field span {
  font-size: 0.75rem;
  color: var(--text-muted);
  min-width: 2.2rem;
  text-align: right;
}

.gear-ratio-field input {
  flex: 1;
  min-width: 0;
}

/* === Axle Ratio Quick Picks === */
.quick-picks {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.3rem;
}

.quick-pick-btn {
  background: var(--bg-input);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.2rem 0.5rem;
  font-size: 0.72rem;
  cursor: pointer;
  transition: all 0.15s;
}

.quick-pick-btn:hover {
  border-color: var(--border-focus);
  color: var(--text-primary);
}

/* === Tire Fields Row === */
.tire-fields-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.4rem;
}

.tire-field label {
  font-size: 0.7rem;
}

/* === RPM Fields Row === */
.rpm-fields-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
}

/* === Graph Controls === */
.graph-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  min-height: 2.5rem; /* Reserve space to prevent CLS */
}

.toggle-group {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.toggle-btn {
  background: var(--bg-input);
  color: var(--text-secondary);
  border: none;
  padding: 0.4rem 0.9rem;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}

.toggle-btn.active {
  background: var(--border-focus);
  color: #fff;
}

.toggle-btn:not(:last-child) {
  border-right: 1px solid var(--border);
}

/* === Chart Area === */
.chart-container {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
  position: relative;
}

.chart-wrapper {
  position: relative;
  width: 100%;
  height: 450px;
}

.chart-wrapper canvas {
  width: 100% !important;
  height: 100% !important;
}

.chart-side-by-side {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.chart-side-by-side .chart-wrapper {
  height: 400px;
}

.chart-side-label {
  text-align: center;
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 0.3rem;
}

.chart-side-label-a { color: var(--accent-a); }
.chart-side-label-b { color: var(--accent-b); }

.chart-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 400px;
  color: var(--text-muted);
  font-size: 1rem;
}

/* === Action Buttons (Share / Print) === */
.action-btn {
  background: var(--bg-input);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.4rem 0.9rem;
  font-size: 0.8rem;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}

.action-btn:hover {
  border-color: var(--border-focus);
  color: var(--text-primary);
}

/* === SEO Presets Section === */
.seo-presets {
  margin-top: 2rem;
  padding: 1.5rem;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.seo-presets h2 {
  font-size: 1.1rem;
  margin-bottom: 1rem;
  color: var(--text-primary);
}

.seo-presets h3 {
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
  margin-top: 1rem;
  color: var(--text-secondary);
}

.seo-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}

.seo-presets ul {
  list-style: none;
  padding: 0;
}

.seo-presets li {
  font-size: 0.8rem;
  color: var(--text-muted);
  padding: 0.2rem 0;
  line-height: 1.4;
}

.seo-presets li strong {
  color: var(--text-secondary);
}

/* === Toast notification === */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--success);
  color: #fff;
  padding: 0.6rem 1.2rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
  z-index: 9999;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}

.toast.visible {
  opacity: 1;
}

/* === Section Headings inside panel === */
.section-heading {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.4rem;
  margin-top: 0.6rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.2rem;
}

/* === Responsive === */
@media (max-width: 900px) {
  .panels-row {
    grid-template-columns: 1fr;
  }

  .chart-side-by-side {
    grid-template-columns: 1fr;
  }

  .chart-wrapper {
    height: 350px;
  }
}

@media (max-width: 900px) {
  .seo-columns {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 500px) {
  html {
    font-size: 13px;
  }

  .gear-ratios-grid {
    grid-template-columns: 1fr;
  }

  .tire-fields-row {
    grid-template-columns: 1fr;
  }

  /* Single-column grids make panels taller */
  .setup-panel {
    min-height: 960px;
  }

  .header h1 {
    font-size: 1.2rem;
  }

  .chart-wrapper {
    height: 280px;
  }
}

/* === Print Styles === */
@media print {
  body {
    background: #fff;
    color: #000;
    font-size: 11px;
  }

  .header {
    background: none;
    border-bottom: 2px solid #000;
    padding: 0.5rem 0;
  }

  .header h1 { color: #000; }
  .header p { color: #333; }

  .setup-panel {
    background: #fff;
    border: 1px solid #ccc;
    box-shadow: none;
    break-inside: avoid;
  }

  .setup-panel[data-setup="A"] { border-top: 3px solid #d97706; }
  .setup-panel[data-setup="B"] { border-top: 3px solid #2563eb; }

  .graph-controls {
    display: none;
  }

  .chart-container {
    background: #fff;
    border: 1px solid #ccc;
    box-shadow: none;
    break-inside: avoid;
  }

  .chart-wrapper {
    height: 350px;
  }

  .seo-presets {
    display: none;
  }

  .toast {
    display: none;
  }

  select, input[type="number"], input[type="text"] {
    background: #fff;
    color: #000;
    border: 1px solid #999;
  }

  .section-heading {
    color: #333;
    border-color: #ccc;
  }

  .quick-picks {
    display: none;
  }

  .panel-reset {
    display: none;
  }

  .field-group label {
    color: #333;
  }

  .gear-ratio-field span {
    color: #555;
  }
}
