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

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

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

/* Login Modal */
#login-modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0a0a12;
  z-index: 1000;
}

#login-box {
  text-align: center;
  padding: 3rem 2.5rem;
  border: 1px solid #2a2a3a;
  border-radius: 8px;
  background: #12121e;
}

#login-box h1 {
  font-size: 2.5rem;
  letter-spacing: 0.3em;
  color: #d4a847;
  margin-bottom: 0.5rem;
}

#login-box p {
  color: #888;
  margin-bottom: 2rem;
  font-size: 0.9rem;
}

#username-input {
  display: block;
  width: 100%;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  background: #1a1a2e;
  border: 1px solid #2a2a3a;
  border-radius: 4px;
  color: #e0e0e0;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
}

#username-input:focus {
  border-color: #d4a847;
}

#username-input::placeholder {
  color: #555;
}

#join-btn {
  width: 100%;
  padding: 0.75rem;
  background: #d4a847;
  color: #0a0a12;
  border: none;
  border-radius: 4px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

#join-btn:hover {
  background: #e0b85a;
}

/* Player name labels */
.player-label {
  position: absolute;
  color: #e0e0e0;
  font-size: 11px;
  font-weight: 600;
  text-align: center;
  transform: translate(-50%, -100%);
  pointer-events: none;
  text-shadow: 0 0 4px #000, 0 0 2px #000;
  white-space: nowrap;
  z-index: 10;
}

.other-player-label {
  color: #ccc;
  font-size: 10px;
}

/* HUD overlay */
#hud {
  position: absolute;
  inset: 0;
  z-index: 50;
  pointer-events: none;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

#hud .hud-panel,
#hud .hud-chat-input,
#build-menu {
  pointer-events: auto;
}

.hud-bar {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: min(96vw, 920px);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.65rem 1rem;
  padding: 0.75rem 1rem;
  background: rgba(10, 10, 18, 0.75);
  border: 1px solid rgba(212, 168, 71, 0.35);
  border-top: none;
  border-radius: 0 0 8px 8px;
  box-sizing: border-box;
}

.hud-bar-left {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 0;
}

.hud-connection {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.72rem;
  font-weight: 600;
  color: #b8b8c8;
}

.hud-conn-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.hud-conn-dot-connecting {
  background: #6a6a78;
}

.hud-conn-dot-connected {
  background: #4ada7b;
  box-shadow: 0 0 6px rgba(74, 218, 123, 0.45);
}

.hud-conn-dot-disconnected {
  background: #c44a4a;
  box-shadow: 0 0 6px rgba(196, 74, 74, 0.35);
}

.hud-conn-dot-reconnecting {
  background: #da9e4a;
  animation: hud-conn-pulse 1s ease-in-out infinite;
}

@keyframes hud-conn-pulse {
  50% {
    opacity: 0.45;
  }
}

.hud-players {
  font-size: 0.72rem;
  font-weight: 600;
  color: #9a9aaa;
  font-variant-numeric: tabular-nums;
}

.hud-players-sep {
  margin: 0 0.2rem;
  opacity: 0.45;
}

.hud-bar-resources {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
}

.resource-pill {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: #e8e8e8;
}

.res-emoji {
  font-size: 1rem;
  opacity: 0.95;
}

#hud-float-anchor {
  position: absolute;
  top: 22%;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  pointer-events: none;
}

.gather-float {
  padding: 0.35rem 0.75rem;
  background: rgba(18, 18, 30, 0.9);
  border: 1px solid rgba(212, 168, 71, 0.5);
  border-radius: 6px;
  color: #d4a847;
  font-size: 0.9rem;
  font-weight: 600;
  animation: floatUp 1.2s ease-out forwards;
  text-shadow: 0 0 8px rgba(0, 0, 0, 0.8);
}

.gather-float-warn {
  color: #c98a6a;
  border-color: rgba(200, 120, 80, 0.45);
}

.gather-float-production {
  color: #7ec8e8;
  border-color: rgba(100, 180, 220, 0.45);
}

.gather-float-out {
  opacity: 0;
  transform: translateY(-12px);
  transition: opacity 0.35s ease, transform 0.35s ease;
}

@keyframes floatUp {
  0% {
    opacity: 0;
    transform: translateY(8px);
  }
  15% {
    opacity: 1;
    transform: translateY(0);
  }
  100% {
    opacity: 1;
    transform: translateY(-6px);
  }
}

.hud-hints {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  padding: 0.65rem 1.25rem;
  background: rgba(10, 10, 18, 0.72);
  border: 1px solid rgba(212, 168, 71, 0.25);
  border-bottom: none;
  border-radius: 8px 8px 0 0;
  font-size: 0.8rem;
  color: #a8a8b8;
}

.hud-hints .hint-sep {
  margin: 0 0.35rem;
  opacity: 0.5;
}

#hint-gather.hint-cooldown {
  color: #6a6a78;
}

.hud-panel {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 220px;
  max-height: 42vh;
  padding: 0.75rem;
  background: rgba(12, 12, 22, 0.82);
  border: 1px solid rgba(212, 168, 71, 0.28);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.hud-left {
  left: 0.75rem;
}

.hud-right {
  right: 0.75rem;
}

.hud-panel-title {
  font-size: 0.75rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #d4a847;
  font-weight: 700;
}

.hud-chat-log {
  flex: 1;
  min-height: 80px;
  max-height: 160px;
  overflow-y: auto;
  font-size: 0.8rem;
  color: #888;
  padding: 0.35rem 0;
}

.hud-chat-input {
  width: 100%;
  padding: 0.45rem 0.5rem;
  font-size: 0.8rem;
  background: #1a1a2e;
  border: 1px solid #2a2a3a;
  border-radius: 4px;
  color: #666;
}

.hud-chat-input:not(:disabled) {
  color: #e0e0e0;
}

.hud-chat-tabs {
  display: flex;
  gap: 0.35rem;
  margin-bottom: 0.35rem;
}

.hud-chat-tab {
  flex: 1;
  padding: 0.35rem 0.5rem;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: #1a1a2e;
  border: 1px solid #2a2a3a;
  border-radius: 4px;
  color: #888;
  cursor: pointer;
}

.hud-chat-tab:hover:not(:disabled) {
  border-color: rgba(212, 168, 71, 0.45);
  color: #c8c8d0;
}

.hud-chat-tab:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.hud-chat-tab-active {
  border-color: rgba(212, 168, 71, 0.55);
  color: #d4a847;
}

.hud-chat-log-hidden {
  display: none !important;
}

.hud-chat-line {
  margin-bottom: 0.25rem;
  line-height: 1.35;
}

.hud-chat-user {
  color: #d4a847;
  font-weight: 600;
}

.hud-chat-text {
  color: #b8b8c8;
}

.hud-section-clan {
  margin-top: 0.65rem;
  padding-top: 0.65rem;
  border-top: 1px solid rgba(212, 168, 71, 0.2);
}

.clan-block {
  margin-bottom: 0.5rem;
}

.clan-block-hidden {
  display: none !important;
}

.clan-label {
  display: block;
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #7a7a8a;
  margin-bottom: 0.25rem;
}

.clan-row {
  display: flex;
  gap: 0.35rem;
  align-items: stretch;
}

.clan-input,
.clan-select {
  flex: 1;
  min-width: 0;
  padding: 0.35rem 0.45rem;
  font-size: 0.78rem;
  background: #1a1a2e;
  border: 1px solid #2a2a3a;
  border-radius: 4px;
  color: #e0e0e0;
}

.clan-btn {
  padding: 0.35rem 0.55rem;
  font-size: 0.72rem;
  font-weight: 600;
  background: #d4a847;
  color: #0a0a12;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
}

.clan-btn:hover {
  background: #e0b85a;
}

.clan-btn-secondary {
  background: #2a2a3a;
  color: #d0d0d8;
}

.clan-btn-secondary:hover {
  background: #3a3a4a;
}

.clan-btn-small {
  padding: 0.2rem 0.45rem;
  font-size: 0.65rem;
}

.clan-my-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: #d4a847;
  margin-bottom: 0.35rem;
}

.clan-invites-list {
  list-style: none;
  max-height: 100px;
  overflow-y: auto;
  font-size: 0.72rem;
}

.clan-invite-empty {
  color: #5a5a68;
  font-style: italic;
  padding: 0.2rem 0;
}

.clan-invite-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem;
  padding: 0.35rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  color: #b0b0c0;
}

.clan-invite-actions {
  display: flex;
  gap: 0.25rem;
}

#hud-build.hud-panel {
  max-height: 52vh;
  overflow-y: auto;
}

.hud-build-list {
  list-style: none;
  overflow-y: auto;
  max-height: 36vh;
}

.hud-build-item {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.45rem 0.35rem;
  font-size: 0.78rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  color: #b0b0c0;
}

.hud-build-item.locked .build-name {
  opacity: 0.65;
}

.build-name {
  text-transform: capitalize;
  font-weight: 600;
}

.build-cost {
  font-size: 0.7rem;
  color: #7a7a8a;
  white-space: nowrap;
}

.build-tier-badge {
  font-size: 1.1rem;
  font-weight: 700;
  color: #d4a847;
  letter-spacing: 0.06em;
}

.build-hint {
  font-size: 0.72rem;
  color: #888;
  margin-top: 0.25rem;
}

.kbd-hint {
  display: inline-block;
  padding: 0.1rem 0.35rem;
  background: #1a1a2e;
  border: 1px solid #3a3a4a;
  border-radius: 4px;
  font-size: 0.75rem;
  color: #ccc;
}

.build-menu {
  position: absolute;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6, 6, 12, 0.72);
}

.build-menu.hidden {
  display: none;
}

.build-menu-inner {
  width: min(380px, 92vw);
  max-height: 78vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: #12121e;
  border: 1px solid rgba(212, 168, 71, 0.4);
  border-radius: 10px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
}

.build-menu-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid rgba(212, 168, 71, 0.2);
}

.build-menu-header h2 {
  font-size: 1rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: #d4a847;
  margin: 0;
}

.build-menu-close {
  padding: 0.35rem 0.65rem;
  font-size: 0.8rem;
  background: #1a1a2e;
  border: 1px solid #3a3a4a;
  border-radius: 4px;
  color: #ccc;
  cursor: pointer;
}

.build-menu-close:hover {
  border-color: #d4a847;
  color: #fff;
}

.build-menu-list {
  list-style: none;
  overflow-y: auto;
  padding: 0.5rem 0;
  max-height: 60vh;
}

.build-menu-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 1rem;
  cursor: pointer;
  font-size: 0.88rem;
  color: #e0e0e8;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.build-menu-item:hover:not(.unaffordable) {
  background: rgba(212, 168, 71, 0.08);
}

.build-menu-item.affordable {
  border-left: 3px solid rgba(212, 168, 71, 0.6);
}

.build-menu-item.unaffordable {
  opacity: 0.45;
  cursor: not-allowed;
  border-left: 3px solid transparent;
}

.build-menu-name {
  font-weight: 600;
}

.build-menu-cost {
  font-size: 0.75rem;
  color: #9a9aaa;
  white-space: nowrap;
}

/* Trade modal */
.trade-modal {
  position: absolute;
  inset: 0;
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6, 6, 12, 0.75);
}

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

.trade-modal-inner {
  width: min(420px, 94vw);
  max-height: 86vh;
  overflow-y: auto;
  background: #12121e;
  border: 1px solid rgba(212, 168, 71, 0.45);
  border-radius: 10px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
  padding: 0 0 1rem;
}

.trade-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid rgba(212, 168, 71, 0.2);
}

.trade-modal-header h2 {
  font-size: 0.95rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #d4a847;
  margin: 0;
}

.trade-hint {
  font-size: 0.72rem;
  color: #888;
  margin: 0.5rem 1rem 0.25rem;
}

.trade-column-labels {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 1fr 1fr;
  gap: 0.5rem;
  padding: 0 1rem;
  font-size: 0.7rem;
  color: #9a9aaa;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  align-items: center;
}

.trade-col-spacer {
  min-width: 0;
}

.trade-rows {
  padding: 0.35rem 1rem 0.75rem;
}

.trade-resource-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 1fr 1fr;
  gap: 0.35rem;
  align-items: center;
  padding: 0.35rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  font-size: 0.82rem;
  color: #e0e0e8;
}

.trade-res-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.trade-stepper {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
}

.trade-step {
  width: 1.65rem;
  height: 1.65rem;
  padding: 0;
  font-size: 1rem;
  line-height: 1;
  background: #1a1a2e;
  border: 1px solid #3a3a4a;
  border-radius: 4px;
  color: #ccc;
  cursor: pointer;
}

.trade-step:hover {
  border-color: #d4a847;
  color: #fff;
}

.trade-step-val {
  min-width: 1.5rem;
  text-align: center;
  font-weight: 600;
  color: #f0e8d8;
}

.trade-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  padding: 0.5rem 1rem 0;
}

.trade-btn {
  padding: 0.45rem 1rem;
  font-size: 0.85rem;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid #3a3a4a;
  background: #1a1a2e;
  color: #e0e0e8;
}

.trade-btn-primary {
  border-color: rgba(212, 168, 71, 0.55);
  background: rgba(212, 168, 71, 0.12);
  color: #d4a847;
  font-weight: 600;
}

.trade-btn-primary:hover {
  background: rgba(212, 168, 71, 0.22);
}

.trade-btn-secondary:hover {
  border-color: #d4a847;
  color: #fff;
}

.trade-section.hidden {
  display: none;
}

.trade-incoming-summary {
  padding: 0.75rem 1rem;
  font-size: 0.88rem;
  color: #d8d8e0;
  line-height: 1.5;
}

.trade-incoming-summary p {
  margin: 0.35rem 0;
}

/* ── HP Bar ── */
.hp-pill {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: #e8e8e8;
  margin-left: 0.5rem;
}

.hp-bar-container {
  width: 60px;
  height: 10px;
  background: rgba(40, 40, 50, 0.8);
  border-radius: 5px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.hp-bar-fill {
  width: 100%;
  height: 100%;
  background-color: #4ade80;
  border-radius: 5px;
  transition: width 0.3s ease, background-color 0.3s ease;
}

/* ── Combat Floats ── */
.combat-float {
  position: absolute;
  font-size: 1.1rem;
  font-weight: 700;
  color: #ef4444;
  text-shadow: 0 0 4px rgba(0, 0, 0, 0.8);
  pointer-events: none;
  z-index: 200;
  transform: translateX(-50%);
}
