:root {
  color-scheme: light dark;
  --brand-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --brand-primary: #667eea;
  --brand-shadow: rgba(102, 126, 234, 0.3);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background: #f5f7fa;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  background: var(--brand-gradient);
  color: white;
  padding: 40px 20px;
  text-align: center;
}

header h1 {
  font-size: 2.5em;
  font-weight: 600;
  margin-bottom: 10px;
  letter-spacing: -0.02em;
}

.subtitle {
  font-size: 1.1em;
  opacity: 0.9;
  font-weight: 300;
}

.main-content {
  flex: 1;
  max-width: 1200px;
  margin: 0 auto;
  padding: 40px 20px;
  width: 100%;
}

.tabs {
  display: flex;
  border-radius: 999px;
  background: #e2e8f0;
  padding: 4px;
  margin-bottom: 25px;
  max-width: 420px;
  margin-left: auto;
  margin-right: auto;
}

.tab-btn {
  flex: 1;
  border: none;
  background: transparent;
  padding: 10px 16px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  color: #4a5568;
  transition: all 0.2s;
}

.tab-btn.active {
  background: white;
  color: #2d3748;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
}

.tab-btn span {
  display: block;
  font-size: 11px;
  font-weight: 400;
  opacity: 0.8;
}

.calculator-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 25px;
  margin-bottom: 30px;
}

.calculator-section {
  background: white;
  border-radius: 12px;
  padding: 28px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 4px 12px rgba(0, 0, 0, 0.06);
}

h2 {
  color: #34495e;
  margin-bottom: 20px;
  padding-bottom: 10px;
  border-bottom: 3px solid var(--brand-primary);
}

.input-group {
  margin-bottom: 18px;
}

label {
  display: block;
  margin-bottom: 5px;
  color: #555;
  font-weight: 500;
}

input[type="number"] {
  width: 100%;
  padding: 10px 12px;
  border: 2px solid #ddd;
  border-radius: 8px;
  font-size: 16px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

input[type="number"]:focus {
  outline: none;
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.12);
}

.hydration-buttons,
.starter-hydration-buttons,
.dough-hydration-buttons,
.weight-buttons,
.starter-pct-buttons {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-top: 10px;
}

.starter-pct-buttons {
  grid-template-columns: repeat(3, 1fr);
  /* 3 columns for starter percentage */
}


.flour-buttons,
.time-buttons {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 10px;
}

.hydration-btn,
.flour-btn,
.time-btn,
.weight-btn,
.starter-pct-btn {
  background: white;
  border: 2px solid #ddd;
  padding: 12px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: #555;
  transition: border-color 0.2s, color 0.2s, transform 0.15s, box-shadow 0.2s, background 0.2s;
  text-align: center;
}

@media (hover: hover) {

  .hydration-btn:hover,
  .flour-btn:hover,
  .time-btn:hover,
  .weight-btn:hover,
  .starter-pct-btn:hover {
    border-color: var(--brand-primary);
    color: var(--brand-primary);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.15);
  }
}

.hydration-btn.active,
.flour-btn.active,
.time-btn.active,
.weight-btn.active,
.starter-pct-btn.active {
  background: var(--brand-gradient);
  border-color: var(--brand-primary);
  color: white;
  box-shadow: 0 4px 12px var(--brand-shadow);
}

.hydration-label,
.flour-label,
.time-label {
  display: block;
  font-size: 16px;
  font-weight: 600;
}

.hydration-ratio,
.time-ratio {
  display: block;
  font-size: 10px;
  opacity: 0.7;
  margin-top: 2px;
  font-weight: 400;
}

.hydration-desc,
.flour-desc,
.time-desc {
  display: block;
  font-size: 11px;
  opacity: 0.8;
  margin-top: 3px;
}

.results {
  background: #f8f9fa;
  padding: 20px;
  border-radius: 10px;
  margin-top: 24px;
  border: 1px solid #e9ecef;
}

.results h3 {
  color: #2c3e50;
  margin-bottom: 15px;
  font-size: 1.1em;
}

.result-item {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid #dee2e6;
}

.result-item:last-child {
  border-bottom: none;
}

.result-label {
  font-weight: 500;
  color: #555;
}

.result-value {
  font-weight: bold;
  color: #2c3e50;
}

.highlight {
  background: var(--brand-gradient);
  color: white;
  padding: 14px 16px;
  border-radius: 8px;
  margin-top: 12px;
}

.highlight .result-item {
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.highlight .result-item:last-child {
  border-bottom: none;
}

.highlight .result-label,
.highlight .result-value {
  color: white;
}

.info-text {
  font-size: 0.9em;
  color: #7f8c8d;
  margin-top: 5px;
}

.hydration-btn:focus-visible,
.flour-btn:focus-visible,
.time-btn:focus-visible,
.weight-btn:focus-visible,
.starter-pct-btn:focus-visible,
.tab-btn:focus-visible {
  outline: 2px solid var(--brand-primary);
  outline-offset: 2px;
}

footer {
  background: #2d3748;
  color: white;
  padding: 30px;
  text-align: center;
}

footer a {
  color: #667eea;
  text-decoration: none;
}

footer a:hover {
  text-decoration: underline;
}

footer p {
  margin: 5px 0;
}

@media (max-width: 768px) {
  header h1 {
    font-size: 2em;
  }

  .hydration-buttons,
  .starter-hydration-buttons,
  .dough-hydration-buttons,
  .flour-buttons,
  .time-buttons,
  .weight-buttons,
  .starter-pct-buttons {
    grid-template-columns: 1fr;
  }
}

.hidden {
  display: none;
}

/* Auto dark mode */
@media (prefers-color-scheme: dark) {
  body {
    background: #111827;
    color: #f3f4f6;
  }

  .calculator-section {
    background: #1f2937;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2), 0 4px 12px rgba(0, 0, 0, 0.15);
  }

  h2 {
    color: #f3f4f6;
  }

  label,
  .result-label,
  .result-value {
    color: #e5e7eb;
  }

  .info-text,
  .hydration-ratio,
  .hydration-desc,
  .flour-desc,
  .time-desc,
  .time-ratio {
    color: #9ca3af;
  }

  .results {
    background: #374151;
    border-color: #4b5563;
  }

  .results h3 {
    color: #f3f4f6;
  }

  .result-item {
    border-bottom-color: #4b5563;
  }

  input[type="number"] {
    background: #111827;
    color: white;
    border-color: #4b5563;
  }

  .tabs {
    background: #374151;
  }

  .tab-btn {
    color: #9ca3af;
  }

  .tab-btn.active {
    background: #1f2937;
    color: white;
  }

  .hydration-btn,
  .flour-btn,
  .time-btn,
  .weight-btn,
  .starter-pct-btn {
    background: #374151;
    border-color: #4b5563;
    color: #e5e7eb;
  }

  /* Dark mode hover only on hover-capable devices (prevents sticky hover on mobile) */
  @media (hover: hover) {

    .hydration-btn:hover,
    .flour-btn:hover,
    .time-btn:hover,
    .weight-btn:hover,
    .starter-pct-btn:hover {
      border-color: var(--brand-primary);
      color: #a3bffa;
      background: #1f2937;
    }
  }

  /* Ensure active state always wins in dark mode */
  .hydration-btn.active,
  .flour-btn.active,
  .time-btn.active,
  .weight-btn.active,
  .starter-pct-btn.active {
    background: var(--brand-gradient);
    border-color: var(--brand-primary);
    color: white;
    box-shadow: 0 4px 12px var(--brand-shadow);
  }

  input[type="number"]:focus {
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
  }
}
