:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #111316;
  color: #f7f1df;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 22% 16%, rgba(244, 196, 48, 0.18), transparent 30%),
    radial-gradient(circle at 80% 72%, rgba(61, 160, 255, 0.16), transparent 32%),
    linear-gradient(145deg, #16191c 0%, #23242a 48%, #15171a 100%);
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  border-radius: 8px;
  min-height: 46px;
  padding: 0 18px;
  font-weight: 850;
  color: #17130a;
  background: #f4c430;
  box-shadow: 0 5px 0 #9d7415;
  cursor: pointer;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
  filter: brightness(1.06);
}

button:active:not(:disabled) {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #9d7415;
}

button:disabled {
  cursor: wait;
  opacity: 0.58;
}

.game-shell {
  width: min(920px, 100%);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 340px);
  gap: 18px;
  padding: clamp(18px, 3vw, 30px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(20, 22, 26, 0.88);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(14px);
}

.scorebar {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.scorebar div,
.history-panel,
.controls {
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.055);
}

.scorebar div {
  min-height: 78px;
  display: grid;
  align-content: center;
  gap: 4px;
  padding: 14px;
}

.scorebar span,
.history-head span,
.wager-control span {
  color: #beb9aa;
  font-size: 13px;
  font-weight: 850;
  text-transform: uppercase;
}

.scorebar strong {
  font-size: clamp(26px, 5vw, 40px);
  line-height: 1;
}

.stage {
  min-height: 470px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 30px;
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.02)),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.035) 0 1px, transparent 1px 56px);
}

.stage p {
  width: min(420px, 90%);
  min-height: 58px;
  margin: 0;
  text-align: center;
  font-size: clamp(22px, 4vw, 34px);
  font-weight: 900;
  line-height: 1.1;
}

.coin {
  position: relative;
  width: min(260px, 58vw);
  aspect-ratio: 1;
  transform-style: preserve-3d;
  transition: transform 360ms ease;
}

.coin::before {
  content: "";
  position: absolute;
  inset: 5%;
  border-radius: 50%;
  background: #9d7415;
  transform: translateZ(-13px);
}

.coin-face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border: 13px solid #ffe28a;
  border-radius: 50%;
  background:
    radial-gradient(circle at 34% 28%, #fff3b7 0 11%, transparent 12%),
    radial-gradient(circle at 50% 52%, #f5cc45 0 48%, #c58e18 72%, #8b5d0c 100%);
  box-shadow:
    inset 0 0 0 13px rgba(120, 76, 8, 0.24),
    inset -20px -28px 34px rgba(87, 51, 3, 0.28),
    0 22px 42px rgba(0, 0, 0, 0.34);
  backface-visibility: hidden;
}

.coin-face span {
  width: 46%;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border: 8px solid rgba(116, 72, 6, 0.28);
  border-radius: 50%;
  color: #6f4708;
  font-size: clamp(68px, 16vw, 112px);
  font-weight: 950;
  line-height: 1;
  text-shadow: 0 2px 0 rgba(255, 245, 178, 0.5);
}

.coin-tails {
  transform: rotateY(180deg);
}

.coin.heads {
  transform: rotateY(0deg);
}

.coin.tails {
  transform: rotateY(180deg);
}

.coin.flipping {
  animation: flip 900ms cubic-bezier(0.25, 0.9, 0.35, 1.2);
}

.coin.flipping.heads {
  animation-name: flip-heads;
}

.coin.flipping.tails {
  animation-name: flip-tails;
}

@keyframes flip-heads {
  0% { transform: rotateY(0deg) translateY(0); }
  45% { transform: rotateY(900deg) translateY(-38px); }
  100% { transform: rotateY(1800deg) translateY(0); }
}

@keyframes flip-tails {
  0% { transform: rotateY(0deg) translateY(0); }
  45% { transform: rotateY(990deg) translateY(-38px); }
  100% { transform: rotateY(1980deg) translateY(0); }
}

.controls {
  display: grid;
  gap: 18px;
  align-content: start;
  padding: 18px;
}

.choice-group,
.action-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.choice {
  color: #f7f1df;
  background: #2e343d;
  box-shadow: 0 5px 0 #161a20;
}

.choice.active {
  color: #17130a;
  background: #78d676;
  box-shadow: 0 5px 0 #377737;
}

.wager-control {
  display: grid;
  gap: 10px;
}

.wager-control strong {
  justify-self: start;
  min-width: 76px;
  border-radius: 8px;
  padding: 8px 12px;
  color: #17130a;
  background: #f7f1df;
}

input[type="range"] {
  width: 100%;
  accent-color: #f4c430;
}

.flip-button {
  background: #f4c430;
}

.all-in-button {
  color: #f7f1df;
  background: #cf4c4c;
  box-shadow: 0 5px 0 #762828;
}

.reset-button {
  color: #f7f1df;
  background: #46505d;
  box-shadow: 0 5px 0 #232a32;
}

.history-panel {
  grid-column: 2;
  padding: 16px;
}

.history-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.history-head small {
  color: #f4c430;
  font-weight: 800;
  text-align: right;
}

.history {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 46px;
}

.history-chip {
  min-width: 42px;
  border-radius: 999px;
  padding: 8px 10px;
  text-align: center;
  font-weight: 950;
  color: #17130a;
  background: #f4c430;
}

.history-chip.loss {
  color: #f7f1df;
  background: #cf4c4c;
}

.game-over-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(12, 13, 16, 0.86);
  backdrop-filter: blur(10px);
}

.game-over-overlay.hidden {
  display: none;
}

.game-over-window {
  width: min(560px, 100%);
  display: grid;
  justify-items: center;
  gap: 18px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  padding: clamp(28px, 7vw, 54px);
  text-align: center;
  background: #1f1618;
  box-shadow: 0 26px 80px rgba(0, 0, 0, 0.52);
}

.game-over-window span {
  color: #ff5c5c;
  font-size: clamp(58px, 13vw, 118px);
  font-weight: 950;
  line-height: 0.9;
  text-transform: uppercase;
}

.game-over-window p {
  margin: 0;
  color: #f7f1df;
  font-size: 18px;
  font-weight: 800;
}

.game-over-window button {
  min-width: 180px;
  background: #78d676;
  box-shadow: 0 5px 0 #377737;
}

@media (max-width: 760px) {
  body {
    padding: 12px;
    align-items: start;
  }

  .game-shell {
    grid-template-columns: 1fr;
  }

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

  .stage {
    min-height: 380px;
  }

  .history-panel {
    grid-column: auto;
  }
}
