/* 스페이스맨 테이블.
   로비(First Step Games)의 색 체계를 따르되, 바탕은 크래시(남색)가 아니라 보라로 잡는다.
   같은 섹션에 카드가 둘 나란히 놓이므로 한눈에 구분돼야 한다. */

:root {
  color-scheme: dark;
  --bg: #0a0620;
  --panel: rgba(23, 16, 46, 0.92);
  --line: #3a2d68;
  --text: #f5f3ff;
  --muted: #a99ec8;
  --violet: #b78bff;
  --cyan: #53dcff;
  --amber: #ffbc3d;
  --red: #ff5470;
  --green: #5ce6a4;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  padding: 22px 16px 32px;
  background:
    radial-gradient(circle at 50% -12%, rgba(183, 139, 255, 0.18), transparent 34rem),
    linear-gradient(150deg, #0b0722 0%, #140c2e 48%, #070512 100%);
  color: var(--text);
  font-family: "Pretendard", "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-text-size-adjust: 100%;
}

.table {
  width: min(1180px, 100%);
  margin: 0 auto;
}

/* ───────────────────────────────────────────── 상단 바 */

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  padding: 14px 18px;
  background: var(--panel);
  border: 1px solid rgba(146, 116, 214, 0.3);
  border-radius: 16px;
}

.title { display: flex; align-items: center; gap: 12px; margin-right: auto; }

/* 헬멧 하나로 브랜드 마크를 만든다. */
.brand-mark {
  position: relative;
  width: 38px;
  height: 38px;
  border: 1px solid rgba(183, 139, 255, 0.55);
  border-radius: 12px;
  background: linear-gradient(140deg, rgba(183, 139, 255, .3), rgba(83, 220, 255, .08));
}

.brand-mark::before {
  content: "";
  position: absolute;
  inset: 9px;
  border-radius: 50%;
  background: #f7f9ff;
}

.brand-mark::after {
  content: "";
  position: absolute;
  left: 12px; top: 15px;
  width: 14px; height: 10px;
  border-radius: 50%;
  background: linear-gradient(135deg, #3d2f86, #120c2c);
  box-shadow: inset 2px 2px 0 rgba(255, 255, 255, .35);
}

.brand-copy { display: grid; line-height: 1.15; }
.brand-copy strong { font-size: 17px; letter-spacing: .12em; }
.brand-copy small { color: var(--muted); font-size: 10px; letter-spacing: .06em; }

.round-state {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 13px;
  background: rgba(183, 139, 255, .1);
  border: 1px solid rgba(183, 139, 255, .35);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.state-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--violet);
  box-shadow: 0 0 9px var(--violet);
  animation: pulse 1.6s ease-in-out infinite;
}

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }

.wallet { display: flex; gap: 10px; }

.wallet-item {
  display: grid;
  gap: 1px;
  min-width: 92px;
  padding: 7px 13px;
  background: rgba(8, 5, 18, .6);
  border: 1px solid var(--line);
  border-radius: 11px;
  text-align: right;
}

.wallet-item span { color: var(--muted); font-size: 10px; letter-spacing: .06em; }
.wallet-item strong { font-size: 16px; font-variant-numeric: tabular-nums; }
.wallet-item.staked strong { color: var(--amber); }

/* ───────────────────────────────────────────── 레이아웃 */

.layout {
  display: grid;
  grid-template-columns: 286px minmax(0, 1fr);
  gap: 14px;
}

.stage {
  grid-area: 1 / 2;
  display: grid;
  gap: 10px;
  align-content: start;
  min-width: 0;
}

.side { grid-area: 1 / 1; display: grid; gap: 10px; align-content: start; min-width: 0; min-height: 0; }

/* ───────────────────────────────────────────── 히스토리 */

.history-strip {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 9px 11px;
  background: var(--panel);
  border: 1px solid rgba(146, 116, 214, 0.25);
  border-radius: 13px;
  scrollbar-width: thin;
}

.history-strip:empty::before {
  content: "아직 결과가 없습니다";
  color: #6b5f90;
  font-size: 11px;
}

.hist {
  flex: 0 0 auto;
  padding: 4px 10px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.hist[data-tier="bust"] { background: rgba(255, 84, 112, .13); border-color: rgba(255, 84, 112, .4); color: #ff8098; }
.hist[data-tier="low"]  { background: rgba(169, 158, 200, .12); border-color: rgba(169, 158, 200, .32); color: #c3b9e0; }
.hist[data-tier="mid"]  { background: rgba(183, 139, 255, .14); border-color: rgba(183, 139, 255, .4); color: var(--violet); }
.hist[data-tier="high"] { background: rgba(92, 230, 164, .13); border-color: rgba(92, 230, 164, .4); color: var(--green); }
.hist[data-tier="epic"] { background: rgba(255, 188, 61, .15); border-color: rgba(255, 188, 61, .5); color: var(--amber); }

/* ───────────────────────────────────────────── 무대 */

.screen {
  position: relative;
  aspect-ratio: 16 / 9;
  min-height: 300px;
  overflow: hidden;
  background: #0a0620;
  border: 1px solid rgba(146, 116, 214, 0.3);
  border-radius: 18px;
}

.screen[data-phase="crashed"] {
  border-color: rgba(255, 84, 112, .45);
  box-shadow: inset 0 0 90px rgba(255, 84, 112, .12);
}

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

/* 우주인이 화면 가운데를 쓰므로 숫자는 위쪽에 둔다. 겹치면 둘 다 안 보인다. */
.readout {
  position: absolute;
  inset: 0 0 auto;
  display: grid;
  justify-items: center;
  gap: 2px;
  padding-top: 14px;
  pointer-events: none;
  text-align: center;
}

.mult {
  font-size: clamp(40px, 7vw, 68px);
  font-weight: 900;
  letter-spacing: -0.045em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  text-shadow: 0 2px 26px rgba(10, 6, 32, .95);
  transition: color .12s ease;
}

.mult span { font-size: .45em; margin-left: .06em; opacity: .65; }

.screen[data-phase="betting"] .mult { color: var(--muted); }
.screen[data-phase="flying"] .mult { color: #fff; }
.screen[data-phase="crashed"] .mult { color: var(--red); }

.stage-note {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .04em;
  text-shadow: 0 1px 10px rgba(10, 6, 32, .9);
}

.screen[data-phase="crashed"] .stage-note { color: #ff8098; }

/* 절반을 빼낸 뒤에는 "하늘에 얼마가 남았나"가 제일 중요한 정보다.
   배수 바로 아래에 둔다. 띄워 놓으면 숫자를 가린다. */
.half-badge {
  margin-top: 6px;
  padding: 5px 13px;
  background: rgba(10, 6, 32, .88);
  border: 1px solid rgba(83, 220, 255, .5);
  border-radius: 999px;
  color: var(--cyan);
  font-size: 11.5px;
  font-weight: 800;
  white-space: nowrap;
}

.half-badge[hidden] { display: none; }

.toasts {
  position: absolute;
  left: 50%;
  bottom: 16px;
  display: grid;
  gap: 6px;
  justify-items: center;
  transform: translateX(-50%);
  pointer-events: none;
}

.toast {
  padding: 6px 14px;
  background: rgba(10, 6, 32, .92);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
  animation: rise .3s ease both;
}

.toast[data-kind="win"] { border-color: rgba(92, 230, 164, .55); color: var(--green); }
.toast[data-kind="half"] { border-color: rgba(83, 220, 255, .55); color: var(--cyan); }
.toast[data-kind="warn"] { border-color: rgba(255, 188, 61, .55); color: var(--amber); }

@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

/* ───────────────────────────────────────────── 베팅 패널 */

.panel {
  display: grid;
  gap: 10px;
  padding: 13px;
  background: var(--panel);
  border: 1px solid rgba(146, 116, 214, 0.3);
  border-radius: 15px;
}

.panel[data-status="active"] { border-color: rgba(183, 139, 255, .55); }
.panel[data-status="cashed"] { border-color: rgba(92, 230, 164, .45); }
.panel[data-status="bust"] { border-color: rgba(255, 84, 112, .4); }

.bet-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr) minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.bet-col { display: grid; gap: 8px; min-width: 0; }
.bet-col.acts { gap: 7px; }

.field { display: grid; gap: 4px; }
.field > span { color: var(--muted); font-size: 11px; font-weight: 700; }

input[type="number"], select {
  width: 100%;
  padding: 9px 11px;
  background: rgba(8, 5, 18, .7);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  font: 700 15px/1.1 "Segoe UI", system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
}

input[type="number"]:focus-visible, select:focus-visible { outline: 2px solid var(--violet); outline-offset: 1px; }
input[type="number"]:disabled, select:disabled { opacity: .5; }

.chips { display: grid; grid-template-columns: repeat(6, 1fr); gap: 5px; }

.chips button {
  padding: 7px 0;
  background: rgba(45, 34, 82, .85);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: #cfc4ec;
  font: 800 11px/1 "Segoe UI", system-ui, sans-serif;
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
}

.chips button:hover:not(:disabled) { background: #3d2f6e; color: #fff; }
.chips button:disabled { opacity: .35; cursor: default; }

.autos { gap: 10px; }
.auto-row { display: grid; gap: 5px; }

.switch { display: flex; align-items: center; gap: 7px; color: #cfc4ec; font-size: 12px; font-weight: 700; cursor: pointer; }
.switch b { color: #fff; }
.switch input { width: 15px; height: 15px; accent-color: var(--violet); cursor: pointer; }

.auto-target { position: relative; display: flex; align-items: center; gap: 8px; }
.auto-target input { flex: 0 0 100px; padding-right: 22px; }
.auto-target .suffix { position: absolute; left: 82px; color: var(--muted); font-size: 12px; font-weight: 700; pointer-events: none; }
.auto-target .odds { color: var(--muted); font-size: 11px; font-weight: 700; font-variant-numeric: tabular-nums; }

.act {
  padding: 13px 10px;
  border: 1px solid transparent;
  border-radius: 12px;
  font: 900 14px/1.15 "Segoe UI", system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: filter .15s ease, transform .1s ease;
}

.act:active:not(:disabled) { transform: translateY(1px); }
.act:hover:not(:disabled) { filter: brightness(1.12); }
.act:disabled { opacity: .4; cursor: default; }

.act.bet { background: linear-gradient(135deg, #8f5cff, #6a34d8); color: #fff; }
.act.cancel { background: rgba(45, 34, 82, .9); border-color: var(--line); color: #cfc4ec; }
.act.cash { background: linear-gradient(135deg, #ffcf66, #ff9d37); color: #2a1700; }

/* 50% 회수는 주 버튼이 아니다. 같은 무게로 두면 무엇이 전액인지 헷갈린다. */
.act.half {
  padding: 10px;
  background: rgba(83, 220, 255, .12);
  border-color: rgba(83, 220, 255, .5);
  color: var(--cyan);
  font-size: 13px;
}

.panel-result { margin: 0; font-size: 11.5px; font-weight: 700; min-height: 15px; line-height: 1.4; }
.panel-result[data-kind="cashed"] { color: var(--green); }
.panel-result[data-kind="bust"] { color: #ff8098; }

/* ───────────────────────────────────────────── 자동 진행 */

.panel-head { display: flex; align-items: center; gap: 8px; }

.panel-name {
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .14em;
  text-transform: uppercase;
}

.auto-state {
  margin-left: auto;
  padding: 2px 9px;
  background: rgba(45, 34, 82, .8);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 800;
  color: var(--muted);
}

.auto-state[data-on="true"] { background: rgba(92, 230, 164, .14); border-color: rgba(92, 230, 164, .45); color: var(--green); }

.auto-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr)) auto;
  gap: 8px;
  align-items: end;
}

.act.auto-run { padding: 10px 18px; background: rgba(45, 34, 82, .9); border-color: var(--line); color: #cfc4ec; font-size: 13px; }
.act.auto-run.on { background: linear-gradient(135deg, #ff7a8f, #e0364f); border-color: transparent; color: #fff; }

.auto-note { margin: 0; color: #7b6ea3; font-size: 10.5px; line-height: 1.5; }

/* ───────────────────────────────────────────── 라이브 목록 · 통계 */

.live, .stats {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  padding: 12px;
  background: var(--panel);
  border: 1px solid rgba(146, 116, 214, 0.3);
  border-radius: 15px;
}

.live header, .stats header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .14em;
  text-transform: uppercase;
}

.live-count, .stat-count { margin-left: auto; color: var(--violet); letter-spacing: .02em; }

.live-list {
  display: grid;
  align-content: start;
  gap: 2px;
  flex: 1;
  min-height: 150px;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
  scrollbar-width: thin;
}

.live-list li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto 86px;
  gap: 8px;
  align-items: center;
  padding: 5px 8px;
  border-radius: 7px;
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
}

.live-list li[data-state="in"] { background: rgba(45, 34, 82, .5); color: #b6abd4; }
.live-list li[data-state="out"] { background: rgba(92, 230, 164, .1); color: var(--green); }
.live-list li[data-state="bust"] { background: rgba(255, 84, 112, .08); color: #96788f; }

.bot-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.bot-stake { color: inherit; opacity: .7; }
.bot-out { text-align: right; font-weight: 800; }

.stat-bars { display: grid; gap: 5px; }

.stat-row {
  display: grid;
  grid-template-columns: 78px minmax(0, 1fr) 42px;
  gap: 7px;
  align-items: center;
  font-size: 10.5px;
  font-variant-numeric: tabular-nums;
}

.stat-label { color: var(--muted); font-weight: 700; }

.stat-track {
  height: 8px;
  background: rgba(8, 5, 18, .7);
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
}

.stat-fill { display: block; height: 100%; width: 0; border-radius: 999px; transition: width .3s ease; }
.stat-fill[data-tier="bust"] { background: #ff5470; }
.stat-fill[data-tier="low"] { background: #9d93bd; }
.stat-fill[data-tier="mid"] { background: var(--violet); }
.stat-fill[data-tier="high"] { background: var(--green); }
.stat-fill[data-tier="epic"] { background: var(--amber); }

.stat-value { text-align: right; color: #cfc4ec; font-weight: 800; }

/* 항목과 값이 세로로 붙어야 한다. 기본 흐름대로 두면 dt·dd가 가로로 흩어진다. */
.stat-sum {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: auto auto;
  grid-auto-flow: column;
  gap: 4px;
  margin: 2px 0 0;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  text-align: center;
}

.stat-sum dt { color: var(--muted); font-size: 10px; font-weight: 700; }
.stat-sum dd { margin: 2px 0 0; font-size: 13px; font-weight: 800; font-variant-numeric: tabular-nums; }

/* ───────────────────────────────────────────── 공정성 */

.fair {
  margin-top: 14px;
  background: var(--panel);
  border: 1px solid rgba(146, 116, 214, 0.25);
  border-radius: 15px;
  overflow: hidden;
}

.fair-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 13px 16px;
  background: none;
  border: 0;
  color: #cfc4ec;
  font: 800 12px/1 "Segoe UI", system-ui, sans-serif;
  letter-spacing: .06em;
  text-align: left;
  cursor: pointer;
}

.fair-toggle .chev { margin-left: auto; transition: transform .18s ease; }
.fair-toggle.open .chev { transform: rotate(180deg); }

.fair-body { padding: 0 16px 16px; }

.fair-lead, .fair-formula {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.65;
}

.fair-lead b { color: #e2dbf5; }

.fair-grid {
  display: grid;
  grid-template-columns: 128px minmax(0, 1fr);
  gap: 6px 12px;
  margin: 0 0 12px;
  font-size: 11.5px;
}

.fair-grid dt { color: var(--muted); font-weight: 700; }
.fair-grid dd { margin: 0; overflow-wrap: anywhere; }

.mono { font-family: "Cascadia Mono", Consolas, monospace; color: #b2a4d8; font-size: 10.5px; }

#fairVerdict[data-ok="true"] { color: var(--green); font-weight: 800; }
#fairVerdict[data-ok="false"] { color: var(--red); font-weight: 800; }

.fair-formula code {
  padding: 1px 6px;
  background: rgba(8, 5, 18, .7);
  border: 1px solid var(--line);
  border-radius: 5px;
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 11px;
  color: #d3c5f5;
}

footer {
  margin-top: 18px;
  color: #74679a;
  font-size: 11px;
  line-height: 1.7;
  text-align: center;
}

footer b { color: #a294c6; }

/* ───────────────────────────────────────────── 좁은 화면 */

@media (max-width: 1040px) {
  .bet-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .bet-col.acts { grid-column: 1 / -1; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); display: grid; }
  .bet-col.acts .panel-result { grid-column: 1 / -1; }
}

@media (max-width: 940px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .stage { grid-area: auto; }
  .side { grid-area: auto; }
  .live-list { flex: none; max-height: 200px; }
  .auto-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .act.auto-run { grid-column: 1 / -1; }
}

@media (max-width: 640px) {
  body { padding: 14px 10px 26px; }
  .topbar { gap: 10px; padding: 11px 13px; }
  .title { width: 100%; }
  .round-state { order: 3; }
  .wallet { flex: 1; }
  .wallet-item { min-width: 0; flex: 1; }
  .screen { aspect-ratio: 3 / 4; min-height: 300px; }
  .bet-grid { grid-template-columns: minmax(0, 1fr); }
  .bet-col.acts { grid-template-columns: minmax(0, 1fr); }
  .chips { grid-template-columns: repeat(3, 1fr); }
  .fair-grid { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .fair-grid dt { margin-top: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  .state-dot, .toast { animation: none; }
}
