:root {
  --gold: #d4af37;
  --gold-hi: #f1d06e;
  --panel: rgba(13, 18, 26, 0.82);
  --panel-border: rgba(212, 175, 55, 0.35);
  --text: #e8eef5;
  --muted: #8fa3b8;
  --hp: #e0453a;
  --xp: #e0a83a;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #0b0f14;
  font-family: 'Segoe UI', system-ui, -apple-system, Roboto, sans-serif;
  color: var(--text);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#app { position: fixed; inset: 0; }
#gl { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.hidden { display: none !important; }

/* ---------- screens ---------- */
.screen {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(1200px 700px at 50% -10%, rgba(48, 84, 120, 0.55), transparent 60%),
    radial-gradient(900px 600px at 80% 110%, rgba(212, 175, 55, 0.12), transparent 55%),
    linear-gradient(180deg, #0c1420 0%, #0b0f14 100%);
  z-index: 30;
}

.menuInner, .createInner { text-align: center; max-width: 520px; width: 92%; padding: 30px 0; }

.logo {
  font-size: clamp(34px, 8vw, 56px);
  font-weight: 900; letter-spacing: 2px;
  background: linear-gradient(180deg, #f7e6a8, var(--gold) 55%, #8a6d1f);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 4px 30px rgba(212, 175, 55, 0.25);
  margin-bottom: 6px;
}
.logoSub { color: var(--muted); font-size: 16px; letter-spacing: 6px; text-transform: uppercase; margin-bottom: 40px; }

.goldBtn {
  display: block; width: 100%; max-width: 340px; margin: 14px auto;
  padding: 16px 20px;
  font-size: 20px; font-weight: 700; letter-spacing: 1px;
  color: #17130a;
  background: linear-gradient(180deg, var(--gold-hi), var(--gold) 60%, #a8862a);
  border: none; border-radius: 14px;
  box-shadow: 0 6px 24px rgba(212, 175, 55, 0.35), inset 0 1px 0 rgba(255,255,255,0.5);
  cursor: pointer;
  transition: transform 0.08s, box-shadow 0.2s;
}
.goldBtn:active { transform: scale(0.97); }

.menuNote { color: var(--muted); margin-top: 26px; font-size: 15px; }
.menuNote.small { font-size: 12px; margin-top: 10px; opacity: 0.75; }

/* ---------- creation ---------- */
.createTitle { font-size: 26px; font-weight: 800; margin-bottom: 18px; color: var(--gold-hi); }
#nameInput {
  width: 100%; max-width: 340px;
  padding: 14px 16px; font-size: 17px;
  background: rgba(255,255,255,0.06); color: var(--text);
  border: 1px solid var(--panel-border); border-radius: 12px;
  outline: none; text-align: center;
}
#nameInput:focus { border-color: var(--gold); }
.createLabel { margin: 22px 0 10px; color: var(--muted); text-transform: uppercase; font-size: 12px; letter-spacing: 3px; }

#classCards { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.classCard {
  width: 150px; padding: 14px 10px;
  background: var(--panel); border: 2px solid rgba(255,255,255,0.08);
  border-radius: 14px; cursor: pointer; text-align: center;
  transition: border-color 0.15s, transform 0.1s;
}
.classCard .icon { font-size: 30px; }
.classCard .cname { font-weight: 700; margin: 6px 0 4px; }
.classCard .cdesc { font-size: 11.5px; color: var(--muted); line-height: 1.35; }
.classCard .cstat { font-size: 11px; margin-top: 6px; color: var(--gold-hi); }
.classCard.selected { border-color: var(--gold); transform: translateY(-3px); box-shadow: 0 8px 24px rgba(212,175,55,0.25); }

.swatchRow { display: flex; gap: 10px; justify-content: center; }
.swatch {
  width: 40px; height: 40px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.15);
  cursor: pointer; transition: transform 0.1s, border-color 0.15s;
}
.swatch.selected { border-color: var(--gold); transform: scale(1.15); }
.err { color: #ff6b5e; margin-top: 14px; min-height: 20px; font-size: 14px; }

/* ---------- HUD ---------- */
#hud { position: absolute; inset: 0; pointer-events: none; z-index: 10; }
#hud button, #hud input { pointer-events: auto; }

#topbar {
  position: absolute; top: calc(10px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 12px;
  background: var(--panel); border: 1px solid var(--panel-border);
  padding: 8px 14px; border-radius: 14px;
  backdrop-filter: blur(8px);
}
#levelBadge {
  width: 46px; height: 46px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(180deg, #2a3550, #1a2338);
  border: 1px solid var(--panel-border);
  font-weight: 900; font-size: 20px; color: var(--gold-hi);
}
#stats { display: flex; flex-direction: column; gap: 5px; }
.bar {
  position: relative; width: 190px; height: 15px;
  background: rgba(255,255,255,0.08);
  border-radius: 8px; overflow: hidden;
}
.bar .fill { position: absolute; inset: 0; width: 100%; border-radius: 8px; transition: width 0.2s; }
.bar.hp .fill { background: linear-gradient(90deg, #8e2f27, var(--hp)); }
.bar.xp .fill { background: linear-gradient(90deg, #9a6b1e, var(--xp)); width: 0%; }
.bar span {
  position: absolute; inset: 0; font-size: 10.5px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  text-shadow: 0 1px 2px rgba(0,0,0,0.8);
}
#killInfo { font-size: 12px; color: var(--gold-hi); }

#minimap {
  position: absolute; top: calc(12px + env(safe-area-inset-top)); right: 12px;
  border-radius: 50%;
  border: 2px solid var(--panel-border);
  background: rgba(8, 12, 18, 0.55);
  pointer-events: none;
}

#announces {
  position: absolute; top: 88px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  pointer-events: none;
}
.toast {
  background: var(--panel); border: 1px solid var(--panel-border);
  padding: 8px 18px; border-radius: 20px; font-size: 14px;
  animation: toastIn 0.25s ease-out;
  backdrop-filter: blur(6px);
}
@keyframes toastIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

#chatlog {
  position: absolute; left: 12px; bottom: 90px;
  max-width: min(320px, 70vw); max-height: 34vh;
  overflow: hidden; display: flex; flex-direction: column-reverse; gap: 4px;
  font-size: 13px; pointer-events: none;
}
.chatMsg { background: rgba(10, 14, 20, 0.55); padding: 4px 10px; border-radius: 10px; backdrop-filter: blur(4px); }
.chatMsg b { color: var(--gold-hi); }
.chatMsg.sys { color: var(--muted); font-style: italic; }

#chatWrap {
  position: absolute; left: 12px; bottom: 14px;
  display: flex; gap: 8px; align-items: center;
  pointer-events: auto;
}
#chatInput {
  width: min(280px, 62vw);
  padding: 10px 14px; font-size: 15px;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--panel-border); border-radius: 12px; outline: none;
}
#chatSend {
  width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--panel-border);
  background: var(--panel); color: var(--gold-hi); font-size: 17px; cursor: pointer;
}

.roundBtn {
  position: absolute; width: 58px; height: 58px; border-radius: 50%;
  border: 1px solid var(--panel-border);
  background: var(--panel); color: var(--text); font-size: 24px;
  backdrop-filter: blur(6px); cursor: pointer;
}
.roundBtn.big { width: 82px; height: 82px; font-size: 34px; }
#attackBtn { right: 18px; bottom: calc(20px + env(safe-area-inset-bottom)); background: radial-gradient(circle at 35% 30%, #6d2f2a, #3a1512 70%); border-color: rgba(255, 100, 90, 0.5); }
#chatBtn { right: 18px; bottom: calc(118px + env(safe-area-inset-bottom)); }

#joystickBase {
  position: absolute; width: 130px; height: 130px; border-radius: 50%;
  background: rgba(255,255,255,0.06); border: 2px solid rgba(255,255,255,0.15);
}
#joystickStick {
  position: absolute; width: 56px; height: 56px; border-radius: 50%;
  background: rgba(212, 175, 55, 0.55); border: 2px solid var(--gold);
  left: 50%; top: 50%; transform: translate(-50%, -50%);
}
#joystick { position: absolute; pointer-events: none; }

#vignette {
  position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(180, 30, 20, 0.0) 100%);
  transition: background 0.25s;
}
#vignette.hurt { background: radial-gradient(ellipse at center, transparent 40%, rgba(180, 30, 20, 0.45) 100%); }

#deathScreen {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px;
  background: radial-gradient(ellipse at center, rgba(60, 5, 5, 0.55), rgba(8, 5, 5, 0.85));
  z-index: 5;
}
.deathTitle { font-size: 34px; font-weight: 900; color: #ff6b5e; text-shadow: 0 2px 20px rgba(255, 60, 40, 0.5); }

#levelBanner {
  position: absolute; top: 34%; left: 50%; transform: translate(-50%, -50%);
  font-size: 40px; font-weight: 900; color: var(--gold-hi);
  text-shadow: 0 0 30px rgba(212, 175, 55, 0.8);
  z-index: 6; pointer-events: none;
  animation: banner 2.4s ease-out forwards;
}
@keyframes banner { 0% { opacity: 0; transform: translate(-50%, -30%) scale(0.7); } 18% { opacity: 1; transform: translate(-50%, -50%) scale(1.05); } 30% { transform: translate(-50%, -50%) scale(1); } 80% { opacity: 1; } 100% { opacity: 0; } }

#hintBar {
  position: absolute; bottom: calc(6px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  font-size: 11px; color: var(--muted); opacity: 0.7; white-space: nowrap;
}

#loading .spinner {
  width: 54px; height: 54px; margin: 0 auto 18px;
  border: 4px solid rgba(212,175,55,0.2);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loadingText { color: var(--muted); font-size: 15px; }

#errorBanner {
  position: absolute; top: 0; left: 0; right: 0; z-index: 100;
  background: #7d1f18; color: #ffd9d5; text-align: center;
  padding: 10px 16px; font-size: 13px;
}

@media (max-width: 520px) {
  .bar { width: 130px; }
  #minimap { width: 110px; height: 110px; }
}
