/* ============================================
   МЕТРО: Последний Рубеж — Стили
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Share+Tech+Mono&family=Oswald:wght@300;400;700&family=Roboto+Condensed:wght@300;400;700&display=swap');

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

html, body {
  width: 100%; height: 100%; overflow: hidden;
  background: #020204; color: #c8c8d0;
  font-family: 'Roboto Condensed', sans-serif;
  user-select: none; cursor: default;
}

#game-canvas {
  display: block; width: 100%; height: 100%;
  cursor: grab;
}
#game-canvas:active { cursor: grabbing; }

/* ===== TOP BAR ===== */
#top-bar {
  position: fixed; top: 0; left: 0; right: 0; height: 44px;
  background: rgba(10,10,14,0.88); backdrop-filter: blur(8px);
  border-bottom: 1px solid rgba(42,42,53,0.6);
  display: flex; align-items: center; padding: 0 16px; gap: 20px;
  z-index: 100;
}
#game-title {
  font-family: 'Oswald', sans-serif; font-weight: 700; font-size: 15px;
  letter-spacing: 4px; text-transform: uppercase;
  color: #d4a028; text-shadow: 0 0 20px rgba(212,160,40,0.3);
  white-space: nowrap;
}
#day-counter {
  font-family: 'Share Tech Mono', monospace; font-size: 13px;
  color: #888; letter-spacing: 1px;
}
.speed-controls { display: flex; gap: 2px; margin-left: auto; }
.speed-btn {
  background: rgba(26,26,34,0.8); border: 1px solid rgba(42,42,53,0.6);
  color: #666680; padding: 4px 12px;
  font-family: 'Share Tech Mono', monospace; font-size: 12px;
  cursor: pointer; transition: all 0.2s; line-height: 1;
}
.speed-btn:first-child { border-radius: 3px 0 0 3px; }
.speed-btn:last-child { border-radius: 0 3px 3px 0; }
.speed-btn:hover { background: rgba(42,42,53,0.8); color: #c8c8d0; }
.speed-btn.active {
  background: rgba(212,160,40,0.15); border-color: rgba(212,160,40,0.4);
  color: #d4a028;
}

/* ===== RESOURCE BAR ===== */
#resource-bar {
  position: fixed; top: 48px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 4px;
  background: rgba(10,10,14,0.88); backdrop-filter: blur(8px);
  border: 1px solid rgba(42,42,53,0.5); border-top: none;
  border-radius: 0 0 8px 8px; padding: 6px 14px; z-index: 99;
}
.res-item {
  display: flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 4px; transition: background 0.3s;
}
.res-item.critical { background: rgba(196,48,48,0.15); animation: criticalPulse 1.5s ease-in-out infinite; }
@keyframes criticalPulse {
  0%, 100% { background: rgba(196,48,48,0.1); }
  50% { background: rgba(196,48,48,0.25); }
}
.res-icon { font-size: 14px; line-height: 1; }
.res-val {
  font-family: 'Share Tech Mono', monospace; font-size: 14px;
  font-weight: 700; color: #e0e0e8; min-width: 20px; text-align: right;
}
.res-delta { font-family: 'Share Tech Mono', monospace; font-size: 10px; min-width: 20px; }
.res-delta.positive { color: #4ade80; }
.res-delta.negative { color: #ef4444; }
.res-label { font-size: 10px; color: #666680; text-transform: uppercase; letter-spacing: 0.5px; }
.res-divider { width: 1px; height: 20px; background: rgba(42,42,53,0.6); margin: 0 4px; }

/* ===== POPULATION PANEL (left) ===== */
#pop-panel {
  position: fixed; top: 100px; left: 12px; width: 170px;
  background: rgba(10,10,14,0.88); backdrop-filter: blur(8px);
  border: 1px solid rgba(42,42,53,0.5); border-radius: 6px;
  padding: 10px 10px 6px; z-index: 90;
  max-height: calc(100vh - 120px); overflow-y: auto;
  scrollbar-width: thin; scrollbar-color: #333 transparent;
}
.pop-header {
  font-family: 'Oswald', sans-serif; font-weight: 700; font-size: 11px;
  letter-spacing: 2px; color: #d4a028; margin-bottom: 6px;
}
.pop-row {
  display: flex; justify-content: space-between; font-size: 12px;
  padding: 2px 0; color: #aaa;
}
.pop-row span:last-child {
  color: #e0e0e8; font-family: 'Share Tech Mono', monospace;
}
.morale-bar {
  margin: 6px 0 8px; height: 3px; background: rgba(255,255,255,0.05);
  border-radius: 2px; overflow: hidden;
}
.morale-fill {
  height: 100%; width: 60%; background: #a3e635;
  border-radius: 2px; transition: width 0.5s, background 0.5s;
}

/* Colonist list in pop panel */
.pop-list { display: flex; flex-direction: column; gap: 1px; }
.pop-entry {
  display: flex; align-items: center; gap: 4px;
  padding: 3px 4px; border-radius: 3px;
  cursor: pointer; transition: background 0.15s;
  font-size: 11px;
}
.pop-entry:hover { background: rgba(255,255,255,0.05); }
.pop-entry-sel { background: rgba(212,160,40,0.12) !important; }
.pop-hp-low .pop-entry-name { color: #ef4444; }
.pop-entry-color { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.pop-entry-name {
  flex: 1; color: #bbb; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.pop-entry-task { font-size: 10px; flex-shrink: 0; }

/* ===== COLONIST PANEL (right) ===== */
#colonist-panel {
  position: fixed; top: 100px; right: 12px; width: 260px;
  background: rgba(10,10,14,0.92); backdrop-filter: blur(10px);
  border: 1px solid rgba(42,42,53,0.5); border-radius: 8px;
  padding: 14px; z-index: 95;
  max-height: calc(100vh - 120px); overflow-y: auto;
  scrollbar-width: thin; scrollbar-color: #333 transparent;
  transition: opacity 0.2s, transform 0.2s;
}
#colonist-panel.hidden {
  opacity: 0; transform: translateX(20px); pointer-events: none;
}
.cp-close {
  position: absolute; top: 8px; right: 10px;
  background: none; border: none; color: #555; font-size: 14px;
  cursor: pointer; transition: color 0.2s;
}
.cp-close:hover { color: #ef4444; }

.cp-header { display: flex; gap: 10px; margin-bottom: 12px; align-items: center; }

.cp-portrait {
  width: 44px; height: 44px; border-radius: 6px;
  display: flex; align-items: flex-end; justify-content: center;
  position: relative; overflow: hidden;
  border: 1px solid rgba(255,255,255,0.08);
}
.cp-head {
  width: 22px; height: 22px; border-radius: 50%;
  position: relative; margin-bottom: 4px;
}
.cp-hair {
  position: absolute; top: -2px; left: -2px; right: -2px; height: 12px;
  border-radius: 12px 12px 0 0;
}

.cp-info { flex: 1; }
.cp-name {
  font-family: 'Oswald', sans-serif; font-size: 16px; font-weight: 700;
  color: #e0e0e8; letter-spacing: 1px;
}
.cp-age { font-size: 11px; color: #888; }
.cp-status { font-size: 11px; margin-top: 2px; }

.cp-section { margin-bottom: 10px; }
.cp-title {
  font-family: 'Oswald', sans-serif; font-size: 10px; font-weight: 700;
  letter-spacing: 2px; color: #555; margin-bottom: 5px;
  border-bottom: 1px solid rgba(42,42,53,0.3); padding-bottom: 3px;
}

/* Traits */
.cp-traits { display: flex; flex-wrap: wrap; gap: 4px; }
.trait-tag {
  font-size: 10px; padding: 2px 6px; border-radius: 3px;
  border: 1px solid; background: rgba(255,255,255,0.02);
  cursor: default; white-space: nowrap;
}

/* Needs */
.need-row { display: flex; align-items: center; gap: 5px; margin-bottom: 3px; }
.need-icon { font-size: 11px; width: 16px; text-align: center; flex-shrink: 0; }
.need-bar-bg {
  flex: 1; height: 6px; background: rgba(255,255,255,0.05);
  border-radius: 3px; overflow: hidden;
}
.need-bar-fill { height: 100%; border-radius: 3px; transition: width 0.3s, background 0.3s; }
.need-pct {
  font-family: 'Share Tech Mono', monospace; font-size: 10px;
  color: #888; width: 22px; text-align: right; flex-shrink: 0;
}

/* Skills */
.skill-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 2px; }
.skill-name { font-size: 11px; color: #aaa; }
.skill-dots {
  font-size: 8px; letter-spacing: 1px; color: #d4a028;
  font-family: monospace;
}

/* Inventory */
.cp-inventory { display: flex; flex-wrap: wrap; gap: 4px; }
.inv-item {
  font-size: 10px; padding: 3px 6px; border-radius: 3px;
  background: rgba(255,255,255,0.04); border: 1px solid rgba(42,42,53,0.3);
  color: #bbb;
}
.inv-empty { font-size: 11px; color: #444; font-style: italic; }

/* ===== LOG ===== */
#log-toggle {
  position: fixed; bottom: 12px; right: 12px;
  width: 40px; height: 40px; border-radius: 50%;
  background: rgba(10,10,14,0.85); border: 1px solid rgba(42,42,53,0.6);
  color: #888; font-size: 18px; cursor: pointer; z-index: 95;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s;
}
#log-toggle:hover { border-color: rgba(212,160,40,0.5); color: #d4a028; }

#log-panel {
  position: fixed; bottom: 60px; right: 12px; width: 300px; max-height: 300px;
  background: rgba(10,10,14,0.92); backdrop-filter: blur(8px);
  border: 1px solid rgba(42,42,53,0.5); border-radius: 6px;
  padding: 10px; z-index: 95; overflow: hidden;
  transition: opacity 0.2s, transform 0.2s;
}
#log-panel.hidden { opacity: 0; transform: translateY(10px); pointer-events: none; }
.log-header {
  font-family: 'Oswald', sans-serif; font-weight: 700; font-size: 11px;
  letter-spacing: 2px; color: #d4a028; margin-bottom: 8px;
}
.log-entries {
  max-height: 250px; overflow-y: auto;
  scrollbar-width: thin; scrollbar-color: #333 transparent;
}
.log-entry {
  font-size: 11px; padding: 3px 0;
  border-bottom: 1px solid rgba(255,255,255,0.03); line-height: 1.4;
}
.log-day {
  font-family: 'Share Tech Mono', monospace; color: #555;
  margin-right: 6px; font-size: 10px;
}
.log-info { color: #aaa; }
.log-success { color: #4ade80; }
.log-warning { color: #facc15; }
.log-danger { color: #ef4444; }

/* ===== GAME OVER ===== */
#game-over {
  position: fixed; inset: 0; background: rgba(0,0,0,0.85);
  display: flex; align-items: center; justify-content: center;
  z-index: 999; backdrop-filter: blur(4px);
}
#game-over.hidden { display: none; }
.go-content { text-align: center; }
.go-title {
  font-family: 'Oswald', sans-serif; font-size: 48px; font-weight: 700;
  letter-spacing: 8px; color: #c43030;
  text-shadow: 0 0 40px rgba(196,48,48,0.5); margin-bottom: 16px;
}
.go-reason { font-size: 16px; color: #888; margin-bottom: 24px; }
.go-stats {
  font-family: 'Share Tech Mono', monospace; font-size: 14px;
  color: #aaa; margin-bottom: 32px;
}
.go-stats b { color: #d4a028; font-size: 20px; }
.go-restart {
  font-family: 'Oswald', sans-serif; font-size: 16px; letter-spacing: 3px;
  padding: 12px 40px; background: rgba(212,160,40,0.15);
  border: 1px solid rgba(212,160,40,0.5); color: #d4a028;
  cursor: pointer; border-radius: 4px; transition: all 0.2s;
}
.go-restart:hover { background: rgba(212,160,40,0.3); }

/* ===== BUILD PANEL ===== */
#build-toggle, #demolish-toggle {
  position: fixed; bottom: 12px; left: 12px;
  width: 44px; height: 44px; border-radius: 8px;
  background: rgba(10,10,14,0.88); border: 1px solid rgba(42,42,53,0.6);
  color: #888; font-size: 20px; cursor: pointer; z-index: 95;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s;
}
#demolish-toggle { left: 62px; }
#build-toggle:hover, #demolish-toggle:hover {
  border-color: rgba(212,160,40,0.5); color: #d4a028;
}
#build-toggle.active {
  background: rgba(212,160,40,0.15); border-color: rgba(212,160,40,0.5); color: #d4a028;
}
#demolish-toggle.active {
  background: rgba(200,50,50,0.15); border-color: rgba(200,50,50,0.5); color: #ef4444;
}

#build-panel {
  position: fixed; bottom: 62px; left: 12px; width: 320px;
  background: rgba(10,10,14,0.92); backdrop-filter: blur(10px);
  border: 1px solid rgba(42,42,53,0.5); border-radius: 8px;
  padding: 0; z-index: 96; overflow: hidden;
  transition: opacity 0.2s, transform 0.2s;
  max-height: calc(100vh - 200px);
}
#build-panel.hidden {
  opacity: 0; transform: translateY(10px); pointer-events: none;
}

.build-categories {
  display: flex; gap: 0; border-bottom: 1px solid rgba(42,42,53,0.4);
}
.build-cat-btn {
  flex: 1; padding: 8px 4px; background: none; border: none; border-bottom: 2px solid transparent;
  color: #666; cursor: pointer; transition: all 0.15s;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 14px;
}
.build-cat-btn:hover { color: #bbb; background: rgba(255,255,255,0.03); }
.build-cat-btn.active {
  color: #d4a028; border-bottom-color: #d4a028; background: rgba(212,160,40,0.05);
}
.build-cat-name {
  font-family: 'Share Tech Mono', monospace; font-size: 9px;
  letter-spacing: 0.5px; text-transform: uppercase;
}

.build-list {
  max-height: 300px; overflow-y: auto; padding: 6px;
  scrollbar-width: thin; scrollbar-color: #333 transparent;
}

.build-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 8px; margin-bottom: 2px; border-radius: 6px;
  cursor: pointer; transition: all 0.15s;
  border: 1px solid transparent;
}
.build-item:hover {
  background: rgba(255,255,255,0.04); border-color: rgba(42,42,53,0.4);
}
.build-item.build-selected {
  background: rgba(212,160,40,0.08); border-color: rgba(212,160,40,0.3);
}
.build-item.build-unaffordable {
  opacity: 0.45;
}
.build-item.build-unaffordable:hover { opacity: 0.65; }

.build-item-icon { font-size: 24px; flex-shrink: 0; width: 32px; text-align: center; }
.build-item-info { flex: 1; min-width: 0; }
.build-item-name {
  font-family: 'Oswald', sans-serif; font-size: 13px; font-weight: 700;
  color: #ddd; letter-spacing: 0.5px;
}
.build-item-desc { font-size: 10px; color: #777; margin-top: 1px; }
.build-item-cost {
  display: flex; gap: 6px; margin-top: 3px;
}
.cost-item {
  font-family: 'Share Tech Mono', monospace; font-size: 10px; color: #aaa;
}
.cost-item.cost-lacking { color: #ef4444; }

.build-item-meta {
  display: flex; flex-direction: column; align-items: flex-end; gap: 2px;
  flex-shrink: 0;
}
.meta-energy, .meta-workers, .meta-size {
  font-family: 'Share Tech Mono', monospace; font-size: 9px; color: #666;
}

/* Build tooltip */
#build-tooltip {
  position: fixed; z-index: 200; padding: 10px 12px;
  background: rgba(15,15,20,0.95); backdrop-filter: blur(8px);
  border: 1px solid rgba(42,42,53,0.6); border-radius: 6px;
  min-width: 180px; max-width: 250px; pointer-events: none;
  transition: opacity 0.15s;
}
#build-tooltip.hidden { opacity: 0; pointer-events: none; }
.tt-header {
  font-family: 'Oswald', sans-serif; font-size: 14px; font-weight: 700;
  color: #d4a028; margin-bottom: 4px; letter-spacing: 1px;
}
.tt-desc { font-size: 11px; color: #999; margin-bottom: 6px; }
.tt-divider { height: 1px; background: rgba(42,42,53,0.4); margin: 6px 0; }
.tt-section { font-size: 10px; color: #888; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 3px; }
.tt-row { font-size: 11px; color: #bbb; padding: 1px 0; }

/* Mode indicator */
#mode-indicator {
  position: fixed; top: 96px; left: 50%; transform: translateX(-50%);
  font-family: 'Share Tech Mono', monospace; font-size: 12px;
  padding: 6px 16px; border-radius: 4px; z-index: 98;
  pointer-events: none; white-space: nowrap; letter-spacing: 0.5px;
}
#mode-indicator.hidden { display: none; }
#mode-indicator.mode-build {
  background: rgba(59,130,246,0.15); border: 1px solid rgba(59,130,246,0.4);
  color: #60a5fa;
}
#mode-indicator.mode-demolish {
  background: rgba(239,68,68,0.15); border: 1px solid rgba(239,68,68,0.4);
  color: #ef4444;
}

/* ===== HINT ===== */
#hint-overlay {
  position: fixed; bottom: 14px; left: 50%; transform: translateX(-50%);
  font-family: 'Share Tech Mono', monospace; font-size: 11px;
  color: rgba(102,102,128,0.5); letter-spacing: 1px; text-align: center;
  pointer-events: none; animation: hintPulse 3s ease-in-out infinite;
  white-space: nowrap;
}
@keyframes hintPulse { 0%, 100% { opacity: 0.3; } 50% { opacity: 0.7; } }

/* Scanline */
body::after {
  content: ''; position: fixed; inset: 0;
  background: repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(0,0,0,0.03) 2px, rgba(0,0,0,0.03) 4px);
  pointer-events: none; z-index: 9999;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  #resource-bar {
    gap: 2px; padding: 4px 8px; flex-wrap: wrap; max-width: 95vw;
  }
  .res-label { display: none; }
  .res-item { padding: 2px 4px; }
  #pop-panel { width: 140px; }
  #colonist-panel { width: 220px; }
  #game-title { font-size: 12px; letter-spacing: 2px; }
}

/* ===== COMBAT UI ===== */
#wave-indicator {
  position: fixed; top: 50px; left: 50%; transform: translateX(-50%);
  padding: 6px 20px; border-radius: 4px;
  font-family: 'Share Tech Mono', monospace;
  font-size: 14px; font-weight: bold; letter-spacing: 1px;
  z-index: 100; pointer-events: none;
  transition: opacity 0.4s;
}
#wave-indicator.hidden { opacity: 0; }
#wave-indicator.warning {
  background: rgba(180, 80, 20, 0.2);
  border: 1px solid rgba(200, 80, 30, 0.5);
  color: #f59e0b;
  animation: wavePulse 1.5s ease-in-out infinite;
}
#wave-indicator.active {
  background: rgba(200, 30, 20, 0.25);
  border: 1px solid rgba(220, 40, 30, 0.6);
  color: #ef4444;
  animation: wavePulse 0.8s ease-in-out infinite;
}
@keyframes wavePulse {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 1; }
}

/* Enemy tooltip */
.enemy-info {
  color: #ef4444;
  font-size: 11px;
}

/* Log danger entries - make them more visible */
.log-entry.log-danger {
  border-left: 3px solid #ef4444;
  padding-left: 8px;
  background: rgba(200, 30, 20, 0.08);
}
