/* ── Reset & Base ── */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0a0b0f;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  color: #e8e6e3;
}

#game-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
}

#game-container {
  width: 100%;
  height: 100%;
}

#game-container canvas {
  display: block;
}

/* ── Overlay UI ── */
#ui-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

#ui-overlay > * {
  pointer-events: auto;
}

.screen {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

.screen.hidden {
  display: none;
}

/* ── Lobby ── */
.lobby-card {
  background: linear-gradient(145deg, #1a1d26 0%, #12141c 100%);
  border: 1px solid #2a2e3a;
  border-radius: 20px;
  padding: 3rem 4rem;
  text-align: center;
  max-width: 500px;
  width: 90%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}

.game-title {
  font-size: 2.8rem;
  font-weight: 800;
  letter-spacing: 2px;
  background: linear-gradient(135deg, #e8b84b 0%, #c9912a 50%, #a6751e 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-shadow: none;
  margin-bottom: 0.3rem;
}

.subtitle {
  color: #888a94;
  font-size: 1rem;
  letter-spacing: 4px;
  text-transform: uppercase;
  margin-bottom: 2rem;
}

.lobby-status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  color: #a8aab3;
  font-size: 0.9rem;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid #2a2e3a;
  border-top-color: #e8b84b;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.player-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 2rem;
  min-height: 60px;
}

.player-item {
  background: #1e212b;
  border: 1px solid #2a2e3a;
  border-radius: 8px;
  padding: 0.6rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.9rem;
  animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.player-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #2a2e3a;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
}

.player-name {
  flex: 1;
  text-align: left;
  color: #c8c6c3;
}

.player-ready {
  color: #4ade80;
  font-size: 0.8rem;
}

/* ── Buttons ── */
.btn {
  border: none;
  border-radius: 10px;
  padding: 0.8rem 2.5rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.btn:focus-visible {
  outline: 2px solid #e8b84b;
  outline-offset: 3px;
}

.btn-primary {
  background: linear-gradient(135deg, #e8b84b 0%, #c9912a 100%);
  color: #0a0b0f;
  box-shadow: 0 4px 20px rgba(233, 184, 75, 0.25);
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 30px rgba(233, 184, 75, 0.35);
}

.btn-secondary {
  background: linear-gradient(135deg, #4a5568 0%, #2d3748 100%);
  color: #e8e6e3;
  box-shadow: 0 4px 20px rgba(74, 85, 104, 0.25);
}

.btn-secondary:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 30px rgba(74, 85, 104, 0.35);
}

.btn-primary:disabled,
.btn-secondary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

/* ── Matchmaking Panel ── */
.matchmaking-panel {
  background: #1a1d26;
  border: 1px solid #e8b84b55;
  border-radius: 10px;
  padding: 1rem;
  margin-bottom: 1rem;
  animation: pulseBorder 1.5s ease-in-out infinite;
}

@keyframes pulseBorder {
  0%, 100% { border-color: #e8b84b55; }
  50% { border-color: #e8b84baa; }
}

.mm-status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-size: 1rem;
  color: #e8e6e3;
  margin-bottom: 0.5rem;
}

.mm-icon {
  font-size: 1.2rem;
  animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.mm-info {
  text-align: center;
  font-size: 0.85rem;
  color: #888a94;
}

/* ── Game Room Panel ── */
.game-room-panel {
  background: #1a1d26;
  border: 1px solid #2a2e3a;
  border-radius: 10px;
  padding: 0.8rem;
  margin-bottom: 1rem;
}

.room-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid #2a2e3a;
}

.room-title {
  font-weight: 700;
  color: #e8b84b;
}

.room-count {
  font-size: 0.85rem;
  color: #888a94;
}

.room-player-list {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-bottom: 0.5rem;
  min-height: 30px;
}

.room-player-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  padding: 0.3rem 0.5rem;
  background: #1e212b;
  border-radius: 6px;
}

.room-player-avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
}

.room-player-name {
  flex: 1;
  color: #c8c6c3;
}

.room-player-ready-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.room-ready-bar {
  margin-top: 0.3rem;
}

.room-ready-text {
  font-size: 0.75rem;
  color: #888a94;
  display: block;
  margin-bottom: 0.25rem;
}

.room-ready-progress {
  height: 4px;
  background: #2a2e3a;
  border-radius: 2px;
  overflow: hidden;
}

.room-ready-fill {
  height: 100%;
  background: linear-gradient(90deg, #e8b84b, #4ade80);
  border-radius: 2px;
  transition: width 0.3s ease;
}

/* ── Lobby Chat ── */
.lobby-chat-box {
  margin-top: 1rem;
  border-top: 1px solid #2a2e3a;
  padding-top: 0.5rem;
}

.lobby-chat-messages {
  height: 80px;
  overflow-y: auto;
  background: #12141c;
  border: 1px solid #2a2e3a;
  border-radius: 6px;
  padding: 0.4rem;
  margin-bottom: 0.3rem;
  font-size: 0.8rem;
  text-align: left;
}

.lobby-chat-messages .msg {
  padding: 0.15rem 0;
  border-bottom: 1px solid rgba(42, 46, 58, 0.2);
}

#lobby-chat-input {
  width: 100%;
  background: #1e212b;
  border: 1px solid #2a2e3a;
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
  color: #e8e6e3;
  font-size: 0.8rem;
  font-family: inherit;
}

#lobby-chat-input:focus {
  outline: none;
  border-color: #e8b84b;
}

/* ── Lobby name input ── */
.lobby-name-input {
  margin-bottom: 0.8rem;
}

.lobby-name-input input {
  width: 100%;
  background: #1e212b;
  border: 1px solid #2a2e3a;
  border-radius: 8px;
  padding: 0.7rem 1rem;
  color: #e8e6e3;
  font-size: 0.95rem;
  text-align: center;
  font-family: inherit;
  transition: border-color 0.2s;
}

.lobby-name-input input:focus {
  outline: none;
  border-color: #e8b84b;
}

.lobby-name-input input::placeholder {
  color: #555;
}

.player-count {
  color: #888a94;
  font-size: 0.85rem;
  margin-bottom: 0.8rem;
}

.lobby-buttons {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
}

/* ── HUD ── */
#hud {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

#hud > * {
  pointer-events: auto;
}

#resources-bar {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 1.5rem;
  background: rgba(10, 11, 15, 0.85);
  border: 1px solid #2a2e3a;
  border-radius: 12px;
  padding: 0.5rem 1.5rem;
  backdrop-filter: blur(8px);
}

.res {
  font-size: 0.9rem;
  font-weight: 600;
  color: #e8e6e3;
}

#minimap {
  position: absolute;
  bottom: 12px;
  right: 12px;
  width: 180px;
  height: 180px;
  background: rgba(10, 11, 15, 0.85);
  border: 1px solid #2a2e3a;
  border-radius: 8px;
  backdrop-filter: blur(8px);
}

#zone-timer {
  position: absolute;
  top: 60px;
  right: 12px;
  background: rgba(10, 11, 15, 0.85);
  border: 1px solid #2a2e3a;
  border-radius: 8px;
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  backdrop-filter: blur(8px);
}

#chat-box {
  position: absolute;
  bottom: 12px;
  left: 12px;
  width: 280px;
  pointer-events: auto;
}

#chat-messages {
  background: rgba(10, 11, 15, 0.8);
  border: 1px solid #2a2e3a;
  border-radius: 8px 8px 0 0;
  height: 120px;
  overflow-y: auto;
  padding: 0.5rem;
  font-size: 0.8rem;
  backdrop-filter: blur(8px);
}

#chat-messages .msg {
  padding: 0.2rem 0;
  border-bottom: 1px solid rgba(42, 46, 58, 0.3);
}

#chat-input {
  width: 100%;
  background: rgba(10, 11, 15, 0.85);
  border: 1px solid #2a2e3a;
  border-radius: 0 0 8px 8px;
  padding: 0.5rem;
  color: #e8e6e3;
  font-size: 0.85rem;
  backdrop-filter: blur(8px);
}

#chat-input:focus {
  outline: none;
  border-color: #e8b84b;
}

/* ── Action Panels (Build / Train) ── */
#action-panels {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: auto;
}

.action-panel {
  background: rgba(10, 11, 15, 0.88);
  border: 1px solid #2a2e3a;
  border-radius: 10px;
  padding: 0.5rem 0.6rem;
  backdrop-filter: blur(8px);
  min-width: 130px;
}

.panel-header {
  font-size: 0.7rem;
  font-weight: 700;
  color: #e8b84b;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.35rem;
  text-align: center;
  border-bottom: 1px solid #2a2e3a;
  padding-bottom: 0.3rem;
}

.panel-buttons {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.btn-build,
.btn-train {
  background: #1e212b;
  border: 1px solid #2a2e3a;
  border-radius: 6px;
  padding: 0.35rem 0.6rem;
  color: #e8e6e3;
  font-size: 0.78rem;
  cursor: pointer;
  text-align: left;
  transition: all 0.15s;
  font-family: inherit;
  pointer-events: auto;
}

.btn-build:hover,
.btn-train:hover {
  background: #2a2e3a;
  border-color: #e8b84b44;
  color: #fff;
}

.btn-build:active,
.btn-train:active {
  transform: scale(0.97);
}

/* ── Chat header ── */
.chat-header {
  font-size: 0.7rem;
  font-weight: 700;
  color: #e8b84b;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  background: rgba(10, 11, 15, 0.85);
  border: 1px solid #2a2e3a;
  border-bottom: none;
  border-radius: 8px 8px 0 0;
  padding: 0.3rem 0.5rem;
  text-align: center;
  backdrop-filter: blur(8px);
}

/* ── Resource labels ── */
.res-label {
  display: block;
  font-size: 0.55rem;
  font-weight: 400;
  color: #888a94;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 1px;
}

.res-value {
  font-size: 0.9rem;
  font-weight: 600;
  color: #e8e6e3;
}

.res {
  text-align: center;
  line-height: 1.2;
}

/* ── Victory / Defeat ── */
.end-card {
  background: linear-gradient(145deg, #1a1d26 0%, #12141c 100%);
  border-radius: 20px;
  padding: 3rem 4rem;
  text-align: center;
  max-width: 450px;
  width: 90%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  animation: fadeIn 0.5s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.end-card h1 {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
}

.end-card p {
  color: #888a94;
  margin-bottom: 1.5rem;
}

.end-card .end-stats {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-bottom: 1.5rem;
  font-size: 0.9rem;
  color: #c8c6c3;
}

.end-card .end-stats span {
  display: block;
}

.end-card.victory h1 {
  color: #e8b84b;
}

.end-card.defeat h1 {
  color: #ef4444;
}

/* ── Toast / Notificação ── */
.toast {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(10, 11, 15, 0.9);
  border: 1px solid #ef444488;
  border-radius: 10px;
  padding: 0.6rem 1.5rem;
  color: #f0f0f0;
  font-size: 0.9rem;
  z-index: 1000;
  animation: toastIn 0.3s ease-out;
  pointer-events: none;
  backdrop-filter: blur(6px);
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(-10px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ── Responsivo ── */
@media (max-width: 600px) {
  .lobby-card,
  .end-card {
    padding: 2rem 1.5rem;
  }

  .game-title {
    font-size: 2rem;
  }

  #resources-bar {
    gap: 0.8rem;
    padding: 0.4rem 1rem;
    font-size: 0.8rem;
  }

  #minimap {
    width: 120px;
    height: 120px;
  }

  #chat-box {
    width: 200px;
  }
}

/* ── prefers-reduced-motion ── */
@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation: none;
    border-top-color: #2a2e3a;
  }

  .player-item,
  .end-card {
    animation: none;
  }

  .btn-primary:hover:not(:disabled) {
    transform: none;
  }
}
