* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Segoe UI', Verdana, sans-serif;
  background: #f0f4f8;
  color: #1e293b;
}

#topbar {
  background: #ffcc00;
  border-bottom: 6px solid #e0a800;
  padding: 10px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
}
.brand { font-weight: 800; font-size: 20px; letter-spacing: 1px; }
.player-info { display: flex; gap: 14px; align-items: center; font-weight: 600; }
.tier-badge {
  background: #d32f2f;
  color: #fff;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 13px;
}
.cred-display { background: #111827; color: #ffcc00; padding: 4px 10px; border-radius: 12px; }

#tabs {
  display: flex;
  background: #1e293b;
  overflow-x: auto;
}
.tab-btn {
  background: none;
  border: none;
  color: #cbd5e1;
  padding: 12px 18px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  border-bottom: 4px solid transparent;
  white-space: nowrap;
}
.tab-btn:hover { color: #fff; }
.tab-btn.active { color: #ffcc00; border-bottom-color: #ffcc00; }

main { padding: 16px 20px 60px; max-width: 1100px; margin: 0 auto; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.hint { color: #475569; font-size: 14px; }

canvas {
  display: block;
  background: #7fd858;
  border-radius: 10px;
  border: 4px solid #1e293b;
  margin: 0 auto;
  max-width: 100%;
}

#worldTools { display: flex; gap: 10px; margin: 12px auto 0; max-width: 800px; }
#worldChatForm { display: flex; gap: 8px; flex: 1; }
#worldChatInput { flex: 1; min-width: 100px; }
#worldSocial { display: grid; grid-template-columns: 220px 1fr; gap: 12px; margin: 12px auto 0; max-width: 800px; }
#onlinePlayersBox, #worldChatBox { background: #fff; border-radius: 8px; padding: 10px 16px; box-shadow: 0 2px 6px rgba(0,0,0,0.08); }
#onlinePlayersBox h3 { margin: 0; font-size: 15px; }
#onlinePlayersBox ul { list-style: none; padding: 0; margin: 6px 0 0; }
#onlinePlayersBox li { padding: 3px 0; font-size: 14px; }
#worldChatBox { height: 92px; overflow-y: auto; font-size: 13px; }
.chat-line { margin-bottom: 5px; }
.chat-line strong { color: #b91c1c; }

@media (max-width: 620px) {
  #worldTools { flex-direction: column; }
  #worldSocial { grid-template-columns: 1fr; }
}

.store-columns, .inventory-columns, .market-columns { display: flex; gap: 24px; flex-wrap: wrap; }
.store-columns > div, .inventory-columns > div, .market-columns > div { flex: 1 1 300px; }

.item-grid { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 8px; }
.item-card {
  background: #fff;
  border: 3px solid #1e293b;
  border-radius: 10px;
  padding: 10px;
  width: 160px;
  box-shadow: 3px 3px 0 rgba(0,0,0,0.15);
  font-size: 13px;
  position: relative;
}
.item-card.locked { opacity: 0.55; }
.item-card.equipped { border-color: #22c55e; }
.store-columns .item-card { padding: 8px; }
.store-art {
  display: block;
  width: 100%;
  height: 88px;
  margin-bottom: 8px;
  border: 2px solid #cbd5e1;
  border-radius: 6px;
  background: #f1f5f9;
}
.store-columns .item-name { min-height: 30px; }
.item-name { font-weight: 700; margin-bottom: 4px; }
.item-stat { color: #334155; margin-bottom: 4px; }
.item-cost { font-weight: 700; color: #b45309; margin-bottom: 6px; }
.owned-tag { color: #16a34a; font-size: 11px; font-weight: 700; }
.locked-tag { color: #dc2626; font-size: 11px; font-weight: 700; }
.thumb { width: 100%; height: 80px; object-fit: cover; border-radius: 6px; border: 2px solid #94a3b8; margin-bottom: 6px; background: #e5e7eb; }

button {
  background: #d32f2f;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 12px;
  font-weight: 700;
  cursor: pointer;
  font-size: 13px;
}
button:hover { background: #b91c1c; }
input, select {
  padding: 8px;
  border-radius: 8px;
  border: 2px solid #94a3b8;
  font-size: 13px;
  margin: 4px 0;
  width: 100%;
}

.buy-btn, .equip-btn { background: #16a34a; }
.buy-btn:hover, .equip-btn:hover { background: #15803d; }
.unequip-btn, .cancel-btn { background: #6b7280; }
.unequip-btn:hover, .cancel-btn:hover { background: #4b5563; }
.buy-listing-btn { background: #2563eb; }
.buy-listing-btn:hover { background: #1d4ed8; }

.build-layout { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-start; }
.palette { display: flex; flex-wrap: wrap; gap: 6px; }
.brick-swatch {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 3px solid #1e293b;
  padding: 0;
}
.brick-swatch.selected { outline: 3px solid #ffcc00; }
.brick-swatch.eraser { background: #fff; color: #1e293b; font-weight: 900; }
.build-controls { display: flex; flex-direction: column; gap: 8px; width: 200px; }

/* ---------------------------------------------------------- 3D brick studio */
.studio { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.studio-left {
  width: 250px;
  flex: 0 0 250px;
  background: #fff;
  border: 3px solid #1e293b;
  border-radius: 12px;
  padding: 10px;
  box-shadow: 3px 3px 0 rgba(0,0,0,0.15);
}
.studio-main { flex: 1 1 460px; min-width: 420px; }
.canvas-wrap { width: 100%; }
#buildCanvas { cursor: crosshair; background: #bfe3ff; }

.group-tabs { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.group-tab {
  background: #e2e8f0;
  color: #1e293b;
  font-size: 11px;
  padding: 5px 8px;
  border-radius: 6px;
}
.group-tab:hover { background: #cbd5e1; }
.group-tab.active { background: #1e293b; color: #ffcc00; }

.part-palette {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  max-height: 330px;
  overflow-y: auto;
  padding-right: 4px;
}
.part-btn {
  background: #f8fafc;
  color: #1e293b;
  border: 2px solid #cbd5e1;
  border-radius: 8px;
  padding: 4px 2px;
  font-size: 10px;
  font-weight: 600;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  line-height: 1.1;
}
.part-btn:hover { background: #e2e8f0; }
.part-btn.selected { border-color: #ffcc00; background: #fff7d6; box-shadow: 0 0 0 2px #ffcc00 inset; }
.part-icon { width: 48px; height: 48px; image-rendering: auto; }
.palette-title { font-weight: 700; font-size: 12px; margin: 10px 0 4px; }

.studio-toolbar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 8px 0; }
.studio-toolbar button { background: #475569; }
.studio-toolbar button:hover { background: #334155; }
.studio-toolbar .tool-btn.active { background: #ffcc00; color: #1e293b; }
.studio-toolbar .primary-btn { background: #16a34a; }
.studio-toolbar .primary-btn:hover { background: #15803d; }
.toolbar-label { font-size: 12px; font-weight: 700; color: #475569; }
.brick-counter { font-size: 12px; color: #475569; margin-left: auto; }
.save-row input { width: 180px; margin: 0; }
.save-row select { width: 160px; margin: 0; }

/* -------------------------------------------------------------- my home tab */
.home-layout { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.home-side {
  width: 280px;
  flex: 0 0 280px;
  background: #fff;
  border: 3px solid #1e293b;
  border-radius: 12px;
  padding: 12px;
  box-shadow: 3px 3px 0 rgba(0,0,0,0.15);
}
.home-side h3 { margin: 12px 0 6px; font-size: 14px; }
.home-main { flex: 1 1 460px; min-width: 380px; }
#homeCanvas { background: #e2e8f0; cursor: pointer; }
.row { display: flex; gap: 6px; }
.row button { flex: 1; }
.home-card { display: flex; gap: 8px; align-items: center; font-size: 12px; }
.home-card .thumb { width: 64px; height: 64px; margin: 0; flex: 0 0 64px; object-fit: contain; background: #eef4fb; }
.home-card .thumb.big { width: 84px; height: 84px; flex-basis: 84px; }
.bonus-list { display: flex; flex-direction: column; gap: 4px; }
.bonus { display: flex; justify-content: space-between; font-size: 13px; background: #f1f5f9; padding: 5px 8px; border-radius: 6px; }
.primary-btn { background: #16a34a; }
.primary-btn:hover { background: #15803d; }
.danger-btn { background: #6b7280; }
.danger-btn:hover { background: #4b5563; }
.hidden { display: none; }

.cat-badge {
  display: inline-block;
  background: #1e293b;
  color: #ffcc00;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 6px;
  margin-bottom: 4px;
}
.use-note { font-size: 11px; color: #2563eb; margin-bottom: 4px; }
.edit-build-btn { background: #2563eb; width: 100%; margin-top: 6px; }
.edit-build-btn:hover { background: #1d4ed8; }
.item-card .thumb { object-fit: contain; background: #eef4fb; }
.modal-box.wide { width: 620px; text-align: left; }
.modal-box.wide .item-card { cursor: pointer; }

.hunt-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; }
.hunt-status { display: flex; gap: 18px; font-size: 15px; }
.hunt-track { display: flex; gap: 6px; overflow-x: auto; padding: 6px 2px 10px; scroll-behavior: smooth; }
.hunt-cell {
  flex: 0 0 56px;
  height: 64px;
  background: #1e293b;
  border: 3px solid #334155;
  border-radius: 8px;
  position: relative;
  text-align: center;
}
.hunt-cell img { width: 48px; height: 48px; display: block; margin: 0 auto; }
.hunt-cell span { position: absolute; bottom: 1px; left: 0; right: 0; font-size: 11px; font-weight: 800; color: #fff; }
.hunt-cell.boss { border-color: #dc2626; }
.hunt-cell.locked img { filter: grayscale(1) brightness(0.35); }
.hunt-cell.beaten { background: #14532d; border-color: #22c55e; }
.hunt-cell.beaten img { opacity: 0.6; }
.hunt-cell.current { background: #facc15; border-color: #f59e0b; transform: scale(1.12); }
.hunt-cell.current span { color: #1e293b; }

.hunt-layout { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.hunt-layout .battle-area { flex: 1 1 520px; min-width: 0; }
.loadout { flex: 0 1 360px; background: #fff; border-radius: 12px; padding: 12px 16px; box-shadow: 0 2px 6px rgba(0,0,0,0.08); }
.loadout h3 { margin: 0 0 6px; }
.loadout h4 { margin: 12px 0 0; font-size: 14px; }
.loadout .item-card { width: 140px; padding: 8px; }
.loadout-stats { font-size: 13px; color: #334155; }
.empty-note { font-size: 12px; color: #64748b; }

.battle-area { background: #0f172a; border-radius: 12px; padding: 16px; }
#battleCanvas { width: 100%; height: auto; display: block; border-radius: 8px; cursor: crosshair; }
.attack-modes { display: flex; gap: 8px; align-items: center; margin-top: 10px; color: #fff; font-size: 13px; flex-wrap: wrap; }
.attack-mode-btn { background: #334155; border: 2px solid #475569; }
.attack-mode-btn.active { background: #2563eb; border-color: #93c5fd; }
.attack-mode-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.attack-mode-btn small { opacity: 0.8; margin-left: 4px; }
#fightBtn { flex: 1; font-size: 16px; padding: 12px; }
#fightBtn.hitting { background: #dc2626; }
.battle-bars { color: #fff; margin-top: 10px; }
.bar-label { font-size: 13px; margin-top: 6px; }
.hp-bar { background: #334155; border-radius: 6px; overflow: hidden; height: 16px; }
.hp-fill { height: 100%; transition: width 0.3s; }
.hp-fill.player { background: #22c55e; width: 100%; }
.hp-fill.enemy { background: #ef4444; width: 100%; }
.battle-log {
  background: #111827;
  color: #d1d5db;
  font-size: 12px;
  height: 100px;
  overflow-y: auto;
  border-radius: 6px;
  padding: 8px;
  margin-top: 10px;
}
.battle-buttons { display: flex; gap: 10px; margin-top: 10px; }

#toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #1e293b;
  color: #ffcc00;
  padding: 10px 18px;
  border-radius: 10px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
  z-index: 999;
}
#toast.show { opacity: 1; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal.hidden { display: none; }
.modal-box {
  background: #fff;
  border: 4px solid #1e293b;
  border-radius: 14px;
  padding: 24px;
  width: 320px;
  max-width: 90vw;
  text-align: center;
  box-shadow: 6px 6px 0 rgba(0,0,0,0.3);
}
.modal-box h2 { margin-top: 0; }
.auth-tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.auth-tab { flex: 1; opacity: 0.55; }
.auth-tab.active { opacity: 1; }
.auth-form { display: flex; flex-direction: column; gap: 8px; }
.auth-error { color: #d32f2f; font-size: 13px; min-height: 16px; }
.auth-divider { margin: 12px 0 8px; color: #64748b; font-size: 13px; }
#googleButton { display: flex; justify-content: center; }
.logout-btn { padding: 4px 10px; font-size: 12px; }
.modal-box input { text-align: center; }
