:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #14141f;
  --bg-tertiary: #1e1e2e;
  --text-primary: #ffffff;
  --text-secondary: #a0a0b0;
  --text-muted: #606070;
  --accent: #00d4ff;
  --accent-secondary: #00ff88;
  --danger: #ff4466;
  --gold: #f4c430;
  --gold-light: #ffe98a;
  --focus-ring: #00d4ff;
  --focus-glow: rgba(0, 212, 255, 0.4);
  --radius-md: 12px;
  --radius-sm: 8px;
}

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

html, body {
  width: 600px;
  height: 600px;
  overflow: hidden;
  background: #000;
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
}

#app { width: 100%; height: 100%; position: relative; }

.screen {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 12px;
}

.screen.hidden { display: none; }

.focusable {
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
  border: 2px solid transparent;
  cursor: pointer;
  outline: none;
}

.focusable:focus {
  border-color: var(--focus-ring);
  box-shadow: 0 0 20px var(--focus-glow);
}

.focusable:disabled { cursor: not-allowed; opacity: 0.32; }

.hidden { display: none !important; }

/* ---- Header ---- */
.header {
  background: var(--bg-primary);
  border-radius: var(--radius-md);
  padding: 12px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 64px;
  flex-shrink: 0;
}

.header-info { display: flex; flex-direction: column; gap: 3px; }
.header-total { display: flex; flex-direction: column; gap: 3px; align-items: flex-end; }

.header h1 { font-size: 23px; font-weight: 500; color: var(--text-primary); }

.header-label {
  font-size: 10px;
  letter-spacing: 2px;
  color: var(--text-muted);
  font-weight: 700;
  text-transform: uppercase;
}

.header-num { font-size: 26px; font-weight: 400; font-variant-numeric: tabular-nums; }
.accent-green { color: var(--accent-secondary); }
.accent-cyan { color: var(--accent); }

/* ---- Coin stage ---- */
.coin-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  min-height: 0;
}

.coin-wrap {
  width: 168px;
  height: 168px;
  perspective: 900px;
  flex-shrink: 0;
}

.coin {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transform: rotateX(0deg);
  transition: transform 1.1s cubic-bezier(0.12, 0.6, 0.2, 1);
  will-change: transform;
}

.coin-face {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  font-size: 86px;
  font-weight: 800;
  border: 5px solid rgba(255, 255, 255, 0.2);
  box-shadow: inset 0 7px 22px rgba(255, 255, 255, 0.28), inset 0 -10px 24px rgba(0, 0, 0, 0.45);
}

.coin-face span { text-shadow: 0 2px 3px rgba(0, 0, 0, 0.22); line-height: 1; }

.coin-heads {
  transform: translateZ(5px);
  background: radial-gradient(circle at 36% 30%, var(--gold-light) 0%, var(--gold) 52%, #c8920f 100%);
  color: #6b4a00;
}

.coin-tails {
  transform: rotateX(180deg) translateZ(5px);
  background: radial-gradient(circle at 36% 30%, #adeaff 0%, var(--accent) 52%, #0079a8 100%);
  color: #00323f;
}

@keyframes toss {
  0%   { transform: translateY(0) scale(1); }
  45%  { transform: translateY(-66px) scale(1.07); }
  100% { transform: translateY(0) scale(1); }
}

.coin-wrap.tossing { animation: toss 1.1s cubic-bezier(0.2, 0.5, 0.3, 1); }

.result-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 34px;
  flex-wrap: wrap;
}

.result {
  font-size: 26px;
  font-weight: 600;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  transition: color 0.2s ease;
}

.result.heads { color: var(--gold); }
.result.tails { color: var(--accent); }
.result.flipping { color: var(--text-muted); }

.streak-badge {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 4px 11px;
  border-radius: 20px;
  background: rgba(0, 255, 136, 0.14);
  color: var(--accent-secondary);
  white-space: nowrap;
}

/* ---- Tally ---- */
.tally { display: flex; gap: 12px; height: 76px; flex-shrink: 0; }

.tally-card {
  flex: 1;
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  border: 2px solid transparent;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.tally-label {
  font-size: 11px;
  letter-spacing: 2px;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--text-muted);
}

.tally-count {
  font-size: 40px;
  font-weight: 300;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
}

#tallyHeads.leading { border-color: rgba(244, 196, 48, 0.55); background: var(--bg-tertiary); }
#tallyHeads.leading .tally-count { color: var(--gold); }
#tallyTails.leading { border-color: rgba(0, 212, 255, 0.55); background: var(--bg-tertiary); }
#tallyTails.leading .tally-count { color: var(--accent); }

/* ---- Buttons ---- */
.controls { display: flex; gap: 8px; flex-shrink: 0; }

.btn {
  flex: 1;
  height: 60px;
  font-family: inherit;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 1.5px;
  cursor: pointer;
}

.btn-flip {
  flex: none;
  width: 100%;
  height: 84px;
  font-size: 22px;
  letter-spacing: 3px;
}

.btn-primary { background: var(--accent); color: #001218; }
.btn-tertiary { background: var(--bg-tertiary); color: var(--text-primary); }
.btn-danger { background: var(--danger); color: var(--text-primary); }

.btn-tertiary.focusable:focus { background: #2a2a3e; }

/* ---- Stats screen ---- */
.stat-grid { display: flex; gap: 12px; flex-shrink: 0; }

.stat-box {
  flex: 1;
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 96px;
  justify-content: center;
}

.stat-name {
  font-size: 11px;
  letter-spacing: 2px;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--text-muted);
}

.stat-num {
  font-size: 38px;
  font-weight: 300;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
  line-height: 1.05;
}

.stat-sub { font-size: 13px; color: var(--text-secondary); }

.stat-box.heads .stat-num { color: var(--gold); }
.stat-box.tails .stat-num { color: var(--accent); }

.stat-bar-wrap { display: flex; flex-direction: column; gap: 8px; flex-shrink: 0; }

.stat-bar {
  height: 22px;
  border-radius: 11px;
  overflow: hidden;
  display: flex;
  background: var(--bg-tertiary);
}

.stat-bar-heads {
  width: 0;
  background: linear-gradient(90deg, #c8920f, var(--gold-light));
  transition: width 0.4s ease;
}

.stat-bar-tails {
  width: 0;
  background: linear-gradient(90deg, #adeaff, #0079a8);
  transition: width 0.4s ease;
}

.stat-bar-caption {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  letter-spacing: 0.5px;
}

/* ---- Confirm screen ---- */
.confirm-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  text-align: center;
  padding: 0 36px;
  min-height: 0;
}

.confirm-icon {
  font-size: 60px;
  width: 112px;
  height: 112px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--bg-secondary);
  color: var(--danger);
}

.confirm-text {
  font-size: 17px;
  line-height: 1.5;
  color: var(--text-secondary);
  max-width: 430px;
}

@media (prefers-reduced-motion: reduce) {
  .coin { transition: transform 0.2s ease; }
  .coin-wrap.tossing { animation: none; }
}
