:root {
  color-scheme: dark;
  --gold: #ffd15c;
  --orange: #ff8f2e;
  --cyan: #42f5ff;
  --green: #6dff9f;
  --purple: #9d7cff;
  --pink: #ff66df;
  --danger: #ff4f66;
  --bg: #07101e;
  --panel: rgba(8, 16, 31, 0.78);
  --line: rgba(255, 255, 255, 0.14);
  font-family: Inter, ui-rounded, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; width: 100%; height: 100%; overflow: hidden; background: radial-gradient(circle at 50% 20%, #122547, #050914 64%); touch-action: manipulation; }
#game-canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; outline: none; }
#ui-overlay { position: fixed; inset: 0; color: white; text-shadow: 0 2px 14px rgba(0,0,0,.55); pointer-events: none; }
#ui-overlay button, .glass, dialog { pointer-events: auto; }

.glass {
  border: 1px solid var(--line);
  background: linear-gradient(145deg, rgba(10, 20, 38, .84), rgba(32, 15, 50, .72));
  box-shadow: 0 24px 90px rgba(0,0,0,.42), inset 0 1px 0 rgba(255,255,255,.12);
  backdrop-filter: blur(16px) saturate(130%);
}

button {
  border: 0; border-radius: 16px; padding: 11px 15px; margin: 0;
  color: #f8fbff; background: rgba(255,255,255,.12); font-weight: 900; font-size: 14px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.16), 0 9px 20px rgba(0,0,0,.22); cursor: pointer;
  transition: transform .16s ease, filter .16s ease, border-color .16s ease;
}
button:hover { transform: translateY(-1px); filter: brightness(1.08); }
button:active { transform: translateY(1px) scale(.99); }
button:disabled { opacity: .45; cursor: not-allowed; transform: none; }
button.primary { background: linear-gradient(135deg, var(--orange), var(--gold)); color: #281300; font-size: 16px; }
button.danger { background: linear-gradient(135deg, #ff4f66, #ffd15c); }

.ambient-ui { position: fixed; inset: 0; overflow: hidden; pointer-events: none; opacity: .55; }
.ambient-ui span { position: absolute; color: rgba(255,209,92,.45); font-size: clamp(28px, 7vw, 80px); filter: blur(.2px) drop-shadow(0 0 20px rgba(255,209,92,.35)); animation: floatCoin 8s infinite ease-in-out; }
.ambient-ui span:nth-child(1) { left: 8%; top: 16%; animation-delay: -1s; }
.ambient-ui span:nth-child(2) { left: 82%; top: 12%; animation-delay: -3s; color: rgba(66,245,255,.35); }
.ambient-ui span:nth-child(3) { left: 18%; top: 74%; animation-delay: -5s; }
.ambient-ui span:nth-child(4) { left: 74%; top: 78%; animation-delay: -2s; color: rgba(255,102,223,.35); }
.ambient-ui span:nth-child(5) { left: 48%; top: 8%; animation-delay: -6s; }

.screen { position: absolute; inset: 0; pointer-events: none; }
.home-screen { display: grid; place-items: center; padding: 22px; }
.brand-card { width: min(94vw, 780px); padding: clamp(24px, 5vw, 48px); border-radius: 32px; text-align: center; pointer-events: auto; }
.eyebrow { display: inline-flex; padding: 8px 12px; border-radius: 99px; background: rgba(66,245,255,.15); color: var(--cyan); font-weight: 900; letter-spacing: .04em; text-transform: uppercase; font-size: 12px; }
h1 { margin: 14px 0 12px; font-size: clamp(48px, 9vw, 92px); line-height: .86; letter-spacing: -.06em; }
h1 span { color: var(--gold); filter: drop-shadow(0 0 24px rgba(255,209,92,.45)); }
.brand-card p { max-width: 65ch; margin: 0 auto 22px; color: #dbe7ff; font-weight: 700; line-height: 1.55; }
.hero-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 18px 0; }
.hero-stats div, .stat, .metrics-grid div { border: 1px solid rgba(255,255,255,.12); border-radius: 18px; background: rgba(255,255,255,.08); padding: 10px 12px; }
small { display: block; color: #aebee7; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; font-weight: 900; }
strong { display: block; color: #fff; font-size: 20px; }
.cta-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; margin-top: 16px; }
.loading { display: inline-flex; gap: 10px; align-items: center; margin-top: 14px; color: #ffe7ad; font-weight: 900; }
.loading span { width: 12px; height: 12px; border-radius: 50%; background: var(--gold); box-shadow: 0 0 18px var(--gold); animation: pulse .8s infinite alternate; }

.game-screen { display: grid; grid-template-columns: minmax(260px, 360px) 1fr minmax(320px, 430px); grid-template-rows: auto 1fr; gap: 14px; padding: 14px; }
.topbar { grid-column: 1 / -1; display: flex; gap: 10px; align-items: stretch; border-radius: 24px; padding: 10px; }
.stat { min-width: 118px; }
.primary-stat strong { color: var(--gold); font-size: 26px; }
.top-actions { display: flex; gap: 8px; margin-left: auto; align-items: center; }
.left-panel { align-self: end; border-radius: 28px; padding: 18px; max-height: calc(100vh - 104px); overflow: auto; }
.room-title h2 { margin: 5px 0 8px; font-size: 30px; color: var(--gold); }
.xp-bar { height: 12px; border-radius: 99px; background: rgba(255,255,255,.12); overflow: hidden; border: 1px solid rgba(255,255,255,.12); }
.xp-bar i { display: block; height: 100%; width: 20%; border-radius: 99px; background: linear-gradient(90deg, var(--cyan), var(--gold)); box-shadow: 0 0 18px rgba(66,245,255,.4); transition: width .25s ease; }
#nextTier { color: #c8d7ff; font-weight: 800; margin: 8px 0 16px; }
.mine-button { width: 100%; min-height: 76px; font-size: clamp(22px, 4vw, 32px); border-radius: 24px; background: radial-gradient(circle at 30% 20%, #fff7ad, #ff9f1f 42%, #ff536d); color: #230d00; box-shadow: 0 0 40px rgba(255,143,46,.34), 0 16px 34px rgba(0,0,0,.28); }
.event-banner { margin: 14px 0; padding: 13px 14px; border-radius: 18px; border: 1px solid rgba(255,255,255,.12); background: rgba(66,245,255,.12); color: #e9f9ff; font-weight: 800; min-height: 72px; }
.event-banner.good { background: rgba(109,255,159,.14); }
.event-banner.bad { background: rgba(255,79,102,.18); }
.event-banner b { display: block; color: #fff; margin-bottom: 4px; }
.metrics-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.metrics-grid strong { font-size: 16px; }

.dashboard { grid-column: 3; align-self: end; border-radius: 28px; padding: 14px; max-height: calc(100vh - 104px); overflow: hidden; display: flex; flex-direction: column; }
.tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; margin-bottom: 12px; }
.tab { padding: 10px 8px; border-radius: 13px; font-size: 12px; }
.tab.active { background: linear-gradient(135deg, rgba(66,245,255,.32), rgba(255,209,92,.22)); color: white; outline: 1px solid rgba(66,245,255,.32); }
.tab-panel { display: none; min-height: 0; overflow: auto; padding-right: 4px; }
.tab-panel.active { display: block; }
.card-list { display: grid; gap: 10px; }
.card { border: 1px solid rgba(255,255,255,.12); border-radius: 18px; padding: 12px; background: rgba(255,255,255,.075); }
.card.locked { opacity: .55; filter: grayscale(.25); }
.card-head { display: flex; align-items: center; gap: 10px; }
.card-icon { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 13px; background: rgba(255,255,255,.12); font-size: 22px; }
.card h3 { margin: 0; font-size: 18px; }
.card p { margin: 4px 0 0; color: #cad7f5; font-size: 13px; font-weight: 700; line-height: 1.35; }
.card-meta { display: grid; grid-template-columns: repeat(2, 1fr); gap: 7px; margin: 10px 0; }
.card-meta span { padding: 7px 8px; border-radius: 11px; background: rgba(0,0,0,.18); color: #e8efff; font-size: 12px; font-weight: 900; }
.card-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.coin-card.selected { border-color: rgba(255,209,92,.65); box-shadow: 0 0 26px rgba(255,209,92,.13); }
.trend-up { color: var(--green); }
.trend-down { color: var(--danger); }
.progress { height: 9px; border-radius: 99px; background: rgba(255,255,255,.12); overflow: hidden; margin-top: 10px; }
.progress i { display: block; height: 100%; background: linear-gradient(90deg, var(--purple), var(--cyan)); }
.prestige-panel { color: #dbe7ff; }
.prestige-preview { margin: 14px 0; padding: 14px; border-radius: 18px; background: rgba(255,209,92,.12); color: #ffe9ad; font-weight: 900; }

.modal { position: fixed; inset: auto; width: min(92vw, 520px); border-radius: 26px; color: white; padding: 22px; }
.modal::backdrop { background: rgba(0,0,0,.55); backdrop-filter: blur(5px); }
.close { float: right; width: 38px; height: 38px; padding: 0; border-radius: 50%; }
.leaderboard-list { display: grid; gap: 8px; }
.leaderboard-row { display: grid; grid-template-columns: 48px 1fr auto; gap: 10px; align-items: center; padding: 10px; border-radius: 14px; background: rgba(255,255,255,.09); font-weight: 900; }
.leaderboard-row.you { color: var(--gold); outline: 1px solid rgba(255,209,92,.42); }
.muted { color: #bcc9e7; font-weight: 700; }
.toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); max-width: min(92vw, 620px); padding: 13px 18px; border-radius: 18px; background: rgba(10,20,38,.88); border: 1px solid rgba(255,209,92,.34); color: #fff0b8; font-weight: 900; pointer-events: none; box-shadow: 0 16px 36px rgba(0,0,0,.35); }

@keyframes pulse { from { transform: scale(.78); opacity: .55; } to { transform: scale(1.15); opacity: 1; } }
@keyframes floatCoin { 0%, 100% { transform: translateY(0) rotate(0deg); } 50% { transform: translateY(-30px) rotate(18deg); } }

@media (max-width: 980px) {
  .game-screen { grid-template-columns: 1fr; grid-template-rows: auto auto 1fr; overflow: auto; pointer-events: auto; }
  .topbar { position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
  .top-actions { margin-left: 0; }
  .left-panel, .dashboard { grid-column: 1; align-self: stretch; max-height: none; }
  .cta-grid { grid-template-columns: 1fr 1fr; }
  .hero-stats { grid-template-columns: 1fr; }
  .stat { min-width: 45%; flex: 1; }
}

@media (max-width: 560px) {
  .brand-card { padding: 22px 16px; }
  .cta-grid, .card-actions, .card-meta, .metrics-grid { grid-template-columns: 1fr; }
  .tabs { grid-template-columns: 1fr 1fr; }
  .topbar { gap: 7px; }
  .stat { min-width: calc(50% - 4px); padding: 8px; }
  strong { font-size: 17px; }
}
