:root {
  --bg: #0d1017;
  --bg-2: #141924;
  --panel: #182031;
  --panel-2: #1f2940;
  --border: #2a3550;
  --text: #eaf0fb;
  --muted: #8a95ad;
  --gold: #f5b921;
  --gold-2: #ffce54;
  --green: #46d17a;
  --red: #ff5d6c;
  --accent: #5aa2ff;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  background-image: radial-gradient(900px 500px at 50% -240px, #1b2540 0%, transparent 70%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
img { display: block; }
button { font-family: inherit; cursor: pointer; }
.pos { color: var(--green); }
.neg { color: var(--red); }
.muted { color: var(--muted); }

/* buttons */
.btn-primary {
  background: linear-gradient(120deg, var(--gold), var(--gold-2));
  color: #201400;
  border: none;
  border-radius: 10px;
  font-weight: 800;
  padding: 11px 20px;
  font-size: 15px;
  transition: transform 0.1s, filter 0.15s, opacity 0.15s;
}
.btn-primary:hover { filter: brightness(1.06); }
.btn-primary:active { transform: scale(0.97); }
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; filter: grayscale(0.4); }
.btn-ghost {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 8px 14px;
  font-weight: 600;
  transition: border-color 0.15s, background 0.15s;
}
.btn-ghost:hover { border-color: var(--muted); }
.btn-ghost.small { padding: 6px 11px; font-size: 13px; }

/* ============================== auth ============================== */
.auth { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px; gap: 14px; }
.auth-card {
  width: 100%;
  max-width: 400px;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 30px 26px;
  text-align: center;
}
.auth-card .logo { font-size: 46px; }
.auth-card h1 { font-size: 26px; margin-top: 4px; letter-spacing: -0.02em; }
.tagline { color: var(--muted); margin: 8px 0 18px; font-size: 14px; }
.tagline strong { color: var(--gold); }
.tabs { display: flex; gap: 6px; background: var(--bg-2); border-radius: 10px; padding: 4px; margin-bottom: 14px; }
.tab { flex: 1; background: none; border: none; color: var(--muted); font-weight: 700; padding: 8px; border-radius: 7px; }
.tab.active { background: var(--panel-2); color: var(--text); }
#auth-form { display: flex; flex-direction: column; gap: 10px; }
#auth-form input {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 11px 13px;
  color: var(--text);
  font-size: 15px;
}
#auth-form input:focus { outline: none; border-color: var(--accent); }
.auth-hint { font-size: 12px; color: var(--muted); text-align: left; }
.auth-error { color: var(--red); font-size: 13px; min-height: 16px; }
.footer-note { color: var(--muted); font-size: 12px; margin-top: 16px; }

/* ============================== topbar ============================== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 16px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 800; font-size: 17px; cursor: pointer; }
.brand span { background: linear-gradient(120deg, var(--gold), var(--gold-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.topbar .right { display: flex; align-items: center; gap: 8px; }
.balance { display: flex; align-items: center; gap: 6px; background: var(--panel); border: 1px solid var(--border); border-radius: 999px; padding: 6px 12px; font-weight: 800; }
#balance.flash { animation: flash 0.5s; }
@keyframes flash { 0%, 100% { color: var(--text); } 40% { color: var(--gold); } }
.who { color: var(--muted); font-size: 13px; }
@media (max-width: 560px) { .who { display: none; } }

main { max-width: 1040px; margin: 0 auto; padding: 18px 16px 60px; }

/* ============================== lobby builder ============================== */
.builder {
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
  margin-bottom: 18px;
  position: sticky;
  top: 60px;
  z-index: 10;
}
.builder-row { display: flex; flex-wrap: wrap; gap: 18px; margin-bottom: 12px; }
.opt { display: flex; flex-direction: column; gap: 5px; }
.opt-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 700; }
.seg { display: flex; gap: 4px; background: var(--bg-2); border-radius: 9px; padding: 3px; }
.seg-btn { background: none; border: none; color: var(--muted); font-weight: 700; padding: 6px 12px; border-radius: 6px; font-size: 13px; }
.seg-btn.active { background: var(--panel-2); color: var(--text); box-shadow: 0 0 0 1px var(--border); }
.builder-cases { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.chosen { flex: 1; min-width: 200px; display: flex; gap: 6px; flex-wrap: wrap; min-height: 44px; align-items: center; }
.chosen-empty { color: var(--muted); font-size: 13px; }
.chosen-chip { position: relative; width: 52px; height: 40px; border-radius: 7px; background: var(--bg-2); border: 1px solid var(--border); display: grid; place-items: center; }
.chosen-chip img { width: 46px; height: 34px; object-fit: contain; }
.chosen-chip .rm { position: absolute; top: -6px; right: -6px; width: 16px; height: 16px; background: var(--red); color: #fff; border-radius: 50%; font-size: 10px; display: grid; place-items: center; cursor: pointer; }
.builder-actions { display: flex; align-items: center; gap: 10px; }
.entry { font-weight: 800; color: var(--gold); font-size: 14px; white-space: nowrap; }

/* case catalog */
.catalog { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.case-card {
  background: linear-gradient(180deg, var(--panel), var(--bg-2));
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 10px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: transform 0.14s, border-color 0.14s, box-shadow 0.14s;
}
.case-card:hover { transform: translateY(-3px); border-color: var(--gold); box-shadow: 0 10px 24px -14px #000; }
.case-card:active { transform: translateY(-1px) scale(0.98); }
.case-card img { width: 100%; height: 84px; object-fit: contain; }
.cc-name { font-size: 12px; font-weight: 700; text-align: center; line-height: 1.2; min-height: 29px; display: flex; align-items: center; }
.cc-cost { color: var(--gold); font-weight: 800; font-size: 14px; }

/* ============================== battle ============================== */
.battle-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.battle-title { font-weight: 800; font-size: 15px; text-align: center; }
.battle-players { display: grid; grid-template-columns: repeat(var(--n), 1fr); gap: 10px; }
.bp-col { min-width: 0; background: linear-gradient(180deg, var(--panel), var(--bg-2)); border: 1px solid var(--border); border-radius: 12px; padding: 10px; transition: box-shadow 0.3s, border-color 0.3s; }
.bp-col.me { border-color: color-mix(in srgb, var(--accent) 50%, var(--border)); }
.bp-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.bp-name { font-weight: 800; font-size: 13px; }
.bp-total { font-weight: 800; color: var(--gold); font-size: 14px; }
.bp-reel-wrap { position: relative; height: 74px; overflow: hidden; border-radius: 8px; background: #0a0d14; border: 1px solid var(--border); }
.bp-reel-wrap::before { content: ""; position: absolute; left: 50%; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: var(--gold); z-index: 2; box-shadow: 0 0 8px var(--gold); }
.bp-reel { display: flex; height: 100%; will-change: transform; }
.reel-tile { flex: 0 0 auto; width: 66px; height: 74px; display: grid; place-items: center; border-bottom: 3px solid var(--tier, #555); }
.reel-tile img { width: 58px; height: 46px; object-fit: contain; }
.bp-items { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; max-height: 320px; overflow-y: auto; }
.won-item { display: flex; align-items: center; gap: 8px; background: var(--bg-2); border-left: 3px solid var(--tier, #555); border-radius: 6px; padding: 5px 7px; animation: pop 0.3s ease; }
.won-item.special { box-shadow: inset 0 0 0 1px var(--gold); }
@keyframes pop { from { transform: scale(0.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.won-item img { width: 40px; height: 30px; object-fit: contain; flex-shrink: 0; }
.wi-meta { display: flex; flex-direction: column; min-width: 0; }
.wi-name { font-size: 11px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wi-val { font-size: 12px; font-weight: 800; color: var(--gold); }
.bp-col.winner { border-color: var(--gold); box-shadow: 0 0 0 2px var(--gold), 0 0 26px -6px var(--gold); }
.bp-col.loser { opacity: 0.62; }

.battle-banner { margin-top: 16px; text-align: center; border-radius: 14px; padding: 18px; border: 1px solid var(--border); background: var(--panel); }
.battle-banner.win { border-color: var(--gold); background: radial-gradient(400px 200px at 50% 0, color-mix(in srgb, var(--gold) 22%, transparent), var(--panel)); }
.battle-banner.lose { border-color: var(--red); }
.bb-main { font-size: 24px; font-weight: 900; letter-spacing: -0.02em; }
.bb-sub { color: var(--muted); margin-top: 4px; }
.bb-sub b { font-size: 16px; }
.bb-actions { display: flex; gap: 10px; justify-content: center; margin-top: 14px; }

@media (max-width: 640px) {
  .battle-players { grid-template-columns: repeat(var(--n), 1fr); gap: 6px; }
  .bp-col { padding: 6px; }
  .reel-tile { width: 54px; }
  .reel-tile img { width: 46px; }
  .wi-name { font-size: 10px; }
}

/* ============================== stats ============================== */
.statsview h2 { margin: 10px 0 14px; }
.statsview h3 { margin: 22px 0 10px; font-size: 15px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: 11px; padding: 12px 14px; }
.stat b { font-size: 20px; display: block; }
.stat span { color: var(--muted); font-size: 12px; }
.lb, .hist { background: var(--panel); border: 1px solid var(--border); border-radius: 11px; overflow: hidden; }
.lb-row, .hist-row { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-bottom: 1px solid var(--border); font-size: 14px; }
.lb-row:last-child, .hist-row:last-child { border-bottom: none; }
.lb-row.you { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.lb-rank { width: 24px; color: var(--muted); font-weight: 800; }
.lb-name { flex: 1; font-weight: 700; }
.lb-bal { font-weight: 800; color: var(--gold); }
.lb-w { color: var(--muted); font-size: 12px; width: 42px; text-align: right; }
.hist-row { justify-content: space-between; }
.hist-row .pos, .hist-row .neg { font-weight: 800; }

/* ============================== toast ============================== */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 11px 18px;
  border-radius: 10px;
  font-weight: 600;
  z-index: 100;
  box-shadow: 0 10px 30px -10px #000;
  max-width: 90vw;
}
.toast.good { border-color: var(--green); }
.toast.show { animation: toastIn 0.25s ease; }
@keyframes toastIn { from { transform: translate(-50%, 12px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }
