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

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: #1a1a2e;
  color: #eee;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
}

header {
  text-align: center;
  padding: 1rem;
}

/* --- Status Bar (toast messages) --- */

.status-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 200;
  display: flex;
  justify-content: center;
  padding: 0.5rem;
  pointer-events: none;
  transition: opacity 0.3s;
}

.status-bar.hidden {
  opacity: 0;
}

.status-bar:not(.hidden) {
  opacity: 1;
}

.status-bar-inner {
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  font-size: 0.9rem;
  font-weight: bold;
  color: #eee;
  background: rgba(22, 33, 62, 0.95);
  border: 2px solid #7CB342;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

.status-bar.error .status-bar-inner {
  border-color: #e74c3c;
  background: rgba(80, 10, 10, 0.95);
}

.status-bar.success .status-bar-inner {
  border-color: #7CB342;
  background: rgba(20, 60, 10, 0.95);
}

h1 {
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
}

#toolbar {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  flex-wrap: wrap;
}

#toolbar button {
  font-size: 1.25rem;
  padding: 0.5rem 1rem;
  border: 2px solid transparent;
  border-radius: 0.5rem;
  background: #16213e;
  color: #eee;
  cursor: pointer;
  transition: border-color 0.15s;
}

#toolbar button:hover {
  border-color: #eee;
}

#toolbar button.active {
  border-color: #7CB342;
  background: #1b3a10;
}

#grid {
  display: grid;
  gap: 1px;
  padding: 0.5rem;
  background: #0f0f23;
  border-radius: 0.5rem;
  overflow: auto;
  max-width: 95vw;
  max-height: 80vh;
}

.cell {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  border-radius: 2px;
  user-select: none;
  cursor: pointer;
  transition: background-color 0.15s;
  position: relative;
  overflow: hidden;
}

.cell:hover {
  outline: 2px solid #fff;
  outline-offset: -2px;
}

/* --- Creature overlay on landmark tiles --- */

.creature-overlay {
  position: absolute;
  bottom: 1px;
  right: 1px;
  font-size: 10px;
  line-height: 1;
  pointer-events: none;
  z-index: 2;
}

/* --- Mobile unit overlay (top-left) --- */

.unit-overlay {
  position: absolute;
  top: 0px;
  left: 0px;
  font-size: 13px;
  line-height: 1;
  pointer-events: none;
  z-index: 3;
}

/* --- Biome Terrain Styles (CSS gradients + textures) --- */

.cell::before {
  z-index: -1; /* Keep texture behind emoji text */
}

.cell[data-biome="water"] {
  background: linear-gradient(135deg, #1e5799 0%, #2989d8 50%, #2076b8 100%);
}

.cell[data-biome="water"]::before {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    90deg,
    transparent,
    transparent 4px,
    rgba(255, 255, 255, 0.06) 4px,
    rgba(255, 255, 255, 0.06) 8px
  );
  pointer-events: none;
}

.cell[data-biome="grassland"] {
  background: linear-gradient(135deg, #558b2f 0%, #7cb342 50%, #689f38 100%);
}

.cell[data-biome="grassland"]::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle 1px at 6px 6px, rgba(30, 80, 10, 0.25) 50%, transparent 50%),
              radial-gradient(circle 1px at 16px 14px, rgba(30, 80, 10, 0.25) 50%, transparent 50%);
  pointer-events: none;
}

.cell[data-biome="desert"] {
  background: linear-gradient(135deg, #d4a843 0%, #e8b84d 50%, #c99a32 100%);
}

.cell[data-biome="desert"]::before {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    170deg,
    transparent,
    transparent 3px,
    rgba(160, 110, 30, 0.15) 3px,
    rgba(160, 110, 30, 0.15) 6px
  );
  pointer-events: none;
}

.cell[data-biome="mountain"] {
  background: linear-gradient(135deg, #6d4c41 0%, #8d6e63 50%, #795548 100%);
}

.cell[data-biome="mountain"]::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    linear-gradient(45deg, transparent 40%, rgba(255, 255, 255, 0.1) 45%, transparent 50%),
    linear-gradient(-45deg, transparent 40%, rgba(255, 255, 255, 0.1) 45%, transparent 50%);
  pointer-events: none;
}

.cell[data-biome="ice"] {
  background: linear-gradient(135deg, #e0f7fa 0%, #b2ebf2 40%, #e0f2f1 100%);
}

.cell[data-biome="ice"]::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    linear-gradient(30deg, rgba(255, 255, 255, 0.5) 25%, transparent 25%, transparent 75%, rgba(255, 255, 255, 0.5) 75%),
    linear-gradient(-30deg, rgba(255, 255, 255, 0.5) 25%, transparent 25%, transparent 75%, rgba(255, 255, 255, 0.5) 75%);
  background-size: 8px 8px;
  pointer-events: none;
}

.cell[data-biome="forest"] {
  background: linear-gradient(135deg, #1b5e20 0%, #2e7d32 50%, #388e3c 100%);
}

.cell[data-biome="forest"]::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle 2px at 5px 8px, rgba(27, 94, 32, 0.4) 50%, transparent 50%),
              radial-gradient(circle 2px at 18px 5px, rgba(27, 94, 32, 0.4) 50%, transparent 50%),
              radial-gradient(circle 2px at 12px 18px, rgba(27, 94, 32, 0.4) 50%, transparent 50%);
  pointer-events: none;
}

.cell[data-biome="jungle"] {
  background: linear-gradient(135deg, #0a3d0a 0%, #1b5e20 50%, #2e7d32 100%);
}

.cell[data-biome="jungle"]::before {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    45deg,
    transparent,
    transparent 3px,
    rgba(27, 94, 32, 0.2) 3px,
    rgba(27, 94, 32, 0.2) 6px
  );
  pointer-events: none;
}

/* --- Civilization Tool Buttons --- */

.civ-buttons {
  display: flex;
  gap: 0.25rem;
  padding-left: 0.75rem;
  border-left: 2px solid #333;
  margin-left: 0.25rem;
}

.civ-buttons button {
  font-size: 1.1rem;
  padding: 0.45rem 0.75rem;
}

.civ-buttons button.active {
  border-color: #E8B84D;
  background: #3a2e0a;
  box-shadow: 0 0 6px rgba(232, 184, 77, 0.5);
}

/* --- Biome Selection Buttons --- */

.biome-buttons {
  display: flex;
  gap: 0.25rem;
  padding-left: 0.75rem;
  border-left: 2px solid #333;
  margin-left: 0.25rem;
}

.biome-buttons button {
  font-size: 1.4rem;
  padding: 0.35rem 0.55rem;
  min-width: 2.5rem;
  line-height: 1;
}

.biome-buttons button.active {
  border-color: #7CB342;
  background: #1b3a10;
  box-shadow: 0 0 6px rgba(124, 179, 66, 0.5);
  transform: scale(1.1);
}

/* --- Inspect Tooltip --- */

.inspect-tooltip {
  position: fixed;
  z-index: 100;
  padding: 0.5rem 0.75rem;
  background: #16213e;
  border: 2px solid #7CB342;
  border-radius: 0.5rem;
  color: #eee;
  font-size: 0.85rem;
  line-height: 1.4;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.6);
  pointer-events: auto;
  max-width: 320px;
  cursor: pointer;
}

.inspect-tooltip.hidden {
  display: none;
}

.tooltip-panels {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
}

.tooltip-section {
  flex: 1;
  text-align: center;
}

.tooltip-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #888;
  margin-bottom: 0.2rem;
}

.tooltip-biome {
  font-weight: bold;
  font-size: 0.9rem;
}

.tooltip-creature,
.tooltip-civilization {
  color: #ccc;
  font-size: 0.8rem;
}

/* --- T39e: Civ Picker Panel --- */

.civ-picker {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.5rem;
  background: rgba(10, 10, 30, 0.92);
  border: 1px solid #7CB342;
  border-radius: 0.5rem;
  margin: 0.3rem auto;
  max-width: 95vw;
  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;
}

.civ-picker.hidden {
  display: none;
}

#btn-civ-close {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border: 1px solid #888;
  border-radius: 50%;
  background: #333;
  color: #ccc;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

#btn-civ-close:hover {
  background: #555;
  color: #fff;
}

#civ-picker-stages {
  display: flex;
  gap: 0.3rem;
  align-items: center;
}

.civ-stage-btn {
  flex-shrink: 0;
  padding: 0.25rem 0.55rem;
  border: 2px solid #7CB342;
  border-radius: 0.35rem;
  background: #1a3a1a;
  color: #e0e0e0;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.civ-stage-btn.active:hover {
  background: #2a5a2a;
  color: #fff;
  border-color: #9ccc65;
}

.civ-stage-btn.disabled {
  opacity: 0.3;
  pointer-events: none;
  border-color: #555;
  background: #222;
  color: #666;
}
