:root {
  color-scheme: dark;
  --bg: #080a0f;
  --panel: #0f131b;
  --panel-solid: #121823;
  --panel-soft: #171f2c;
  --line: rgba(255, 255, 255, 0.08);
  --text: #f3f6fb;
  --muted: #8b94a7;
  --green: #35d487;
  --cyan: #4aa8ff;
  --red: #ef4665;
  --yellow: #eab84f;
  --shadow: 0 18px 42px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

body.flash-win .stage {
  box-shadow: inset 0 0 0 1px rgba(53, 212, 135, 0.5);
}

body.flash-crash .stage {
  box-shadow: inset 0 0 0 1px rgba(239, 70, 101, 0.55);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

.app-shell {
  width: min(1280px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 14px;
}

.game-panel,
.control-panel {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.game-panel {
  min-width: 0;
  display: flex;
  flex-direction: column;
  border-radius: 8px;
  overflow: hidden;
}

.control-panel {
  border-radius: 8px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.topbar {
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 1.45rem;
  line-height: 1;
  letter-spacing: 0;
}

h2 {
  font-size: 0.86rem;
  letter-spacing: 0;
  color: #cbd3e2;
  text-transform: uppercase;
}

.balance-card {
  min-width: 160px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0b0f16;
  text-align: right;
}

.balance-card span,
.stats-grid span,
.field > span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.balance-card strong {
  display: block;
  margin-top: 3px;
  font-size: 1.08rem;
}

.stage {
  position: relative;
  flex: 1;
  min-height: 430px;
  background:
    linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    #090d14;
  background-size: 56px 56px;
  overflow: hidden;
  transition: box-shadow 180ms ease;
}

.stage::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(8, 10, 15, 0), rgba(8, 10, 15, 0.44));
}

.stage.is-live::after {
  background: linear-gradient(180deg, rgba(8, 10, 15, 0), rgba(8, 10, 15, 0.34));
}

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

.stage-overlay {
  position: relative;
  z-index: 1;
  height: 100%;
  min-height: 430px;
  padding: 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  pointer-events: none;
}

.round-status {
  min-height: 1.15rem;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 800;
  text-transform: uppercase;
}

.multiplier {
  margin-top: 8px;
  color: var(--green);
  font-size: clamp(4rem, 10vw, 8.5rem);
  font-weight: 900;
  line-height: 0.9;
  letter-spacing: 0;
  text-shadow: none;
}

.multiplier.crashed {
  color: var(--red);
  text-shadow: none;
}

.multiplier.won {
  color: var(--yellow);
  text-shadow: none;
}

.cashout-readout {
  max-width: 36rem;
  min-height: 1.2rem;
  margin-top: 14px;
  color: #b8c1d0;
  font-size: 0.92rem;
  font-weight: 700;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-top: 1px solid var(--line);
}

.stats-grid div {
  padding: 14px 16px;
  border-right: 1px solid var(--line);
}

.stats-grid div:last-child {
  border-right: 0;
}

.stats-grid strong {
  display: block;
  margin-top: 5px;
  font-size: 1.02rem;
}

.controls-group,
.history-panel {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0b0f16;
}

.section-title {
  display: flex;
  align-items: center;
  margin-bottom: 12px;
}

.field {
  display: grid;
  gap: 8px;
}

.input-wrap {
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.input-wrap span {
  color: var(--muted);
  font-weight: 900;
}

input[type="number"] {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-weight: 850;
}

.quick-bets {
  margin-top: 8px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.quick-bets button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-solid);
  color: #dfe6f5;
  font-weight: 850;
}

.quick-bets button:hover,
.quick-bets button:focus-visible {
  border-color: rgba(74, 168, 255, 0.5);
}

.quick-bets button:active,
.primary-action:active,
.cashout-action:active {
  transform: translateY(1px);
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.toggle-row strong {
  display: block;
}

.toggle-row strong {
  font-size: 0.92rem;
}

input[type="checkbox"] {
  appearance: none;
  flex: 0 0 48px;
  width: 48px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #2a3143;
  position: relative;
  outline: none;
}

input[type="checkbox"]::after {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  transition: transform 140ms ease;
}

input[type="checkbox"]:checked {
  background: var(--green);
}

input[type="checkbox"]:checked::after {
  transform: translateX(20px);
}

.actions {
  display: grid;
  gap: 10px;
}

.primary-action,
.cashout-action {
  min-height: 50px;
  border: 0;
  border-radius: 8px;
  color: #03110b;
  font-size: 1rem;
  font-weight: 950;
}

.primary-action {
  background: var(--green);
  box-shadow: none;
}

.cashout-action {
  background: var(--yellow);
}

.primary-action:disabled,
.cashout-action:disabled {
  opacity: 0.5;
  box-shadow: none;
}

.history-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.history-pill {
  min-width: 58px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--green);
  font-size: 0.86rem;
  font-weight: 900;
  text-align: center;
}

.history-pill.hot {
  color: var(--yellow);
}

.history-pill.cold {
  color: var(--red);
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .control-panel {
    order: -1;
  }

  .stage,
  .stage-overlay {
    min-height: 400px;
  }
}

@media (max-width: 620px) {
  .app-shell {
    padding: 12px;
    gap: 12px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    padding: 14px;
  }

  .balance-card {
    width: 100%;
    text-align: left;
  }

  .stage,
  .stage-overlay {
    min-height: 330px;
  }

  .stage-overlay {
    padding: 18px;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .stats-grid div {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .stats-grid div:last-child {
    border-bottom: 0;
  }

  .control-panel {
    padding: 12px;
  }
}
