* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

body, html {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: #12161f;
  color: #e2e8f0;
}

#app {
  position: relative;
  width: 100vw;
  height: 100vh;
}

/* TOP HUD BAR */
#hud-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 50px;
  background: rgba(18, 22, 31, 0.92);
  border-bottom: 1px solid #2d3748;
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 100;
}

.hud-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand {
  font-weight: bold;
}

.game-title {
  color: #38bdf8;
  font-size: 1.1rem;
  letter-spacing: 1px;
}

.player-tag-btn {
  font-size: 0.85rem;
  background: #1e293b;
  padding: 3px 10px;
  border-radius: 6px;
  color: #94a3b8;
  border: 1px solid #334155;
  cursor: pointer;
  transition: all 0.2s;
}

.player-tag-btn:hover {
  background: #334155;
  color: #f8fafc;
}

.resources {
  display: flex;
  gap: 16px;
  flex-wrap: nowrap;
  overflow-x: auto;
}

.res-item {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.9rem;
  font-weight: 600;
  background: rgba(30, 41, 59, 0.6);
  padding: 4px 8px;
  border-radius: 6px;
}

.res-item .icon {
  font-size: 1rem;
}

.coords-display {
  font-family: monospace;
  font-size: 0.95rem;
  background: #0f172a;
  color: #38bdf8;
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid #334155;
}

.tick-display {
  font-size: 0.8rem;
  color: #64748b;
}

/* CANVAS */
#game-canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
}

#game-canvas:active {
  cursor: grabbing;
}

/* VIEW CONTROLS */
#view-controls {
  position: absolute;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 90;
}

.ctrl-btn {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: #1e293b;
  color: #f1f5f9;
  border: 1px solid #334155;
  font-size: 1.2rem;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 6px rgba(0,0,0,0.3);
  touch-action: manipulation;
}

.ctrl-btn:active {
  background: #334155;
}

/* DRAWER / INSPECTOR */
.drawer {
  position: absolute;
  top: 60px;
  right: 20px;
  width: 320px;
  max-height: calc(100vh - 100px);
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid #334155;
  border-radius: 12px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.5);
  backdrop-filter: blur(10px);
  z-index: 95;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform 0.25s ease, opacity 0.25s ease;
}

.drawer.hidden {
  transform: translateX(360px);
  opacity: 0;
  pointer-events: none;
}

.drawer-header {
  padding: 12px 16px;
  background: #1e293b;
  border-bottom: 1px solid #334155;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.drawer-header h3 {
  font-size: 1rem;
  color: #f8fafc;
}

.close-btn {
  background: none;
  border: none;
  color: #94a3b8;
  font-size: 1.5rem;
  cursor: pointer;
}

.drawer-body {
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.info-card {
  background: #0f172a;
  padding: 12px;
  border-radius: 8px;
  border: 1px solid #1e293b;
  font-size: 0.85rem;
  line-height: 1.6;
}

.info-card span {
  color: #38bdf8;
}

.actions-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.action-btn {
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  border: none;
  background: #2563eb;
  color: white;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.action-btn:hover {
  background: #1d4ed8;
}

.action-btn.secondary {
  background: #334155;
  color: #cbd5e1;
}

.action-btn.secondary:hover {
  background: #475569;
}

.action-btn.danger {
  background: #dc2626;
}

.action-btn.danger:hover {
  background: #b91c1c;
}

/* HOME PAGE LOBBY SELECTOR OVERLAY */
.lobby-home-overlay {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, #1e293b 0%, #0f172a 100%);
  z-index: 300;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 24px;
  overflow-y: auto;
}

.lobby-home-container {
  width: 100%;
  max-width: 1100px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.home-header {
  text-align: center;
}

.home-title {
  font-size: 2.5rem;
  color: #38bdf8;
  letter-spacing: 2px;
  text-shadow: 0 0 20px rgba(56, 189, 248, 0.4);
}

.home-subtitle {
  color: #94a3b8;
  font-size: 0.95rem;
  margin-top: 4px;
}

.home-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 20px;
}

.home-card {
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid #334155;
  border-radius: 12px;
  padding: 20px;
  backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  box-shadow: 0 10px 20px rgba(0,0,0,0.4);
}

.home-card h3 {
  font-size: 1.1rem;
  margin-bottom: 4px;
}

.card-desc {
  font-size: 0.8rem;
  color: #64748b;
  margin-bottom: 12px;
}

.lobby-card-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 280px;
  overflow-y: auto;
  padding-right: 4px;
}

.lobby-item {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: background 0.2s, border-color 0.2s;
}

.lobby-item:hover {
  background: #334155;
  border-color: #38bdf8;
}

.lobby-item-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.lobby-item-title {
  font-weight: bold;
  font-size: 0.9rem;
  color: #f8fafc;
}

.lobby-item-meta {
  font-size: 0.75rem;
  color: #94a3b8;
}

.empty-msg {
  font-size: 0.85rem;
  color: #64748b;
  font-style: italic;
  padding: 12px 0;
  text-align: center;
}

/* MODAL */
.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-overlay.hidden {
  display: none;
}

.modal-box {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 12px;
  width: 90%;
  max-width: 420px;
  padding: 20px;
  box-shadow: 0 20px 30px rgba(0,0,0,0.6);
}

.modal-box h3 {
  margin-bottom: 12px;
  color: #38bdf8;
}

.modal-body {
  font-size: 0.9rem;
  margin-bottom: 16px;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.hidden {
  display: none !important;
}

/* MOBILE ADAPTATION */
@media (max-width: 768px) {
  #hud-top {
    height: 44px;
    padding: 0 8px;
  }
  .resources {
    gap: 8px;
  }
  .res-item {
    font-size: 0.75rem;
    padding: 2px 5px;
  }
  .drawer {
    left: 10px;
    right: 10px;
    width: auto;
    bottom: 10px;
    top: auto;
    max-height: 50vh;
  }
  .drawer.hidden {
    transform: translateY(120%);
  }
}
