:root{
  --bg:#06070b;
  --bg2:#0b0f18;
  --panel:rgba(14,18,27,.88);
  --panel-2:rgba(20,24,36,.92);
  --border:rgba(255,255,255,.08);
  --text:#f3f6fb;
  --muted:#98a2b6;
  --gold:#f5bc43;
  --gold2:#ff9f1a;
  --blue:#72adff;
  --violet:#a286ff;
  --green:#4ade80;
}
*{box-sizing:border-box}
html,body{
  margin:0;padding:0;
  background:
    radial-gradient(circle at top, rgba(245,188,67,.11), transparent 26%),
    radial-gradient(circle at 84% 14%, rgba(114,173,255,.08), transparent 22%),
    linear-gradient(180deg,#04050a,#090c13);
  color:var(--text);
  font-family:Inter,system-ui,-apple-system,Segoe UI,Roboto,Arial,sans-serif
}
a{text-decoration:none;color:inherit}
button,input{font:inherit}
code{background:rgba(255,255,255,.06);padding:2px 6px;border-radius:8px}
.layout{display:flex;min-height:100vh}

/* SIDEBAR - full version retained */
.sidebar{
  width:286px;flex:0 0 286px;
  background:linear-gradient(180deg, rgba(10,13,20,.95), rgba(7,10,16,.95));
  border-right:1px solid var(--border);
  padding:20px;
  position:sticky;top:0;height:100vh;
  backdrop-filter:blur(14px);
  overflow:auto;
  transition:transform .24s ease, opacity .24s ease;
  z-index:30;
}
.sidebar-header{
  display:flex;align-items:center;justify-content:space-between;gap:12px;margin-bottom:18px
}
.brand{display:flex;align-items:center;gap:12px}
.brand-mark{
  width:44px;height:44px;border-radius:14px;display:grid;place-items:center;
  background:linear-gradient(135deg, rgba(245,188,67,.28), rgba(162,134,255,.18));
  border:1px solid rgba(245,188,67,.18);
  box-shadow:0 0 28px rgba(245,188,67,.12);
  font-weight:800
}
.brand-title{font-weight:800;font-size:18px}
.brand-sub{font-size:10px;letter-spacing:.22em;text-transform:uppercase;color:var(--muted)}
.nav-label{
  font-size:11px;letter-spacing:.22em;text-transform:uppercase;color:var(--muted);
  margin:16px 12px 8px
}
.nav-link{
  display:flex;align-items:center;justify-content:space-between;gap:10px;
  padding:12px 14px;border-radius:16px;margin-bottom:8px;
  color:#d9e1f0;border:1px solid transparent;
  transition:.18s ease
}
.nav-link:hover,.nav-link.active{
  background:rgba(255,255,255,.05);
  border-color:var(--border)
}
.nav-left{display:flex;align-items:center;gap:10px}
.nav-icon{
  width:30px;height:30px;border-radius:10px;display:grid;place-items:center;
  background:rgba(255,255,255,.05);border:1px solid rgba(255,255,255,.05);font-size:13px
}
.nav-tag{
  font-size:11px;padding:5px 8px;border-radius:999px;background:rgba(255,255,255,.05);color:var(--muted)
}
.sidebar-spacer{height:8px}
.sidebar-bottom{
  margin-top:18px;padding:16px;border-radius:20px;
  background:linear-gradient(180deg, rgba(245,188,67,.10), rgba(245,188,67,.03));
  border:1px solid rgba(245,188,67,.18)
}
.rank-row{display:flex;align-items:center;justify-content:space-between;gap:12px;margin-bottom:10px}
.rank-badge{
  width:42px;height:42px;border-radius:14px;display:grid;place-items:center;
  background:rgba(245,188,67,.14);border:1px solid rgba(245,188,67,.2);font-weight:800;color:var(--gold)
}
.progress{
  height:10px;border-radius:999px;background:rgba(255,255,255,.06);overflow:hidden
}
.progress > span{
  display:block;height:100%;width:68%;
  background:linear-gradient(90deg,var(--gold),var(--gold2))
}

/* MAIN */
.main{flex:1;min-width:0;padding:20px}

/* NEW COMPACT TOPBAR */
.topbar.compact{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  padding:10px 14px;
  margin-bottom:14px;
  background:rgba(14,18,27,.72);
  border:1px solid rgba(255,255,255,.08);
  border-radius:18px;
  backdrop-filter:blur(10px);
  box-shadow:0 18px 40px rgba(0,0,0,.22);
}
.topbar-left,.topbar-right{display:flex;align-items:center;gap:10px}
.title-wrap{display:flex;align-items:center}
.page-title{
  font-size:18px;
  font-weight:700;
  line-height:1.1;
  letter-spacing:.01em;
}
.icon-btn,.btn,.btn-soft,.btn-ghost{
  border:none;cursor:pointer;font:inherit;transition:.18s ease
}
.icon-btn{
  width:46px;height:46px;border-radius:16px;
  background:rgba(255,255,255,.05);color:white;border:1px solid var(--border)
}
.icon-btn.small{
  width:38px;
  height:38px;
  border-radius:12px;
  font-size:16px;
}
.icon-btn:hover,.btn-soft:hover,.btn-ghost:hover{background:rgba(255,255,255,.08)}
.btn{
  padding:10px 15px;border-radius:12px;
  background:linear-gradient(90deg,var(--gold),var(--gold2));
  color:#151515;font-weight:800;
  box-shadow:0 10px 24px rgba(245,188,67,.18)
}
.btn-soft{
  padding:10px 14px;border-radius:12px;
  background:rgba(255,255,255,.05);color:white;border:1px solid var(--border)
}
.btn-ghost{
  padding:10px 14px;border-radius:12px;
  background:transparent;color:#dce4f1;border:1px solid var(--border)
}
.account-pill{
  display:flex;align-items:center;gap:10px;
  padding:7px 10px;border-radius:999px;
  background:rgba(255,255,255,.05);border:1px solid var(--border)
}
.user-avatar{
  width:30px;height:30px;border-radius:10px;display:grid;place-items:center;
  background:linear-gradient(135deg, rgba(114,173,255,.18), rgba(162,134,255,.18));
  border:1px solid rgba(255,255,255,.08);font-weight:800;font-size:12px
}
.account-meta{line-height:1.05}
.account-name{font-size:12px;font-weight:700}
.account-role{font-size:10px;color:var(--muted)}

/* UTILITIES */
.card{
  background:var(--panel);
  border:1px solid var(--border);
  border-radius:24px;padding:20px;
  box-shadow:0 20px 60px rgba(0,0,0,.35)
}
.grid{display:grid;gap:18px}
.grid-2{grid-template-columns:repeat(2,minmax(0,1fr))}
.heading-lg{font-size:clamp(24px,4vw,34px);margin:0 0 10px}
.heading-md{font-size:20px;margin:0 0 10px}
.muted{color:var(--muted)}
.badge{
  display:inline-flex;align-items:center;padding:8px 12px;border-radius:999px;
  background:rgba(255,255,255,.05);border:1px solid var(--border);font-size:13px
}
.section{margin-top:20px}
.page-content{animation:fade .25s ease}
@keyframes fade{from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:translateY(0)}}

@media (max-width:860px){
  .sidebar{
    position:fixed;left:0;top:0;transform:translateX(-100%);
    height:100vh;z-index:40
  }
  .sidebar.open{transform:translateX(0)}
  .main{padding:14px}
  .topbar.compact{
    padding:8px 10px;
    border-radius:16px;
  }
  .topbar-right{
    gap:8px;
    flex-wrap:wrap;
    justify-content:flex-end;
  }
  .btn,.btn-soft,.btn-ghost{
    padding:9px 12px;
    font-size:13px;
  }
  .account-pill{
    padding:6px 9px;
  }
  .page-title{
    font-size:16px;
  }
  .grid-2{grid-template-columns:1fr}
}


/* ===== GAME UI - UNIFIED CLEAN VERSION ===== */

:root{
  --game-topbar-h: 74px;
  --enemy-h: 76px;
  --input-h: 96px;
  --hud-handle-gap: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --game-side-pad: 16px;
}

html, body{
  min-height: 100%;
}

body.game-page{
  overflow: hidden;
  background:
    radial-gradient(circle at bottom, rgba(255,180,60,0.08), transparent 60%),
    url('../img/bg.png') center / cover no-repeat fixed;
}

@media (max-width:768px){
  body.game-page{
    background:
      radial-gradient(circle at bottom, rgba(255,180,60,0.08), transparent 60%),
      url('../img/bg-mobile.png') center / cover no-repeat;
  }
}

#topbarMount{
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  padding: 14px 14px 0;
  pointer-events: none;
}
#topbarMount > *{
  pointer-events: auto;
}

.main{
  padding-top: calc(var(--game-topbar-h) + 12px);
}

.page-content{
  position: relative;
  min-height: calc(var(--vvh, 100dvh) - var(--game-topbar-h));
}

.game-shell{
  position: relative;
  min-height: calc(var(--vvh, 100dvh) - var(--game-topbar-h));
}

.enemy-card{
  position: fixed;
  top: calc(var(--game-topbar-h) + 6px);
  left: 14px;
  right: 14px;
  z-index: 95;
  padding: 14px 16px;
  border-radius: 22px;
  background: rgba(20,25,40,.66);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,.10);
  box-shadow: 0 14px 34px rgba(0,0,0,.22), 0 0 18px rgba(255,120,70,.10);
}

.enemy-name-row{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  margin-bottom: 10px;
}
.enemy-name{
  font-size: 20px;
  font-weight: 800;
  letter-spacing: .01em;
}
.enemy-hp-label{
  font-size: 12px;
  color: var(--muted);
}
.enemy-hp-bar{
  width: 100%;
  height: 14px;
  border-radius: 999px;
  background: rgba(255,255,255,.08);
  overflow: hidden;
}
.enemy-hp-fill{
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg,#ff4d4d,#ff9933);
  transition: width .25s ease;
}

.game-chat{
  position: fixed;
  top: calc(var(--game-topbar-h) + var(--enemy-h) + 18px);
  left: 14px;
  right: 14px;
  bottom: calc(var(--input-h) + var(--hud-handle-gap) + var(--safe-bottom));
  overflow-y: auto;
  padding: 4px 0 14px;
  display:flex;
  flex-direction:column;
  gap:12px;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.msg{
  padding:14px 16px;
  border-radius:20px;
  max-width: min(85%, 540px);
  backdrop-filter: blur(10px);
  border:1px solid rgba(255,255,255,.08);
  box-shadow: 0 12px 36px rgba(0,0,0,.14);
}
.msg.gm{
  align-self: flex-start;
  background: rgba(255,200,100,.14);
}
.msg.player{
  align-self:flex-end;
  background: rgba(100,150,255,.14);
}
.msg.system{
  align-self:center;
  background: rgba(14,18,27,.80);
  color: var(--muted);
  font-size: 12px;
}
.msg-head{
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:10px;
  font-size:12px;
  margin-bottom:6px;
}
.msg-body{
  line-height: 1.45;
}
.hp{
  opacity:.75;
  white-space: nowrap;
}

.toast{
  position:fixed;
  top: calc(var(--game-topbar-h) + 94px);
  left:50%;
  transform:translateX(-50%) translateY(-20px);
  background:rgba(20,25,40,.92);
  padding:12px 18px;
  border-radius:16px;
  color:#fff;
  opacity:0;
  transition:.24s ease;
  border:1px solid rgba(255,180,60,.28);
  box-shadow:0 0 20px rgba(255,180,60,.3);
  z-index:110;
}
.toast.show{
  opacity:1;
  transform:translateX(-50%) translateY(0);
}

.damage-pop{
  position:fixed;
  left:50%;
  top: calc(var(--game-topbar-h) + 114px);
  transform:translateX(-50%);
  font-weight:bold;
  font-size:20px;
  color:#ff4d4d;
  text-shadow:0 0 10px rgba(255,80,80,.8);
  animation:popUp .8s ease forwards;
  pointer-events:none;
  z-index:111;
}
@keyframes popUp{
  0%{opacity:1; transform:translate(-50%,0) scale(1);}
  100%{opacity:0; transform:translate(-50%,-40px) scale(1.2);}
}
.enemy-hit{
  animation:hitFlash .3s ease;
}
@keyframes hitFlash{
  0%{box-shadow:0 0 24px rgba(255,80,80,.85);}
  100%{box-shadow:0 0 0 rgba(255,80,80,0);}
}

.game-input-wrap{
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--safe-bottom) + 8px + var(--kb-offset, 0px));
  z-index: 105;
  display: flex;
  justify-content: center;
  padding: 0 12px;
}
.game-input-inner{
  width: 100%;
  max-width: 920px;
}
.game-input{
  display:flex;
  gap:10px;
  padding:10px;
  border-radius:24px;
  background:linear-gradient(180deg, rgba(255,200,100,0.15), rgba(0,0,0,0.75));
  backdrop-filter:blur(12px);
  border:1px solid rgba(255,200,100,0.25);
  box-shadow: 0 10px 40px rgba(0,0,0,0.5), 0 0 25px rgba(255,180,60,0.15);
}
.game-input input{
  flex:1;
  min-width:0;
  background:transparent;
  border:none;
  color:#fff;
  font-size:14px;
  outline:none;
}
.game-input input::placeholder{
  color:rgba(255,255,255,0.55);
}
.send-btn{
  border:none;
  border-radius:18px;
  padding:12px 22px;
  background:linear-gradient(180deg,#f5c94a,#f2a93b);
  color:#000;
  font-weight:700;
  box-shadow:0 0 20px rgba(255,180,60,0.4), inset 0 0 6px rgba(255,255,255,0.2);
}

.hud-handle{
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--input-h) - 18px + var(--safe-bottom) + var(--kb-offset, 0px));
  z-index: 104;
  display:flex;
  flex-direction:column;
  align-items:center;
  gap:4px;
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
}
.hud-bar{
  width:42px;
  height:5px;
  border-radius:999px;
  background:rgba(255,255,255,.25);
}
.hud-chevron{
  font-size:14px;
  color:rgba(255,255,255,.7);
  transition: transform .22s ease;
}
.hud-handle.open .hud-chevron{
  transform: rotate(180deg);
}

.hud-panel{
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--input-h) + 8px + var(--safe-bottom) + var(--kb-offset, 0px));
  z-index: 103;
  max-height: min(54vh, 420px);
  transform: translateY(calc(100% + 18px));
  transition: transform .28s ease;
  pointer-events: none;
}
.hud-panel.open{
  transform: translateY(0);
  pointer-events: auto;
}
.hud-panel-inner{
  margin: 0 14px;
  border-radius: 24px 24px 0 0;
  background: rgba(10,14,22,.96);
  border: 1px solid rgba(255,255,255,.08);
  backdrop-filter: blur(14px);
  box-shadow: 0 16px 40px rgba(0,0,0,.35);
  padding: 16px;
  overflow: hidden;
}
.hud-tabs{
  display:grid;
  grid-template-columns: repeat(4, minmax(0,1fr));
  gap:8px;
  margin-bottom: 14px;
}
.hud-tab{
  padding: 10px 8px;
  border-radius: 12px;
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(255,255,255,.08);
  color: #fff;
  cursor: pointer;
}
.hud-tab.active{
  background: rgba(245,188,67,.16);
  border-color: rgba(245,188,67,.22);
}
.hud-tab-panel{
  display: none;
}
.hud-tab-panel.active{
  display: block;
}
.hud-card{
  border-radius: 18px;
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(255,255,255,.06);
  padding: 14px;
}
.hud-title{
  font-size: 12px;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 12px;
}
.party-row{
  display:flex;
  justify-content:space-between;
  gap:12px;
  padding:10px 0;
  border-bottom:1px solid rgba(255,255,255,.06);
}
.party-row:last-child{border-bottom:none}
.chip-grid{
  display:flex;
  flex-wrap:wrap;
  gap:8px;
}
.hud-chip{
  display:inline-flex;
  padding:8px 12px;
  border-radius:999px;
  background:rgba(255,255,255,.04);
  border:1px solid rgba(255,255,255,.06);
}
.stats-grid{
  display:grid;
  grid-template-columns: repeat(3, minmax(0,1fr));
  gap:10px;
}
.stat-box{
  padding:12px;
  border-radius:14px;
  background:rgba(255,255,255,.03);
  border:1px solid rgba(255,255,255,.06);
  text-align:center;
}
.stat-box span{
  display:block;
  font-size:11px;
  color:var(--muted);
  margin-bottom:6px;
}
.log-list{
  display:flex;
  flex-direction:column;
  gap:8px;
  max-height: 220px;
  overflow:auto;
}
.log-entry{
  padding:10px 12px;
  border-radius:14px;
  background:rgba(255,255,255,.03);
  border:1px solid rgba(255,255,255,.06);
  font-size: 13px;
}

@media (max-width:860px){
  :root{
    --game-topbar-h: 74px;
    --enemy-h: 86px;
    --input-h: 96px;
    --hud-handle-gap: 58px;
  }

  .main{
    padding: 0;
    padding-top: calc(var(--game-topbar-h) + 8px);
  }

  #topbarMount{
    padding: 8px 10px 0;
  }

  .enemy-card{
    left: 10px;
    right: 10px;
    top: calc(var(--game-topbar-h) + 2px);
  }

  .game-chat{
    left: 10px;
    right: 10px;
    top: calc(var(--game-topbar-h) + var(--enemy-h) + 10px);
    bottom: calc(var(--input-h) + var(--hud-handle-gap) + var(--safe-bottom));
  }

  .msg{
    max-width: 82%;
  }

  .game-input-wrap{
    padding: 0 10px;
  }

  .send-btn{
    padding: 12px 18px;
  }

  .hud-panel-inner{
    margin: 0 10px;
  }

  .stats-grid{
    grid-template-columns: repeat(2, minmax(0,1fr));
  }
}


/* === SIDEBAR SYSTEM FINAL === */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  height: 100dvh;
  width: 300px;
  z-index: 9999;
  transform: translateX(-100%);
  transition: transform 0.3s ease;
  padding: 16px;
  background: linear-gradient(180deg,#0a0e16,#060a12);
  backdrop-filter: blur(20px);
}
.sidebar.open { transform: translateX(0); }

.sidebar-inner { display:flex; flex-direction:column; height:100%; }

.sidebar-item { padding:12px; display:block; border-radius:10px; }
.sidebar-item:hover { background:rgba(255,255,255,.05); }

#sidebarBackdrop {
  position:fixed;
  inset:0;
  background:rgba(0,0,0,.6);
  z-index:9998;
  opacity:0;
  pointer-events:none;
}
#sidebarBackdrop.show { opacity:1; pointer-events:auto; }
/* ===== SIDEBAR FINAL POLISH ===== */

.sidebar {
  background:
    radial-gradient(circle at top, rgba(255,180,60,0.15), transparent 40%),
    linear-gradient(180deg,#0a0e16,#060a12);
  border-right: 1px solid rgba(255,180,60,0.2);
  box-shadow:
    0 0 40px rgba(255,180,60,0.12),
    inset 0 0 40px rgba(255,180,60,0.05);
}

.sidebar::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 20% 10%, rgba(255,180,60,0.18), transparent 40%),
    radial-gradient(circle at 80% 60%, rgba(255,120,60,0.08), transparent 50%);
  pointer-events: none;
}

.sidebar::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  width: 2px;
  height: 100%;
  background: linear-gradient(
    180deg,
    transparent,
    rgba(255,180,60,0.6),
    transparent
  );
  box-shadow: 0 0 12px rgba(255,180,60,0.6);
}

.nav-link.active {
  background: rgba(255,180,60,0.12);
  border-color: rgba(255,180,60,0.3);
  box-shadow:
    0 0 12px rgba(255,180,60,0.25),
    inset 0 0 8px rgba(255,180,60,0.15);
}

.nav-link:hover {
  background: rgba(255,255,255,0.06);
  transform: translateX(4px);
}

.sidebar-bottom {
  background:
    linear-gradient(180deg, rgba(255,180,60,.18), rgba(255,180,60,.05));
  border: 1px solid rgba(255,180,60,.3);
  box-shadow:
    0 0 25px rgba(255,180,60,.15);
}

#sidebarBackdrop {
  transition: opacity .3s ease;
}

body.sidebar-active {
  overflow: hidden;
}

/* ICON FIX */
.nav-item{display:flex;align-items:center;gap:12px;}
.nav-item .icon{width:22px;display:inline-flex;justify-content:center;font-size:16px;opacity:.85;}