:root {
  color-scheme: dark;
  --ink: #f4f2ea;
  --muted: #aba8a0;
  --panel: #17191d;
  --panel-strong: #20242a;
  --line: #30363f;
  --gold: #e0b84f;
  --gold-dark: #8a6420;
  --green: #6adf9d;
  --red: #ff7171;
  --blue: #7bb7ff;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 70% 20%, rgba(224, 184, 79, 0.14), transparent 32rem),
    linear-gradient(135deg, #101216 0%, #1b1f25 48%, #11151a 100%);
}

button {
  font: inherit;
}

.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 23rem;
  gap: 1px;
  min-height: 100vh;
  background: var(--line);
}

.stage,
.audit {
  background: rgba(15, 17, 21, 0.94);
}

.stage {
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  align-items: center;
  justify-items: center;
  gap: 1.5rem;
  padding: clamp(1rem, 4vw, 3rem);
}

.topline {
  display: flex;
  justify-content: space-between;
  width: min(100%, 44rem);
  color: var(--muted);
  font-size: 0.95rem;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

.status::before {
  content: "";
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 999px;
  background: var(--red);
}

.status.connected::before {
  background: var(--green);
}

.coin {
  position: relative;
  width: min(52vw, 21rem);
  min-width: 13rem;
  aspect-ratio: 1;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  transform-style: preserve-3d;
  background: radial-gradient(circle at 30% 25%, #ffe79b 0 8%, var(--gold) 31%, var(--gold-dark) 72%, #4b3313 100%);
  box-shadow:
    inset -1.1rem -1.3rem 2.8rem rgba(49, 31, 7, 0.62),
    inset 0.7rem 0.7rem 2rem rgba(255, 244, 182, 0.35),
    0 2.25rem 5rem rgba(0, 0, 0, 0.42);
  transition: transform 420ms cubic-bezier(.2, .8, .2, 1), filter 200ms ease;
}

.coin:hover {
  filter: brightness(1.06);
}

.coin:disabled {
  cursor: default;
  filter: saturate(0.75);
}

.coin.flipping {
  animation: flip 900ms cubic-bezier(.35, .05, .25, 1) infinite;
}

.coin[data-side="tails"] {
  background: radial-gradient(circle at 30% 25%, #fff0ad 0 8%, #d6d8db 31%, #7a828a 72%, #30363d 100%);
}

.coin-face {
  position: absolute;
  inset: 14%;
  display: grid;
  place-items: center;
  border: 0.35rem solid rgba(255, 255, 255, 0.28);
  border-radius: 50%;
  color: rgba(28, 21, 9, 0.78);
  font-size: clamp(4.5rem, 18vw, 9rem);
  font-weight: 900;
  line-height: 1;
  text-shadow: 0 0.12rem 0 rgba(255, 255, 255, 0.32);
  backface-visibility: hidden;
}

.coin-tails {
  color: rgba(14, 19, 24, 0.75);
  transform: rotateY(180deg);
}

.coin[data-side="tails"] .coin-heads {
  transform: rotateY(180deg);
}

.coin[data-side="tails"] .coin-tails {
  transform: rotateY(0deg);
}

.result {
  min-height: 7rem;
  text-align: center;
}

.result h1 {
  margin: 0;
  font-size: clamp(3rem, 10vw, 7.5rem);
  line-height: 0.95;
  letter-spacing: 0;
  text-transform: uppercase;
}

.result p {
  margin: 1rem 0 0;
  color: var(--muted);
  font-size: 1rem;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.75rem;
}

.primary,
.secondary {
  min-width: 8.5rem;
  min-height: 2.75rem;
  border: 1px solid transparent;
  border-radius: 0.45rem;
  cursor: pointer;
  font-weight: 750;
}

.primary {
  color: #171308;
  background: var(--gold);
}

.secondary {
  color: var(--ink);
  background: transparent;
  border-color: var(--line);
}

.primary:disabled {
  color: #848078;
  cursor: not-allowed;
  background: #34302a;
}

.audit {
  overflow: auto;
  padding: 1.25rem;
}

.audit-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.audit h2 {
  margin: 0;
  font-size: 1.1rem;
}

.audit-head span {
  color: var(--blue);
  font-size: 0.86rem;
  font-weight: 700;
}

dl {
  display: grid;
  gap: 0.65rem;
  margin: 0;
}

dl div {
  padding-bottom: 0.65rem;
  border-bottom: 1px solid var(--line);
}

dt {
  margin-bottom: 0.25rem;
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

dd {
  overflow-wrap: anywhere;
  margin: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.78rem;
  line-height: 1.45;
}

.history {
  display: grid;
  gap: 0.5rem;
  margin: 1.25rem 0 0;
  padding: 0;
  list-style: none;
}

.history li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 2.4rem;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 0.45rem;
  background: var(--panel);
}

.history strong {
  text-transform: uppercase;
}

.history span {
  color: var(--muted);
  font-size: 0.8rem;
}

@keyframes flip {
  from {
    transform: rotateY(0deg) rotateX(0deg);
  }
  to {
    transform: rotateY(720deg) rotateX(360deg);
  }
}

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

  .stage {
    min-height: 72vh;
  }

  .audit {
    max-height: none;
  }
}
