* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; width: 100%; height: 100%;
  font-family: 'Segoe UI', Tahoma, sans-serif;
  overflow: hidden; background: #0d0d12; color: #eee;
  -webkit-user-select: none; user-select: none;
  touch-action: none;
}
.screen { position: fixed; inset: 0; }
.hidden { display: none !important; }

/* ---------------- AUTH ---------------- */
#authScreen {
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 30%, #1b1b2f, #0a0a12 70%);
}
.auth-box {
  background: #16161f; padding: 32px; border-radius: 16px;
  width: 90%; max-width: 340px; text-align: center;
  box-shadow: 0 10px 40px rgba(0,0,0,.5); border: 1px solid #2a2a3a;
}
.auth-box h1 { margin-top: 0; font-size: 24px; }
.tabs { display: flex; margin-bottom: 16px; border-radius: 8px; overflow: hidden; }
.tab {
  flex: 1; padding: 10px; background: #24243a; color: #999; border: none; cursor: pointer;
}
.tab.active { background: #4a4ae0; color: #fff; }
.auth-form { display: flex; flex-direction: column; gap: 10px; }
.auth-form input {
  padding: 12px; border-radius: 8px; border: 1px solid #333; background: #0f0f18; color: #fff; font-size: 15px;
}
.auth-form button {
  padding: 12px; border-radius: 8px; border: none; background: #4a4ae0; color: #fff;
  font-size: 15px; cursor: pointer; margin-top: 4px;
}
.auth-form button:hover { background: #5a5af5; }
.error { color: #ff6b6b; min-height: 20px; font-size: 13px; margin-top: 10px; }

/* ---------------- GAME ---------------- */
#gameCanvas { position: absolute; inset: 0; background: #1a2e1a; display: block; }

.hud {
  position: absolute; top: 10px; left: 10px; width: 220px;
  background: rgba(10,10,15,0.7); border-radius: 10px; padding: 10px; z-index: 10;
}
.hud-name { font-weight: bold; margin-bottom: 6px; font-size: 14px; }
.bar { position: relative; height: 14px; background: #222; border-radius: 7px; margin-bottom: 5px; overflow: hidden; }
.bar .fill { height: 100%; width: 0%; transition: width .2s; }
.hp-bar .fill { background: linear-gradient(90deg,#e0413a,#ff6b5e); }
.mp-bar .fill { background: linear-gradient(90deg,#3a7de0,#5eaaff); }
.exp-bar { height: 6px; }
.exp-bar .fill { background: linear-gradient(90deg,#e0d13a,#fff05e); }
.bar-text { position: absolute; inset: 0; text-align: center; font-size: 10px; line-height: 14px; }
.hud-gold { font-size: 13px; margin-top: 4px; }

#floatingText { position: absolute; inset: 0; pointer-events: none; z-index: 9; overflow: hidden; }
.float-dmg {
  position: absolute; font-weight: bold; font-size: 15px; color: #fff;
  animation: floatUp 1s ease-out forwards; pointer-events: none;
}
.float-dmg.crit { color: #ffd23a; font-size: 19px; }
.float-dmg.heal { color: #6bff8f; }
@keyframes floatUp {
  0% { transform: translateY(0); opacity: 1; }
  100% { transform: translateY(-40px); opacity: 0; }
}

.skill-bar {
  position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 10px; z-index: 10;
}
.skill-btn {
  width: 54px; height: 54px; border-radius: 12px; background: rgba(30,30,45,.85);
  border: 2px solid #4a4ae0; color: #fff; font-size: 20px; position: relative;
  display: flex; align-items: center; justify-content: center;
}
.skill-btn.disabled { opacity: 0.4; border-color: #555; }
.skill-btn .cd-overlay {
  position: absolute; inset: 0; background: rgba(0,0,0,.6); border-radius: 12px;
  display: flex; align-items: center; justify-content: center; font-size: 13px;
}

.action-buttons { position: absolute; bottom: 16px; right: 16px; z-index: 10; }
.round-btn {
  width: 66px; height: 66px; border-radius: 50%; background: rgba(224,65,58,.9);
  border: 2px solid #ff8b7f; color: #fff; font-size: 26px;
}

.joystick-zone {
  position: absolute; bottom: 16px; left: 16px; width: 130px; height: 130px; z-index: 10;
}
.joystick-base {
  width: 100%; height: 100%; border-radius: 50%; background: rgba(255,255,255,.08);
  border: 2px solid rgba(255,255,255,.2); position: relative;
}
.joystick-stick {
  width: 50px; height: 50px; border-radius: 50%; background: rgba(74,74,224,.85);
  position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);
}

.panel-toggles { position: absolute; top: 10px; right: 10px; display: flex; gap: 8px; z-index: 10; }
.icon-btn {
  width: 42px; height: 42px; border-radius: 10px; background: rgba(10,10,15,.7);
  border: 1px solid #333; color: #fff; font-size: 18px;
}

.panel {
  position: absolute; top: 60px; right: 10px; width: 260px; max-height: 60vh; overflow-y: auto;
  background: rgba(15,15,22,.95); border: 1px solid #333; border-radius: 12px; padding: 12px; z-index: 20;
}
.panel h3 { margin: 0 0 10px; display: flex; justify-content: space-between; font-size: 15px; }
.closeBtn { background: none; border: none; color: #aaa; font-size: 14px; }

.item-list { display: flex; flex-direction: column; gap: 6px; }
.item-row {
  display: flex; align-items: center; gap: 8px; background: #1c1c28; padding: 6px 8px; border-radius: 8px; font-size: 13px;
}
.item-row .icon { font-size: 18px; }
.item-row .name { flex: 1; }
.item-row button {
  background: #4a4ae0; border: none; color: #fff; border-radius: 6px; padding: 4px 8px; font-size: 11px;
}
.item-row .equipped-tag { color: #6bff8f; font-size: 11px; }

.stats-list { font-size: 13px; display: flex; flex-direction: column; gap: 6px; }
.stat-row { display: flex; justify-content: space-between; align-items: center; }
.stat-row button {
  background: #2f6; border: none; border-radius: 6px; width: 22px; height: 22px; font-size: 12px; color: #032;
}

.chat-log { height: 160px; overflow-y: auto; font-size: 12px; margin-bottom: 8px; display: flex; flex-direction: column; gap: 3px; }
.chat-log .sys { color: #888; font-style: italic; }
.chat-log .from { color: #6bd0ff; font-weight: bold; }
#chatForm input {
  width: 100%; padding: 8px; border-radius: 6px; border: 1px solid #333; background: #0f0f18; color: #fff;
}

.death-overlay {
  position: absolute; inset: 0; background: rgba(0,0,0,.75); z-index: 30;
  display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 26px;
}
.death-overlay .small { font-size: 14px; color: #aaa; margin-top: 8px; }

@media (max-width: 600px) {
  .panel { width: 80vw; right: 5vw; }
  .hud { width: 180px; }
}
