:root {
  --bg: #eef2ed;
  --ink: #173337;
  --muted: #556c70;
  --teal-900: #004445;
  --teal-700: #0f6b67;
  --panel: rgba(255, 255, 255, 0.92);
  --border: rgba(120, 148, 150, 0.3);
  --shadow-elev: 0 10px 32px rgba(20, 43, 53, 0.11);
  --focus: #0f172a;
  --focus-glow: #ffd166;
  --slender: #4aa7df;
  --medium: #d0a933;
  --heavy: #a45c2f;
  --nectar-food: #ee7aa7;
  --seed-food: #d6ae40;
  --nut-food: #6e8b4e;
  --calm: #3c9460;
  --drought: #d88034;
  --recovery: #4d95d1;
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(circle at top left, rgba(218, 241, 224, 0.85), transparent 28%),
    radial-gradient(circle at bottom right, rgba(214, 229, 239, 0.78), transparent 34%),
    linear-gradient(180deg, #f7fbf6 0%, var(--bg) 100%);
  color: var(--ink);
  font-family: Roboto, Arial, sans-serif;
}

button,
input,
dialog {
  font: inherit;
}

button {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
#canvas-card:focus-visible,
.tab-btn:focus-visible,
.timeline-anchor:focus-visible,
.food-mix-anchor:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  box-shadow: 0 0 0 5px var(--focus-glow);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── App shell ── */

#sim-app {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 8px;
  gap: 0;
}

#stage-panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--panel);
  box-shadow: var(--shadow-elev);
}

/* ── Canvas column ── */

#canvas-column {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#canvas-card {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  border-radius: 16px;
  background: linear-gradient(180deg, #cee7f4 0%, #eef8ff 18%, #f3f4ea 100%);
  border: 1px solid rgba(117, 146, 145, 0.18);
}

#sim-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* ── Timeline ── */

#timeline-panel {
  flex: 0 0 auto;
  padding: 8px 10px;
  border-radius: 14px;
  border: 1px solid rgba(117, 146, 145, 0.18);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(246, 249, 248, 0.88));
}

.timeline-heading {
  margin: 0 0 5px;
  padding: 0 2px;
  font-size: 13px;
  font-weight: 700;
  color: var(--teal-900);
}

.timeline-gen-labels {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
  padding: 0 2px;
}

.timeline-gen-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}

.timeline-track-shell {
  position: relative;
}

#timeline-track {
  position: relative;
  height: 36px;
  display: flex;
  overflow: visible;
  border-radius: 999px;
  background: rgba(210, 221, 219, 0.72);
  box-shadow: inset 0 0 0 1px rgba(107, 138, 136, 0.18);
}

.timeline-segment {
  height: 100%;
}

.timeline-segment--calm {
  border-radius: 999px 0 0 999px;
  background: linear-gradient(90deg, #5db77d, var(--calm));
}

.timeline-segment--drought {
  background: linear-gradient(90deg, #edb064, var(--drought));
}

.timeline-segment--recovery {
  flex: 1;
  border-radius: 0 999px 999px 0;
  background: linear-gradient(90deg, #8ab9e4, var(--recovery));
}

/* ── Timeline anchors — pill style matching food-mix-anchor ── */

.timeline-anchor {
  position: absolute;
  top: 50%;
  width: 18px;
  height: 52px;
  border: 2px solid rgba(29, 55, 57, 0.24);
  border-radius: 12px;
  background: linear-gradient(180deg, #ffffff 0%, #edf2f1 100%);
  box-shadow:
    0 7px 16px rgba(21, 39, 43, 0.18),
    inset 0 1px 0 rgba(255, 255, 255, 0.96);
  transform: translate(-50%, -50%);
  cursor: grab;
  z-index: 3;
  display: none;
  touch-action: none;
  user-select: none;
}

.timeline-anchor::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 11px;
  width: 4px;
  height: 28px;
  border-radius: 999px;
  transform: translateX(-50%);
  background: linear-gradient(180deg, rgba(94, 114, 116, 0.78), rgba(94, 114, 116, 0.34));
}

body.phase-setup .timeline-anchor {
  display: block;
}

.timeline-anchor:hover,
.timeline-anchor:active {
  background: linear-gradient(180deg, #f0f7f7 0%, #e0eded 100%);
}

#timeline-marker {
  position: absolute;
  top: -4px;
  bottom: -4px;
  width: 2px;
  border-radius: 999px;
  background: #10272c;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.78);
  transform: translateX(-1px);
  z-index: 4;
  display: none;
}

body.phase-running #timeline-marker,
body.phase-paused #timeline-marker,
body.phase-ended #timeline-marker {
  display: block;
}

/* ── Timeline legend — evenly spaced chips matching food-mix-values ── */

.timeline-legend {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.timeline-key {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(117, 146, 145, 0.18);
}

.timeline-key::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.timeline-key--calm::before    { background: var(--calm); }
.timeline-key--drought::before { background: var(--drought); }
.timeline-key--recovery::before { background: var(--recovery); }


/* ── Setup overlay (inline, always visible) ── */

#setup-overlay {
  flex: 0 0 auto;
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
}

/* Read-only / disabled state when sim is running or ended */
body:not(.phase-setup) .food-mix-anchor {
  cursor: default;
  pointer-events: none;
  opacity: 0.45;
}

body:not(.phase-setup) .food-mix-track {
  opacity: 0.78;
}

.control-column {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid rgba(117, 146, 145, 0.2);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.86);
  flex: 1 1 200px;
  min-width: 0;
}

.control-column legend {
  padding: 0 6px;
  font-size: 13px;
  font-weight: 700;
  color: var(--teal-900);
}

.control-column--food {
  flex: 1 1 260px;
}

.food-mix-shell {
  display: grid;
  gap: 12px;
  margin-top: 4px;
}

.food-mix-track {
  position: relative;
  display: flex;
  height: 44px;
  border-radius: 20px;
  overflow: visible;
  border: 1px solid rgba(117, 146, 145, 0.22);
  background: rgba(231, 237, 234, 0.92);
  box-shadow: inset 0 2px 8px rgba(30, 56, 60, 0.12);
}

.food-mix-segment {
  height: 100%;
}

.food-mix-segment--nectar {
  border-radius: 20px 0 0 20px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.28), transparent 58%),
    linear-gradient(180deg, var(--nectar-food) 0%, #df668f 100%);
}

.food-mix-segment--seeds {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.28), transparent 58%),
    linear-gradient(180deg, var(--seed-food) 0%, #c69728 100%);
}

.food-mix-segment--nuts {
  border-radius: 0 20px 20px 0;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.24), transparent 58%),
    linear-gradient(180deg, var(--nut-food) 0%, #5b7540 100%);
}

.food-mix-anchor {
  position: absolute;
  top: 50%;
  width: 18px;
  height: 54px;
  border: 2px solid rgba(29, 55, 57, 0.24);
  border-radius: 12px;
  background: linear-gradient(180deg, #ffffff 0%, #edf2f1 100%);
  box-shadow:
    0 7px 16px rgba(21, 39, 43, 0.18),
    inset 0 1px 0 rgba(255, 255, 255, 0.96);
  transform: translate(-50%, -50%);
  cursor: grab;
  touch-action: none;
  z-index: 2;
}

.food-mix-anchor::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 11px;
  width: 4px;
  height: 28px;
  border-radius: 999px;
  transform: translateX(-50%);
  background: linear-gradient(180deg, rgba(94, 114, 116, 0.78), rgba(94, 114, 116, 0.34));
}

.food-mix-anchor:hover,
.food-mix-anchor:active {
  background: linear-gradient(180deg, #f0f7f7 0%, #e0eded 100%);
}

/* ── Food mix value chips ── */

.food-mix-values {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.food-mix-chip {
  flex: 1 1 108px;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  border-radius: 12px;
  border: 1px solid rgba(117, 146, 145, 0.18);
  background: rgba(255, 255, 255, 0.9);
  color: var(--ink);
}

.food-mix-chip::before {
  content: '';
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.food-mix-chip--nectar::before { background: var(--nectar-food); }
.food-mix-chip--seeds::before  { background: var(--seed-food); }
.food-mix-chip--nuts::before   { background: var(--nut-food); }

.food-mix-chip-label {
  font-size: 12px;
  font-weight: 600;
  flex: 1;
  min-width: 0;
}

.food-mix-chip-value {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  color: var(--teal-900);
  white-space: nowrap;
}

/* ── Dialog ── */

#info-dialog {
  border: none;
  border-radius: 14px;
  padding: 0;
  width: min(640px, calc(100vw - 32px));
  max-height: calc(100vh - 80px);
  background: #fff;
  color: var(--ink);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.24);
  overflow: hidden;
}

#info-dialog::backdrop {
  background: rgba(0, 0, 0, 0.45);
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px 10px;
  background: var(--teal-900);
  color: #fff;
}

.dialog-header h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

#dialog-close-btn {
  background: transparent;
  border: none;
  color: #fff;
  font-size: 18px;
  width: 32px;
  height: 32px;
  border-radius: 8px;
}

#dialog-close-btn:hover {
  background: rgba(255, 255, 255, 0.14);
}

.dialog-tabs {
  display: flex;
  border-bottom: 1px solid #e2ebe8;
  background: #f8fbfb;
}

.tab-btn {
  flex: 1;
  padding: 10px 0;
  border: none;
  background: transparent;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  border-bottom: 3px solid transparent;
}

.tab-btn.active {
  color: var(--teal-900);
  border-bottom-color: var(--teal-900);
}

.dialog-body {
  padding: 16px 20px;
  max-height: calc(100vh - 240px);
  overflow-y: auto;
  font-size: 14px;
  line-height: 1.55;
}

.dialog-body h3 {
  font-size: 14px;
  font-weight: 700;
  margin: 14px 0 6px;
  color: var(--teal-900);
}

.dialog-body h3:first-child {
  margin-top: 0;
}

.dialog-body p {
  margin: 0 0 10px;
}

.dialog-body ul {
  margin: 0 0 10px;
  padding-left: 20px;
}

.dialog-body li {
  margin-bottom: 4px;
}

.dialog-footer {
  display: flex;
  justify-content: flex-end;
  padding: 12px 20px;
  border-top: 1px solid #e2ebe8;
  background: #f8fbfb;
}

.dialog-close-footer {
  background: var(--teal-900);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 18px;
  font-size: 14px;
  font-weight: 600;
}

.dialog-close-footer:hover {
  background: #006466;
}

/* ── Responsive ── */

@media (max-width: 500px) {
  #sim-app {
    padding: 6px;
  }

  #stage-panel {
    padding: 8px;
    border-radius: 16px;
    gap: 6px;
  }

  #canvas-card {
    border-radius: 12px;
  }

  #timeline-panel {
    padding: 6px 8px;
    border-radius: 10px;
  }

  .timeline-legend {
    gap: 4px;
  }

  .timeline-key {
    font-size: 10px;
    padding: 5px 6px;
  }

  #setup-overlay {
    gap: 8px;
  }

  .control-column {
    padding: 8px 10px;
    border-radius: 10px;
  }

  .food-mix-track {
    height: 40px;
  }

  .food-mix-anchor {
    width: 16px;
    height: 48px;
  }

  .food-mix-anchor::before {
    top: 10px;
    height: 24px;
  }

  .food-mix-values {
    gap: 6px;
  }

  .food-mix-chip {
    flex-basis: 100px;
    padding: 6px 8px;
  }

  .food-mix-chip-label,
  .food-mix-chip-value {
    font-size: 11px;
  }
}
