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

body {
  overflow: hidden;
  background: #0a0a0f;
  font-family: 'JetBrains Mono', monospace;
  color: #e0d8c8;
  user-select: none;
  -webkit-user-select: none;
}

#canvas {
  display: block;
  position: absolute;
  top: 0; left: 0;
  width: 100vw; height: 100vh;
  image-rendering: pixelated;
  cursor: crosshair;
}

/* ===== TOOLBAR ===== */
#toolbar {
  position: fixed; top: 0; left: 0; right: 0;
  height: 48px;
  background: linear-gradient(180deg, rgba(15,12,20,0.95) 0%, rgba(15,12,20,0.85) 100%);
  border-bottom: 1px solid rgba(212,175,55,0.3);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 12px;
  z-index: 100;
  backdrop-filter: blur(8px);
}

#toolbar-left, #toolbar-right { display: flex; align-items: center; gap: 12px; }

#game-title {
  font-family: 'Cinzel', serif;
  font-weight: 900;
  font-size: 20px;
  color: #d4af37;
  text-shadow: 0 0 20px rgba(212,175,55,0.5), 0 0 40px rgba(212,175,55,0.2);
  letter-spacing: 2px;
}

#time-controls { display: flex; gap: 4px; }

.time-btn {
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.15);
  color: #a09880;
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s;
}
.time-btn:hover { background: rgba(212,175,55,0.15); color: #d4af37; }
.time-btn.active {
  background: rgba(212,175,55,0.25);
  border-color: #d4af37;
  color: #d4af37;
  box-shadow: 0 0 10px rgba(212,175,55,0.3);
}

.stat {
  display: flex; align-items: center; gap: 4px;
  font-size: 12px; color: #a09880;
  padding: 0 8px;
}
.stat-icon { font-size: 14px; }

.toolbar-actions { display: flex; gap: 6px; align-items: center; }

#world-size {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  color: #e0d8c8;
  padding: 4px 8px;
  border-radius: 4px;
  font-family: inherit;
  font-size: 11px;
}
#world-size option { background: #1a1520; }

#new-world-btn, #save-btn, #load-btn {
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.15);
  color: #a09880;
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  font-family: inherit;
  transition: all 0.2s;
}
#new-world-btn:hover, #save-btn:hover, #load-btn:hover {
  background: rgba(212,175,55,0.15); color: #d4af37;
}

/* ===== SIDEBAR ===== */
#sidebar {
  position: fixed; top: 52px; left: 0;
  width: 180px;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  background: linear-gradient(90deg, rgba(15,12,20,0.92) 0%, rgba(15,12,20,0.8) 100%);
  border-right: 1px solid rgba(212,175,55,0.15);
  z-index: 90;
  backdrop-filter: blur(8px);
  scrollbar-width: thin;
  scrollbar-color: rgba(212,175,55,0.3) transparent;
}
#sidebar::-webkit-scrollbar { width: 4px; }
#sidebar::-webkit-scrollbar-thumb { background: rgba(212,175,55,0.3); border-radius: 2px; }

.tool-category { border-bottom: 1px solid rgba(255,255,255,0.06); }

.cat-header {
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 700;
  color: #d4af37;
  cursor: pointer;
  display: flex; gap: 6px; align-items: center;
  transition: background 0.2s;
}
.cat-header:hover { background: rgba(212,175,55,0.08); }

.cat-tools {
  display: none;
  padding: 4px 8px 8px;
}
.tool-category.open .cat-tools { display: block; }

.tool-btn {
  display: block;
  width: 100%;
  text-align: left;
  background: rgba(255,255,255,0.03);
  border: 1px solid transparent;
  color: #c0b8a8;
  padding: 5px 8px;
  border-radius: 3px;
  cursor: pointer;
  font-family: inherit;
  font-size: 11px;
  margin-bottom: 2px;
  transition: all 0.15s;
}
.tool-btn:hover {
  background: rgba(212,175,55,0.1);
  border-color: rgba(212,175,55,0.3);
  color: #d4af37;
}
.tool-btn.active {
  background: rgba(212,175,55,0.2);
  border-color: #d4af37;
  color: #d4af37;
  box-shadow: inset 0 0 8px rgba(212,175,55,0.15);
}

.brush-size-control {
  padding: 4px 0 6px;
  font-size: 10px;
  color: #888;
}
.brush-size-control input[type="range"] {
  width: 100%;
  accent-color: #d4af37;
  height: 4px;
}

.laws-tools label {
  display: block;
  font-size: 11px;
  padding: 3px 0;
  color: #a09880;
  cursor: pointer;
}
.laws-tools input[type="checkbox"] { accent-color: #d4af37; margin-right: 4px; }

/* ===== INSPECTOR ===== */
#inspector {
  position: fixed; top: 52px; right: 0;
  width: 220px;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  background: linear-gradient(270deg, rgba(15,12,20,0.95) 0%, rgba(15,12,20,0.85) 100%);
  border-left: 1px solid rgba(212,175,55,0.15);
  z-index: 90;
  backdrop-filter: blur(8px);
  padding: 12px;
  transition: transform 0.3s ease;
}
#inspector.hidden { transform: translateX(250px); pointer-events: none; }
#inspector-close {
  position: absolute; top: 8px; right: 10px;
  cursor: pointer; color: #666; font-size: 16px;
}
#inspector-close:hover { color: #d4af37; }

#inspector-content h3 {
  font-family: 'Cinzel', serif;
  color: #d4af37;
  font-size: 14px;
  margin-bottom: 8px;
}
#inspector-content .insp-row {
  font-size: 11px;
  padding: 2px 0;
  color: #a09880;
  display: flex;
  justify-content: space-between;
}
#inspector-content .insp-row span:last-child { color: #e0d8c8; }

.health-bar {
  width: 100%;
  height: 6px;
  background: rgba(255,255,255,0.1);
  border-radius: 3px;
  margin: 4px 0;
  overflow: hidden;
}
.health-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s;
}

/* ===== EVENT LOG ===== */
#event-log {
  position: fixed; bottom: 24px; left: 180px; right: 160px;
  height: 80px;
  background: rgba(10,8,15,0.85);
  border-top: 1px solid rgba(212,175,55,0.15);
  overflow-y: auto;
  padding: 6px 12px;
  z-index: 80;
  backdrop-filter: blur(6px);
  scrollbar-width: thin;
  scrollbar-color: rgba(212,175,55,0.2) transparent;
}
#event-log::-webkit-scrollbar { width: 3px; }
#event-log::-webkit-scrollbar-thumb { background: rgba(212,175,55,0.2); }

#event-log-content {
  font-size: 10px;
  line-height: 1.6;
}
.event-entry { cursor: pointer; padding: 1px 0; }
.event-entry:hover { opacity: 0.7; }
.event-founding { color: #6ecf6e; }
.event-war { color: #e85555; }
.event-diplomacy { color: #5599e8; }
.event-disaster { color: #e8a555; }
.event-supernatural { color: #b06ee8; }
.event-death { color: #888; }

/* ===== MINIMAP ===== */
#minimap {
  position: fixed;
  bottom: 28px; right: 8px;
  width: 150px; height: 150px;
  background: rgba(10,8,15,0.9);
  border: 1px solid rgba(212,175,55,0.3);
  border-radius: 4px;
  z-index: 85;
  image-rendering: pixelated;
}

/* ===== FOOTER ===== */
#footer {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: 22px;
  background: rgba(10,8,15,0.9);
  border-top: 1px solid rgba(255,255,255,0.05);
  display: flex; align-items: center; justify-content: center;
  font-size: 10px;
  color: #555;
  z-index: 100;
}
#footer a { color: #d4af37; text-decoration: none; }
#footer a:hover { text-decoration: underline; }

/* ===== MOBILE ===== */
@media (max-width: 768px) {
  #sidebar { width: 50px; }
  .cat-header span:last-child, .cat-tools { display: none; }
  .tool-category.open .cat-tools {
    display: block;
    position: absolute;
    left: 50px;
    background: rgba(15,12,20,0.95);
    border: 1px solid rgba(212,175,55,0.2);
    border-radius: 4px;
    padding: 8px;
    min-width: 140px;
    z-index: 200;
  }
  .cat-header { padding: 10px 14px; font-size: 16px; justify-content: center; }
  #event-log { left: 50px; right: 10px; bottom: 24px; height: 60px; }
  #minimap { display: none; }
  #inspector { width: 200px; }
  #game-title { font-size: 14px; letter-spacing: 1px; }
  .stat { font-size: 10px; }
  #toolbar { padding: 0 6px; }
  .toolbar-actions { gap: 3px; }
}