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

html, body {
  height: 100%;
  font-family: Arial, sans-serif;
  background-color: #f0f0f0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── TOP BAR ── */
#topbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  background: #fff;
  border-bottom: 1px solid #ddd;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  flex-shrink: 0;
  flex-wrap: nowrap;   /* single line always */
  white-space: nowrap;
  overflow: hidden;
}

#topbar-title {
  font-size: 0.78rem;
  font-weight: bold;
  color: #333;
  flex-shrink: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

#topbar-hud {
  display: flex;
  gap: 8px;
  font-size: 11px;
  color: #555;
  flex-shrink: 0;
}
#topbar-hud strong { color: #111; }

#topbar-btns {
  display: flex;
  gap: 4px;
  margin-left: auto;
  flex-shrink: 0;
}

button {
  padding: 4px 8px;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: 11px;
  transition: background-color 0.2s;
  white-space: nowrap;
}
button:disabled { background-color: #ccc; cursor: not-allowed; }

#startButton  { background-color: #4CAF50; color: #fff; }
#startButton:hover:enabled  { background-color: #45a049; }
#pauseButton  { background-color: #f44336; color: #fff; }
#pauseButton:hover:enabled  { background-color: #da190b; }
#resetButton  { background-color: #008CBA; color: #fff; }
#resetButton:hover:enabled  { background-color: #007bb5; }
#toggleControls { background-color: #eee; color: #333; border: 1px solid #ccc; }
#toggleControls:hover { background-color: #ddd; }

/* ── COLLAPSIBLE CONTROLS ── */
#controls-bar {
  background: #fff;
  border-bottom: 1px solid #ddd;
  overflow: hidden;
  transition: max-height 0.25s ease;
  max-height: 400px;
  flex-shrink: 0;
}
#controls-bar.collapsed { max-height: 0; }

#controls-inner {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  padding: 12px 16px;
  align-items: flex-start;
}

.ctrl-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.slider-container {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}
.slider-container label { min-width: 130px; color: #444; }
.slider-container input[type=range] { width: 140px; }
.slider-container span { min-width: 44px; color: #555; font-size: 12px; }

.autostop-controls select,
.migration-controls select {
  padding: 4px 6px;
  border-radius: 4px;
  border: 1px solid #ccc;
  font-size: 12px;
}

#color-legend strong,
#island-stats strong {
  display: block;
  font-size: 12px;
  color: #555;
  margin-bottom: 6px;
}

.spectrum-container {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: #777;
}
.fitness-gradient {
  width: 120px;
  height: 13px;
  background: linear-gradient(to right, #ff4d4d, #ffff4d, #4dff4d);
  border-radius: 4px;
  border: 1px solid #ddd;
}

.island-stat-item {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  gap: 12px;
  padding: 2px 0;
  border-bottom: 1px solid #f0f0f0;
}
.island-stat-item b { color: #4CAF50; }

/* ── SIMULATION AREA ── */
#simulation-area {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  overflow: hidden;
  min-height: 0;
}

#grid-wrap {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#grid-container {
  display: grid;
  border: 1px solid #ccc;
  background-color: #e0ffee;
  box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.grid-cell {
  width: 15px;
  height: 15px;
  border: 1px dotted #ccc;
  box-sizing: border-box;
  position: relative;
  background-color: #e0ffee;
}

.grid-cell.water-cell {
  background-color: #aaddff;
  border: 1px solid #77bbff;
}

.grid-cell.flash-source {
  animation: cell-flash-source 0.4s ease-out;
}
.grid-cell.flash-destination {
  animation: cell-flash-destination 0.4s ease-out;
}

@keyframes cell-flash-source {
  0%   { background-color: black; transform: scale(1.3); opacity: 1; z-index: 10; }
  100% { background-color: inherit; transform: scale(1); opacity: inherit; z-index: 1; }
}
@keyframes cell-flash-destination {
  0%   { background-color: white; transform: scale(1.3); opacity: 1; z-index: 10; }
  100% { background-color: inherit; transform: scale(1); opacity: inherit; z-index: 1; }
}

/* ── FLOATING TOOLTIP ── */
#tooltip {
  position: fixed;
  background: rgba(255,255,255,0.96);
  color: #222;
  border: 1px solid #ccc;
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 12px;
  line-height: 1.8;
  pointer-events: none;
  display: none;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  z-index: 1000;
  max-width: 240px;
}
