/* Palette inspired by Master of Coin: parchment, gold, slate blue, ink, banner red. */
:root {
  --parchment: #f3e7cf;
  --parchment-dark: #e3d2b4;
  --ink: #382d22;
  --gold: #d6a73f;
  --gold-dark: #a87f2c;
  --blue: #8fb2c3;
  --blue-dark: #5c8496;
  --red: #b5382e;
  --red-dark: #8e2b23;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  font-family: Georgia, 'Times New Roman', serif;
  color: var(--ink);
  background: radial-gradient(ellipse at 50% 30%, #f8efdd 0%, var(--parchment) 55%, #e9d9bc 100%);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

/* ---- header banner ---- */
.banner {
  background:
    repeating-conic-gradient(from 45deg, rgba(0,0,0,0.08) 0% 25%, transparent 0% 50%) 0 0 / 18px 18px,
    var(--red);
  color: var(--parchment);
  text-align: center;
  padding: calc(env(safe-area-inset-top, 0px) + 0.5rem) 1rem 0.55rem;
  border-bottom: 3px solid var(--ink);
  box-shadow: 0 2px 6px rgba(56, 45, 34, 0.3);
}

.banner h1 {
  margin: 0;
  font-size: 1.5rem;
  font-variant: small-caps;
  letter-spacing: 0.14em;
  font-weight: 700;
}

.subtitle {
  margin: 0;
  font-size: 0.75rem;
  font-style: italic;
  opacity: 0.9;
}

.subtitle a { color: inherit; }

/* ---- main ---- */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 42rem;
  margin: 0 auto;
  padding: 0.9rem 0.9rem 0.4rem;
  overflow-y: auto;
}

/* ---- readout ---- */
.readout {
  display: flex;
  gap: 0.75rem;
  width: 100%;
  justify-content: center;
}

.stat {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex: 1;
  max-width: 12rem;
  padding: 0.45rem 0.8rem;
  background: var(--parchment-dark);
  border: 2px solid var(--ink);
  border-radius: 0.6rem;
  box-shadow: inset 0 0 0 2px var(--parchment), 0 2px 3px rgba(56, 45, 34, 0.25);
}

.stat-icon { width: 2.1rem; height: 2.1rem; flex: none; }

.stat-text { display: flex; flex-direction: column; line-height: 1.05; }

.stat-label {
  font-variant: small-caps;
  letter-spacing: 0.1em;
  font-size: 0.8rem;
}

.stat-value {
  font-size: 1.7rem;
  font-weight: 700;
  min-height: 1.2em;
}

.stat-value.pop { animation: pop 0.35s ease-out; }

/* Total-coin count, styled like the board's yellow diamond markers. */
.total-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  flex: none;
}

.total {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  background: #f0c04a;
  border: 2px solid var(--ink);
  border-radius: 0.25rem;
  transform: rotate(45deg);
  box-shadow: 0 2px 3px rgba(56, 45, 34, 0.25);
}

.total span {
  transform: rotate(-45deg);
  font-size: 1.15rem;
  font-weight: 700;
}

.total span.pop { animation: pop-diamond 0.35s ease-out; }

@keyframes pop-diamond {
  0% { transform: rotate(-45deg) scale(0.6); }
  60% { transform: rotate(-45deg) scale(1.25); }
  100% { transform: rotate(-45deg) scale(1); }
}

.total-label {
  font-variant: small-caps;
  letter-spacing: 0.1em;
  font-size: 0.65rem;
  line-height: 1;
}

@keyframes pop {
  0% { transform: scale(0.6); }
  60% { transform: scale(1.25); }
  100% { transform: scale(1); }
}

/* ---- coin field ---- */
.coin-field {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  align-content: center;
  justify-content: center;
  gap: 0.7rem;
  width: 100%;
  padding: 1rem 0;
  perspective: 900px;
}

.coin {
  width: clamp(64px, 24vw, 110px);
  height: clamp(64px, 24vw, 110px);
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
  perspective: 700px;
  -webkit-tap-highlight-color: transparent;
}

.coin-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  will-change: transform;
}

.coin-face {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  filter: drop-shadow(0 3px 3px rgba(56, 45, 34, 0.35));
}

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

.coin.hop { animation: hop 0.55s ease-in-out; }

@keyframes hop {
  0% { transform: translateY(0) scale(1); }
  40% { transform: translateY(-12%) scale(1.08); }
  100% { transform: translateY(0) scale(1); }
}

/* ---- controls ---- */
.controls {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  width: 100%;
  max-width: 42rem;
  margin: 0 auto;
  padding: 0.7rem 0.9rem calc(env(safe-area-inset-bottom, 0px) + 0.8rem);
}

.count-row {
  display: flex;
  gap: 0.55rem;
}

.btn {
  font-family: inherit;
  font-weight: 700;
  color: var(--ink);
  background: var(--parchment-dark);
  border: 2px solid var(--ink);
  border-radius: 0.6rem;
  box-shadow: 0 3px 0 var(--ink);
  cursor: pointer;
  transition: transform 0.06s ease, box-shadow 0.06s ease;
}

.btn:active {
  transform: translateY(3px);
  box-shadow: 0 0 0 var(--ink);
}

.btn-count, .btn-preset {
  flex: 1;
  font-size: 1.45rem;
  padding: 0.5rem 0;
  line-height: 1;
}

.btn-preset.active {
  background: var(--gold);
  box-shadow: 0 3px 0 var(--gold-dark), inset 0 0 0 2px var(--parchment);
}

.btn-preset.active:active { box-shadow: 0 0 0 var(--gold-dark); }

.btn-flip {
  font-size: 1.35rem;
  font-variant: small-caps;
  letter-spacing: 0.12em;
  padding: 0.7rem 0;
  color: var(--parchment);
  background: var(--red);
  box-shadow: 0 4px 0 var(--red-dark);
}

.btn-flip:active {
  transform: translateY(4px);
  box-shadow: 0 0 0 var(--red-dark);
}

@media (prefers-reduced-motion: reduce) {
  .coin.hop { animation: none; }
  .stat-value.pop { animation: none; }
  .total span.pop { animation: none; }
}
