:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --cyan: #38f2ff;
  --mint: #43f4a5;
  --pink: #ff5c91;
  --violet: #a65cff;
  --gold: #ffd98d;
  --text: #f8fbff;
  --muted: #9ca7bd;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; }
body {
  overflow: hidden;
  background: #02050d;
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, 'PingFang SC', 'Microsoft YaHei', sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button {
  border: 0;
  color: inherit;
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
}

.game {
  position: relative;
  isolation: isolate;
  width: min(100vw, 480px);
  height: 100dvh;
  min-height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
  display: grid;
  grid-template-rows:
    calc(7.4dvh + var(--safe-top))
    23.6dvh
    27.2dvh
    32.2dvh
    calc(7.4dvh + var(--safe-bottom));
  gap: clamp(4px, 0.75dvh, 8px);
  padding: 0 clamp(8px, 2.2vw, 14px);
}

.bg {
  position: fixed;
  inset: 0;
  z-index: -2;
  background:
    linear-gradient(180deg, rgba(2, 6, 16, 0.02), rgba(2, 5, 13, 0.52)),
    url('./assets-v2/bg.png') center / cover no-repeat;
}

.game::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(circle at 50% 42%, rgba(52, 242, 255, 0.14), transparent 38%),
    linear-gradient(90deg, rgba(52, 242, 255, 0.08), transparent 18%, transparent 82%, rgba(166, 92, 255, 0.12));
}

.topbar {
  padding-top: var(--safe-top);
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(96px, 1fr) auto minmax(128px, 1fr);
  gap: clamp(6px, 1.8vw, 10px);
  align-items: center;
}

.brand {
  display: flex;
  align-items: center;
  gap: clamp(7px, 2vw, 10px);
  min-width: 0;
}

.brand-mark {
  flex: 0 0 auto;
  width: clamp(32px, 9.2vw, 46px);
  height: clamp(32px, 9.2vw, 46px);
  background: linear-gradient(145deg, #3bf5ff, #7d46ff 58%, #180a2f);
  clip-path: polygon(50% 0, 95% 25%, 84% 82%, 50% 100%, 16% 82%, 5% 25%);
  box-shadow: inset 0 0 18px rgba(255,255,255,.24), 0 0 18px rgba(72, 200, 255, .34);
}

.brand strong {
  display: block;
  font-size: clamp(23px, 6.8vw, 36px);
  line-height: .9;
  font-weight: 950;
  font-style: italic;
}
.brand strong span { color: var(--cyan); }
.brand em {
  display: block;
  margin-top: 4px;
  color: rgba(255,255,255,.72);
  font-size: clamp(8px, 2.4vw, 12px);
  font-style: normal;
  font-weight: 900;
  letter-spacing: .02em;
}

.live {
  height: clamp(32px, 5.2dvh, 48px);
  min-width: clamp(78px, 21vw, 104px);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  color: #82ffc2;
  border-radius: 14px;
  border: 1px solid rgba(67, 244, 165, .44);
  background: rgba(5, 27, 29, .76);
  box-shadow: 0 0 18px rgba(67, 244, 165, .16);
  font-size: clamp(14px, 4vw, 21px);
  font-weight: 950;
}
.live i {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--mint);
  box-shadow: 0 0 12px var(--mint);
}

.wallet {
  justify-self: end;
  min-width: clamp(132px, 36vw, 178px);
  height: clamp(34px, 5.4dvh, 50px);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  padding: 0 6px 0 11px;
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(24, 20, 48, .92), rgba(9, 10, 27, .92));
  border: 1px solid rgba(151, 120, 255, .45);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.11);
}
.wallet i {
  color: var(--gold);
  font-style: normal;
  font-size: 13px;
}
.wallet b {
  white-space: nowrap;
  font-size: clamp(16px, 4.8vw, 25px);
  font-weight: 950;
}
.wallet span {
  color: var(--gold);
  font-size: clamp(9px, 2.5vw, 12px);
  font-weight: 900;
}
.wallet button {
  width: clamp(28px, 7.8vw, 38px);
  height: clamp(28px, 7.8vw, 38px);
  display: grid;
  place-items: center;
  border-radius: 11px;
  background: linear-gradient(145deg, #8a52ff, #44208e);
  font-size: clamp(24px, 6.6vw, 34px);
  font-weight: 950;
}

.market,
.betting,
.actions {
  position: relative;
  min-height: 0;
  overflow: hidden;
}

.market {
  padding: clamp(12px, 2dvh, 18px) clamp(14px, 3.2vw, 22px) clamp(9px, 1.3dvh, 14px);
  background: rgba(3, 8, 20, .72);
  border: 1px solid rgba(118, 85, 255, .28);
  border-radius: clamp(18px, 4.4vw, 26px);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.09), 0 10px 28px rgba(0,0,0,.28);
}
.market::before,
.betting::before,
.actions::before {
  content: '';
  position: absolute;
  inset: -3px;
  pointer-events: none;
  z-index: 1;
  background: url('./assets-v2/panel-market.png') center / 100% 100% no-repeat;
  opacity: .86;
}

.market-copy {
  position: relative;
  z-index: 2;
  height: calc(100% - clamp(28px, 4.7dvh, 42px));
  display: grid;
  grid-template-columns: minmax(145px, 44%) 1fr;
  gap: clamp(8px, 2vw, 14px);
}
.market h1 {
  margin: 0 0 clamp(10px, 1.8dvh, 16px);
  font-size: clamp(29px, 8.5vw, 48px);
  line-height: .94;
  font-weight: 950;
}
.market h1 span {
  color: rgba(255,255,255,.55);
  font-size: .54em;
}
.market strong {
  display: block;
  color: var(--cyan);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: clamp(34px, 10vw, 56px);
  line-height: .95;
  font-weight: 950;
  letter-spacing: -1.4px;
  text-shadow: 0 0 18px rgba(56, 242, 255, .36);
}
.market em {
  display: block;
  margin-top: 9px;
  color: var(--mint);
  font-size: clamp(15px, 4.2vw, 22px);
  font-style: normal;
  font-weight: 950;
}
#chart {
  width: 100%;
  height: 100%;
  align-self: stretch;
  border-radius: 14px;
  background: rgba(0, 4, 13, .55);
}
.tabs {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: clamp(13px, 4vw, 28px);
  height: clamp(28px, 4.7dvh, 42px);
  color: rgba(255,255,255,.58);
  font-size: clamp(13px, 3.6vw, 18px);
  font-weight: 900;
}
.tabs b {
  color: var(--cyan);
  padding: 5px 13px;
  border-radius: 10px;
  background: linear-gradient(180deg, rgba(130, 69, 255, .8), rgba(50, 21, 115, .92));
  border: 1px solid rgba(190, 120, 255, .42);
}
.price-tag {
  position: absolute;
  z-index: 4;
  right: clamp(18px, 4vw, 28px);
  top: 56%;
  color: #031b1e;
  background: var(--cyan);
  border-radius: 6px;
  padding: 4px 9px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: clamp(12px, 3.3vw, 16px);
  font-weight: 950;
}

.reactor-zone {
  position: relative;
  min-height: 0;
  overflow: visible;
}
.info {
  position: absolute;
  z-index: 4;
  top: 4px;
  width: min(35vw, 172px);
  height: clamp(54px, 8.2dvh, 78px);
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  column-gap: 10px;
  align-content: center;
  padding: 0 clamp(10px, 2.4vw, 16px);
  border-radius: 14px;
  background: rgba(5, 10, 27, .84);
  border: 1px solid rgba(122, 84, 255, .42);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.08), 0 0 18px rgba(121, 72, 255, .18);
}
.info-period { left: 4px; }
.info-lock { right: 4px; }
.info i {
  grid-row: 1 / 3;
  align-self: center;
  color: var(--gold);
  font-size: clamp(26px, 7vw, 38px);
  font-style: normal;
}
.info span {
  color: rgba(255,255,255,.68);
  font-size: clamp(12px, 3.2vw, 17px);
  font-weight: 900;
}
.info b {
  margin-top: 2px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: clamp(15px, 4vw, 21px);
  line-height: 1;
  font-weight: 950;
}
.info-lock b {
  color: var(--cyan);
  font-size: clamp(26px, 7vw, 40px);
}

.reactor {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
}
.reactor::before {
  content: '';
  position: absolute;
  width: min(86vw, 410px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(56,242,255,.22), rgba(166,92,255,.14) 42%, transparent 66%);
  filter: blur(8px);
}
.reactor img {
  position: relative;
  z-index: 1;
  width: min(84vw, 390px);
  max-height: 118%;
  object-fit: contain;
  filter: drop-shadow(0 0 24px rgba(56,242,255,.42));
  animation: pulse 2.5s ease-in-out infinite;
}
.ring {
  position: absolute;
  z-index: 2;
  width: min(37vw, 178px);
  aspect-ratio: 1;
  border-radius: 50%;
  border: 5px solid rgba(56,242,255,.35);
  border-top-color: var(--cyan);
  border-left-color: rgba(166,92,255,.9);
  box-shadow: inset 0 0 24px rgba(0,0,0,.8), 0 0 20px rgba(56,242,255,.42);
  animation: spin 7s linear infinite;
}
.counter {
  position: relative;
  z-index: 3;
  display: grid;
  justify-items: center;
  transform: translateY(4px);
  text-shadow: 0 4px 18px rgba(0,0,0,.9), 0 0 22px rgba(56,242,255,.26);
}
.counter strong {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: clamp(80px, 25vw, 132px);
  line-height: .88;
  font-weight: 950;
}
.counter span {
  margin-top: 8px;
  color: #d8e8ff;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: clamp(22px, 6vw, 32px);
  font-weight: 850;
}

.betting {
  display: grid;
  grid-template-rows: 1fr clamp(54px, 8.2dvh, 74px) clamp(52px, 7.4dvh, 76px);
  gap: clamp(5px, .85dvh, 9px);
  padding: clamp(6px, 1dvh, 10px);
  border-radius: clamp(18px, 4.5vw, 28px);
  background: rgba(3, 8, 20, .78);
  border: 1px solid rgba(126, 77, 255, .26);
}
.cards,
.stake,
.confirm,
.actions > button {
  position: relative;
  z-index: 2;
}
.cards {
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: clamp(6px, 1.6vw, 10px);
}
.card {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: 1fr auto auto;
  justify-items: center;
  align-items: center;
  padding: clamp(10px, 1.8dvh, 16px) 2px clamp(8px, 1.2dvh, 12px);
  background: var(--card) center / 100% 100% no-repeat;
  border-radius: 16px;
}
.card.active {
  transform: translateY(-2px);
  filter: brightness(1.16) drop-shadow(0 0 14px color-mix(in srgb, var(--tone) 64%, transparent));
}
.card b {
  color: white;
  font-size: clamp(45px, 14vw, 74px);
  line-height: .92;
  font-weight: 950;
  text-shadow: 0 4px 14px rgba(0,0,0,.72);
}
.card span {
  color: rgba(255,255,255,.84);
  font-size: clamp(15px, 4.4vw, 23px);
  font-weight: 950;
}
.card em {
  color: rgba(255,255,255,.78);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: clamp(11px, 3vw, 16px);
  font-style: normal;
  font-weight: 850;
  white-space: nowrap;
}
.big { --card: url('./assets-v2/card-big.png'); --tone: #188cff; }
.small { --card: url('./assets-v2/card-small.png'); --tone: #10d0aa; }
.odd { --card: url('./assets-v2/card-odd.png'); --tone: #a242ff; }
.even { --card: url('./assets-v2/card-even.png'); --tone: #ff4c91; }

.stake {
  display: grid;
  grid-template-columns: minmax(90px, 25%) 1fr;
  gap: clamp(7px, 2vw, 12px);
  align-items: center;
  padding: 6px 10px;
  border-radius: 14px;
  background: rgba(3, 8, 20, .82);
  border: 1px solid rgba(122, 153, 225, .24);
}
.amount {
  min-width: 0;
  display: grid;
  grid-template-columns: 1fr auto;
  column-gap: 7px;
  border-right: 1px solid rgba(122,153,225,.25);
}
.amount span {
  grid-column: 1 / -1;
  color: var(--gold);
  font-size: clamp(12px, 3.2vw, 16px);
  font-weight: 900;
}
.amount b {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: clamp(30px, 8.4vw, 44px);
  line-height: 1;
  font-weight: 950;
}
.amount em {
  align-self: end;
  color: var(--gold);
  font-size: clamp(13px, 3.4vw, 18px);
  font-style: normal;
  font-weight: 900;
}
.chips {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
}
.chips button {
  height: clamp(34px, 5.4dvh, 48px);
  min-width: 0;
  color: rgba(255,255,255,.66);
  border-radius: 11px;
  background: rgba(9, 14, 30, .84);
  border: 1px solid rgba(130, 165, 240, .3);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: clamp(12px, 3.2vw, 16px);
  font-weight: 950;
}
.chips button.active {
  color: white;
  background: linear-gradient(180deg, rgba(157, 72, 255, .98), rgba(74, 27, 165, .94));
  border-color: rgba(215, 150, 255, .72);
  box-shadow: 0 0 15px rgba(166,92,255,.45);
}
.confirm {
  color: white;
  background: url('./assets-v2/button-primary.png') center / 100% 100% no-repeat;
  font-size: clamp(28px, 8vw, 42px);
  font-weight: 950;
  text-shadow: 0 2px 12px rgba(0,0,0,.72);
}
.confirm.locked {
  color: #fff2bf;
  text-shadow: 0 2px 10px rgba(40, 17, 0, .88), 0 0 10px rgba(255, 210, 80, .42);
}

.actions {
  margin-bottom: var(--safe-bottom);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  border-radius: clamp(18px, 4.4vw, 26px);
  background: rgba(3, 8, 20, .84);
}
.actions::before {
  background-image: url('./assets-v2/bottom-actions.png');
  opacity: .9;
}
.actions button {
  min-width: 0;
  display: grid;
  grid-template-columns: auto auto 1fr;
  align-items: center;
  justify-content: center;
  gap: clamp(8px, 2.4vw, 14px);
  background: transparent;
}
.actions i {
  width: clamp(34px, 9vw, 50px);
  height: clamp(34px, 9vw, 50px);
  display: grid;
  place-items: center;
  color: var(--cyan);
  border-radius: 13px;
  background: rgba(56,242,255,.1);
  border: 1px solid rgba(56,242,255,.32);
  font-size: clamp(22px, 5.6vw, 30px);
  font-style: normal;
}
.actions b {
  font-size: clamp(22px, 6.4vw, 34px);
  font-weight: 950;
}
.actions span {
  justify-self: start;
  color: rgba(255,255,255,.48);
  font-size: clamp(10px, 2.7vw, 14px);
  font-weight: 850;
}

.sheet-mask {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0,0,0,.54);
  backdrop-filter: blur(5px);
}
.sheet {
  position: fixed;
  left: max(8px, env(safe-area-inset-left, 0px));
  right: max(8px, env(safe-area-inset-right, 0px));
  bottom: calc(-72dvh - var(--safe-bottom));
  z-index: 41;
  max-width: 480px;
  margin: 0 auto;
  height: min(64dvh, 540px);
  border-radius: 24px 24px 0 0;
  background: linear-gradient(180deg, rgba(8, 18, 42, .98), rgba(2, 6, 17, .98));
  border: 1px solid rgba(126, 77, 255, .42);
  box-shadow: 0 -18px 40px rgba(0,0,0,.44), inset 0 1px 0 rgba(255,255,255,.1);
  transition: bottom .28s ease;
  overflow: hidden;
}
.sheet.open {
  bottom: 0;
}
.sheet-head {
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  border-bottom: 1px solid rgba(120, 150, 230, .22);
}
.sheet-head b {
  font-size: 20px;
}
.sheet-head button {
  width: 34px;
  height: 34px;
  border-radius: 12px;
  background: rgba(255,255,255,.08);
  color: rgba(255,255,255,.8);
  font-size: 24px;
}
.sheet-body {
  height: calc(100% - 58px);
  overflow: auto;
  padding: 14px;
}
.history-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 11px 8px;
  border-bottom: 1px solid rgba(120,150,230,.14);
}
.digit {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: white;
  background: radial-gradient(circle at 30% 22%, rgba(255,255,255,.45), transparent 24%), linear-gradient(145deg, #15d4e4, #4b20b5);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 25px;
  font-weight: 950;
}
.verify-code {
  padding: 12px;
  margin: 10px 0;
  border-radius: 14px;
  background: rgba(0,0,0,.28);
  border: 1px solid rgba(56,242,255,.18);
  color: rgba(255,255,255,.78);
  word-break: break-all;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  line-height: 1.55;
}
.verify-ok {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  color: var(--mint);
  font-weight: 950;
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.035); } }

@media (max-height: 700px) {
  .game {
    grid-template-rows:
      calc(6.6dvh + var(--safe-top))
      20.5dvh
      24.2dvh
      35dvh
      calc(8.2dvh + var(--safe-bottom));
    gap: 4px;
    padding-inline: 7px;
  }
  .brand em,
  .tabs span:nth-child(n + 4),
  .counter span,
  .actions span {
    display: none;
  }
  .market {
    padding: 9px 10px 6px;
  }
  .market-copy {
    height: calc(100% - 30px);
    grid-template-columns: minmax(118px, 40%) 1fr;
  }
  .tabs {
    height: 30px;
  }
  .info {
    height: 42px;
    width: min(37vw, 150px);
    padding-inline: 9px;
  }
  .info i {
    display: none;
  }
  .reactor img {
    width: min(70vw, 260px);
  }
  .ring {
    width: min(31vw, 124px);
  }
  .counter strong {
    font-size: clamp(58px, 19vw, 88px);
  }
  .betting {
    grid-template-rows: 1fr 40px 44px;
    padding: 5px;
    gap: 4px;
  }
  .card {
    padding-top: 7px;
    padding-bottom: 5px;
  }
  .stake {
    padding: 4px 8px;
  }
  .amount span {
    display: none;
  }
  .chips button {
    height: 28px;
  }
}

@media (max-width: 360px) {
  .topbar {
    grid-template-columns: auto auto minmax(98px, 1fr);
    gap: 5px;
  }
  .wallet i,
  .wallet span,
  .wallet button {
    display: none;
  }
  .wallet {
    min-width: 90px;
    padding-inline: 8px;
  }
  .live {
    min-width: 64px;
  }
  .card em {
    font-size: 9px;
  }
}
