* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #000000;
  --panel: #16181c;
  --panel-hover: #1d1f23;
  --line: #2f3336;
  --text: #e7e9ea;
  --dim: #71767b;
  --blue: #1d9bf0;
  --blue-hover: #1a8cd8;
  --gold: #ffd400;
  --green: #00ba7c;
  --red: #f4212e;
  font-size: 15px;
}

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  height: 100dvh;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

#game { touch-action: none; user-select: none; -webkit-user-select: none; }

::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- top bar ---------- */

/* the header floats transparently over the game — no bar, no line;
   pointer-events pass through the empty middle so bubbles stay poppable */
#topbar {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 58px;
  padding: 0 20px;
  z-index: 6;
  pointer-events: none;
}
#topbar .brand, #topbar .account { pointer-events: auto; }

.brand { display: flex; align-items: center; gap: 10px; }

.brand-mark { display: block; flex-shrink: 0; filter: drop-shadow(0 0 10px rgba(127, 196, 235, 0.25)); }

.brand-name { font-weight: 800; font-size: 1.2rem; letter-spacing: -0.4px; }
.socials { display: inline-flex; align-items: center; gap: 2px; margin-left: 8px; }
.socials a {
  width: 28px; height: 28px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--dim); transition: color 0.15s, background 0.15s;
}
.socials a:hover { color: var(--text); background: rgba(255, 255, 255, 0.08); }
.socials svg { width: 15px; height: 15px; fill: currentColor; }

/* the pot is the hero of the stage, not a header widget */
.pot {
  position: absolute;
  top: 64px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center;
  line-height: 1.15;
  z-index: 3;
  pointer-events: none;
  text-align: center;
}
.pot-label {
  font-size: 0.62rem; color: var(--dim); font-weight: 700;
  text-transform: uppercase; letter-spacing: 2px;
  opacity: 0.85;
  margin-bottom: 3px;
}
.pot-row { display: flex; align-items: baseline; gap: 10px; }
.pot-eth {
  font-size: 2rem; font-weight: 800;
  font-variant-numeric: tabular-nums; letter-spacing: -0.8px;
}
.pot-usd { color: var(--dim); font-size: 0.95rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.pot.bump .pot-eth { animation: pot-bump 0.6s ease; }
@keyframes pot-bump { 30% { color: var(--green); transform: scale(1.05); } }

.account { display: flex; align-items: center; gap: 14px; }

.hud-online { color: var(--dim); font-size: 0.8rem; display: flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; font-weight: 600; flex-shrink: 0; }
.hud-online .eye { color: var(--dim); flex-shrink: 0; }

/* avatar opens a small account menu — keeps the header to two elements */
.avatar-menu-wrap { position: relative; }
.avatar-btn { background: none; border: none; padding: 0; cursor: pointer; display: block; border-radius: 50%; }
/* the header avatar: real X photos must be forced to a 32px circle, or they
   render at natural size (giant square). Fallback letter already sized below. */
.avatar-btn { width: 32px; height: 32px; }
.avatar-btn img, .avatar-btn .avatar-fallback {
  display: block;
  width: 32px; height: 32px;
  border-radius: 50%;
  object-fit: cover;
}
.menu {
  position: absolute; top: 44px; right: 0;
  min-width: 210px;
  background: #16181c;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 6px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.7);
  z-index: 10;
  animation: menu-in 0.14s ease;
}
@keyframes menu-in { from { opacity: 0; transform: translateY(-4px); } }
.menu-id { padding: 10px 12px; }
.menu-id strong { display: block; font-size: 0.92rem; }
.menu-wallet { color: var(--dim); font-size: 0.78rem; font-variant-numeric: tabular-nums; margin-top: 2px; display: block; }
.menu-item {
  display: block; width: 100%; text-align: left;
  background: none; border: none; color: var(--text);
  font-family: inherit; font-size: 0.88rem; font-weight: 700;
  padding: 10px 12px; border-radius: 11px; cursor: pointer;
}
.menu-item:hover { background: rgba(255, 255, 255, 0.07); }

.userchip { display: flex; align-items: center; gap: 10px; }
.userchip img, .avatar-fallback {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg, #1d3a52, #16181c);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 0.85rem; font-weight: 700; color: var(--blue);
  flex-shrink: 0; object-fit: cover;
}
.userchip .handle { font-weight: 700; font-size: 0.9rem; }
.userchip .wallet-short { color: var(--dim); font-size: 0.78rem; font-variant-numeric: tabular-nums; }

/* ---------- buttons ---------- */

.btn {
  border: none;
  border-radius: 9999px;
  height: 36px;
  padding: 0 18px;
  font-weight: 700;
  font-size: 0.9rem;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, transform 0.06s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }

.btn-sm { height: 30px; padding: 0 14px; font-size: 0.8rem; }

.btn-white { background: var(--text); color: #0f1419; }
.btn-white:hover { background: #d7dbdc; }

.btn-blue { background: var(--blue); color: #fff; }
.btn-blue:hover { background: var(--blue-hover); }

.btn-ghost {
  background: transparent; color: var(--text);
  box-shadow: inset 0 0 0 1px #536471;
}
.btn-ghost:hover { background: rgba(239, 243, 244, 0.1); }

.x-glyph { font-weight: 900; font-size: 1.05rem; line-height: 1; }

.icon-btn {
  background: none; border: none; color: var(--dim); cursor: pointer;
  font-size: 0.8rem; font-weight: 600; font-family: inherit; padding: 5px 8px;
  border-radius: 9999px;
}
.icon-btn:hover { color: var(--text); background: var(--panel); }

/* ---------- layout ---------- */

main { flex: 1; display: flex; min-height: 0; position: relative; }

#stage { position: relative; flex: 1; min-width: 0; }

#game { position: absolute; inset: 0; width: 100%; height: 100%; }

/* leaderboard floats over the game as translucent glass; toggle in the header */
#panel {
  position: absolute;
  top: 62px; right: 14px; bottom: 14px;
  width: 330px;
  display: flex; flex-direction: column; gap: 14px;
  overflow-y: auto;
  z-index: 4;
  transition: transform 0.25s cubic-bezier(0.3, 1, 0.4, 1), opacity 0.2s;
}
body.panel-hidden #panel {
  transform: translateX(24px);
  opacity: 0;
  pointer-events: none;
}

.panel-toggle {
  background: none;
  border: 1px solid var(--line);
  border-radius: 9999px;
  color: var(--dim);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 5px 13px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.panel-toggle:hover { color: var(--text); }
.panel-toggle.on { color: var(--blue); border-color: rgba(29, 155, 240, 0.45); }

.panel-card {
  background: rgba(18, 20, 24, 0.92);
  border: 1px solid rgba(47, 51, 54, 0.7);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-height: 100%;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px 10px;
}
.panel-head h3 { font-size: 1.1rem; font-weight: 800; letter-spacing: -0.3px; }
.panel-body { overflow-y: auto; min-height: 0; padding-bottom: 6px; }
.panel-how {
  background: none; border: none; border-top: 1px solid var(--line);
  color: var(--dim); font-family: inherit; font-size: 0.82rem; font-weight: 600;
  padding: 12px 16px; text-align: left; cursor: pointer; border-radius: 0 0 16px 16px;
}
.panel-how:hover { color: var(--text); background: rgba(255,255,255,0.04); }

.seg {
  display: flex;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 9999px;
  padding: 3px;
}
.seg-btn {
  border: none; background: none;
  color: var(--dim);
  font-family: inherit; font-size: 0.78rem; font-weight: 700;
  padding: 4px 14px; border-radius: 9999px;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}
.seg-btn.active { background: var(--text); color: #0f1419; }

.modal-sub { color: var(--dim); font-size: 0.88rem; line-height: 1.55; margin: -6px 0 16px; }
.modal-sub b { color: var(--text); }

#wallet-form { display: flex; gap: 8px; }
.modal #wallet-form .btn { width: auto; margin-top: 0; flex-shrink: 0; }
#wallet-input {
  flex: 1; min-width: 0;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 9999px;
  color: var(--text);
  padding: 0 15px;
  height: 36px;
  font-size: 0.85rem;
  font-family: inherit;
  font-variant-numeric: tabular-nums;
}
#wallet-input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 1px var(--blue); }
#wallet-input::placeholder { color: var(--dim); }

.field-error { color: var(--red); font-size: 0.8rem; margin-top: 8px; }

/* ---------- leaderboard ---------- */

.board { list-style: none; }
.board li {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  transition: background 0.1s;
}
.board li:hover { background: rgba(255, 255, 255, 0.04); }

.board li.is-me { background: rgba(29, 155, 240, 0.07); }
.board .rank {
  width: 20px; text-align: center;
  color: var(--dim); font-weight: 800; font-size: 0.85rem;
  font-variant-numeric: tabular-nums; flex-shrink: 0;
}
.board img, .board .avatar-fallback { width: 38px; height: 38px; border-radius: 50%; object-fit: cover; }
.board .who { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.board .who .handle { font-weight: 700; font-size: 0.92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
a.handle { color: inherit; text-decoration: none; }
a.handle:hover { color: var(--blue); text-decoration: underline; }
.board .who .sub { color: var(--dim); font-size: 0.78rem; }
.board .who .sub.won { color: var(--green); font-weight: 600; }
.board .pops { font-weight: 800; font-size: 0.95rem; font-variant-numeric: tabular-nums; flex-shrink: 0; }

/* ---------- wins feed ---------- */

.wins { list-style: none; }
.wins li {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 16px;
  font-size: 0.87rem; line-height: 1.35;
  transition: background 0.1s;
}
.wins li:hover { background: rgba(255, 255, 255, 0.04); }

.wins img, .wins .avatar-fallback { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; }
.wins .body { flex: 1; min-width: 0; }
.wins .amount { color: var(--green); font-weight: 700; }
.wins .pct { color: var(--dim); font-weight: 600; }
.wins .when { color: var(--dim); font-size: 0.76rem; flex-shrink: 0; }
.wins a { color: var(--blue); text-decoration: none; font-size: 0.78rem; }
.wins a:hover { text-decoration: underline; }
.wins .dry { color: var(--dim); font-size: 0.76rem; }

.empty { color: var(--dim); font-size: 0.85rem; padding: 14px 16px; }

/* ---------- HUD (bottom bar) ---------- */

#hud {
  position: absolute;
  bottom: 18px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 14px;
  height: 52px;
  padding: 0 18px 0 10px;
  border-radius: 9999px;
  background: rgba(18, 20, 24, 0.92);
  border: 1px solid rgba(47, 51, 54, 0.9);
  z-index: 4;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.55);
  white-space: nowrap;
  max-width: calc(100% - 32px);
}

#hud-user { display: flex; align-items: center; flex-shrink: 0; }

.hud-avatar-wrap { position: relative; width: 40px; height: 40px; }
.hud-avatar-wrap img, .hud-avatar-wrap .avatar-fallback {
  position: absolute; inset: 4px;
  width: 32px; height: 32px; border-radius: 50%;
  object-fit: cover;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #1d3a52, #16181c);
  color: var(--blue); font-weight: 700; font-size: 0.85rem;
}
.hud-ring { position: absolute; inset: 0; transform: rotate(-90deg); }
.hud-ring circle { fill: none; stroke-width: 2.5; }
.hud-ring .track { stroke: rgba(47, 51, 54, 0.8); }
.hud-ring .fill { stroke: var(--blue); stroke-linecap: round; transition: stroke 0.2s; }
.hud-ring.ready .fill { stroke: var(--green); }

#hud-body { display: flex; align-items: center; gap: 12px; min-width: 0; }
.hud-status { font-size: 0.87rem; font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; }
.hud-status .dim { color: var(--dim); font-weight: 500; }
.hud-status .green { color: var(--green); }
.hud-status .gold { color: var(--gold); }

.chip {
  font-size: 0.72rem; font-weight: 700;
  color: var(--dim);
  border: 1px solid var(--line);
  border-radius: 9999px;
  padding: 3px 10px;
  flex-shrink: 0;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.chip.dry { color: var(--gold); border-color: rgba(255, 212, 0, 0.35); }

.hud-link {
  background: none; border: none; color: var(--dim);
  font-size: 0.82rem; font-weight: 600; cursor: pointer; font-family: inherit;
  flex-shrink: 0; padding: 0;
}
.hud-link:hover { color: var(--text); }

/* ---------- toasts ---------- */

#toasts {
  position: absolute; bottom: 84px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; align-items: center; z-index: 4;
  pointer-events: none;
}
.toast {
  padding: 9px 17px; border-radius: 9999px;
  background: rgba(22, 24, 28, 0.95); border: 1px solid var(--line);
  font-size: 0.85rem; font-weight: 600;
  animation: toast-in 0.2s ease, toast-out 0.3s ease 3.4s forwards;
  max-width: 80vw;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}
.toast.warn { color: var(--gold); }
.toast.win { color: var(--text); border-color: rgba(29, 155, 240, 0.5); }

@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-6px); } }

/* ---------- modals ---------- */

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(91, 112, 131, 0.4);
  display: flex; align-items: center; justify-content: center; z-index: 20;
}
.modal {
  width: min(440px, 92vw);
  background: var(--bg); border-radius: 16px;
  padding: 30px 32px;
  box-shadow: 0 0 0 1px var(--line), 0 16px 48px rgba(0, 0, 0, 0.7);
  animation: modal-in 0.22s cubic-bezier(0.2, 1.4, 0.4, 1);
}
@keyframes modal-in { from { transform: scale(0.92); opacity: 0; } }
.modal h2 { margin-bottom: 16px; font-size: 1.3rem; font-weight: 800; letter-spacing: -0.3px; }
.how-list { padding-left: 20px; display: flex; flex-direction: column; gap: 11px; color: var(--dim); line-height: 1.55; font-size: 0.9rem; }
.how-list b { color: var(--text); }
.modal .btn { margin-top: 22px; width: 100%; }

.modal.win { text-align: center; }
.win-pct {
  display: inline-block;
  font-size: 0.82rem; font-weight: 800; color: var(--gold);
  border: 1px solid rgba(255, 212, 0, 0.4); border-radius: 9999px;
  padding: 4px 14px; margin-bottom: 14px;
  text-transform: uppercase; letter-spacing: 0.5px;
}
.win-amount { font-size: 2.3rem; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -0.5px; }
.win-sub { color: var(--dim); font-size: 0.9rem; margin-top: 6px; }
.win-tx { display: inline-block; color: var(--blue); font-size: 0.85rem; margin-top: 12px; text-decoration: none; }
.win-tx:hover { text-decoration: underline; }
.win-actions { display: flex; gap: 10px; margin-top: 24px; }
.win-actions .btn { flex: 1; margin-top: 0; }

.hidden { display: none !important; }

/* ---------- responsive ---------- */

@media (max-width: 900px) {
  #panel { width: min(330px, calc(100vw - 28px)); }
}

@media (max-width: 640px) {
  #topbar { padding: 0 12px; gap: 10px; height: 52px; }
  .brand-name { font-size: 1.05rem; }
  .pot-eth { font-size: 1.7rem; }
  .pot-usd { font-size: 0.85rem; }
  .pot { top: 58px; }
  #hud { gap: 9px; padding: 0 12px 0 7px; height: 46px; bottom: 12px; max-width: calc(100% - 20px); }
  .hud-status { font-size: 0.8rem; }
  /* declutter the mobile HUD: the "How it works" link moves to the leaderboard
     panel, the Preview chip and viewer count drop off — keeps avatar + status
     + Add wallet, which are what actually matter mid-game */
  #hud .hud-link, #hud .hud-online, #hud .chip { display: none; }
  .win-amount { font-size: 1.9rem; }
}
