:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --ink: #172033;
  --muted: #69748a;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --line: #d8dfec;
  --shadow: 0 24px 70px rgba(23, 32, 51, 0.14);
  --gold: #f59e0b;
  --gold-dark: #d97706;
  --silver: #94a3b8;
}

* { box-sizing: border-box; margin: 0; }

html, body { min-height: 100%; }

body {
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(245, 158, 11, 0.10), rgba(37, 99, 235, 0.10)),
    var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.app {
  width: min(100%, 420px);
  display: grid;
  gap: 16px;
}

.panel {
  display: grid;
  justify-items: center;
  gap: 18px;
  padding: 36px 28px 28px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  box-shadow: var(--shadow);
  text-align: center;
}

.eyebrow {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1 {
  margin-top: -6px;
  font-size: clamp(2rem, 7vw, 3rem);
  line-height: 1;
}

.coin-stage {
  perspective: 600px;
  width: 140px;
  height: 140px;
  margin: 8px 0;
}

.coin {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.1s ease;
}

.coin-face {
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 3rem;
  font-weight: 900;
  backface-visibility: hidden;
  border: 4px solid;
}

.coin-heads {
  background: linear-gradient(145deg, #fef3c7, #fbbf24);
  border-color: var(--gold-dark);
  color: #92400e;
  box-shadow:
    inset 0 -4px 12px rgba(146, 64, 14, 0.2),
    0 6px 20px rgba(245, 158, 11, 0.3);
}

.coin-tails {
  background: linear-gradient(145deg, #e2e8f0, #94a3b8);
  border-color: #64748b;
  color: #1e293b;
  transform: rotateY(180deg);
  box-shadow:
    inset 0 -4px 12px rgba(30, 41, 59, 0.15),
    0 6px 20px rgba(100, 116, 139, 0.3);
}

.coin.flip-heads {
  animation: flipToHeads 0.8s ease-out forwards;
}

.coin.flip-tails {
  animation: flipToTails 0.8s ease-out forwards;
}

@keyframes flipToHeads {
  0%   { transform: rotateY(0deg); }
  100% { transform: rotateY(1080deg); }
}

@keyframes flipToTails {
  0%   { transform: rotateY(0deg); }
  100% { transform: rotateY(1260deg); }
}

.result {
  font-size: 1.4rem;
  font-weight: 800;
  min-height: 1.8em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.result.heads { color: var(--gold-dark); }
.result.tails { color: #475569; }

.result-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.heads .result-badge {
  background: #fef3c7;
  color: #92400e;
}

.tails .result-badge {
  background: #e2e8f0;
  color: #1e293b;
}

button {
  width: min(100%, 220px);
  min-height: 52px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font: inherit;
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  transition: background 140ms ease, transform 140ms ease;
}

button:hover { background: var(--accent-dark); }
button:active { transform: translateY(1px); }
button:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.3);
  outline-offset: 3px;
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.tally-panel {
  padding: 20px 24px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  box-shadow: 0 8px 30px rgba(23, 32, 51, 0.08);
}

.tally-panel h2 {
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 14px;
  text-align: center;
}

.tally {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
}

.tally-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 80px;
}

.tally-label {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.tally-count {
  font-size: 2rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  line-height: 1;
}

.tally-divider {
  width: 1px;
  height: 48px;
  background: var(--line);
}

.tally-total {
  text-align: center;
  margin-top: 12px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
}

@keyframes pop {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.15); }
  100% { transform: scale(1); }
}

.tally-count.bump {
  animation: pop 300ms ease;
}
