:root {
  --accent: #f7c948;
  --accent2: #fb923c;
}
body {
  background:
    radial-gradient(circle at 88% 0, #56340c 0, transparent 35%),
    radial-gradient(circle at 7% 18%, #2c245d 0, transparent 28%), var(--bg);
}
main {
  display: flex;
  flex-direction: column;
}
.hero {
  order: 1;
}
.workspace {
  order: 2;
}
.ad {
  order: 3;
}
.info {
  order: 4;
}
.hero {
  padding: 26px 0 12px;
}
.hero h1 {
  max-width: 980px;
  margin: 8px 0 10px;
  font-size: clamp(2rem, 4vw, 3.6rem);
}
.hero p {
  max-width: 900px;
  margin: 0;
  font-size: 1rem;
}
.workspace {
  padding: 14px 0 42px;
}
.controls-panel .row > .field {
  flex: 1;
  min-width: 130px;
}
.controls-panel input[type="color"] {
  height: 46px;
  padding: 4px;
}
.check {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 4px 0 18px;
  color: #d8e1ef;
  font-size: 0.9rem;
}
.button-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}
.hint {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
}
.stage-panel {
  position: relative;
  min-height: 630px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.round-progress {
  position: absolute;
  top: 20px;
  left: 22px;
  right: 22px;
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}
.coin-scene {
  width: 290px;
  height: 290px;
  perspective: 1100px;
}
.coin {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
}
.coin.flipping {
  animation: coinFlip var(--flip-duration, 1450ms)
    cubic-bezier(0.18, 0.72, 0.22, 1) forwards;
}
.coin-face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 13px solid rgba(255, 255, 255, 0.28);
  border-radius: 50%;
  backface-visibility: hidden;
  box-shadow:
    inset 0 0 0 5px rgba(0, 0, 0, 0.18),
    inset 0 0 45px rgba(255, 255, 255, 0.22),
    0 24px 65px rgba(0, 0, 0, 0.42);
  font-size: 2.15rem;
  font-weight: 950;
  letter-spacing: 0.08em;
  text-shadow: 0 2px 2px rgba(255, 255, 255, 0.35);
}
.coin-face:after {
  position: absolute;
  inset: 18px;
  content: "";
  border: 2px dashed rgba(0, 0, 0, 0.24);
  border-radius: 50%;
}
.coin-face span {
  position: relative;
  z-index: 2;
}
.coin-face.has-image span {
  width: 100%;
  height: 100%;
  background-position: center;
  background-size: cover;
  color: transparent;
}
.coin-heads {
  background: linear-gradient(
    145deg,
    #fff1a6,
    var(--heads, #f7c948) 55%,
    #b56d08
  );
  color: #4c2e00;
}
.coin-tails {
  background: linear-gradient(
    145deg,
    #ffe3bd,
    var(--tails, #fb923c) 55%,
    #9f4113
  );
  color: #4b1f08;
  transform: rotateY(180deg);
}
.coin.show-tails {
  transform: rotateY(180deg);
}
.coin[data-theme="silver"] .coin-face {
  border-color: #edf4fb;
  filter: saturate(0.35);
  box-shadow:
    inset 0 0 0 5px #748398,
    inset 0 0 45px rgba(255, 255, 255, 0.5),
    0 24px 65px rgba(0, 0, 0, 0.42);
}
.coin[data-theme="copper"] .coin-face {
  border-color: #d97737;
  filter: saturate(1.35) sepia(0.28);
  box-shadow:
    inset 0 0 0 5px #743511,
    inset 0 0 42px rgba(255, 218, 175, 0.32),
    0 24px 65px rgba(0, 0, 0, 0.42);
}
.coin[data-theme="neon"] .coin-face {
  border-color: #5eead4;
  box-shadow:
    inset 0 0 0 5px #111827,
    inset 0 0 45px rgba(94, 234, 212, 0.38),
    0 0 36px rgba(139, 92, 246, 0.8),
    0 24px 65px rgba(0, 0, 0, 0.42);
}
.coin[data-theme="minimal"] .coin-face {
  border-width: 5px;
  border-color: #fff;
  box-shadow:
    inset 0 0 0 2px rgba(0, 0, 0, 0.2),
    0 18px 42px rgba(0, 0, 0, 0.34);
  text-shadow: none;
}
@keyframes coinFlip {
  0% {
    transform: rotateY(var(--from, 0deg)) translateY(0) scale(1);
  }
  35% {
    transform: rotateY(calc(var(--turns) * 0.35)) translateY(-85px) scale(1.08);
  }
  70% {
    transform: rotateY(calc(var(--turns) * 0.75)) translateY(-24px) scale(1.03);
  }
  100% {
    transform: rotateY(var(--to)) translateY(0) scale(1);
  }
}
.result {
  min-height: 38px;
  margin-top: 27px;
  text-align: center;
  font-size: 1.28rem;
  font-weight: 900;
}
.stage-flip {
  min-width: 170px;
  margin-top: 8px;
}
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 9px;
  width: 100%;
  margin-top: 24px;
}
.stats article {
  padding: 13px;
  background: #0a1627;
  border: 1px solid var(--line);
  border-radius: 11px;
  text-align: center;
}
.stats b,
.stats span {
  display: block;
}
.stats b {
  font-size: 1.35rem;
}
.stats span {
  color: var(--muted);
  font-size: 0.72rem;
}
.history-panel {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 18px;
  margin-top: 18px;
}
.history-panel h2,
.history-panel p {
  margin: 0;
}
.history-panel p {
  color: var(--muted);
  font-size: 0.85rem;
}
.history-actions {
  display: flex;
  gap: 8px;
}
.history-panel ol {
  grid-column: 1/-1;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.history-panel li {
  padding: 9px 11px;
  background: #0a1627;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: #dbe7f6;
  font-size: 0.78rem;
}
.history-panel .empty-history {
  grid-column: 1/-1;
  color: var(--muted);
  text-align: center;
}
.celebrate:before,
.celebrate:after {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  content: "✦  ●  ◆  ✦  ●  ◆  ✦";
  color: var(--accent);
  font-size: 2rem;
  letter-spacing: 1.4rem;
  text-align: center;
  animation: confetti 1.2s ease-out forwards;
}
.celebrate:after {
  color: var(--accent2);
  animation-delay: 0.08s;
}
@keyframes confetti {
  0% {
    translate: 0 -40%;
    opacity: 0;
  }
  25% {
    opacity: 1;
  }
  100% {
    translate: 0 75%;
    opacity: 0;
  }
}
.ad {
  display: grid;
  margin-top: 0;
}
.stage-panel:fullscreen {
  width: 100vw;
  height: 100vh;
  padding: 24px;
  background:
    radial-gradient(circle at 80% 0, #56340c 0, transparent 38%), #08111f;
  border: 0;
  border-radius: 0;
}
.stage-panel:fullscreen .coin-scene {
  width: min(55vh, 520px);
  height: min(55vh, 520px);
}
.stage-panel:fullscreen .stage-flip {
  padding: 15px 30px;
  font-size: 1.08rem;
}
@media (max-width: 820px) {
  .stage-panel {
    min-height: 540px;
  }
  .coin-scene {
    width: 240px;
    height: 240px;
  }
  .history-panel ol {
    grid-template-columns: repeat(3, 1fr);
  }
}
@media (max-width: 560px) {
  .button-grid,
  .stats {
    grid-template-columns: 1fr 1fr;
  }
  .history-panel {
    grid-template-columns: 1fr;
  }
  .history-actions {
    grid-column: 1;
  }
  .history-panel ol {
    grid-template-columns: 1fr 1fr;
  }
  .coin-scene {
    width: 210px;
    height: 210px;
  }
  .coin-face {
    font-size: 1.55rem;
  }
}
