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

:root {
  --bg: #14121a;
  --panel: #1f1b2b;
  --panel-edge: #3a3252;
  --text: #e8e2f4;
  --muted: #9b91b8;
  --accent: #c9a14d;
  --hp: #d04545;
  --xp: #7a5fd0;
  --good: #5fb86a;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
}

.hidden { display: none !important; }

/* ============ AUTH ============ */
#auth-screen {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, #221d33 0%, var(--bg) 70%);
}
.auth-card {
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 12px;
  padding: 36px 40px;
  width: 360px;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0,0,0,.5);
}
.auth-card h1 { font-size: 32px; letter-spacing: 2px; }
.auth-tagline { color: var(--muted); font-size: 13px; margin: 8px 0 20px; }
.auth-tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.auth-tab {
  flex: 1; padding: 8px; border: 1px solid var(--panel-edge);
  background: transparent; color: var(--muted); border-radius: 6px; cursor: pointer;
}
.auth-tab.active { background: var(--panel-edge); color: var(--text); }
.auth-form { display: flex; flex-direction: column; gap: 10px; }
.auth-form input {
  padding: 10px 12px; border-radius: 6px; border: 1px solid var(--panel-edge);
  background: #161222; color: var(--text); font-size: 14px;
}
.auth-form input:focus { outline: 1px solid var(--accent); }
.auth-form button {
  padding: 11px; border: none; border-radius: 6px; cursor: pointer;
  background: var(--accent); color: #1c1505; font-weight: 700; font-size: 14px;
}
.auth-form button:hover { filter: brightness(1.1); }
.auth-error { margin-top: 12px; color: #ff7b7b; font-size: 13px; }

/* ============ GAME LAYOUT ============ */
#game-screen { height: 100%; display: flex; align-items: center; justify-content: center; }
#game-wrap { position: relative; }
#game {
  display: block;
  border: 2px solid var(--panel-edge);
  border-radius: 6px;
  background: #000;
  max-width: 100vw;
  max-height: 100vh;
  image-rendering: pixelated;
}

/* ============ HUD ============ */
#hud {
  position: absolute; top: 8px; left: 8px; right: 8px;
  display: flex; justify-content: space-between; align-items: flex-start;
  pointer-events: none;
}
.hud-left, .hud-right {
  display: flex; align-items: center; gap: 8px;
  background: rgba(20, 16, 32, .85);
  border: 1px solid var(--panel-edge);
  border-radius: 8px; padding: 6px 10px;
  pointer-events: auto;
}
.hud-left { flex-direction: row; }
#hud-name { font-weight: 700; font-size: 14px; }
.hud-pill {
  background: var(--panel-edge); border-radius: 999px;
  padding: 2px 10px; font-size: 12px;
}
.hud-pill.gold { background: #4d3c12; color: #ffd76a; font-weight: 700; }
.hp-bar, .xp-bar {
  position: relative; width: 140px; height: 16px;
  background: #0d0b14; border-radius: 999px; overflow: hidden;
  border: 1px solid var(--panel-edge);
}
.hp-bar.small { width: 120px; height: 12px; }
#hp-fill, #combat-player-hp, #combat-enemy-hp {
  height: 100%; background: var(--hp); width: 100%;
  transition: width .25s ease;
}
.xp-bar { height: 12px; }
#xp-fill { height: 100%; background: var(--xp); width: 0; transition: width .25s ease; }
#hp-text, #xp-text {
  position: absolute; inset: 0; text-align: center;
  font-size: 10px; line-height: 15px; color: #fff; text-shadow: 0 1px 2px #000;
}
.hud-btn {
  position: relative;
  background: var(--panel-edge); border: none; border-radius: 6px;
  width: 32px; height: 32px; cursor: pointer; font-size: 15px; color: var(--text);
}
.hud-btn:hover { filter: brightness(1.25); }
.badge {
  position: absolute; top: -5px; right: -5px;
  background: var(--hp); color: #fff; border-radius: 999px;
  font-size: 10px; min-width: 16px; height: 16px; line-height: 16px;
}

#zone-label {
  position: absolute; top: 56px; left: 50%; transform: translateX(-50%);
  font-size: 13px; color: var(--accent); letter-spacing: 3px; text-transform: uppercase;
  text-shadow: 0 1px 3px #000; pointer-events: none;
}
#interact-hint {
  position: absolute; bottom: 64px; left: 50%; transform: translateX(-50%);
  background: rgba(20, 16, 32, .9); border: 1px solid var(--accent);
  border-radius: 8px; padding: 6px 14px; font-size: 13px; pointer-events: none;
}
#controls-help {
  position: absolute; bottom: 8px; left: 50%; transform: translateX(-50%);
  font-size: 11px; color: var(--muted); pointer-events: none;
  text-shadow: 0 1px 2px #000;
}

/* ============ PANELS (chat, combat) ============ */
.panel {
  position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%);
  width: 560px; max-width: 95%;
  background: rgba(26, 21, 40, .96);
  border: 1px solid var(--panel-edge); border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0,0,0,.6);
  display: flex; flex-direction: column;
}
.panel-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px; border-bottom: 1px solid var(--panel-edge);
  font-weight: 700; color: var(--accent);
}
.panel-close {
  background: none; border: none; color: var(--muted);
  font-size: 14px; cursor: pointer;
}
.panel-close:hover { color: var(--text); }

#chat-messages {
  max-height: 220px; min-height: 80px; overflow-y: auto;
  padding: 12px 14px; display: flex; flex-direction: column; gap: 8px;
}
.chat-msg { max-width: 85%; padding: 8px 12px; border-radius: 10px; font-size: 13px; line-height: 1.45; }
.chat-msg.player { align-self: flex-end; background: #34406b; }
.chat-msg.npc { align-self: flex-start; background: #2c2440; }
.chat-msg.npc .cursor { animation: blink .8s infinite; }
@keyframes blink { 50% { opacity: 0; } }

#chat-form { display: flex; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--panel-edge); }
#chat-input {
  flex: 1; padding: 9px 12px; border-radius: 6px;
  border: 1px solid var(--panel-edge); background: #161222; color: var(--text);
}
#chat-form button {
  padding: 9px 18px; border: none; border-radius: 6px; cursor: pointer;
  background: var(--accent); color: #1c1505; font-weight: 700;
}

.offer-card {
  align-self: flex-start;
  background: #3b3013; border: 1px solid var(--accent); border-radius: 10px;
  padding: 10px 14px; font-size: 13px;
  display: flex; align-items: center; gap: 12px;
}
.offer-card button {
  background: var(--accent); border: none; border-radius: 6px;
  padding: 6px 14px; cursor: pointer; font-weight: 700; color: #1c1505;
}
.offer-card button:disabled { opacity: .5; cursor: default; }

/* ============ COMBAT ============ */
.combat-bars {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; gap: 10px;
}
.combat-fighter { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 700; }
.combat-vs { color: var(--muted); font-size: 12px; }
.hp-bar.enemy #combat-enemy-hp { background: #b5772e; }
#combat-log {
  height: 130px; overflow-y: auto; padding: 8px 16px;
  font-size: 12.5px; line-height: 1.6; border-top: 1px solid var(--panel-edge);
}
#combat-log .taunt { color: #8fdc91; font-style: italic; }
#combat-log .hit { color: #ffb1b1; }
#combat-log .info { color: var(--muted); }
.combat-actions {
  display: flex; gap: 10px; padding: 10px 16px;
  border-top: 1px solid var(--panel-edge); align-items: stretch;
}
#combat-moves { display: flex; gap: 8px; flex: 1; }
.move-btn {
  position: relative; flex: 1;
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  padding: 7px 4px 6px; border: 1px solid var(--panel-edge); border-radius: 8px;
  background: #2a2240; color: var(--text); cursor: pointer;
}
.move-btn:hover:not(:disabled) { background: #383058; }
.move-btn:disabled { opacity: .45; cursor: default; }
.move-key {
  position: absolute; top: 3px; left: 5px;
  font-size: 9px; color: var(--muted); border: 1px solid var(--panel-edge);
  border-radius: 3px; padding: 0 3px;
}
.move-icon { font-size: 16px; }
.move-name { font-size: 11px; font-weight: 700; }
.move-desc { font-size: 9px; color: var(--muted); text-align: center; line-height: 1.2; }
.move-cd {
  position: absolute; top: -6px; right: -6px;
  background: var(--hp); color: #fff; border-radius: 999px;
  min-width: 17px; height: 17px; line-height: 17px; font-size: 10px; font-weight: 700;
}
#btn-flee {
  background: var(--panel-edge); color: var(--text);
  border: none; border-radius: 8px; padding: 0 16px;
  cursor: pointer; font-weight: 700; font-size: 13px;
}
#btn-flee:disabled { opacity: .45; cursor: default; }

/* ============ MODALS (inventory, friends, buy) ============ */
.modal-backdrop {
  position: absolute; inset: 0; background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center;
  border-radius: 6px;
}
.modal {
  width: 480px; max-width: 92%; max-height: 80%;
  background: var(--panel); border: 1px solid var(--panel-edge);
  border-radius: 10px; display: flex; flex-direction: column;
  box-shadow: 0 14px 40px rgba(0,0,0,.7);
}
.modal-body { padding: 12px 16px; overflow-y: auto; }

.item-row, .friend-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px; border-radius: 8px; gap: 10px;
}
.item-row:nth-child(odd), .friend-row:nth-child(odd) { background: rgba(255,255,255,.03); }
.item-row .item-meta { font-size: 11px; color: var(--muted); }
.item-row .item-name { font-size: 13px; font-weight: 600; }
.item-name .equipped-tag { color: var(--good); font-size: 11px; margin-left: 6px; }
.item-row button, .friend-row button {
  border: none; border-radius: 6px; padding: 5px 12px; cursor: pointer;
  background: var(--panel-edge); color: var(--text); font-size: 12px;
}
.item-row button:hover, .friend-row button:hover { filter: brightness(1.3); }
.friend-row .friend-level { color: var(--muted); font-size: 12px; }
.friend-row .danger { background: #562424; }

.friend-search { display: flex; gap: 8px; padding: 12px 16px 0; }
.friend-search input {
  flex: 1; padding: 8px 12px; border-radius: 6px;
  border: 1px solid var(--panel-edge); background: #161222; color: var(--text);
}
.friend-search button {
  padding: 8px 14px; border: none; border-radius: 6px; cursor: pointer;
  background: var(--accent); color: #1c1505; font-weight: 700;
}
.section-label {
  padding: 10px 16px 2px; font-size: 11px; letter-spacing: 2px;
  text-transform: uppercase; color: var(--muted);
}
.empty-note { padding: 10px 16px; color: var(--muted); font-size: 13px; }

/* ============ SHOP ============ */
.shop-tabs {
  display: flex; gap: 8px; align-items: center;
  padding: 10px 16px 0;
}
.shop-tabs button {
  padding: 7px 22px; border: 1px solid var(--panel-edge); border-radius: 6px;
  background: transparent; color: var(--muted); cursor: pointer; font-weight: 700;
}
.shop-tabs button.active { background: var(--panel-edge); color: var(--text); }
.shop-gold { margin-left: auto; color: #ffd76a; font-size: 13px; font-weight: 700; }
.item-row .shop-buy { background: #4d3c12; color: #ffd76a; font-weight: 700; }
.item-row .shop-sell { background: #1f4128; color: #9fdca9; font-weight: 700; }
.item-row button:disabled { opacity: .4; cursor: default; }

.panel-header-actions { display: flex; align-items: center; gap: 8px; }
.chat-shop {
  background: var(--accent); color: #1c1505; border: none; border-radius: 6px;
  padding: 4px 12px; font-size: 12px; font-weight: 700; cursor: pointer;
}
.chat-shop:hover { filter: brightness(1.1); }

#hud-online.offline { color: #ff9b9b; }

/* ============ TOASTS ============ */
#toasts {
  position: absolute; top: 70px; right: 12px;
  display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
.toast {
  background: rgba(26, 21, 40, .95); border: 1px solid var(--panel-edge);
  border-left: 3px solid var(--accent);
  border-radius: 8px; padding: 10px 14px; font-size: 13px;
  animation: toast-in .25s ease;
  max-width: 280px;
}
.toast.good { border-left-color: var(--good); }
.toast.bad { border-left-color: var(--hp); }
@keyframes toast-in { from { transform: translateX(20px); opacity: 0; } }
