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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #18141f;
  user-select: none;
  -webkit-user-select: none;
}

canvas {
  display: block;
  touch-action: none;
}

#muteBtn {
  position: fixed;
  top: 0.7rem;
  right: 0.9rem;
  background: rgba(60, 50, 80, 0.72);
  color: #c4b4d4;
  border: 1px solid rgba(180, 150, 210, 0.28);
  border-radius: 0.4rem;
  padding: 0.3rem 0.65rem;
  font-size: 0.82rem;
  font-family: monospace;
  cursor: pointer;
  backdrop-filter: blur(4px);
  transition: background 0.15s;
  z-index: 10;
}

#muteBtn:hover {
  background: rgba(90, 70, 120, 0.82);
}

#lbBtn {
  position: fixed;
  top: 0.7rem;
  right: 4.2rem;
  background: rgba(60, 50, 80, 0.72);
  color: #c4b4d4;
  border: 1px solid rgba(180, 150, 210, 0.28);
  border-radius: 0.4rem;
  padding: 0.3rem 0.55rem;
  font-size: 0.82rem;
  cursor: pointer;
  backdrop-filter: blur(4px);
  transition: background 0.15s;
  z-index: 10;
}

#lbBtn:hover {
  background: rgba(90, 70, 120, 0.82);
}

.lb-hidden {
  display: none !important;
}

#lbOverlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(3px);
}

#lbPanel {
  background: #1e1a28;
  border: 1px solid rgba(180, 150, 210, 0.3);
  border-radius: 0.7rem;
  width: min(90vw, 360px);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

#lbHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 1rem;
  border-bottom: 1px solid rgba(180, 150, 210, 0.15);
  font-family: monospace;
  font-weight: bold;
  font-size: 1rem;
  color: #d4c4e4;
}

#lbClose {
  background: none;
  border: none;
  color: #a89ab8;
  font-size: 1.3rem;
  cursor: pointer;
  padding: 0 0.3rem;
  line-height: 1;
}

#lbClose:hover {
  color: #fff;
}

#lbYourScore {
  padding: 0.4rem 1rem;
  font-family: monospace;
  font-size: 0.82rem;
  color: #a89ab8;
}

#lbList {
  overflow-y: auto;
  padding: 0 1rem 0.8rem;
  flex: 1;
}

#lbList table {
  width: 100%;
  border-collapse: collapse;
  font-family: monospace;
  font-size: 0.78rem;
}

#lbList th {
  text-align: left;
  color: #8878a0;
  padding: 0.3rem 0.2rem;
  border-bottom: 1px solid rgba(180, 150, 210, 0.12);
  font-weight: normal;
  text-transform: uppercase;
  font-size: 0.68rem;
  letter-spacing: 0.05em;
}

#lbList td {
  padding: 0.35rem 0.2rem;
  color: #c4b4d4;
  border-bottom: 1px solid rgba(180, 150, 210, 0.06);
}

#lbList tr:first-child td {
  color: #f0d860;
}

#lbList tr:nth-child(2) td {
  color: #c0c8d0;
}

#lbList tr:nth-child(3) td {
  color: #d0a060;
}

#lbList .rank {
  width: 2rem;
  text-align: center;
}

/* Milkbar button */
#depositBtn {
  position: fixed;
  top: 0.7rem;
  left: 0.9rem;
  background: rgba(40, 80, 60, 0.82);
  color: #a8e8c0;
  border: 1px solid rgba(120, 210, 150, 0.38);
  border-radius: 0.4rem;
  padding: 0.3rem 0.65rem;
  font-size: 0.82rem;
  font-family: monospace;
  cursor: pointer;
  backdrop-filter: blur(4px);
  transition: background 0.15s;
  z-index: 10;
}

#depositBtn:hover {
  background: rgba(50, 110, 80, 0.92);
}

#depositBtn:disabled {
  opacity: 0.5;
  cursor: default;
}

.deposit-hidden {
  display: none !important;
}

#milkbarBtn {
  position: fixed;
  top: 0.7rem;
  right: 7.5rem;
  background: rgba(80, 60, 50, 0.82);
  color: #e8d8c0;
  border: 1px solid rgba(200, 180, 140, 0.38);
  border-radius: 0.4rem;
  padding: 0.3rem 0.55rem;
  font-size: 0.82rem;
  cursor: pointer;
  backdrop-filter: blur(4px);
  transition: background 0.15s;
  z-index: 10;
  font-family: monospace;
}

#milkbarBtn:hover {
  background: rgba(120, 80, 50, 0.92);
}

#heroesBtn {
  position: fixed;
  top: 0.7rem;
  right: 13rem;
  background: rgba(50, 60, 90, 0.82);
  color: #b0c8f0;
  border: 1px solid rgba(140, 170, 220, 0.38);
  border-radius: 0.4rem;
  padding: 0.3rem 0.6rem;
  font-size: 0.82rem;
  cursor: pointer;
  backdrop-filter: blur(4px);
  transition: background 0.15s;
  z-index: 10;
  font-family: monospace;
}

#heroesBtn:hover {
  background: rgba(70, 90, 140, 0.92);
}

#heroesBtn:disabled {
  opacity: 0.5;
  cursor: default;
}

.heroes-hidden {
  display: none !important;
}

/* Milkbar overlay */
.milkbar-hidden {
  display: none !important;
}

#milkbarOverlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 15, 10, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}

#milkbarPanel {
  background: linear-gradient(135deg, #2a2018 0%, #1a1410 100%);
  border: 2px solid rgba(180, 140, 80, 0.4);
  border-radius: 0.7rem;
  width: min(95vw, 720px);
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255,220,150,0.08);
}

#milkbarHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 1rem;
  border-bottom: 1px solid rgba(180, 140, 80, 0.25);
  font-family: Georgia, serif;
  font-weight: bold;
  font-size: 1.1rem;
  color: #e8d0a0;
  background: rgba(60, 40, 20, 0.3);
}

#milkbarClose {
  background: none;
  border: none;
  color: #b09878;
  font-size: 1.3rem;
  cursor: pointer;
  padding: 0 0.3rem;
  line-height: 1;
}

#milkbarClose:hover {
  color: #fff;
}

#milkbarContent {
  display: flex;
  flex: 1;
  overflow: hidden;
}

#npcList {
  width: 40%;
  border-right: 1px solid rgba(180, 140, 80, 0.2);
  overflow-y: auto;
  padding: 0.5rem;
}

.npc-card {
  background: rgba(50, 35, 20, 0.6);
  border: 1px solid rgba(180, 140, 80, 0.2);
  border-radius: 0.5rem;
  padding: 0.7rem;
  margin-bottom: 0.5rem;
  cursor: pointer;
  transition: all 0.15s;
}

.npc-card:hover {
  background: rgba(70, 50, 30, 0.8);
  border-color: rgba(200, 160, 100, 0.4);
}

.npc-card.selected {
  background: rgba(90, 65, 35, 0.9);
  border-color: rgba(220, 180, 120, 0.6);
}

.npc-card.hired {
  opacity: 0.5;
  cursor: not-allowed;
}

.npc-name {
  font-family: Georgia, serif;
  font-size: 0.95rem;
  color: #e8d0a0;
  margin-bottom: 0.2rem;
}

.npc-desc {
  font-family: monospace;
  font-size: 0.72rem;
  color: #a09080;
  line-height: 1.3;
}

.npc-wage {
  font-family: monospace;
  font-size: 0.68rem;
  color: #80a060;
  margin-top: 0.3rem;
}

#chatArea {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 0.5rem;
}

#chatMessages {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
  font-family: monospace;
  font-size: 0.82rem;
  color: #c8b898;
  background: rgba(30, 20, 15, 0.4);
  border-radius: 0.4rem;
  margin-bottom: 0.5rem;
}

.chat-msg {
  margin-bottom: 0.6rem;
  line-height: 1.4;
}

.chat-msg.user {
  color: #80b0e8;
}

.chat-msg.npc {
  color: #e8c890;
}

.chat-msg .speaker {
  font-weight: bold;
  margin-right: 0.4rem;
}

#chatInputArea {
  display: flex;
  gap: 0.4rem;
}

#chatInput {
  flex: 1;
  background: rgba(40, 30, 20, 0.8);
  border: 1px solid rgba(180, 140, 80, 0.3);
  border-radius: 0.3rem;
  padding: 0.5rem 0.7rem;
  font-family: monospace;
  font-size: 0.82rem;
  color: #e8d8c0;
}

#chatInput:focus {
  outline: none;
  border-color: rgba(200, 160, 100, 0.5);
}

#chatInput::placeholder {
  color: #706050;
}

#chatSend {
  background: rgba(100, 70, 40, 0.8);
  border: 1px solid rgba(180, 140, 80, 0.4);
  border-radius: 0.3rem;
  padding: 0.5rem 1rem;
  font-family: monospace;
  font-size: 0.82rem;
  color: #e8d0a0;
  cursor: pointer;
  transition: background 0.15s;
}

#chatSend:hover {
  background: rgba(130, 90, 50, 0.9);
}

#chatSend:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#chatInput:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  background: rgba(30, 25, 18, 0.8);
}

#chatInputArea.waiting {
  opacity: 0.7;
}

.chat-msg.typing .typing-dots {
  display: inline-flex;
  gap: 0.15em;
}

.chat-msg.typing .typing-dots span {
  animation: typingPulse 1.2s infinite;
}

.chat-msg.typing .typing-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.chat-msg.typing .typing-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typingPulse {
  0%, 60%, 100% { opacity: 0.3; }
  30% { opacity: 1; }
}

#hireBtn {
  display: none;
  background: rgba(60, 100, 50, 0.8);
  border: 1px solid rgba(100, 180, 80, 0.5);
  border-radius: 0.3rem;
  padding: 0.5rem 1rem;
  font-family: monospace;
  font-size: 0.85rem;
  color: #b0e890;
  cursor: pointer;
  margin-top: 0.4rem;
  transition: background 0.15s;
}

#hireBtn:hover {
  background: rgba(80, 130, 60, 0.9);
}

#buyMilkArea {
  margin-top: 0.5rem;
  padding: 0.5rem 0.6rem;
  background: rgba(30, 55, 55, 0.4);
  border: 1px solid rgba(80, 180, 160, 0.25);
  border-radius: 0.4rem;
}

#buyMilkPriceLine {
  font-family: monospace;
  font-size: 0.78rem;
  color: #90cfc0;
  margin-bottom: 0.4rem;
}

#buyMilkPriceNote {
  color: #6a9990;
  font-size: 0.72rem;
}

#buyMilkBtns {
  display: flex;
  gap: 0.5rem;
}

#buyForSelfBtn,
#buyForNPCBtn {
  flex: 1;
  background: rgba(40, 100, 90, 0.7);
  border: 1px solid rgba(80, 180, 160, 0.4);
  border-radius: 0.3rem;
  padding: 0.4rem 0.6rem;
  font-family: monospace;
  font-size: 0.78rem;
  color: #a0e8d8;
  cursor: pointer;
  transition: background 0.15s;
}

#buyForSelfBtn:hover,
#buyForNPCBtn:hover {
  background: rgba(55, 130, 115, 0.85);
}

#buyForSelfBtn:disabled,
#buyForNPCBtn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#chatPlaceholder {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #706050;
  font-family: monospace;
  font-size: 0.9rem;
  text-align: center;
  padding: 2rem;
}

/* Workers panel */
#workersPanel {
  position: fixed;
  bottom: 0.7rem;
  left: 0.7rem;
  background: rgba(40, 30, 25, 0.85);
  border: 1px solid rgba(180, 140, 80, 0.3);
  border-radius: 0.4rem;
  padding: 0.4rem 0.6rem;
  font-family: monospace;
  font-size: 0.72rem;
  color: #c8b898;
  z-index: 10;
  max-width: 200px;
}

#workersPanel.hidden {
  display: none;
}

.worker-entry {
  padding: 0.25rem 0;
  border-bottom: 1px solid rgba(180, 140, 80, 0.15);
}

.worker-entry:last-child {
  border-bottom: none;
}

.worker-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.worker-life {
  height: 0.28rem;
  margin-top: 0.22rem;
  border-radius: 0.2rem;
  background: rgba(0, 0, 0, 0.35);
  overflow: hidden;
}

.worker-life-fill {
  height: 100%;
  border-radius: 0.2rem;
  transition: width 0.6s linear, background 0.6s linear;
}

.worker-name {
  color: #e8d0a0;
}

.worker-fee {
  color: #e08080;
  font-size: 0.68rem;
}

.worker-fire {
  background: none;
  border: none;
  color: #a06060;
  cursor: pointer;
  font-size: 0.7rem;
  padding: 0.1rem 0.3rem;
}

.worker-fire:hover {
  color: #ff8080;
}

/* Exchange button */
#exchangeBtn {
  position: fixed;
  top: 0.7rem;
  right: 18.5rem;
  background: rgba(30, 60, 80, 0.82);
  color: #80c8e8;
  border: 1px solid rgba(100, 190, 230, 0.38);
  border-radius: 0.4rem;
  padding: 0.3rem 0.55rem;
  font-size: 0.82rem;
  cursor: pointer;
  backdrop-filter: blur(4px);
  transition: background 0.15s;
  z-index: 10;
  font-family: monospace;
}

#exchangeBtn:hover {
  background: rgba(40, 90, 120, 0.92);
}

#milk-ad-slot {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  width: 210px;
  z-index: 10;
}
