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

body {
  font-family: 'Comic Sans MS', 'Chalkboard SE', cursive, sans-serif;
  background: #f5f0e8;
  overflow: hidden;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* --- Auth Screen --- */
#auth-screen {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  width: 100%;
}

.auth-box {
  background: #fffdf7;
  border: 3px solid #c9a96e;
  border-radius: 20px;
  padding: 40px 36px;
  width: 340px;
  text-align: center;
  box-shadow: 4px 4px 0 #d4c4a0;
}

.auth-box h1 { font-size: 32px; color: #5a4a32; margin-bottom: 4px; }
.subtitle { color: #a08c6a; font-size: 14px; margin-bottom: 24px; }

.auth-box input {
  width: 100%; padding: 12px 16px; margin-bottom: 12px;
  border: 2px solid #d4c4a0; border-radius: 12px;
  font-size: 15px; font-family: inherit; background: #faf8f2;
  outline: none; transition: border-color 0.2s;
}
.auth-box input:focus { border-color: #c9a96e; }

.btn-primary {
  width: 100%; padding: 12px; margin-bottom: 8px;
  background: #c9a96e; color: white; border: none; border-radius: 12px;
  font-size: 16px; font-family: inherit; cursor: pointer; font-weight: bold;
  transition: background 0.2s;
}
.btn-primary:hover { background: #b8953e; }

.btn-secondary {
  width: 100%; padding: 10px; background: transparent;
  color: #a08c6a; border: 2px dashed #d4c4a0; border-radius: 12px;
  font-size: 14px; font-family: inherit; cursor: pointer;
  transition: border-color 0.2s;
}
.btn-secondary:hover { border-color: #c9a96e; color: #c9a96e; }

.msg { color: #c44; font-size: 13px; margin-top: 10px; min-height: 20px; }

/* --- Game Screen --- */
#game-screen {
  display: flex; flex-direction: column; height: 100vh; width: 100%;
}

.game-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 20px; background: #fffdf7; border-bottom: 2px solid #d4c4a0;
  flex-shrink: 0; flex-wrap: wrap; gap: 8px;
}

.pet-label { font-size: 18px; font-weight: bold; color: #5a4a32; }
.stats { display: flex; gap: 16px; }
.stat { font-size: 14px; color: #7a6a52; }
.right-group { display: flex; align-items: center; gap: 12px; }
.online { font-size: 13px; color: #6a9a5a; font-weight: bold; }
.coins { font-size: 14px; color: #d4a017; font-weight: bold; }

/* --- Type Selector --- */
.type-selector { display: flex; gap: 4px; background: #f0ece2; border-radius: 10px; padding: 3px; }
.type-btn {
  width: 34px; height: 34px; border: 2px solid transparent; border-radius: 8px;
  background: transparent; font-size: 18px; cursor: pointer; transition: all 0.15s;
  display: flex; align-items: center; justify-content: center;
}
.type-btn:hover { background: #e8e0d0; }
.type-btn.active {
  border-color: #c9a96e; background: #fffdf7;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.btn-logout {
  padding: 4px 12px; font-size: 12px; font-family: inherit;
  border: 1.5px solid #ccc; border-radius: 8px; background: transparent;
  color: #999; cursor: pointer; transition: all 0.2s;
}
.btn-logout:hover { border-color: #c44; color: #c44; }

#game-canvas { flex: 1; width: 100%; cursor: pointer; touch-action: none; }

.actions {
  display: flex; justify-content: center; gap: 12px; padding: 10px;
  background: #fffdf7; border-top: 2px solid #d4c4a0; flex-shrink: 0;
  flex-wrap: wrap;
}

.btn-action {
  padding: 10px 20px; font-size: 14px; font-family: inherit;
  border: 2px solid #c9a96e; border-radius: 14px; background: #faf8f2;
  cursor: pointer; transition: all 0.15s;
}
.btn-action:hover { background: #c9a96e; color: white; transform: scale(1.05); }
.btn-action:active { transform: scale(0.95); }
.btn-gate { border-color: #7a6; }
.btn-gate:hover { background: #7a6; color: white; }
.btn-shop { border-color: #e8a020; }
.btn-shop:hover { background: #e8a020; color: white; }
.btn-trade { border-color: #6a9fd8; }
.btn-trade:hover { background: #6a9fd8; color: white; }
.btn-chat { border-color: #8ab; }
.btn-chat:hover { background: #8ab; color: white; }
.btn-cancel-trade { border-color: #c66; }
.btn-cancel-trade:hover { background: #c66; color: white; }

/* --- Chat Panel --- */
.chat-panel {
  position: fixed;
  left: 10px;
  bottom: 70px;
  width: 260px;
  background: rgba(255, 253, 247, 0.96);
  border: 2px solid #d4c4a0;
  border-radius: 14px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  box-shadow: 2px 2px 8px rgba(0,0,0,0.15);
  max-height: 320px;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid #e8e0d0;
  font-size: 14px;
  font-weight: bold;
  color: #5a4a32;
}

.chat-close {
  cursor: pointer;
  color: #bbb;
  font-size: 16px;
}
.chat-close:hover { color: #c44; }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  max-height: 220px;
  min-height: 100px;
}

.chat-msg {
  margin-bottom: 4px;
  font-size: 12px;
  line-height: 1.4;
  word-break: break-all;
}

.chat-msg .chat-name {
  color: #6a9fd8;
  font-weight: bold;
}

.chat-msg .chat-text {
  color: #5a4a32;
}

.chat-input-wrap {
  display: flex;
  padding: 6px;
  gap: 4px;
  border-top: 1px solid #e8e0d0;
}

.chat-input {
  flex: 1;
  padding: 6px 10px;
  border: 1.5px solid #d4c4a0;
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  background: #faf8f2;
  outline: none;
}
.chat-input:focus { border-color: #c9a96e; }

.chat-send {
  padding: 6px 12px;
  background: #c9a96e;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
}
.chat-send:hover { background: #b8953e; }

/* --- Modal Overlay --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 200;
}

.modal {
  background: #fffdf7;
  border: 3px solid #c9a96e;
  border-radius: 18px;
  padding: 24px 28px;
  min-width: 300px;
  max-width: 400px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 4px 4px 0 #d4c4a0;
}

.modal h3 {
  font-size: 18px;
  color: #5a4a32;
  margin-bottom: 12px;
  text-align: center;
}

.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  justify-content: center;
}

.btn-modal {
  padding: 8px 20px;
  border: 2px solid #c9a96e;
  border-radius: 10px;
  background: #faf8f2;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-modal:hover { background: #c9a96e; color: white; }
.btn-close-modal { border-color: #bbb; color: #888; }
.btn-close-modal:hover { background: #aaa; color: white; border-color: #aaa; }
.btn-confirm { border-color: #e8a020; color: #e8a020; }
.btn-confirm:hover { background: #e8a020; color: white; }

/* --- Shop --- */
.shop-balance {
  text-align: center;
  color: #d4a017;
  font-size: 15px;
  font-weight: bold;
  margin-bottom: 12px;
}

.shop-items {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.shop-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: #f8f4ec;
  border-radius: 10px;
  border: 1px solid #e8e0d0;
}

.shop-item-emoji { font-size: 24px; flex-shrink: 0; }

.shop-item-info {
  flex: 1;
}

.shop-item-name {
  font-size: 14px;
  font-weight: bold;
  color: #5a4a32;
}

.shop-item-count {
  font-size: 11px;
  color: #a08c6a;
}

.shop-item-btns {
  display: flex;
  gap: 4px;
}

.shop-buy-btn {
  padding: 4px 10px;
  border: 1.5px solid #c9a96e;
  border-radius: 8px;
  background: transparent;
  font-size: 11px;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.shop-buy-btn:hover { background: #c9a96e; color: white; }

/* --- Trade --- */
.trade-list {
  max-height: 300px;
  overflow-y: auto;
}

.trade-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: #f8f4ec;
  border-radius: 10px;
  border: 1px solid #e8e0d0;
  margin-bottom: 6px;
}

.trade-item-emoji { font-size: 24px; flex-shrink: 0; }
.trade-item-info { flex: 1; }
.trade-item-name { font-size: 14px; font-weight: bold; color: #5a4a32; }
.trade-item-price { font-size: 12px; color: #d4a017; }

.trade-buy-btn {
  padding: 6px 14px;
  border: 1.5px solid #6a9fd8;
  border-radius: 8px;
  background: transparent;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  color: #6a9fd8;
  transition: all 0.15s;
}
.trade-buy-btn:hover { background: #6a9fd8; color: white; }

.trade-empty {
  text-align: center;
  color: #a08c6a;
  padding: 20px;
  font-size: 14px;
}

/* --- Sell --- */
.sell-desc {
  font-size: 13px;
  color: #a08c6a;
  margin-bottom: 10px;
  text-align: center;
}

.sell-input {
  width: 100%;
  padding: 10px 14px;
  border: 2px solid #d4c4a0;
  border-radius: 10px;
  font-size: 15px;
  font-family: inherit;
  background: #faf8f2;
  outline: none;
  text-align: center;
}
.sell-input:focus { border-color: #c9a96e; }

/* --- Popup Trade Status --- */
.popup-trade {
  font-size: 13px;
  padding: 4px 10px;
  border-radius: 8px;
  margin: 6px 0;
  text-align: center;
}
.popup-trade.on-sale {
  background: #fff3cd;
  color: #856404;
  border: 1px solid #ffc107;
}

.popup-trade-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 8px;
}

/* --- Pet Popup --- */
.popup {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.3); display: flex;
  justify-content: center; align-items: center; z-index: 100;
}

.popup-content {
  background: #fffdf7; border: 3px solid #c9a96e; border-radius: 18px;
  padding: 24px 28px; text-align: center; min-width: 220px;
  max-width: 400px; max-height: 80vh; position: relative;
  box-shadow: 4px 4px 0 #d4c4a0; display: flex; flex-direction: column;
  overflow-y: auto;
}
.popup-wide { min-width: 300px; }

.popup-close {
  position: absolute; top: 10px; right: 14px; font-size: 18px;
  color: #bbb; cursor: pointer; z-index: 10; transition: color 0.2s;
}
.popup-close:hover { color: #c44; }

.popup-icon { font-size: 48px; margin-bottom: 8px; }

#popup-name-wrap {
  display: flex; align-items: center; justify-content: center; gap: 6px; margin-bottom: 4px;
}
.popup-name-text { font-size: 18px; color: #5a4a32; margin: 0; }

.btn-rename {
  background: none; border: none; font-size: 14px; cursor: pointer;
  padding: 2px 4px; border-radius: 6px; transition: background 0.15s;
}
.btn-rename:hover { background: #f0ece2; }

.popup-content p { font-size: 13px; color: #a08c6a; margin-bottom: 12px; }

.popup-stats {
  display: flex; flex-direction: column; gap: 6px;
  font-size: 14px; color: #7a6a52; margin-bottom: 10px;
}

/* --- Rename Input --- */
.rename-input {
  width: 100%; max-width: 200px; padding: 6px 10px;
  border: 2px solid #c9a96e; border-radius: 8px;
  font-size: 15px; font-family: inherit; text-align: center;
  background: #faf8f2; outline: none; margin: 4px auto;
}
.rename-input:focus { border-color: #b8953e; }

/* --- Popup Type Selector --- */
.popup-type { justify-content: center; margin-bottom: 8px; }

/* --- Pet List --- */
.popup-divider { height: 1px; background: #e8e0d0; margin: 12px 0; }
.pets-list-title { font-size: 14px; color: #7a6a52; margin-bottom: 8px; text-align: left; }

.pets-list {
  max-height: 280px; overflow-y: auto; text-align: left; flex-shrink: 1;
}
.pets-list::-webkit-scrollbar { width: 6px; }
.pets-list::-webkit-scrollbar-track { background: #f0ece2; border-radius: 3px; }
.pets-list::-webkit-scrollbar-thumb { background: #c9a96e; border-radius: 3px; }

.pet-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 10px; transition: background 0.15s;
}
.pet-item:hover { background: #f0ece2; }
.pet-item.me { background: #faf3e0; border: 1px solid #e8d8b8; }

.pet-item-emoji { font-size: 24px; flex-shrink: 0; }
.pet-item-info { flex: 1; min-width: 0; }
.pet-item-name {
  font-size: 14px; font-weight: bold; color: #5a4a32;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.pet-item-owner { font-size: 11px; color: #a08c6a; }
.pet-item-stats { display: flex; gap: 8px; font-size: 11px; color: #8a7a62; flex-shrink: 0; }

.pet-item-trade-badge {
  font-size: 10px;
  color: #d4a017;
  background: #fff3cd;
  padding: 1px 6px;
  border-radius: 6px;
  border: 1px solid #ffc107;
}
