@font-face {
  font-family: "Club Arcade";
  src: url("/assets/PressStart2P-Regular.ttf") format("truetype");
  font-display: swap;
}

:root {
  color-scheme: dark;
  --space: #080f18;
  --deck: #0b1b24;
  --mint: #96f7cf;
  --ink: #fff4d7;
  --muted: #adbfbe;
  --peach: #ffc39e;
  --pixel: "Club Arcade", monospace;
  --top: max(env(safe-area-inset-top, 0px), calc(var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px)));
  --bottom: max(env(safe-area-inset-bottom, 0px), calc(var(--tg-safe-area-inset-bottom, 0px) + var(--tg-content-safe-area-inset-bottom, 0px)));
  font: 15px/1.35 system-ui, sans-serif;
  background: var(--space);
  color: var(--ink);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
button, input, a, summary { font: inherit; color: inherit; }
button, a, summary { touch-action: manipulation; }
button { appearance: none; border: 0; cursor: pointer; }
a { text-decoration: none; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid #ffe3a6; outline-offset: 2px; }

.machine {
  width: min(100%, 520px);
  min-height: 100svh;
  margin: auto;
  padding: var(--top)
    max(env(safe-area-inset-right, 0px), calc(var(--tg-safe-area-inset-right, 0px) + var(--tg-content-safe-area-inset-right, 0px)))
    var(--bottom)
    max(env(safe-area-inset-left, 0px), calc(var(--tg-safe-area-inset-left, 0px) + var(--tg-content-safe-area-inset-left, 0px)));
  background: var(--deck);
}
.nav, .nav nav, .brand, .wallet strong, .stepper, .preset-list, .start,
#action-return, .recents, .recents ol, .recents li, .bets-head, .dialog-head {
  display: flex;
  align-items: center;
}
.nav {
  justify-content: space-between;
  min-height: 50px;
  padding: 0 9px 0 16px;
  background: #0a1721;
}
.brand {
  gap: 8px;
  margin: 0;
  font: 12px/1.3 var(--pixel);
  letter-spacing: -.055em;
}
.brand i {
  width: 17px;
  height: 21px;
  background: var(--mint);
  clip-path: polygon(54% 0,100% 0,62% 41%,90% 41%,0 100%,28% 52%,0 52%);
}
.brand span { font-size: 9px; color: var(--mint); }
.nav nav { gap: 2px; }
.back, .icon-button {
  display: grid;
  place-items: center;
  min-height: 44px;
  color: var(--muted);
}
.back { padding-inline: 8px; font-size: 13px; font-weight: 600; }
.icon-button { width: 44px; background: transparent; }
.icon-button svg { width: 20px; height: 20px; }
.guide { font: 13px var(--pixel); }
#sound-toggle[aria-pressed="true"] { color: var(--mint); }
#sound-toggle[aria-pressed="true"] .sound-off,
#sound-toggle[aria-pressed="false"] .sound-on { display: none; }

.stage {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  height: clamp(220px, calc(100svh - var(--top) - var(--bottom) - 252px), 620px);
  background: #0b1f31;
}
.orbit-panorama, #trail { position: absolute; inset: 0; width: 100%; height: 100%; display: block; pointer-events: none; }
.orbit-panorama { object-fit: cover; object-position: 50% 55%; transform: scale(1.055); }
#trail { image-rendering: pixelated; }
.readout {
  position: absolute;
  top: clamp(15px,3vh,24px);
  left: clamp(16px,5vw,24px);
  z-index: 1;
  pointer-events: none;
}
.readout p {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0 0 9px;
  font-size: 13px;
  font-weight: 650;
  color: #bbdbcf;
  text-shadow: 1px 1px #0a1929;
}
.readout p::before {
  content: "";
  width: 9px;
  height: 8px;
  background: var(--mint);
  clip-path: polygon(50% 0,100% 100%,0 100%);
}
.stage[data-phase="crashed"] .readout p::before { transform: rotate(180deg); background: var(--peach); }
.stage[data-phase="idle"] .readout p::before,
.stage[data-phase="betting"] .readout p::before { height: 6px; width: 6px; clip-path: none; }
#mult { display: block; font: clamp(30px,10vw,46px)/1.15 var(--pixel); letter-spacing: -.065em; white-space: nowrap; text-shadow: 2px 3px #0a1929; }
.mult-unit { font-size: .66em; color: var(--mint); margin-left: 4px; }
.stage[data-phase="crashed"] .mult-unit { color: var(--peach); }
.scale { position: absolute; right: 11px; top: 41%; bottom: 22%; width: 34px; pointer-events: none; }
.scale-mark { position: absolute; right: 0; font: 8px/1 var(--pixel); color: #e6f4de; text-shadow: 1px 1px 1px #0b2031; transform: translateY(50%); }
.scale-mark.high { bottom: 100%; }
.scale-mark.middle { bottom: 50%; }
.scale-mark.low { bottom: 0; }
.scale::before, .scale::after { content: ""; position: absolute; right: 0; width: 9px; height: 1px; background: #b6e2db; }
.scale::before { bottom: 25%; }
.scale::after { bottom: 75%; }
#gauge-needle {
  position: absolute; right: 100%; bottom: 0;
  width: 6px; height: 8px;
  background: var(--mint); clip-path: polygon(0 0,100% 50%,0 100%);
  transform: translateY(50%);
}
.stage[data-phase="betting"] .scale, .stage[data-phase="idle"] .scale { visibility: hidden; }

/* The console holds its position when a stake turns into a receipt. */
.deck { padding: 10px 15px 18px; }
.stakes { display: grid; grid-template-columns: minmax(0,1fr) auto; align-items: center; gap: 7px 12px; min-height: 59px; }
.wallet { grid-column: 2; grid-row: 1; justify-self: end; display: grid; justify-items: end; gap: 5px; }
.caption, .presets summary, .recents h2, .bets-head h2, .receipt-label {
  margin: 0; color: #aec7c0; font: 8px/1.55 var(--pixel); letter-spacing: .015em; text-transform: uppercase;
}
.wallet strong, .stake-locked, .stake-input { display: inline-flex; align-items: center; gap: 6px; }
.wallet strong, .stake-locked { color: var(--ink); font: clamp(12px,3.6vw,16px)/1.3 var(--pixel); letter-spacing: -.06em; }
.wallet strong { max-width: 100%; }
.wallet[data-long="true"] strong { font-size: clamp(9px,2.8vw,14px); }
.coin { display: block; width: 21px; height: 21px; flex: 0 0 auto; object-fit: contain; }
#bet-row, #flight-stats { grid-row: 1; grid-column: 1; min-width: 0; }
.presets { position: relative; width: max-content; }
.presets summary {
  width: max-content; list-style: none; cursor: pointer;
  min-height: 23px; display: flex; align-items: center; gap: 6px;
}
.presets summary::-webkit-details-marker { display: none; }
.presets summary::after { content: ""; width: 6px; height: 4px; background: #73938f; clip-path: polygon(0 0,100% 0,50% 100%); }
.presets[open] summary::after { transform: rotate(180deg); }
.preset-list {
  position: absolute; z-index: 2; left: 0; bottom: 100%; gap: 3px; padding: 4px;
  background: #18343b; box-shadow: 0 4px #06141e;
}
.preset-list button { min-width: 44px; height: 44px; padding: 0 5px; font-weight: 650; background: #203e47; border-radius: 3px; }
.preset-list button[aria-pressed="true"] { color: var(--mint); box-shadow: inset 0 -2px #71c3aa; }
.preset-list button:disabled { color: #82959a; }
#flight-stats .caption { display: flex; align-items: center; height: 23px; }
.stake-locked { min-height: 36px; }
.stepper { gap: 4px; min-height: 40px; }
.stepper button {
  display: grid; place-items: center; min-width: 36px; min-height: 40px; padding: 0 4px;
  background: #1e3740; border-radius: 4px; color: #d5ede4; font: 650 18px/1 system-ui,sans-serif;
}
.stepper button:disabled { background: #152b33; color: #789296; }
.stake-input { min-width: 0; gap: 3px; }
.stake-input .coin { width: 16px; height: 16px; }
.stepper input {
  min-width: 0; max-width: 100%; width: var(--digits, 3ch); padding: 0; text-align: center;
  background: transparent; border: 0; border-radius: 0; color: var(--ink);
  font: clamp(10px,3vw,14px)/1.5 var(--pixel); letter-spacing: -.055em;
}
.stepper input:disabled { opacity: 1; -webkit-text-fill-color: var(--ink); }
.start {
  position: relative; isolation: isolate;
  justify-content: center; gap: 11px; width: 100%; min-height: 57px;
  padding: 12px 8px 15px; margin-top: 8px; border: 0;
  background: transparent; color: #092b29; text-align: center;
  font: clamp(10px,3.1vw,14px)/1.45 var(--pixel);
}
.start::before {
  content: ""; position: absolute; z-index: -1; inset: 0;
  background: var(--mint); box-shadow: inset 0 2px #c8ffe1,inset 0 -5px #489181;
  clip-path: polygon(6px 0,calc(100% - 6px) 0,calc(100% - 6px) 3px,100% 3px,100% calc(100% - 6px),calc(100% - 3px) calc(100% - 6px),calc(100% - 3px) 100%,5px 100%,5px calc(100% - 3px),0 calc(100% - 3px),0 6px,3px 6px,3px 3px,6px 3px);
}
.start:active:enabled::before, a.start:active::before { inset-block-start: 3px; box-shadow: inset 0 1px #c8ffe1,inset 0 -2px #489181; }
.start:disabled { color: #c2d9cf; }
.start:disabled::before { background: #29493f; box-shadow: inset 0 2px #3a5b50,inset 0 -4px #1a372f; }
#action-return { gap: 5px; }
.feedback { font-size: 13px; margin: 8px 0 0; }
#notice { color: var(--peach); }
.receipt {
  width: 100%; min-height: 57px; margin-top: 8px; padding: 8px 15px;
  display: grid; grid-template-columns: 28px minmax(0,1fr) auto; align-items: center; gap: 11px;
  background: #193e36; color: #b0ffda;
  clip-path: polygon(6px 0, calc(100% - 6px) 0,100% 6px,100% calc(100% - 6px),calc(100% - 6px) 100%,6px 100%,0 calc(100% - 6px),0 6px);
}
.receipt-mark {
  width: 27px; height: 27px; background: #8de8b9; display: grid; place-items: center;
  clip-path: polygon(5px 0,22px 0,27px 5px,27px 22px,22px 27px,5px 27px,0 22px,0 5px);
}
.receipt-mark::after {
  content: ""; width: 14px; height: 10px; background: #103e32;
  clip-path: polygon(0 30%,20% 30%,20% 50%,38% 50%,38% 70%,55% 70%,55% 48%,70% 48%,70% 24%,84% 24%,84% 0,100% 0,100% 40%,85% 40%,85% 62%,69% 62%,69% 84%,53% 84%,53% 100%,35% 100%,35% 85%,18% 85%,18% 68%,0 68%);
}
.receipt-body { display: grid; align-content: center; gap: 4px; min-width: 0; }
.receipt-label { font-size: 8px; color: #b0e5c8; }
.receipt-value { display: flex; align-items: center; gap: 4px; color: #fff2c4; font: clamp(15px,4.35vw,19px)/1.2 var(--pixel); letter-spacing: -.07em; }
.receipt-value .coin { width: 21px; height: 21px; }
.receipt-price, .bettor-result:not(:empty) { background: #10312e; color: #a7f0ca; white-space: nowrap; }
.receipt-price { padding: 7px 6px; font: clamp(8px,2.35vw,11px)/1.4 var(--pixel); letter-spacing: -.075em; }
.receipt[data-status="lost"] { background: #372e34; color: #f7b8a0; }
.receipt[data-status="lost"] .receipt-mark { background: #bd816f; }
.receipt[data-status="lost"] .receipt-mark::after { width: 12px; height: 3px; background: #392831; clip-path: none; }
.receipt[data-status="lost"] .receipt-label { color: #ebc5ad; }
.receipt[data-status="lost"] .receipt-price { background: #2a252c; color: #ebc5ad; }
.recents { gap: 10px; margin-top: 11px; }
.recents h2 { flex: none; font-size: 7px; color: #91b0ae; }
.recents ol { list-style: none; min-width: 0; gap: 4px; overflow-x: auto; scrollbar-width: thin; margin: 0; padding: 1px; }
.recents li { flex: none; padding: 3px 5px; font: 650 11px/1.3 system-ui,sans-serif; color: #c2d3d2; background: #182c34; border-radius: 3px; }
.round-bets { margin-top: 15px; }
.bets-head { justify-content: space-between; gap: 8px; }
.bets-head h2 { display: flex; align-items: center; gap: 6px; font-size: 8px; color: #d4e4d7; }
#bets-count { min-width: 18px; padding: 3px; background: #253d43; color: #bfd0c9; text-align: center; font: 650 11px/1 system-ui,sans-serif; border-radius: 3px; }
#bets-total, .bettor-stake { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; color: #f6e9c7; }
#bets-total { font: 10px/1.4 var(--pixel); letter-spacing: -.055em; }
#bets-total .coin, .bettor-stake .coin { width: 17px; height: 17px; }
#bets-list { padding: 0; margin: 7px 0 0; list-style: none; display: grid; gap: 4px; }
#bets-list:empty, #bets-list:not(:empty) + #bets-empty { display: none; }
#bets-empty { margin: 8px 0 0; color: #8ba6a9; font-size: 12px; }
#bets-list li { display: flex; align-items: center; gap: 7px; min-height: 36px; padding: 5px 8px; background: #122730; border-radius: 3px; }
#bets-list li[data-mine="true"] { background: #18343b; }
.bettor-name { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; font-weight: 650; color: #dce9e3; }
#bets-list li[data-mine="true"] .bettor-name { color: #aeebd3; }
.my-tag { display: inline-block; padding: 0 4px; vertical-align: 1px; background: #294a4d; color: #c6ebd4; border-radius: 2px; font: 650 10px/1.55 system-ui,sans-serif; }
.bettor-stake { font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; }
.bettor-result:empty { display: none; }
.bettor-result:not(:empty) { padding: 3px 5px; font: 650 11px/1.3 system-ui,sans-serif; border-radius: 3px; }
@media (prefers-reduced-motion: no-preference) {
  .receipt[data-status="cashed_out"]:not([hidden]) .receipt-mark { animation: receipt-tick .24s ease-out both; }
}
@keyframes receipt-tick { from { transform: scale(.72); } to { transform: scale(1); } }

dialog { width: min(360px,calc(100% - 32px)); padding: 14px 18px 18px; border: 1px solid #5b8182; border-radius: 4px; background: #162b35; color: var(--ink); }
dialog::backdrop { background: #071019c9; }
.dialog-head { justify-content: space-between; }
.dialog-head h2 { font: 13px/1.55 var(--pixel); margin: 0; }
.dialog-head button { width: 44px; height: 44px; background: transparent; color: var(--muted); font-size: 24px; }
dialog p { margin: 8px 0 0; color: #d5e3de; font-size: 14px; }

@media (max-width: 350px) {
  .nav { padding: 0 3px 0 10px; }
  .brand { gap: 5px; font-size: 10px; }
  .brand span { font-size: 8px; }
  .back { padding-inline: 3px; }
  .nav nav { gap: 0; }
  .deck { padding-inline: 11px; }
  .stakes { column-gap: 5px; }
}
@media (max-height: 540px) {
  .stage { height: clamp(148px,calc(100svh - var(--top) - var(--bottom) - 218px), 310px); }
  .readout { top: 11px; }
  .deck { padding-top: 7px; }
  .start { min-height: 48px; margin-top: 3px; }
  .round-bets { margin-top: 12px; }
}
