* { margin: 0; padding: 0; box-sizing: border-box; }
body { background: #000; overflow: hidden; font-family: 'Segoe UI', sans-serif; color: #eee; }

canvas { display: block; position: fixed; top: 0; left: 0; }

/* ── Login ── */
#loginScreen {
  position: fixed; inset: 0; background: linear-gradient(160deg,#0d0325 0%,#0a1a30 100%);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
#loginBox {
  background: rgba(10,10,30,0.92); border: 1px solid #334;
  border-radius: 16px; padding: 40px 50px; text-align: center;
  box-shadow: 0 0 60px rgba(0,100,255,0.2);
}
#loginBox h1 { font-size: 2.4rem; letter-spacing: 2px; color: #88ccff; margin-bottom: 4px; }
.subtitle { color: #667; margin-bottom: 28px; font-size: 0.9rem; }
.guest-warning { color: #fbbf24; font-size: 0.85rem; margin-bottom: 12px; }
.account-info { color: #5eead4; font-size: 0.85rem; margin-bottom: 12px; }
.login-links { margin-top: 12px; font-size: 0.85rem; }
.login-links a { color: #88ccff; text-decoration: none; }
.login-links a:hover { text-decoration: underline; }
.save-indicator { margin-left: 6px; font-size: 0.85rem; opacity: 0.7; }
#playerName {
  width: 100%; padding: 10px 14px; border-radius: 8px; border: 1px solid #335;
  background: #0d1020; color: #eee; font-size: 1rem; outline: none; margin-bottom: 14px;
}
#playerName:focus { border-color: #55aaff; }
#startBtn {
  width: 100%; padding: 12px; border: none; border-radius: 8px;
  background: linear-gradient(135deg,#1155cc,#0088ff); color: #fff;
  font-size: 1.05rem; font-weight: 600; cursor: pointer; letter-spacing: 1px;
  transition: opacity .15s;
}
#startBtn:hover { opacity: 0.85; }
.controls-hint {
  margin-top: 22px; color: #556; font-size: 0.78rem; line-height: 1.8;
  border-top: 1px solid #223; padding-top: 16px;
}

/* ── HUD ── */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }

#topBar {
  position: absolute; top: 14px; left: 14px; display: flex; gap: 14px; align-items: flex-start;
}
#statsBox {
  background: rgba(0,0,0,0.65); border: 1px solid #334; border-radius: 10px;
  padding: 10px 14px; display: flex; flex-direction: column; gap: 6px; min-width: 220px;
}
.bar-row { display: flex; align-items: center; gap: 6px; }
.bar-label { font-size: 0.7rem; font-weight: 700; color: #aaa; width: 20px; }
.bar-bg { flex: 1; background: #1a1a2a; border-radius: 4px; height: 12px; overflow: hidden; }
.bar { height: 100%; border-radius: 4px; transition: width .2s; }
.hp-bar { background: linear-gradient(90deg,#cc2222,#ff5555); }
.mp-bar { background: linear-gradient(90deg,#1144cc,#44aaff); }
.xp-bar { background: linear-gradient(90deg,#885500,#ffaa22); }
.bar-text { font-size: 0.68rem; color: #aaa; min-width: 72px; text-align: right; }

#infoBox {
  background: rgba(0,0,0,0.65); border: 1px solid #334; border-radius: 10px;
  padding: 8px 14px; font-size: 0.8rem; color: #99bbdd; line-height: 1.7;
}
#mapName { color: #ddeeaa; font-weight: 600; font-size: 0.85rem; }
#levelXp  { color: #aabbcc; }

/* ── Skill Bar ── */
#skillBar {
  position: absolute; bottom: 80px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 10px; pointer-events: none;
}
.skill-slot {
  position: relative; width: 64px; height: 64px; border-radius: 10px;
  background: rgba(0,0,0,0.75); border: 2px solid #445;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  overflow: hidden;
}
.skill-icon { font-size: 1.8rem; line-height: 1; }
.lightning-icon { filter: drop-shadow(0 0 6px #ffff44); }
.ice-icon        { filter: drop-shadow(0 0 6px #44aaff); }
.wave-icon       { filter: drop-shadow(0 0 6px #88ddff); }
.skill-key  { position: absolute; top: 2px; right: 5px; font-size: 0.62rem; color: #889; font-weight: 700; }
.skill-name { position: absolute; bottom: 2px; font-size: 0.6rem; color: #aab; }
.skill-cd-overlay {
  position: absolute; inset: 0; background: rgba(0,0,0,0); border-radius: 8px;
  transition: background .05s;
}
.skill-slot.on-cd .skill-cd-overlay { background: rgba(0,0,0,0.6); }

/* ── Chat ── */
#chatBox {
  position: absolute; bottom: 14px; left: 14px; width: 320px; pointer-events: all;
}
#chatLog {
  max-height: 120px; overflow-y: auto; padding: 6px 8px;
  background: rgba(0,0,0,0.55); border-radius: 8px 8px 0 0;
  font-size: 0.75rem; line-height: 1.55; color: #bbc;
  border: 1px solid #334; border-bottom: none;
}
#chatLog::-webkit-scrollbar { width: 4px; }
#chatLog::-webkit-scrollbar-thumb { background: #335; border-radius: 2px; }
#chatInput {
  width: 100%; padding: 7px 10px; background: rgba(0,0,10,0.8);
  border: 1px solid #334; border-radius: 0 0 8px 8px; color: #dde;
  font-size: 0.8rem; outline: none;
}
#chatInput:focus { border-color: #55aaff; }

/* ── Coin Display ── */
#coinDisplay {
  font-size: 0.78rem; color: #ffd700; font-weight: 600;
  padding-top: 4px; border-top: 1px solid #223; margin-top: 2px;
}

/* ── Party Panel ── */
#partyPanel {
  position: absolute; top: 14px; right: 14px; width: 200px;
  background: rgba(0,0,0,0.65); border: 1px solid #334;
  border-radius: 10px; padding: 10px 12px;
  pointer-events: none;
}
.party-header {
  font-size: 0.72rem; font-weight: 700; color: #88ccff;
  text-transform: uppercase; letter-spacing: 1px;
  margin-bottom: 8px; border-bottom: 1px solid #223; padding-bottom: 4px;
}
.party-member {
  margin-bottom: 8px;
}
.party-member-name {
  font-size: 0.72rem; color: #aabbcc; margin-bottom: 3px;
  display: flex; align-items: center; gap: 4px;
}
.party-member-name.is-me { color: #88ddff; font-weight: 700; }
.party-map-tag {
  font-size: 0.6rem; color: #556; background: #111; border-radius: 3px;
  padding: 1px 4px; margin-left: auto;
}
.party-mini-bar-bg {
  height: 5px; background: #1a1a2a; border-radius: 3px; overflow: hidden;
  margin-bottom: 2px;
}
.party-mini-hp { height: 100%; background: linear-gradient(90deg,#cc2222,#ff5555); border-radius: 3px; }
.party-mini-mp { height: 100%; background: linear-gradient(90deg,#1144cc,#44aaff); border-radius: 3px; }

/* ── Invite Notification ── */
#inviteNotif {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  background: rgba(0,0,20,0.92); border: 1px solid #446;
  border-radius: 12px; padding: 18px 28px; text-align: center;
  box-shadow: 0 0 40px rgba(0,80,255,0.25);
  pointer-events: all;
}
.invite-name {
  display: block; font-size: 0.9rem; color: #88ccff;
  margin-bottom: 14px; line-height: 1.5;
}
.invite-btns { display: flex; gap: 10px; justify-content: center; }
#acceptBtn, #declineBtn {
  padding: 7px 20px; border: none; border-radius: 7px;
  font-size: 0.82rem; font-weight: 600; cursor: pointer; transition: opacity .15s;
}
#acceptBtn  { background: linear-gradient(135deg,#115522,#22aa44); color: #fff; }
#declineBtn { background: linear-gradient(135deg,#551111,#aa2222); color: #fff; }
#acceptBtn:hover, #declineBtn:hover { opacity: 0.8; }

/* ── Skill Panel ── */
#skillPanel {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%,-50%);
  width: 460px; background: rgba(4,4,18,0.97); border: 1px solid #336;
  border-radius: 14px; z-index: 60; pointer-events: all;
  box-shadow: 0 0 70px rgba(0,80,220,0.35), 0 0 20px rgba(0,0,0,0.8);
}
#skillPanelHeader {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px 10px; border-bottom: 1px solid #223;
  font-size: 0.9rem; font-weight: 700; color: #88ccff; letter-spacing: 1px;
}
#skillPanelClose {
  background: none; border: 1px solid #334; border-radius: 6px;
  color: #778; font-size: 0.82rem; cursor: pointer; padding: 2px 8px;
  transition: all .15s;
}
#skillPanelClose:hover { border-color: #ff6666; color: #ff6666; }
#skillPanelBody { padding: 10px 18px 16px; }
.sp-col-headers {
  display: grid; grid-template-columns: 148px 1fr 1fr 1fr; gap: 8px;
  padding: 0 0 6px; border-bottom: 1px solid #1a1a30; margin-bottom: 4px;
}
.sp-col-headers span { font-size: 0.6rem; color: #446; text-transform: uppercase;
  letter-spacing: .6px; text-align: center; }
.sp-col-headers span:first-child { text-align: left; padding-left: 4px; }
.sp-row {
  display: grid; grid-template-columns: 148px 1fr 1fr 1fr; gap: 8px;
  align-items: center; padding: 9px 0; border-bottom: 1px solid #111222;
}
.sp-row:last-child { border-bottom: none; }
.sp-skill-info { display: flex; align-items: center; gap: 8px; }
.sp-icon { font-size: 1.3rem; width: 28px; text-align: center; flex-shrink: 0; }
.sp-name { font-size: 0.78rem; font-weight: 700; color: #aabbdd; line-height: 1.3; }
.sp-key  { font-size: 0.62rem; color: #556; }
.sp-field { display: flex; flex-direction: column; gap: 2px; }
.sp-field label { font-size: 0.6rem; color: #556; text-transform: uppercase; letter-spacing: .5px; text-align: center; }
.sp-field input[type=number] {
  width: 100%; padding: 5px 6px; background: #0a0e1e; border: 1px solid #2a2a44;
  border-radius: 6px; color: #ccddf0; font-size: 0.8rem; outline: none; text-align: center;
  -moz-appearance: textfield;
}
.sp-field input[type=number]::-webkit-inner-spin-button { opacity: 0.4; }
.sp-field input[type=number]:focus { border-color: #44aaff; box-shadow: 0 0 0 2px rgba(68,170,255,0.15); }
.sp-hint { font-size: 0.68rem; color: #445; text-align: center; padding-top: 10px; border-top: 1px solid #1a1a30; margin-top: 6px; }

/* ── Inventory Panel ── */
#inventoryPanel {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%,-50%);
  width: 520px; max-height: 80vh; overflow-y: auto;
  background: rgba(4,4,18,0.97); border: 1px solid #446;
  border-radius: 14px; z-index: 60; pointer-events: all;
  box-shadow: 0 0 70px rgba(80,0,200,0.3), 0 0 20px rgba(0,0,0,0.8);
}
.inv-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px 10px; border-bottom: 1px solid #223;
  font-size: 0.9rem; font-weight: 700; color: #aa88ff; letter-spacing: 1px;
  position: sticky; top: 0; background: rgba(4,4,18,0.99); z-index: 1;
}
.inv-close {
  background: none; border: 1px solid #334; border-radius: 6px;
  color: #778; font-size: 0.82rem; cursor: pointer; padding: 2px 8px; transition: all .15s;
}
.inv-close:hover { border-color: #ff6666; color: #ff6666; }
.inv-equip-row {
  display: flex; gap: 8px; padding: 8px 12px 6px;
  border-bottom: 1px solid #1a1a30;
}
.inv-equip-slot {
  flex: 1; border: 1px solid #334; border-radius: 8px; padding: 6px 4px;
  text-align: center; cursor: pointer; transition: background .15s; min-height: 72px;
  display: flex; flex-direction: column; align-items: center; gap: 1px;
}
.inv-equip-slot:hover { background: rgba(255,255,255,0.06); }

/* ── Potentials ── */
.inv-potentials {
  display: flex; flex-direction: column; align-items: center;
  margin-top: 3px; width: 100%;
}
.inv-potentials-sm { margin-top: 2px; }
.inv-potential {
  font-size: 0.56rem; line-height: 1.45; white-space: nowrap;
}
.pot-t0 { color: #888; }
.pot-t1 { color: #5599ff; }
.pot-t2 { color: #ffbb00; }
.inv-slot-label { font-size: 0.62rem; color: #556; text-transform: uppercase; letter-spacing: .5px; }
.inv-item-icon { font-size: 1.4rem; }
.inv-item-name { font-size: 0.68rem; font-weight: 600; }
.inv-empty { font-size: 0.65rem; color: #334; margin-top: 10px; }
.inv-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; padding: 12px 16px;
}
.inv-item-cell {
  border: 1px solid #334; border-radius: 8px; padding: 8px 4px;
  text-align: center; cursor: pointer; transition: background .15s;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.inv-item-cell:hover { background: rgba(255,255,255,0.06); }
.inv-item-icon-lg { font-size: 1.6rem; }
.inv-item-name-sm { font-size: 0.65rem; font-weight: 600; line-height: 1.2; }
.inv-item-stats { font-size: 0.6rem; color: #88aacc; }
.inv-empty-msg { grid-column: 1/-1; text-align: center; color: #445; padding: 20px; font-size: 0.8rem; }
.inv-hint { font-size: 0.65rem; color: #334; text-align: center; padding: 8px 0 14px; border-top: 1px solid #1a1a30; margin-top: 4px; }
.inv-shop-tag { color: #ffcc66; font-size: 0.75rem; font-weight: normal; }
.inv-auto-toggle {
  display: flex; align-items: center; gap: 8px; padding: 8px 16px 4px;
  font-size: 0.78rem; color: #aabbcc; pointer-events: all; cursor: pointer;
}
.inv-auto-toggle input { accent-color: #5eead4; width: 16px; height: 16px; }
.inv-sell-bar {
  padding: 6px 16px 8px; border-bottom: 1px solid #1a1a30; pointer-events: all;
}
.inv-sell-all-btn {
  width: 100%; padding: 8px; border-radius: 8px; border: 1px solid #665522;
  background: linear-gradient(135deg, #3a2a08, #5a4010); color: #ffdd88;
  font-size: 0.8rem; font-weight: 600; cursor: pointer;
}
.inv-sell-all-btn:hover { filter: brightness(1.1); }
.inv-item-cell { display: flex; flex-direction: column; gap: 4px; }
.inv-item-main { cursor: pointer; flex: 1; }
.inv-item-cell.inv-item-upgrade { box-shadow: 0 0 0 1px rgba(94,234,212,0.35); }
.inv-item-power { font-size: 0.58rem; color: #667; margin-top: 2px; }
.inv-sell-btn {
  width: 100%; padding: 4px; border: none; border-radius: 6px;
  background: #3a2a10; color: #ffcc66; font-size: 0.65rem; font-weight: 600;
  cursor: pointer; pointer-events: all;
}
.inv-sell-btn:hover { background: #5a4018; }

/* ── Stats Panel ── */
#statsPanel {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%,-50%);
  width: 400px; background: rgba(4,4,18,0.97); border: 1px solid #3a5a44;
  border-radius: 14px; z-index: 60; pointer-events: all;
  box-shadow: 0 0 70px rgba(0,180,120,0.25), 0 0 20px rgba(0,0,0,0.8);
}
#statsPanelHeader {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px 10px; border-bottom: 1px solid #223;
  font-size: 0.9rem; font-weight: 700; color: #5eead4; letter-spacing: 1px;
}
#statsPanelClose {
  background: none; border: 1px solid #334; border-radius: 6px;
  color: #778; font-size: 0.82rem; cursor: pointer; padding: 2px 8px;
}
#statsPanelClose:hover { border-color: #5eead4; color: #5eead4; }
.stat-points-line { padding: 8px 18px 0; font-size: 0.82rem; color: #8899aa; }
.stat-points-line strong { color: #ffdd44; }
#statsPanelBody { padding: 10px 18px 8px; }
.stat-row {
  display: grid; grid-template-columns: 1fr auto auto;
  align-items: center; gap: 10px; padding: 8px 0;
  border-bottom: 1px solid #1a1a30;
}
.stat-row:last-child { border-bottom: none; }
.stat-label { font-weight: 700; font-size: 0.85rem; }
.stat-label.str { color: #ff8888; }
.stat-label.int { color: #88ccff; }
.stat-label.dex { color: #88ffaa; }
.stat-label.luk { color: #ffcc66; }
.stat-desc { font-size: 0.65rem; color: #556; display: block; font-weight: normal; }
.stat-value { font-size: 1.1rem; color: #ddeeff; min-width: 28px; text-align: center; }
.stat-add-btn {
  width: 32px; height: 32px; border-radius: 8px; border: 1px solid #446;
  background: #112233; color: #5eead4; font-size: 1.2rem; font-weight: 700;
  cursor: pointer; pointer-events: all;
}
.stat-add-btn:hover:not(:disabled) { background: #1a3a4a; border-color: #5eead4; }
.stat-add-btn:disabled { opacity: 0.35; cursor: default; }
.derived-stats-box {
  margin: 0 18px 16px; padding: 10px 12px; background: #0a1020;
  border: 1px solid #223; border-radius: 8px; font-size: 0.75rem; color: #8899bb; line-height: 1.7;
}
.derived-stats-box b { color: #ccddee; }
.stat-points-badge {
  display: inline-block; margin-left: 6px; padding: 1px 7px;
  background: #ffdd44; color: #221800; border-radius: 999px;
  font-size: 0.7rem; font-weight: 700; animation: stat-pulse 1.2s ease infinite;
}
@keyframes stat-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,221,68,0.5); }
  50% { box-shadow: 0 0 8px 2px rgba(255,221,68,0.6); }
}
