@import url('https://fonts.googleapis.com/css2?family=DM+Serif+Display:ital@0;1&family=JetBrains+Mono:wght@400;600&family=Outfit:wght@300;400;500;600;700&display=swap');

:root {
  --bg: #0a0e17;
  --bg2: #111827;
  --bg3: #1a2236;
  --surface: #1e293b;
  --border: #2d3a52;
  --text: #e2e8f0;
  --text2: #94a3b8;
  --text3: #64748b;
  --accent: #22d3ee;
  --accent2: #06b6d4;
  --accent-glow: rgba(34, 211, 238, 0.15);
  --green: #4ade80;
  --green-dim: rgba(74, 222, 128, 0.15);
  --yellow: #facc15;
  --yellow-dim: rgba(250, 204, 21, 0.12);
  --red: #f87171;
  --red-dim: rgba(248, 113, 113, 0.12);
  --orange: #fb923c;
  --purple: #a78bfa;
  --font-display: 'DM Serif Display', Georgia, serif;
  --font-body: 'Outfit', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --radius: 12px;
  --radius-sm: 8px;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-weight: 400;
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

/* Background grain effect */
body::before {
  content: '';
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.03'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 0;
}

#app { position: relative; z-index: 1; }

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 24px;
}

/* ===== HEADER ===== */
header {
  padding: 48px 0 32px;
  text-align: center;
  position: relative;
}

header::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 120px;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
}

h1 {
  font-family: var(--font-display);
  font-size: clamp(2rem, 5vw, 3.2rem);
  font-weight: 400;
  letter-spacing: -0.01em;
  color: var(--text);
  margin-bottom: 8px;
}

h1 span { color: var(--accent); }

.subtitle {
  color: var(--text3);
  font-size: 0.95rem;
  font-weight: 300;
  letter-spacing: 0.04em;
}

/* ===== CARDS ===== */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  margin-bottom: 20px;
}

.card-title {
  font-family: var(--font-display);
  font-size: 1.35rem;
  margin-bottom: 20px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 10px;
}

.card-title .icon {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: var(--accent-glow);
  border: 1px solid var(--accent2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}

/* ===== FORM ===== */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.field select,
.field input {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.95rem;
  padding: 10px 14px;
  outline: none;
  transition: border-color 0.2s;
}

.field select:focus,
.field input:focus {
  border-color: var(--accent2);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.field select { cursor: pointer; }

/* ===== BUTTONS ===== */
.btn {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.9rem;
  padding: 12px 28px;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: all 0.2s;
  letter-spacing: 0.02em;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent2), #0891b2);
  color: #0a0e17;
  box-shadow: 0 4px 20px rgba(6, 182, 212, 0.3);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 28px rgba(6, 182, 212, 0.4);
}

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

.btn-secondary {
  background: var(--bg3);
  color: var(--text2);
  border: 1px solid var(--border);
}

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

.btn-sm {
  padding: 6px 14px;
  font-size: 0.78rem;
  border-radius: 6px;
}

.btn-remove {
  background: var(--red-dim);
  color: var(--red);
  border: 1px solid rgba(248, 113, 113, 0.25);
  font-size: 0.72rem;
  padding: 4px 10px;
  border-radius: 5px;
  cursor: pointer;
  transition: all 0.15s;
  font-family: var(--font-body);
  font-weight: 500;
  white-space: nowrap;
}

.btn-remove:hover {
  background: rgba(248, 113, 113, 0.25);
}

.actions {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-top: 20px;
  flex-wrap: wrap;
}

/* ===== RESULTS TABLE ===== */
.results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.results-table th {
  text-align: left;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text3);
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.results-table td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(45, 58, 82, 0.4);
  vertical-align: middle;
}

.results-table tr:hover td {
  background: rgba(34, 211, 238, 0.03);
}

.results-table .food-name {
  font-weight: 500;
  color: var(--text);
  max-width: 220px;
}

.results-table .num {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  text-align: right;
  color: var(--text2);
}

.results-table .why-cell {
  font-size: 0.78rem;
  color: var(--text3);
  max-width: 280px;
}

.why-tag {
  display: inline-block;
  background: var(--accent-glow);
  border: 1px solid rgba(34, 211, 238, 0.2);
  color: var(--accent);
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 0.72rem;
  font-family: var(--font-mono);
  margin: 1px 2px;
  white-space: nowrap;
}

.total-row td {
  font-weight: 600;
  color: var(--text);
  border-top: 2px solid var(--border);
  border-bottom: none;
}

/* ===== NUTRIENT TABLE ===== */
.nutrient-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.nutrient-table th {
  text-align: left;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text3);
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}

.nutrient-table td {
  padding: 6px 10px;
  border-bottom: 1px solid rgba(45, 58, 82, 0.3);
  font-family: var(--font-mono);
  font-size: 0.78rem;
}

.nutrient-table .name-col { font-family: var(--font-body); color: var(--text2); }

.status-ok { color: var(--green); }
.status-binding { color: var(--yellow); }
.status-low { color: var(--red); }
.status-high { color: var(--orange); }

/* Bar visualization */
.nutrient-bar-wrap {
  width: 80px;
  height: 6px;
  background: var(--bg3);
  border-radius: 3px;
  overflow: hidden;
  display: inline-block;
  vertical-align: middle;
  margin-left: 8px;
}

.nutrient-bar {
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s ease;
}

/* ===== ENERGY DISPLAY ===== */
.energy-display {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 6px;
}

.energy-number {
  font-family: var(--font-mono);
  font-size: 2.8rem;
  font-weight: 600;
  color: var(--accent);
  line-height: 1;
}

.energy-unit {
  font-size: 1rem;
  color: var(--text3);
  font-weight: 300;
}

.energy-label {
  font-size: 0.82rem;
  color: var(--text3);
}

/* ===== EXCLUDED LIST ===== */
.excluded-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.excluded-tag {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text3);
  padding: 4px 10px;
  border-radius: 5px;
  font-size: 0.78rem;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: all 0.15s;
}

.excluded-tag:hover {
  border-color: var(--green);
  color: var(--green);
}

.excluded-tag .restore-icon {
  font-size: 0.7rem;
  opacity: 0.6;
}

/* ===== SECTION TOGGLE ===== */
.toggle-section {
  cursor: pointer;
  user-select: none;
}

.toggle-section::after {
  content: '▾';
  font-size: 0.8em;
  margin-left: 8px;
  opacity: 0.5;
}

.toggle-section.collapsed::after {
  content: '▸';
}

/* ===== LOADING ===== */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-right: 8px;
  vertical-align: middle;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ===== INFO BOX ===== */
.info-box {
  background: var(--accent-glow);
  border: 1px solid rgba(34, 211, 238, 0.2);
  border-radius: var(--radius-sm);
  padding: 14px 18px;
  font-size: 0.85rem;
  color: var(--text2);
  line-height: 1.6;
  margin-top: 16px;
}

.info-box strong { color: var(--accent); }

.infeasible-box {
  background: var(--red-dim);
  border-color: rgba(248, 113, 113, 0.25);
}

.infeasible-box strong { color: var(--red); }

/* ===== FOOTER ===== */
footer {
  text-align: center;
  padding: 40px 0;
  color: var(--text3);
  font-size: 0.78rem;
  border-top: 1px solid var(--border);
  margin-top: 40px;
}

footer a { color: var(--text2); }

/* ===== RANGE SLIDER ===== */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent2);
  cursor: pointer;
  border: 2px solid var(--bg2);
  box-shadow: 0 2px 8px rgba(6, 182, 212, 0.4);
}

input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent2);
  cursor: pointer;
  border: 2px solid var(--bg2);
  box-shadow: 0 2px 8px rgba(6, 182, 212, 0.4);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 640px) {
  .container { padding: 0 16px; }
  .card { padding: 20px; }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .results-table { font-size: 0.8rem; }
  h1 { font-size: 1.8rem; }
}
