:root {
  --bg: #0b0d10;
  --bg2: #12151a;
  --card: #161a21;
  --card2: #1d222b;
  --line: #262c37;
  --text: #eef1f5;
  --muted: #8a93a3;
  --gold: #f5c542;
  --gold2: #ffdf7e;
  --green: #3ddc84;
  --red: #ff5d5d;
  --blue: #4da3ff;
  --purple: #b47bff;
  --t-common: #9aa3b2;
  --t-uncommon: #3ddc84;
  --t-rare: #4da3ff;
  --t-epic: #b47bff;
  --t-legendary: #f5c542;
  --radius: 14px;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: radial-gradient(1200px 600px at 70% -10%, #2a2410 0%, transparent 60%), var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
code { font-family: var(--mono); font-size: .9em; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--red); min-height: 1.2em; margin: 8px 0 0; font-size: 14px; }
.grow { flex: 1; }
.row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

.banner { background: #3a2d05; color: var(--gold2); text-align: center; font-size: 13px; padding: 7px 16px; border-bottom: 1px solid #5a470d; }

/* ---------- buttons / inputs ---------- */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--card2); color: var(--text);
  padding: 10px 16px; border-radius: 10px; font: 600 14px Inter, sans-serif; cursor: pointer;
  transition: transform .08s, background .15s, border-color .15s;
}
.btn:hover { border-color: #3a4250; background: #232935; }
.btn:active { transform: scale(.97); }
.btn.primary { background: linear-gradient(180deg, var(--gold2), var(--gold)); color: #1a1405; border: 0; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.ghost { background: transparent; }
.btn.big { padding: 14px 24px; font-size: 16px; }
input {
  width: 100%; background: var(--bg2); border: 1px solid var(--line); color: var(--text);
  padding: 11px 12px; border-radius: 10px; font: 15px Inter, sans-serif; outline: none;
}
input:focus { border-color: var(--gold); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }

.tabs { display: flex; gap: 6px; background: var(--bg2); padding: 4px; border-radius: 11px; }
.tab { flex: 1; background: transparent; border: 0; color: var(--muted); padding: 9px 12px; border-radius: 8px; font: 600 14px Inter, sans-serif; cursor: pointer; white-space: nowrap; }
.tab.active { background: var(--card2); color: var(--text); }

/* ---------- brand ---------- */
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 900; font-size: 20px; letter-spacing: -.02em; }
/* the logo mark is an image; the "$" in the markup stays as a text fallback for screen readers */
.brand .logo { display: inline-block; width: 32px; height: 32px; border-radius: 22%; background: url(/brand/favicon.svg?v=2) center / cover no-repeat; color: transparent; font-size: 0; flex-shrink: 0; box-shadow: 0 0 14px rgba(245,197,66,.25); }
.brand.big { font-size: 44px; }
.brand.big .logo { width: 56px; height: 56px; font-size: 32px; border-radius: 14px; }

/* ---------- auth ---------- */
.auth-card { text-align: left; }
.form { display: grid; gap: 14px; margin-top: 16px; }
.form label { display: grid; gap: 6px; font-size: 13px; font-weight: 600; color: #c3cad6; }

/* ---------- topbar ---------- */
.topbar { display: flex; align-items: center; gap: 24px; padding: 14px 24px; border-bottom: 1px solid var(--line); background: rgba(11,13,16,.8); backdrop-filter: blur(8px); position: sticky; top: 0; z-index: 20; }
.topbar nav { display: flex; gap: 4px; flex: 1; }
.topbar nav a { padding: 8px 12px; border-radius: 8px; color: var(--muted); font-weight: 600; font-size: 14px; }
.topbar nav a.active, .topbar nav a:hover { color: var(--text); background: var(--card); }
.me-chip { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 14px; }
.me-chip button { font-size: 12px; padding: 6px 10px; }

.avatar { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; background: var(--card2); flex-shrink: 0; border: 2px solid var(--line); }
.avatar.sm { width: 28px; height: 28px; border-width: 1px; }
.avatar.lg { width: 96px; height: 96px; border-width: 3px; }
.avatar.xl { width: 120px; height: 120px; border-width: 4px; }

/* ---------- home ---------- */
.view { animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }
.home-grid { max-width: 1100px; margin: 0 auto; padding: 22px 24px 28px; display: grid; grid-template-columns: 1fr 300px; gap: 20px; align-items: start; }
.me-head { display: flex; gap: 14px; align-items: center; }
.me-head h3 { margin: 0; font-size: 20px; }
.rank { font-size: 12px; color: var(--gold); font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat { background: var(--bg2); border-radius: 10px; padding: 10px 12px; }
.stat .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 700; }
.stat .v { font-size: 20px; font-weight: 800; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat .v.gold { color: var(--gold); }
.streak-pill { display: inline-flex; align-items: center; gap: 6px; background: linear-gradient(90deg, #ff6a00, #ee0979); color: white; font-weight: 800; font-size: 13px; padding: 5px 10px; border-radius: 999px; }
.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.mode-card { display: flex; gap: 14px; align-items: flex-start; text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; color: var(--text); font: inherit; cursor: pointer; transition: transform .12s, border-color .15s; }
button.mode-card:hover { transform: translateY(-2px); border-color: var(--gold); }
.mode-card h3 { margin: 0 0 4px; font-size: 18px; }
.mode-card p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.4; }
.mode-icon { font-size: 30px; line-height: 1; }
.mode-quick { background: linear-gradient(135deg, #2a2410, var(--card) 60%); border-color: #4a3d12; }
.room-row { display: flex; gap: 8px; margin-top: 12px; }
.room-row input { width: 90px; text-transform: uppercase; font-family: var(--mono); letter-spacing: .15em; text-align: center; padding: 8px; }
.room-row .btn { padding: 8px 12px; }
.tips h4 { margin: 0 0 8px; }
.tips ul { margin: 0; padding-left: 18px; color: var(--muted); font-size: 14px; line-height: 1.7; }

/* ---------- pages ---------- */
.page { max-width: 900px; margin: 0 auto; padding: 28px 24px 60px; }
.page h2 { font-size: 28px; margin: 0 0 16px; letter-spacing: -.02em; }
.lb-tabs { margin-bottom: 8px; overflow-x: auto; }
table.lb { width: 100%; border-collapse: collapse; }
table.lb td { padding: 10px 8px; border-bottom: 1px solid var(--line); }
table.lb tr:last-child td { border-bottom: 0; }
table.lb tr.me td { background: rgba(245,197,66,.07); }
table.lb .pos { width: 40px; font-weight: 800; color: var(--muted); text-align: center; font-variant-numeric: tabular-nums; }
table.lb tr:nth-child(1) .pos { color: var(--gold); }
table.lb tr:nth-child(2) .pos { color: #cfd6e0; }
table.lb tr:nth-child(3) .pos { color: #d08c5a; }
table.lb .who { display: flex; align-items: center; gap: 10px; font-weight: 600; cursor: pointer; }
table.lb .val { text-align: right; font-weight: 800; font-variant-numeric: tabular-nums; font-family: var(--mono); }
table.lb .sub { text-align: right; color: var(--muted); font-size: 13px; width: 120px; }
.empty { color: var(--muted); text-align: center; padding: 30px; }

.profile-head { display: flex; gap: 22px; align-items: center; margin-bottom: 20px; }
.profile-head h2 { margin: 0; }
.avatar-edit { position: relative; cursor: pointer; }
.avatar-edit::after { content: '📷'; position: absolute; right: 0; bottom: 0; background: var(--card2); border: 1px solid var(--line); border-radius: 50%; width: 32px; height: 32px; display: grid; place-items: center; font-size: 15px; }
.stats.wide { grid-template-columns: repeat(4, 1fr); margin-bottom: 20px; }
.history { display: grid; gap: 8px; }
.hist { display: grid; grid-template-columns: 70px 1fr auto; gap: 12px; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.badge { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; padding: 4px 8px; border-radius: 6px; text-align: center; }
.badge.win { background: rgba(61,220,132,.15); color: var(--green); }
.badge.loss { background: rgba(255,93,93,.15); color: var(--red); }
.badge.draw, .badge.solo, .badge.bot { background: var(--card2); color: var(--muted); }
.hist .items { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hist .money { font-family: var(--mono); font-weight: 700; text-align: right; }

/* ---------- game ---------- */
.cam { position: relative; aspect-ratio: 16 / 9; max-height: calc(100vh - 150px); max-height: calc(100dvh - 150px); width: 100%; background: #000; border-radius: 18px; overflow: hidden; border: 1px solid var(--line); }
.timer { position: relative; width: 74px; height: 74px; background: rgba(0,0,0,.55); border-radius: 50%; backdrop-filter: blur(6px); }
.timer svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.timer circle { fill: none; stroke-width: 3.5; }
.timer .track { stroke: rgba(255,255,255,.12); }
.timer .bar { stroke: var(--gold); stroke-linecap: round; stroke-dasharray: 119.4; transition: stroke .3s; }
.timer.low .bar { stroke: var(--red); }
.timer span { position: absolute; inset: 0; display: grid; place-items: center; font: 800 24px var(--mono); }
.timer.low span { color: var(--red); animation: pulse .5s infinite alternate; }
@keyframes pulse { to { transform: scale(1.12); } }
@keyframes bump { 40% { transform: scale(1.15); color: #fff; } }
.scanline { position: absolute; left: 0; right: 0; height: 3px; background: linear-gradient(90deg, transparent, var(--gold), transparent); box-shadow: 0 0 20px var(--gold); animation: scan 1.2s linear infinite; opacity: .8; }
@keyframes scan { from { top: 0; } to { top: 100%; } }

.pop-layer { position: absolute; inset: 0; pointer-events: none; display: grid; place-items: center; }
.pop { position: absolute; text-align: center; animation: pop 2.2s ease forwards; }
.pop .amt { font: 900 64px var(--mono); text-shadow: 0 4px 30px rgba(0,0,0,.8); }
.pop .nm { font-size: 22px; font-weight: 800; text-shadow: 0 2px 12px rgba(0,0,0,.9); }
.pop .q { font-size: 15px; color: #dfe3ea; text-shadow: 0 2px 10px #000; margin-top: 4px; font-style: italic; }
.pop.dim .amt { font-size: 34px; }
@keyframes pop { 0% { transform: scale(.4) translateY(30px); opacity: 0; } 12% { transform: scale(1.1); opacity: 1; } 20% { transform: scale(1); } 75% { opacity: 1; } 100% { transform: translateY(-80px); opacity: 0; } }
.t-common { color: var(--t-common); }
.t-uncommon { color: var(--t-uncommon); }
.t-rare { color: var(--t-rare); }
.t-epic { color: var(--t-epic); }
.t-legendary { color: var(--t-legendary); }
.pop.legendary .amt { background: linear-gradient(90deg, #fff4c4, var(--gold), #fff4c4); -webkit-background-clip: text; background-clip: text; color: transparent; }

.overlay { position: absolute; inset: 0; background: rgba(5,6,8,.82); backdrop-filter: blur(4px); display: grid; place-items: center; text-align: center; z-index: 5; padding: 16px; }
.streak-callout { font-size: 15px; animation: fire 1s infinite alternate; }
@keyframes fire { to { filter: brightness(1.3); transform: scale(1.06); } }

.feed { list-style: none; margin: 0; padding: 0; display: flex; gap: 8px; flex-wrap: wrap; min-height: 38px; }
.feed li { background: var(--bg2); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; font-size: 13px; font-weight: 600; display: flex; gap: 8px; animation: fade .3s; }
.feed li b { font-family: var(--mono); }
.feed .empty-feed { color: var(--muted); font-size: 14px; }


/* ---------- result ---------- */
.result { text-align: center; max-width: 980px; }
.result-title { font-size: 56px; font-weight: 900; margin: 10px 0 0; letter-spacing: -.03em; }
.result-title.win { color: var(--gold); }
.result-title.loss { color: var(--red); }
.result-sub { color: var(--muted); margin: 6px 0 18px; font-size: 17px; }
.records { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-bottom: 20px; }
.record { background: linear-gradient(90deg, #3a2d05, #2a2410); border: 1px solid #5a470d; color: var(--gold2); padding: 8px 14px; border-radius: 999px; font-weight: 700; font-size: 14px; }
.receipts { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; margin-bottom: 22px; text-align: left; }
/* The torn bottom edge is cut out of the paper with a mask, and the wrapper's drop-shadows trace that
   exact shape, so the outline and the paper always end in the same place. */
.receipt-wrap { min-width: 0; filter: drop-shadow(0 10px 24px rgba(0,0,0,.45)); }
.receipt-wrap.winner { filter: drop-shadow(2.5px 0 0 var(--gold)) drop-shadow(-2.5px 0 0 var(--gold)) drop-shadow(0 2.5px 0 var(--gold)) drop-shadow(0 -2.5px 0 var(--gold)) drop-shadow(0 0 18px rgba(245,197,66,.45)); }
.receipt { background: #f7f3e8; color: #1d1b16; border-radius: 6px 6px 0 0; padding: 18px 18px 30px; font-family: var(--mono); position: relative; min-width: 0;
  -webkit-mask: conic-gradient(from -45deg at bottom, #0000, #000 1deg 89deg, #0000 90deg) 50% / 16px 100%;
  mask: conic-gradient(from -45deg at bottom, #0000, #000 1deg 89deg, #0000 90deg) 50% / 16px 100%; }
.receipt h4 { margin: 0; text-align: center; font-size: 15px; display: flex; gap: 8px; justify-content: center; align-items: center; }
.receipt .rsub { text-align: center; font-size: 11px; color: #6b675c; margin: 4px 0 12px; }
.receipt .ln { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; padding: 3px 0; }
.receipt .ln span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.receipt .ln .tag { font-size: 10px; color: #8a8577; }
.receipt hr { border: 0; border-top: 1px dashed #b7b1a1; margin: 10px 0; }
.receipt .tot { font-weight: 800; font-size: 17px; }
.receipt .title { text-align: center; font-size: 11px; margin-top: 10px; color: #6b675c; text-transform: uppercase; letter-spacing: .1em; }

/* ---------- modal / toast ---------- */
/* Tall dialogs (Settings on a phone) scroll inside the overlay; the auto margins center a card that fits
   and pin a taller one to the top instead of pushing its ends off screen. */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.7); display: grid; place-items: center; z-index: 50; padding: 16px; overflow-y: auto; overscroll-behavior: contain; }
.modal > .card { margin: auto; }
.modal-card { text-align: center; max-width: 400px; width: 100%; }
.modal-card h3 { margin: 14px 0 4px; }
.modal-card .code { font: 800 44px var(--mono); letter-spacing: .2em; color: var(--gold); margin: 6px 0; }
.spinner { width: 42px; height: 42px; border: 4px solid var(--line); border-top-color: var(--gold); border-radius: 50%; margin: 0 auto; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
/* width: max-content, or a left:50% box shrinks to half the screen and wraps short messages on phones */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--card2); border: 1px solid var(--line); padding: 12px 18px; border-radius: 12px; z-index: 60; font-weight: 600; box-shadow: 0 10px 30px rgba(0,0,0,.4); width: max-content; max-width: calc(100% - 32px); text-align: center; line-height: 1.4; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  /* tablets: the one-row top bar only fits if the account chip is just the avatar (a long username pushed
     "Log out" off the screen at 768px) */
  .topbar { gap: 14px; padding: 12px 18px; }
  .topbar nav a { padding: 8px 9px; }
  .me-chip .nm { display: none; }
  .home-grid { grid-template-columns: 1fr; padding: 16px; }
  .tips { grid-column: auto; }
  .stats.wide { grid-template-columns: 1fr 1fr; }
}
/* the two-row top bar (nav on its own line) kicks in a bit above phone width: one row has no slack below ~720px */
@media (max-width: 720px) {
  .topbar { padding: 10px 16px; gap: 10px; flex-wrap: wrap; }
  .topbar nav { order: 3; flex-basis: 100%; } /* flex-basis, not width: the base rule's flex: 1 overrides width */
  .me-chip { margin-left: auto; }
}
@media (max-width: 640px) {
  .me-chip .nm { display: none; }
  .modes { grid-template-columns: 1fr; }
  .page { padding: 18px 16px 40px; }
  .brand.big { font-size: 34px; }
  .avatar.xl { width: 80px; height: 80px; }
  .result-title { font-size: 40px; }
  .pop .amt { font-size: 44px; }
  table.lb .sub { display: none; }
  .hist { grid-template-columns: 60px 1fr; }
  .hist .money { grid-column: 2; text-align: left; }
}
