:root {
  --neon: #44ddff;
  --neon2: #ff44aa;
  --gold: #ffcc44;
  --bg: #05060f;
  --panel: rgba(14, 16, 30, 0.82);
  --glass: rgba(20, 24, 44, 0.55);
  --win: #36e07a;
  --lose: #ff5566;
  --line: rgba(255, 255, 255, 0.12);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--bg);
  font-family: "Rajdhani", "Segoe UI", system-ui, sans-serif;
  color: #eef;
  user-select: none;
}
h1, h2, h3, .display { font-family: "Orbitron", sans-serif; }
#scene { display: block; width: 100vw; height: 100vh; cursor: default; }
#scene.grab { cursor: grab; }
#scene.grabbing { cursor: grabbing; }
.hidden { display: none !important; }
button { font-family: inherit; }

/* ============================ LOBBY ============================ */
#lobby {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center;
  background:
    radial-gradient(60% 60% at 50% 0%, rgba(255,68,170,0.18), transparent 70%),
    radial-gradient(70% 70% at 50% 100%, rgba(68,221,255,0.18), transparent 70%),
    rgba(3, 4, 10, 0.78);
  backdrop-filter: blur(6px);
}
.lobby-vignette { position: absolute; inset: 0; box-shadow: inset 0 0 220px rgba(0,0,0,0.9); pointer-events: none; }
.lobby-card {
  position: relative; width: min(440px, 92vw);
  padding: 30px 30px 24px;
  background: linear-gradient(180deg, rgba(24,26,48,0.92), rgba(12,14,28,0.92));
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: 0 30px 90px rgba(0,0,0,0.7), 0 0 0 1px rgba(255,255,255,0.04) inset,
              0 0 60px rgba(68,221,255,0.12);
  animation: rise .5s cubic-bezier(.2,.8,.2,1);
}
@keyframes rise { from { opacity: 0; transform: translateY(18px) scale(.98); } }

.brand { text-align: center; margin-bottom: 18px; }
.brand-mark {
  font-size: 40px; color: var(--gold);
  text-shadow: 0 0 24px rgba(255,204,68,0.8); line-height: 1;
  animation: pulse 2.4s ease-in-out infinite;
}
@keyframes pulse { 50% { transform: scale(1.12); text-shadow: 0 0 40px rgba(255,204,68,1); } }
.brand h1 {
  margin: 6px 0 2px; font-size: 38px; font-weight: 900; letter-spacing: 4px;
  background: linear-gradient(90deg, #fff, var(--neon));
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.brand h1 span {
  background: linear-gradient(90deg, var(--neon2), var(--gold));
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.brand .tag { margin: 0; font-size: 13px; letter-spacing: 2px; text-transform: uppercase; opacity: .6; }

.field-label { display: block; font-size: 12px; letter-spacing: 1.5px; text-transform: uppercase; opacity: .55; margin: 14px 0 6px; }
#name-input {
  width: 100%; background: #0c0f1e; border: 1px solid var(--line); color: #eef;
  border-radius: 12px; padding: 12px 14px; font-size: 16px; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
#name-input:focus { border-color: var(--neon); box-shadow: 0 0 0 3px rgba(68,221,255,0.15); }

.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch {
  width: 34px; height: 34px; border-radius: 10px; cursor: pointer; border: 2px solid transparent;
  transition: transform .1s, border-color .12s; box-shadow: 0 0 12px rgba(0,0,0,0.4);
}
.swatch:hover { transform: translateY(-2px) scale(1.05); }
.swatch.active { border-color: #fff; box-shadow: 0 0 16px currentColor; }

.lobby-stats { display: flex; gap: 12px; margin-top: 16px; }
.lobby-stats > div {
  flex: 1; background: #0c0f1e; border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 12px; display: flex; flex-direction: column; gap: 2px;
}
.ls-k { font-size: 11px; letter-spacing: 1px; text-transform: uppercase; opacity: .5; }
.ls-v { font-size: 20px; font-weight: 700; font-family: "Orbitron"; }
.ls-v.gold { color: var(--gold); }

.lobby-btn {
  width: 100%; margin-top: 12px; padding: 13px; font-size: 15px; font-weight: 700;
  letter-spacing: 1.5px; border-radius: 12px; cursor: pointer; transition: transform .08s, filter .15s;
}
.lobby-btn:hover { transform: translateY(-1px); filter: brightness(1.08); }
.lobby-btn.ghost { background: transparent; border: 1px solid var(--line); color: #cfe; }
.lobby-btn.ghost.connected { border-color: var(--win); color: var(--win); }
.lobby-btn.primary {
  border: none; color: #04121a; font-family: "Orbitron";
  background: linear-gradient(135deg, var(--neon), #6ad, var(--neon2));
  box-shadow: 0 8px 30px rgba(68,221,255,0.35);
}
.lobby-note { text-align: center; font-size: 12px; opacity: .5; margin: 12px 0 0; min-height: 16px; }
.lobby-foot { position: absolute; bottom: 16px; font-size: 11px; letter-spacing: 1px; opacity: .35; }

/* ============================ HUD ============================ */
#hud {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10;
  display: flex; justify-content: space-between; padding: 14px 18px; pointer-events: none;
}
.hud-left, .hud-right { display: flex; gap: 10px; align-items: center; pointer-events: auto; flex-wrap: wrap; }
.pill {
  background: var(--glass); border: 1px solid var(--line); backdrop-filter: blur(10px);
  border-radius: 999px; padding: 9px 16px; font-size: 15px; font-weight: 600;
  display: flex; align-items: center; gap: 7px;
  box-shadow: 0 4px 18px rgba(0,0,0,0.4); color: #eef;
}
.pill.identity .dot { width: 11px; height: 11px; border-radius: 50%; box-shadow: 0 0 10px currentColor; }
#balance-pill { color: var(--gold); border-color: rgba(255,204,68,0.35); font-family: "Orbitron"; }
.pill.networth { color: var(--neon); border-color: rgba(68,221,255,0.35); font-family: "Orbitron"; }
.pill.pool { color: var(--win); border-color: rgba(54,224,122,0.3); font-family: "Orbitron"; font-size: 13px; }
.sol-mark { color: var(--neon); font-weight: 800; }
.pill.dim { opacity: .75; font-size: 12px; font-weight: 500; }
#net-status.online { color: var(--win); border-color: rgba(54,224,122,0.4); opacity: 1; }
#net-status.offline { color: var(--lose); border-color: rgba(255,85,102,0.4); opacity: 1; }
.btn { cursor: pointer; transition: transform .08s, border-color .15s; }
.btn:hover { transform: translateY(-1px); border-color: var(--neon); }

#hint { position: fixed; bottom: 14px; left: 50%; transform: translateX(-50%); font-size: 13px; opacity: .5; z-index: 10; pointer-events: none; letter-spacing: .5px; }

/* tooltip */
#tooltip {
  position: fixed; z-index: 20; pointer-events: none;
  background: var(--panel); border: 1px solid var(--neon); border-radius: 10px;
  padding: 7px 12px; font-size: 14px; font-weight: 600;
  box-shadow: 0 0 22px rgba(68,221,255,0.45); white-space: nowrap;
  transform: translate(-50%, -150%);
}

/* win toast */
#toast {
  position: fixed; top: 80px; left: 50%; transform: translateX(-50%) translateY(-12px);
  z-index: 40; padding: 14px 26px; border-radius: 14px; font-family: "Orbitron"; font-size: 20px; font-weight: 800;
  background: linear-gradient(135deg, rgba(54,224,122,0.95), rgba(43,208,106,0.95));
  color: #04200f; box-shadow: 0 10px 40px rgba(54,224,122,0.5); opacity: 0; transition: opacity .25s, transform .25s;
}
#toast { pointer-events: none; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.lose { background: linear-gradient(135deg, rgba(255,85,102,0.95), rgba(200,50,70,0.95)); color: #2a0008; box-shadow: 0 10px 40px rgba(255,85,102,0.45); }

/* leaderboard */
#leaderboard {
  position: fixed; top: 70px; right: 18px; z-index: 25; width: 240px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 14px 16px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.5); backdrop-filter: blur(12px);
}
.lb-head { font-family: "Orbitron"; font-size: 14px; margin-bottom: 10px; letter-spacing: .5px; }
#lb-list { margin: 0; padding-left: 22px; font-size: 14px; }
#lb-list li { margin: 6px 0; display: flex; justify-content: space-between; gap: 8px; }
#lb-list .lb-net { color: var(--neon); font-family: "Orbitron"; font-size: 13px; }
#lb-list .me { color: var(--gold); font-weight: 700; }

/* ============================ CHAT ============================ */
#chat {
  position: fixed; bottom: 16px; left: 16px; z-index: 22; width: 320px;
  display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
#chat-log {
  display: flex; flex-direction: column; gap: 4px; max-height: 230px; overflow-y: auto;
  padding: 4px 2px; -webkit-mask-image: linear-gradient(to top, #000 80%, transparent);
}
#chat-log::-webkit-scrollbar { width: 0; }
.chat-msg {
  pointer-events: auto; align-self: flex-start; max-width: 100%;
  background: rgba(10,12,22,0.78); border: 1px solid var(--line); backdrop-filter: blur(6px);
  border-radius: 12px; padding: 6px 11px; font-size: 14px; line-height: 1.3; word-break: break-word;
}
.chat-msg .cn { font-weight: 700; margin-right: 6px; }
.chat-msg.sys { opacity: .65; font-style: italic; font-size: 13px; }
#chat-input {
  pointer-events: auto; width: 100%; background: rgba(10,12,22,0.85);
  border: 1px solid var(--line); color: #eef; border-radius: 12px; padding: 10px 13px;
  font-size: 14px; outline: none; transition: border-color .15s, box-shadow .15s;
}
#chat-input:focus { border-color: var(--neon); box-shadow: 0 0 0 3px rgba(68,221,255,0.15); }

/* ============================ MODAL ============================ */
#modal-root { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; }
#modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.6); backdrop-filter: blur(4px); }
#modal-window {
  position: relative; width: min(460px, 92vw); max-height: 88vh; overflow: hidden;
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px;
  box-shadow: 0 20px 70px rgba(0,0,0,0.7), 0 0 60px rgba(68,221,255,0.1);
  display: flex; flex-direction: column; animation: rise .25s ease;
}
#modal-head {
  display: flex; justify-content: space-between; align-items: center; padding: 15px 20px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(90deg, rgba(68,221,255,0.14), rgba(255,68,170,0.14));
}
#modal-title { font-family: "Orbitron"; font-weight: 700; font-size: 18px; letter-spacing: .5px; }
#modal-close { background: none; border: none; color: #eef; font-size: 20px; cursor: pointer; opacity: .7; }
#modal-close:hover { opacity: 1; }
#modal-body { padding: 20px; overflow-y: auto; }

/* game UI bits */
.row { display: flex; gap: 10px; align-items: center; margin: 10px 0; flex-wrap: wrap; }
.row label { font-size: 14px; opacity: .8; min-width: 56px; }
input[type="number"], input[type="text"] {
  background: #0c0f1e; border: 1px solid var(--line); color: #eef;
  border-radius: 10px; padding: 9px 11px; font-size: 15px; width: 120px; outline: none;
}
input:focus { border-color: var(--neon); }
.chip-btn, .opt {
  background: #161a2e; border: 1px solid var(--line); color: #eef;
  border-radius: 9px; padding: 9px 13px; cursor: pointer; font-size: 14px; font-weight: 600;
  transition: transform .08s, border-color .12s, background .12s;
}
.chip-btn:hover, .opt:hover { transform: translateY(-1px); }
.opt.active { border-color: var(--neon); background: rgba(68,221,255,0.2); box-shadow: 0 0 14px rgba(68,221,255,0.25); }
.play-btn {
  width: 100%; margin-top: 14px; padding: 15px; font-size: 17px; font-weight: 800; font-family: "Orbitron";
  letter-spacing: 1px; border: none; border-radius: 12px; cursor: pointer; color: #04200f;
  background: linear-gradient(135deg, var(--win), #2bd06a); box-shadow: 0 8px 26px rgba(54,224,122,0.35);
  transition: transform .08s, filter .15s;
}
.play-btn:hover { transform: translateY(-1px); filter: brightness(1.06); }
.play-btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.result { margin-top: 14px; text-align: center; font-size: 16px; min-height: 24px; font-weight: 700; font-family: "Orbitron"; }
.result.win { color: var(--win); text-shadow: 0 0 16px rgba(54,224,122,0.5); }
.result.lose { color: var(--lose); }

.reels { display: flex; gap: 12px; justify-content: center; margin: 18px 0; }
.reel {
  width: 82px; height: 82px; display: grid; place-items: center; font-size: 38px;
  background: radial-gradient(circle at 50% 30%, #1a1d33, #0a0c18);
  border: 2px solid var(--gold); border-radius: 14px; box-shadow: 0 0 20px rgba(255,204,68,0.25) inset;
}
.spin { animation: blur .25s linear infinite; }
@keyframes blur { 0% { filter: blur(3px); } 100% { filter: blur(0); } }
.roul-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin: 8px 0; }
.muted { font-size: 13px; opacity: .6; margin-top: 8px; line-height: 1.5; }
code { background: #0c0f1e; padding: 2px 6px; border-radius: 5px; font-size: 12px; word-break: break-all; }

/* ---- bet panel ---- */
.bet-panel { display: flex; flex-direction: column; }
.bp-head { display: flex; justify-content: space-between; align-items: center; font-size: 13px; margin-bottom: 6px; }
.bp-bal { color: var(--gold); font-weight: 700; font-family: "Orbitron"; font-size: 13px; }
.bp-lowbal { color: #ffd27a; font-size: 13px; line-height: 1.4; margin: 2px 0 6px; }
.bp-lowbal:empty { display: none; }
.bp-nonce { cursor: pointer; opacity: .55; text-decoration: underline dotted; font-size: 12px; margin-top: 12px; text-align: center; }
.bp-nonce:hover { opacity: .9; color: var(--neon); }
.bp-session { font-family: "Orbitron"; font-size: 13px; font-weight: 700; opacity: .8; }
.bp-session.up { color: var(--win); } .bp-session.down { color: var(--lose); }
.info-v { font-size: 17px; }
.visual-center { display: flex; justify-content: center; margin: 12px 0; }
.reel.coin { border-radius: 50%; width: 100px; height: 100px; font-size: 46px; }
.reel.wide { width: 132px; height: 80px; font-size: 32px; }
.opts { display: flex; gap: 8px; flex-wrap: wrap; }
.bp-amount input[type="number"] { width: 110px; }
.bp-chips { display: flex; gap: 6px; flex-wrap: wrap; }
input.tgt { width: 84px; }
.bp-info { display: flex; gap: 10px; margin: 10px 0 4px; }
.info-cell { flex: 1; background: #0c0f1e; border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; display: flex; flex-direction: column; gap: 2px; }
.info-k { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; opacity: .5; }
.info-v { font-size: 19px; font-weight: 700; font-family: "Orbitron"; }
.info-v.gold { color: var(--gold); }
.history { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 14px; min-height: 24px; }
.badge { font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 7px; font-family: "Orbitron"; }
.badge.win { background: rgba(54,224,122,0.18); color: var(--win); border: 1px solid rgba(54,224,122,0.4); }
.badge.lose { background: rgba(255,85,102,0.15); color: var(--lose); border: 1px solid rgba(255,85,102,0.35); }

/* ============================ NAMEPLATES (3D→DOM overlay) ============ */
/* One layer holding all avatar labels; each is positioned via transform each
   frame from the projected head position. Sits above the canvas but below HUD
   chrome, and never intercepts clicks. */
/* gentle cinematic vignette — darkens only the outer edges, below the UI layers */
#vignette {
  position: fixed; inset: 0; z-index: 2; pointer-events: none;
  background: radial-gradient(135% 112% at 50% 44%,
    transparent 58%, rgba(2,3,10,0.30) 82%, rgba(2,3,10,0.55) 100%);
}

#nameplates { position: fixed; inset: 0; z-index: 8; pointer-events: none; overflow: hidden; }
.nameplate {
  position: absolute; left: 0; top: 0; will-change: transform;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 14px 7px; border-radius: 11px; white-space: nowrap;
  background: rgba(6, 8, 16, 0.92);
  border: 2px solid var(--np, var(--neon));
  box-shadow: 0 3px 14px rgba(0, 0, 0, 0.7), 0 0 13px -3px var(--np, var(--neon));
}
/* little downward pointer so the label reads as attached to the avatar */
.nameplate::after {
  content: ""; position: absolute; left: 50%; bottom: -7px; transform: translateX(-50%);
  border-left: 7px solid transparent; border-right: 7px solid transparent;
  border-top: 8px solid var(--np, var(--neon));
}
.np-name { font-weight: 700; font-size: 22px; line-height: 1.05; color: #fff; letter-spacing: .3px; text-shadow: 0 1px 3px rgba(0,0,0,.8); }
.np-bal  { font-family: "Orbitron", sans-serif; font-weight: 700; font-size: 14px; line-height: 1; color: #9fe9ff; }

/* ============================ HUD EXTRAS ============================ */
.pool-lbl { text-transform: uppercase; font-size: 11px; letter-spacing: 1px; opacity: .6; }
.net-badge { font-family: "Orbitron"; font-weight: 800; font-size: 12px; letter-spacing: 1px; }
.net-badge.devnet  { color: #9fe9ff; border-color: rgba(68,221,255,0.5); background: rgba(68,221,255,0.10); }
.net-badge.mainnet { color: #ffd27a; border-color: rgba(255,170,40,0.6);  background: rgba(255,170,40,0.14); }
.warn {
  margin-top: 8px; font-size: 13px; line-height: 1.45; font-weight: 600;
  color: #ffd27a; background: rgba(255,170,40,0.12);
  border: 1px solid rgba(255,170,40,0.35); border-radius: 10px; padding: 8px 11px;
}
