/* Game of Life - Evolution Styles */

/* CSS Custom Properties for dynamic sizing */
:root {
  --cell-size: 25px;
  --emoji-scale: 1;
  --base-font-size: 15px;
  --grid-bg-color: rgba(10, 10, 10, 0.8);
  --cell-border-color: rgba(60, 60, 60, 0.4);
  --lifeform-glow: 0 0 8px rgba(255, 255, 255, 0.4);
}

/* Form Layout - Compact Controls */
.form-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 15px;
  margin-bottom: 15px;
  flex-wrap: wrap;
}

.form-group.compact {
  display: flex;
  align-items: center;
  margin-bottom: 0;
  gap: 5px;
}

.form-group.compact label {
  font-size: 12px;
  font-weight: bold;
  min-width: auto;
  margin-right: 5px;
  white-space: nowrap;
}

.form-group.compact input[type="number"] {
  width: 50px;
  padding: 4px 6px;
  font-size: 12px;
  text-align: center;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: "Courier New", monospace;
  background-color: #121212;
  color: #f0f0f0;
  line-height: 1.6;
  height: 100vh;
  overflow: hidden;
}

.container {
  width: 100%;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  text-align: center;
  padding: 10px;
  background-color: #1e1e1e;
  border-bottom: 1px solid #333;
  flex-shrink: 0;
}

header h1 {
  margin: 0;
  font-size: 1.5em;
}

/* Top Panel - 20% of browser height, full width */
.setup-panel {
  background-color: #1e1e1e;
  padding: 20px;
  border-bottom: 1px solid #333;
  height: 20vh;
  width: 100%;
  margin: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  overflow-y: auto;
}

.form-group {
  margin-bottom: 10px;
}

.form-group:not(.compact) label {
  display: inline-block;
  min-width: 120px;
  margin-right: 10px;
  font-weight: bold;
}

input[type="number"] {
  width: 100%;
  padding: 8px;
  border: 1px solid #555;
  background-color: #2a2a2a;
  color: #f0f0f0;
  border-radius: 3px;
  font-family: "Courier New", monospace;
}

/* Override width for compact form inputs */
.form-group.compact input[type="number"] {
  width: 50px;
}

button {
  padding: 6px 12px;
  background-color: #4caf50;
  color: white;
  border: none;
  border-radius: 3px;
  cursor: pointer;
  font-family: "Courier New", monospace;
  font-weight: bold;
  font-size: 12px;
  white-space: nowrap;
  display: inline-block;
}

button:hover {
  background-color: #3e8e41;
}

#reset-game {
  background-color: #f44336;
}

#reset-game:hover {
  background-color: #d32f2f;
}

/* Game Container - Fills remaining space after top panel */
.game-container {
  height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.main-layout {
  height: 90vh; /* Initially 90% of remaining space (90% of 80vh) */
  display: flex;
  overflow: hidden;
  transition: height 0.3s ease;
  width: 100%;
}

.main-layout.expanded-log {
  height: 50vh; /* When log expanded: 50% of remaining space (50% of 80vh) */
}

/* Left Panel - 15% of browser width */
.left-panel {
  width: 15vw;
  background-color: #1e1e1e;
  border-right: 1px solid #333;
  padding: 10px;
  overflow-y: auto;
  min-width: 150px;
}

.left-panel h3 {
  margin-bottom: 10px;
  font-size: 1em;
  border-bottom: 1px solid #333;
  padding-bottom: 5px;
}

.controls {
  margin-top: 15px;
  padding-top: 10px;
  border-top: 1px solid #333;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.controls button {
  flex: 0 0 auto;
  min-width: auto;
  margin: 0;
}

/* Center Panel - Game Field (70% width, fills remaining height) */
.center-panel {
  width: 70vw;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex: 1;
}

/* Game Field - Takes all space in center panel */
.game-field {
  flex: 1;
  background-color: #0a0a0a;
  border: 1px solid #333;
  padding: 20px;
  font-family: "Courier New", monospace;
  font-size: 14px;
  overflow: visible !important; /* Force overflow to be visible */
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  position: relative;
  min-height: 400px;
  max-height: calc(100vh - 250px);
  z-index: 0;
  /* Enhanced styling for better visibility */
  border-radius: 5px;
  box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.5);
}

/* Bottom Panel - Event Log */
/* Initial height: 10% of browser height (10% of 80vh) */
.event-log {
  height: 8vh; /* 10% of remaining 80vh */
  background-color: #1e1e1e;
  border: 1px solid #333;
  border-top: none;
  display: flex;
  flex-direction: column;
  transition: height 0.3s ease;
  width: 100%;
  position: relative;
}

.event-log.expanded {
  height: 32vh; /* 40% of remaining 80vh when expanded */
}

.event-log h3 {
  padding: 10px;
  margin: 0;
  background-color: #2a2a2a;
  border-bottom: 1px solid #333;
  font-size: 0.9em;
  flex-shrink: 0;
}

.event-log h3 a {
  color: #4caf50;
  text-decoration: none;
}

.event-log h3 a:hover {
  color: #6bc76b;
  text-decoration: underline;
}

#eventLog {
  flex: 1;
  padding: 10px;
  overflow: auto;
  font-size: 12px;
  font-family: "Courier New", monospace;
  background-color: #1a1a1a;
  color: #ddd;
  border: 1px solid #333;
  min-height: 50px;
}

.event-item {
  margin-bottom: 2px;
  padding: 2px 0;
  border-bottom: 1px dotted #444;
  color: #ddd;
}

.timestamp {
  color: #888;
  margin-right: 8px;
}

/* Right Panel - 15% of browser width */
.right-panel {
  width: 15vw;
  background-color: #1e1e1e;
  border-left: 1px solid #333;
  padding: 10px;
  overflow-y: auto;
  min-width: 150px;
}

.right-panel h3 {
  margin-bottom: 10px;
  font-size: 1em;
  border-bottom: 1px solid #333;
  padding-bottom: 5px;
}

/* Species Stats */
.species-stat {
  margin-bottom: 15px;
  padding: 8px;
  background-color: #2a2a2a;
  border-radius: 3px;
  border: 1px solid #444;
  font-size: 12px;
}

.species-name {
  font-weight: bold;
  margin-bottom: 5px;
  color: #4caf50;
}

.species-emoji {
  font-size: 16px;
  margin-right: 5px;
}

.stat-line {
  margin-bottom: 3px;
  color: #ccc;
}

.extinct {
  opacity: 0.6;
}

.extinct .species-name {
  color: #f44336;
}

/* Game Stats */
.game-stat {
  margin-bottom: 8px;
  font-size: 13px;
}

.stat-label {
  font-weight: bold;
  color: #4caf50;
}

.stat-value {
  color: #f0f0f0;
}

/* Footer */
footer {
  background-color: #1e1e1e;
  border-top: 1px solid #333;
  padding: 10px;
  text-align: center;
  font-size: 12px;
  color: #888;
  flex-shrink: 0;
}

footer a {
  color: #4caf50;
  text-decoration: none;
}

footer a:hover {
  text-decoration: underline;
}

/* Age Colors for Life Forms */
.age-newborn {
  color: white;
  text-shadow: 0 0 5px rgba(255, 255, 255, 0.7);
}
.age-young {
  color: lightblue;
  text-shadow: 0 0 5px rgba(173, 216, 230, 0.7);
}
.age-adult {
  color: lightgreen;
  text-shadow: 0 0 5px rgba(144, 238, 144, 0.7);
}
.age-mature {
  color: orange;
  text-shadow: 0 0 5px rgba(255, 165, 0, 0.7);
}
.age-elder {
  color: red;
  text-shadow: 0 0 5px rgba(255, 0, 0, 0.7);
}

/* Game Grid Styles */
.game-grid {
  border-collapse: separate;
  border-spacing: 2px;
  font-family: "Courier New", monospace;
  margin: 0 auto;
  background-color: var(--grid-bg-color);
  border-radius: 5px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  table-layout: fixed;
  border: 1px solid #444;
  padding: 5px;
}

.game-grid tr {
  line-height: 1;
}

.game-grid td.grid-cell {
  width: var(--cell-size);
  height: var(--cell-size);
  border: 1px solid var(--cell-border-color);
  background-color: rgba(30, 30, 30, 0.4);
  padding: 0;
  margin: 0;
  font-size: calc(var(--base-font-size) * var(--emoji-scale));
  line-height: 1;
  overflow: visible !important;
  position: relative;
  box-sizing: content-box;
  text-align: center;
  vertical-align: middle;
  z-index: 1;
  white-space: nowrap;
  letter-spacing: -0.5px;
  display: table-cell;
  border-radius: 3px;
}

/* Style for cells that contain lifeforms - enhanced */
.game-grid td.grid-cell.has-lifeform {
  background-color: rgba(40, 40, 70, 0.7);
  box-shadow: inset 0 0 5px rgba(255, 255, 255, 0.3),
    0 0 10px rgba(255, 255, 255, 0.15);
  z-index: 2;
  transform: scale(1.05); /* Make cells with lifeforms slightly larger */
  font-weight: bold;
  border: 1px solid rgba(120, 120, 180, 0.5);
}

/* Enhanced age styles with better visibility */
.age-young {
  color: #8cddff;
  text-shadow: 0 0 8px rgba(140, 221, 255, 0.9);
  font-weight: bold;
}

.age-adult {
  color: #8cff8c;
  text-shadow: 0 0 8px rgba(140, 255, 140, 0.9);
  font-weight: bold;
}

.age-mature {
  color: #ffc966;
  text-shadow: 0 0 8px rgba(255, 201, 102, 0.9);
  font-weight: bold;
}

.age-elder {
  color: #ff8f8f;
  text-shadow: 0 0 8px rgba(255, 143, 143, 0.9);
  font-weight: bold;
}

/* Event Log Entry Styles */
.event-entry {
  margin-bottom: 3px;
  padding: 2px 4px;
  border-bottom: 1px dotted #444;
  font-size: 11px;
  line-height: 1.3;
  color: #ddd;
}

.event-entry:last-child {
  border-bottom: none;
}

.event-cycle {
  color: #4caf50;
  font-weight: bold;
  margin-right: 5px;
}

.event-type {
  color: #ffa500;
  margin-right: 5px;
}

.event-message {
  color: #ddd;
}

/* Game Grid Table Styles */
.game-grid {
  border-collapse: collapse;
  font-family: "Courier New", monospace;
  border: none; /* Hide grid border */
  margin: 0 auto; /* Center the grid */
  table-layout: fixed; /* Fixed layout for consistent sizing */
  width: auto; /* Allow width to be determined by content */
  max-width: 100%; /* But don't exceed container width */
  border-spacing: 0; /* Remove space between cells */
  background-color: rgba(
    0,
    0,
    0,
    0.2
  ); /* Slight background to make grid visible */
}

.game-grid td.grid-cell {
  width: var(--cell-size);
  height: var(--cell-size);
  border: 1px solid var(--cell-border-color);
  background-color: rgba(30, 30, 30, 0.4);
  padding: 0;
  margin: 0;
  font-size: calc(var(--base-font-size) * var(--emoji-scale));
  line-height: 1;
  overflow: visible !important; /* Force emojis to display properly */
  position: relative;
  box-sizing: content-box; /* Change to content-box for better emoji sizing */
  text-align: center;
  vertical-align: middle;
  z-index: 1;
  white-space: nowrap; /* Keep symbols together */
  letter-spacing: -0.5px; /* Tighten spacing between symbols */

  /* Remove flex layout that might be constaining emojis */
  display: table-cell;
}

/* Style for cells that contain lifeforms */
.game-grid td.grid-cell.has-lifeform {
  background-color: rgba(
    20,
    20,
    20,
    0.3
  ); /* Subtle background for cells with lifeforms */
  box-shadow: inset 0 0 3px rgba(255, 255, 255, 0.2); /* Subtle glow effect */
}

/* Stat Item Styles */
.stat-item {
  display: flex;
  justify-content: space-between;
  margin-bottom: 5px;
  padding: 2px 0;
  font-size: 12px;
}

.stat-item label {
  color: #4caf50;
  font-weight: bold;
  margin: 0;
}

.stat-item span {
  color: #f0f0f0;
}

/* Species Stats in Right Panel */
.species-stat {
  margin-bottom: 15px;
  padding: 8px;
  background-color: #2a2a2a;
  border-radius: 3px;
  border: 1px solid #444;
  font-size: 12px;
}

.species-stat h4 {
  margin: 0 0 8px 0;
  color: #4caf50;
  font-size: 13px;
  font-weight: bold;
  border-bottom: 1px solid #555;
  padding-bottom: 4px;
}

.stat-section {
  margin-bottom: 8px;
}

.stat-section:last-child {
  margin-bottom: 0;
}

.stat-header {
  color: #ffa500;
  font-weight: bold;
  font-size: 11px;
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat-detail {
  color: #ccc;
  font-size: 10px;
  margin-bottom: 2px;
  padding-left: 8px;
  line-height: 1.3;
}

.species-stat span:first-child {
  color: #f0f0f0;
}

/* Button State Management */
button:disabled {
  background-color: #666;
  color: #999;
  cursor: not-allowed;
}

button:disabled:hover {
  background-color: #666;
}

/* Game Over Overlay */
.game-over {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background-color: rgba(255, 68, 68, 0.95);
  color: white;
  padding: 30px;
  text-align: center;
  border-radius: 10px;
  border: 2px solid #ff6666;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
  z-index: 1000;
}

.game-over h2 {
  margin-top: 0;
  margin-bottom: 15px;
  font-size: 24px;
}

.game-over p {
  margin: 5px 0;
  font-size: 14px;
}

/* Debug Panel Styles */
.debug-panel {
  display: none; /* Hidden by default */
  background: #f0f0f0;
  border: 1px solid #ccc;
  padding: 10px;
  margin: 10px 0;
  max-height: 200px;
  overflow-y: auto;
  color: #000;
}

.debug-output {
  font-family: monospace;
  font-size: 12px;
  white-space: pre-wrap;
}

/* Empty field state */
.empty-field {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 200px;
  color: #666;
  font-style: italic;
  font-size: 1.2em;
}

/* Responsive Design */
@media (max-width: 1200px) {
  .left-panel,
  .right-panel {
    width: 18vw;
    min-width: 140px;
  }

  .center-panel {
    width: 64vw;
  }
}

@media (max-width: 900px) {
  .left-panel,
  .right-panel {
    width: 15vw;
    min-width: 120px;
  }

  .center-panel {
    width: 70vw;
  }

  .game-field {
    font-size: 12px;
  }
}

@media (max-width: 600px) {
  .main-layout {
    flex-direction: column;
  }

  .left-panel,
  .right-panel {
    width: 100vw;
    height: 120px;
    min-width: unset;
  }

  .center-panel {
    width: 100vw;
    flex: 1;
  }
}
