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

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: linear-gradient(180deg, #87ceeb 0%, #4a90d9 60%, #1e5a8e 100%);
  min-height: 100vh;
  color: #2c3e50;
  overflow-x: hidden;
}

#app { max-width: 1400px; margin: 0 auto; padding: 15px; }

header {
  background: rgba(255,255,255,0.95);
  border-radius: 15px;
  padding: 15px;
  margin-bottom: 15px;
  box-shadow: 0 8px 25px rgba(0,0,0,0.2);
}

#resources {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

.res {
  background: linear-gradient(135deg, #fff 0%, #ecf0f1 100%);
  padding: 10px 18px;
  border-radius: 12px;
  font-weight: bold;
  font-size: 1.2em;
  border: 2px solid #bdc3c7;
  display: flex;
  gap: 8px;
  align-items: center;
  min-width: 90px;
  justify-content: center;
  transition: all 0.3s;
}

.res:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 15px rgba(0,0,0,0.2);
}

main {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 15px;
}

#sidebar {
  background: rgba(255,255,255,0.95);
  border-radius: 15px;
  padding: 15px;
  box-shadow: 0 8px 25px rgba(0,0,0,0.2);
  height: fit-content;
  max-height: calc(100vh - 150px);
  overflow-y: auto;
}

#buildings {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 15px;
}

.building-card {
  background: linear-gradient(135deg, #fff 0%, #f8f9fa 100%);
  border: 3px solid #bdc3c7;
  border-radius: 12px;
  padding: 12px 8px;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
  position: relative;
}

.building-card:hover {
  transform: scale(1.05);
  border-color: #f1c40f;
  box-shadow: 0 6px 20px rgba(241,196,15,0.4);
}

.building-card.selected {
  border-color: #27ae60;
  background: linear-gradient(135deg, #d5f5e3 0%, #abebc6 100%);
  box-shadow: 0 0 20px rgba(39,174,96,0.6);
  animation: selectedPulse 1.5s infinite;
}

@keyframes selectedPulse {
  0%, 100% { box-shadow: 0 0 20px rgba(39,174,96,0.6); }
  50% { box-shadow: 0 0 30px rgba(39,174,96,0.9); }
}

.building-card.disabled {
  opacity: 0.4;
  cursor: not-allowed;
  filter: grayscale(0.5);
}

.building-card .b-icon {
  font-size: 2.5em;
  display: block;
  margin-bottom: 6px;
  filter: drop-shadow(2px 2px 4px rgba(0,0,0,0.3));
}

.building-card .b-cost {
  font-size: 0.75em;
  color: #7f8c8d;
  display: flex;
  justify-content: center;
  gap: 4px;
  flex-wrap: wrap;
}

#menu {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 15px;
}

#menu button {
  padding: 12px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(135deg, #3498db 0%, #2980b9 100%);
  color: white;
  font-size: 1.5em;
  cursor: pointer;
  transition: all 0.2s;
}

#menu button:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(52,152,219,0.4);
}

#board-wrap {
  background: rgba(255,255,255,0.95);
  border-radius: 15px;
  padding: 20px;
  box-shadow: 0 8px 25px rgba(0,0,0,0.2);
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 600px;
  overflow: hidden;
}

#board {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 4px;
  width: 100%;
  max-width: 720px;
  aspect-ratio: 1;
}

.cell {
  aspect-ratio: 1;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(16px, 2.5vw, 32px);
  transition: all 0.2s;
  position: relative;
  user-select: none;
  border: 2px solid transparent;
}

.cell:hover:not(.water) {
  transform: scale(1.15);
  z-index: 10;
  box-shadow: 0 6px 20px rgba(0,0,0,0.4);
  border-color: rgba(255,255,255,0.8);
}

.cell.water {
  background: linear-gradient(135deg, #3498db 0%, #2980b9 100%);
  cursor: default;
  animation: waterWave 3s infinite;
}

@keyframes waterWave {
  0%, 100% { opacity: 0.9; }
  50% { opacity: 1; }
}

.cell.sand {
  background: linear-gradient(135deg, #f4d03f 0%, #f39c12 100%);
}

.cell.grass {
  background: linear-gradient(135deg, #82e0aa 0%, #27ae60 100%);
}

.cell.forest {
  background: linear-gradient(135deg, #1e8449 0%, #145a32 100%);
}

.cell.mountain {
  background: linear-gradient(135deg, #95a5a6 0%, #5d6d7e 100%);
}

.cell.can-build {
  animation: canBuildPulse 1s infinite;
  border-color: #f1c40f;
}

@keyframes canBuildPulse {
  0%, 100% {
    box-shadow: 0 0 15px 3px #f1c40f;
    transform: scale(1);
  }
  50% {
    box-shadow: 0 0 25px 5px #f39c12;
    transform: scale(1.05);
  }
}

.cell .building-icon {
  font-size: 1.4em;
  filter: drop-shadow(2px 2px 4px rgba(0,0,0,0.6));
  animation: buildingAppear 0.4s;
}

@keyframes buildingAppear {
  0% { transform: scale(0) rotate(-180deg); }
  100% { transform: scale(1) rotate(0); }
}

#tooltip {
  position: absolute;
  background: rgba(44,62,80,0.95);
  color: white;
  padding: 10px 15px;
  border-radius: 10px;
  font-size: 0.95em;
  pointer-events: none;
  z-index: 100;
  max-width: 250px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.4);
  border: 2px solid #f1c40f;
}

#tooltip.hidden { display: none; }

#floating-texts {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: hidden;
}

.floating-text {
  position: absolute;
  font-size: 1.5em;
  font-weight: bold;
  animation: floatUp 2s ease-out forwards;
  text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
}

@keyframes floatUp {
  0% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  100% {
    opacity: 0;
    transform: translateY(-80px) scale(1.5);
  }
}

#log {
  max-height: 200px;
  overflow-y: auto;
  font-size: 1.8em;
  background: #f8f9fa;
  padding: 10px;
  border-radius: 10px;
  border: 2px solid #ddd;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}

.log-entry {
  animation: logAppear 0.3s;
  filter: drop-shadow(1px 1px 2px rgba(0,0,0,0.2));
}

@keyframes logAppear {
  from { opacity: 0; transform: scale(0.5); }
  to { opacity: 1; transform: scale(1); }
}

#modal {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0,0,0,0.8);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

#modal.hidden { display: none; }

.modal-content {
  background: white;
  padding: 40px;
  border-radius: 20px;
  max-width: 500px;
  text-align: center;
  animation: modalPop 0.4s;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

@keyframes modalPop {
  from { transform: scale(0.5); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal-content h2 {
  color: #2c3e50;
  margin-bottom: 20px;
  font-size: 2em;
}

.modal-content p {
  margin-bottom: 25px;
  line-height: 1.6;
  font-size: 1.1em;
}

.modal-content button {
  padding: 12px 40px;
  background: linear-gradient(135deg, #27ae60 0%, #229954 100%);
  color: white;
  border: none;
  border-radius: 12px;
  font-weight: bold;
  cursor: pointer;
  font-size: 1.1em;
  transition: all 0.2s;
}

.modal-content button:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(39,174,96,0.4);
}

@media (max-width: 900px) {
  main { grid-template-columns: 1fr; }
  #board { grid-template-columns: repeat(10, 1fr); }
  #buildings { grid-template-columns: repeat(3, 1fr); }
}