/* ===== Top bar =========================================================== */
.topbar {
  position: sticky; top: 0; z-index: 60;
  height: var(--topbar-h);
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 16px;
  padding: 0 20px;
  background: #1c1f26;
  border-bottom: 1px solid rgba(0, 0, 0, 0.45);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.03), 0 8px 24px -12px rgba(0, 0, 0, 0.6);
}
.tb-left, .tb-right { display: flex; align-items: center; gap: 10px; min-width: 0; }
.tb-right { justify-content: flex-end; }
.tb-chat-toggle { display: none; }

.logo { display: inline-flex; align-items: center; gap: 10px; flex: none; }
.logo-mark { width: 36px; height: 36px; filter: drop-shadow(0 4px 12px rgba(255, 166, 0, 0.35)); }
.logo-text { font-weight: 800; font-size: 25px; letter-spacing: 0.01em; line-height: 1; font-style: normal; }
.logo-text b { color: #fff; font-weight: 800; }
.logo-text i { font-style: normal; color: var(--yellow); }
.topbar .logo { margin-right: 22px; }

.tb-games { gap: 10px; color: var(--muted); }
.tb-free { padding: 0 16px; }
.tb-badge {
  position: absolute; top: -6px; right: -6px; min-width: 20px; height: 20px; padding: 0 5px;
  border-radius: 99px; background: var(--red); color: #fff; font-size: 11px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center; box-shadow: 0 0 0 3px #1c1f26;
}
.tb-race { color: var(--muted); }

.balance {
  position: relative;
  display: flex; align-items: center; gap: 10px;
  height: 44px; padding: 0 7px 0 14px;
  background: #14161b; border: 1px solid rgba(255, 255, 255, 0.05); border-radius: 10px;
  font-weight: 700; font-size: 18px; font-variant-numeric: tabular-nums;
  transition: box-shadow 0.3s, border-color 0.3s;
}
.balance .coin { width: 20px; height: 20px; }
.bal-v { min-width: 56px; text-align: left; }
.bal-tag { background: #1f8f47; color: #e9ffef; font-size: 12px; font-weight: 700; padding: 5px 9px; border-radius: 7px; }
.balance:hover { border-color: rgba(255, 255, 255, 0.12); }
.balance.up { animation: balUp 0.8s; }
.balance.down { animation: balDown 0.8s; }
@keyframes balUp { 30% { box-shadow: 0 0 0 3px rgba(36, 198, 97, 0.45); color: var(--green-1); } }
@keyframes balDown { 30% { box-shadow: 0 0 0 3px rgba(255, 77, 94, 0.35); } }
.bal-float {
  position: absolute; left: 50%; top: 100%; transform: translateX(-50%);
  color: var(--green-1); font-size: 13px; font-weight: 700; pointer-events: none; white-space: nowrap;
  animation: balFloat 1.2s var(--ease) forwards;
}
@keyframes balFloat { from { opacity: 0; transform: translate(-50%, -6px); } 20% { opacity: 1; } to { opacity: 0; transform: translate(-50%, 14px); } }

.tb-get { padding: 0 18px; }
.user-chip {
  display: flex; align-items: center; gap: 10px; height: 44px; padding: 0 10px 0 5px;
  background: var(--bg-4); border: 1px solid var(--line); border-radius: 10px; color: var(--muted);
  transition: background 0.15s;
}
.user-chip:hover { background: var(--bg-5); }
.uc-av { position: relative; display: block; }
.uc-av .avatar { width: 34px; height: 34px; border-radius: 9px; }
.uc-text { display: flex; flex-direction: column; align-items: flex-start; gap: 3px; min-width: 0; }
.uc-name { color: #fff; font-size: 13px; max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.uc-lvl { display: flex; align-items: center; gap: 6px; }
.uc-lvl .lvl { height: 16px; min-width: 20px; font-size: 10px; }
.uc-xp { width: 56px; height: 4px; border-radius: 4px; background: rgba(255, 255, 255, 0.1); overflow: hidden; }
.uc-xp i { display: block; height: 100%; background: linear-gradient(90deg, var(--yellow), #ffe58a); border-radius: 4px; }

/* ===== Shell ============================================================= */
.shell { display: flex; align-items: flex-start; }
.main { flex: 1; min-width: 0; min-height: calc(100vh - var(--topbar-h)); display: flex; flex-direction: column;
  background:
    radial-gradient(1200px 500px at 50% -120px, rgba(36, 198, 97, 0.05), transparent 70%),
    var(--bg-2);
}
.page { width: 100%; max-width: 1240px; margin: 0 auto; padding: 26px 24px 56px; flex: 1; animation: fadeUp 0.25s var(--ease); }

/* ===== Sidebar / chat ==================================================== */
.sidebar {
  position: sticky; top: var(--topbar-h); z-index: 40;
  width: var(--sidebar-w); height: calc(100vh - var(--topbar-h)); flex: none;
  display: flex; flex-direction: column;
  background: var(--bg-1); border-right: 1px solid rgba(0, 0, 0, 0.35);
}
body.chat-closed .sidebar { display: none; }

.rain {
  position: relative; margin: 10px 10px 4px; padding: 12px 12px 12px;
  border: 1.5px dashed rgba(255, 198, 26, 0.55); border-radius: 10px; text-align: center;
  background:
    radial-gradient(120px 60px at 15% 0%, rgba(255, 198, 26, 0.13), transparent),
    radial-gradient(120px 60px at 85% 100%, rgba(255, 198, 26, 0.08), transparent),
    rgba(255, 198, 26, 0.03);
}
.rain.open { border-color: var(--yellow); animation: glowPulse 2.4s infinite; }
.rain-top { display: flex; align-items: center; justify-content: center; gap: 8px; }
.rain-ic { width: 22px; height: 22px; color: var(--yellow); }
.rain-pot .amt { font-size: 24px; font-weight: 600; color: #fff; }
.rain-pot .coin { width: 20px; height: 20px; }
.rain-title { margin-top: 4px; color: var(--yellow); font-weight: 700; font-size: 14px; }
.rain-sub { color: var(--text-2); font-size: 12px; margin-top: 2px; }
.rain-actions { display: flex; justify-content: center; gap: 8px; margin-top: 10px; }
.rain-join { min-width: 96px; }

.chat-list { flex: 1; overflow-y: auto; padding: 6px 0 10px; overscroll-behavior: contain; }
.msg { display: flex; gap: 10px; padding: 7px 12px; animation: fadeUp 0.25s var(--ease); }
.msg-you { background: rgba(255, 198, 26, 0.04); }
.msg-body { min-width: 0; flex: 1; }
.msg-head { display: flex; align-items: center; gap: 6px; line-height: 1.2; }
.msg-head b { font-size: 13.5px; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 128px; }
.msg-you .msg-head b { color: var(--yellow); }
.msg-head time { margin-left: auto; font-size: 10.5px; color: var(--muted-2); }
.msg-text { color: var(--muted); font-size: 13.5px; margin-top: 3px; word-wrap: break-word; overflow-wrap: anywhere; }
.msg-sys { padding: 6px 10px; }
.sys-drop, .sys-rain, .sys-level {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 9px;
  background: linear-gradient(90deg, color-mix(in srgb, var(--rc, #ffc61a) 16%, transparent), rgba(255, 255, 255, 0.02));
  border-left: 3px solid var(--rc, var(--yellow)); font-size: 12.5px; color: var(--text-2);
}
.sys-drop img { width: 48px; height: 36px; object-fit: contain; flex: none; filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.5)); }
.sys-drop b, .sys-level b { color: #fff; }
.sd-item { color: var(--rc); font-weight: 600; }
.sd-meta { display: flex; gap: 4px; align-items: center; color: var(--muted); font-size: 11.5px; margin-top: 2px; }
.sys-rain { --rc: #4c8dff; }
.sys-rain .ic, .sys-level .ic { color: var(--rc); width: 22px; height: 22px; }
.sys-level { --rc: #ffc61a; }

.chat-new {
  position: relative; align-self: center; margin-top: -40px; margin-bottom: 8px; z-index: 2;
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 99px;
  background: var(--yellow); color: #231800; font-size: 12px; font-weight: 700; box-shadow: var(--shadow);
}
.chat-form { display: flex; align-items: center; gap: 6px; margin: 0 10px 8px; padding: 6px 6px 6px 12px; background: var(--bg-0); border: 1px solid var(--line); border-radius: 10px; }
.chat-form:focus-within { border-color: rgba(255, 198, 26, 0.4); }
.chat-input { flex: 1; min-width: 0; background: none; border: 0; outline: none; color: #fff; font-size: 13px; height: 28px; }
.chat-input::placeholder { color: var(--muted-2); }
.chat-emoji, .chat-send { width: 30px; height: 30px; border-radius: 7px; display: grid; place-items: center; color: var(--muted); background: var(--bg-4); }
.chat-emoji:hover, .chat-send:hover { color: #fff; background: var(--bg-5); }
.chat-send { color: var(--yellow); }
.emoji-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; padding: 4px; }
.emoji-grid button { font-size: 18px; height: 30px; border-radius: 6px; }
.emoji-grid button:hover { background: var(--bg-5); }

.side-foot { display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.sf-btn { width: 30px; height: 30px; border-radius: 7px; display: grid; place-items: center; background: var(--bg-4); color: var(--muted); }
.sf-btn:hover { color: #fff; }
.sf-btn .ic { width: 16px; height: 16px; }
.sf-lang { display: inline-flex; align-items: center; gap: 6px; padding: 0 8px; height: 30px; border-radius: 7px; background: var(--bg-4); font-weight: 600; }
.flag-us { width: 16px; height: 11px; border-radius: 2px; background:
  linear-gradient(#3c3b6e, #3c3b6e) 0 0 / 7px 6px no-repeat,
  repeating-linear-gradient(#b22234 0 1.6px, #fff 1.6px 3.2px); }
.sf-online { display: inline-flex; align-items: center; gap: 5px; margin-left: auto; font-weight: 600; color: var(--text-2); }
.sf-online i { width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 3px rgba(36, 198, 97, 0.18); animation: pulse 2s infinite; }

.chat-reopen, .help-bubble {
  position: fixed; z-index: 55; display: grid; place-items: center; border-radius: 50%;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.45); transition: transform 0.15s;
}
.chat-reopen { left: 16px; bottom: 16px; width: 46px; height: 46px; background: var(--bg-4); color: var(--text-2); border: 1px solid var(--line-2); display: none; }
body.chat-closed .chat-reopen { display: grid; }
.help-bubble { right: 18px; bottom: 18px; width: 54px; height: 54px; background: linear-gradient(180deg, #ffd44a, #f5a800); color: #2a1c00; }
.help-bubble .ic { width: 24px; height: 24px; }
.chat-reopen:hover, .help-bubble:hover { transform: translateY(-2px); }

/* ===== Footer ============================================================ */
.footer { border-top: 1px solid var(--line); background: #17191f; padding: 34px 24px 20px; color: var(--muted); }
.footer-top { max-width: 1192px; margin: 0 auto; display: grid; grid-template-columns: 2fr 1fr 1fr 1fr; gap: 28px; }
.f-brand p { margin-top: 12px; font-size: 13px; max-width: 360px; line-height: 1.6; }
.f-brand .logo-text { font-size: 21px; }
.f-brand .logo-mark { width: 30px; height: 30px; }
.f-col { display: flex; flex-direction: column; gap: 8px; font-size: 13px; }
.f-col h4 { color: #fff; font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 4px; }
.f-col a:hover { color: #fff; }
.footer-bottom { max-width: 1192px; margin: 26px auto 0; padding-top: 16px; border-top: 1px solid var(--line); display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted-2); }

/* ===== Responsive ======================================================== */
@media (max-width: 1360px) {
  .tb-free span:not(.tb-badge) { display: none; }
  .tb-free { width: 40px; padding: 0; }
}
@media (max-width: 1100px) {
  .tb-chat-toggle { display: inline-flex; }
  .sidebar {
    position: fixed; left: 0; top: var(--topbar-h); z-index: 70;
    transform: translateX(-102%); transition: transform 0.25s var(--ease);
    box-shadow: 20px 0 40px rgba(0, 0, 0, 0.5);
  }
  body.chat-closed .sidebar { display: flex; }
  body.chat-drawer .sidebar { transform: none; }
  body.chat-closed .chat-reopen, .chat-reopen { display: none; }
  .sf-close { display: none; }
  .tb-games { display: none; }
  .topbar .logo { margin-right: 6px; }
}
@media (max-width: 860px) {
  .footer-top { grid-template-columns: 1fr 1fr; }
  .f-brand { grid-column: 1 / -1; }
  .tb-get span, .tb-race { display: none; }
  .tb-get { width: 40px; padding: 0; }
  .uc-text { display: none; }
  .logo-text { display: none; }
}
@media (max-width: 560px) {
  :root { --topbar-h: 62px; }
  .topbar { padding: 0 10px; gap: 8px; grid-template-columns: auto 1fr auto; }
  .tb-center { display: flex; justify-content: center; }
  .balance { height: 40px; font-size: 15px; padding: 0 5px 0 10px; gap: 7px; }
  .bal-tag { display: none; }
  .tb-free { display: none; }
  .tb-get { display: none; }
  .user-chip .ic-sm { display: none; }
  .user-chip { padding: 0 5px; }
  .page { padding: 18px 14px 48px; }
  .help-bubble { width: 46px; height: 46px; right: 12px; bottom: 12px; }
}

/* ===== Mobile bottom navigation ========================================== */
.mobile-nav { display: none; }
@media (max-width: 860px) {
  body { padding-bottom: calc(62px + env(safe-area-inset-bottom)); }
  .mobile-nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 58;
    display: grid; grid-template-columns: repeat(5, 1fr);
    height: calc(62px + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
    background: rgba(28, 31, 38, 0.96); backdrop-filter: blur(8px);
    border-top: 1px solid var(--line-2);
  }
  .mobile-nav a, .mobile-nav button {
    position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    color: var(--muted); font-size: 11px; font-weight: 600;
  }
  .mobile-nav .ic { width: 21px; height: 21px; }
  .mobile-nav .active { color: var(--yellow); }
  .mobile-nav .mn-badge { top: 6px; right: calc(50% - 22px); box-shadow: 0 0 0 2px #1c1f26; }
  .help-bubble { bottom: calc(74px + env(safe-area-inset-bottom)); }
  .toasts { top: auto; bottom: calc(76px + env(safe-area-inset-bottom)); left: 12px; right: 12px; align-items: stretch; }
  .toast { max-width: none; }
  .promo { min-height: 262px; }
  .promo-slide, .promo-dots { width: 86%; }
  .ps-sub { max-width: 72%; }
  .promo-slide .btn { flex-shrink: 0; }
}
