:root {
  --parchment: #FFF8EC;
  --parchment-dark: #F5EAD4;
  --ink: #2B2140;
  --coral: #FF6B6B;
  --coral-dark: #E85555;
  --teal: #2EC4B6;
  --gold: #FFC93D;
  --sage: #6BCB77;
  --line: #E7DAC0;
  --radius-lg: 22px;
  --radius-md: 14px;
  --shadow: 0 6px 0 rgba(43, 33, 64, 0.12);
  --font-display: 'Baloo 2', system-ui, sans-serif;
  --font-body: 'Nunito', system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--parchment);
  color: var(--ink);
  font-family: var(--font-body);
  min-height: 100vh;
}

body {
  background-image:
    radial-gradient(circle at 10% 15%, rgba(255, 201, 61, 0.10) 0, transparent 45%),
    radial-gradient(circle at 90% 85%, rgba(46, 196, 182, 0.10) 0, transparent 45%);
}

button {
  font-family: var(--font-body);
  cursor: pointer;
  border: none;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid var(--teal);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

/* ---------- Top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  max-width: 640px;
  margin: 0 auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.3rem;
}

.brand-badge { font-size: 1.6rem; }

.coin-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--gold);
  color: var(--ink);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
  padding: 8px 16px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  user-select: none;
}

.coin-icon { font-size: 1.15rem; }

/* ---------- Tabs ---------- */

.tabs {
  display: flex;
  gap: 8px;
  max-width: 640px;
  margin: 0 auto;
  padding: 0 18px 10px;
}

.tab {
  flex: 1;
  background: transparent;
  border: 2px solid var(--line);
  padding: 10px;
  border-radius: var(--radius-md);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1rem;
  color: var(--ink);
  opacity: 0.6;
}

.tab.active {
  background: var(--ink);
  color: var(--parchment);
  border-color: var(--ink);
  opacity: 1;
}

main {
  max-width: 640px;
  margin: 0 auto;
  padding: 8px 18px 60px;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---------- Mode picker ---------- */

.mode-picker {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 10px 0 18px;
}

.mode-btn {
  background: white;
  border: 2px solid var(--line);
  border-radius: var(--radius-md);
  padding: 10px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-weight: 700;
  font-size: 0.8rem;
  color: var(--ink);
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.mode-btn .mode-emoji { font-size: 1.5rem; }

.mode-btn.active {
  border-color: var(--coral);
  background: #FFF0EF;
  transform: translateY(-2px);
}

/* ---------- Stage ---------- */

.stage {
  background: white;
  border: 2px solid var(--line);
  border-radius: var(--radius-lg);
  min-height: 280px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  padding: 20px;
}

.go-btn {
  display: block;
  width: 100%;
  margin-top: 16px;
  background: var(--coral);
  color: white;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.15rem;
  padding: 16px;
  border-radius: var(--radius-md);
  box-shadow: 0 5px 0 var(--coral-dark);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}

.go-btn:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 var(--coral-dark);
}

.go-btn:disabled {
  background: #d8d0c4;
  box-shadow: none;
  cursor: not-allowed;
}

/* ---------- Wheel ---------- */

.wheel-wrap {
  position: relative;
  width: 240px;
  height: 240px;
}

.wheel-pointer {
  position: absolute;
  top: -6px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 2rem;
  z-index: 2;
  filter: drop-shadow(0 2px 2px rgba(0,0,0,0.25));
}

.wheel {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 6px solid var(--ink);
  transition: transform 4s cubic-bezier(0.15, 0.8, 0.1, 1);
  transform: rotate(0deg);
}

.wheel-hub {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 34px; height: 34px;
  background: var(--gold);
  border: 4px solid var(--ink);
  border-radius: 50%;
  z-index: 2;
}

/* ---------- Dice ---------- */

.dice-scene {
  perspective: 600px;
}

.dice {
  width: 90px;
  height: 90px;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 1.4s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.dice-face {
  position: absolute;
  width: 90px;
  height: 90px;
  background: white;
  border: 4px solid var(--ink);
  border-radius: 16px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  padding: 12px;
}

.pip {
  width: 12px;
  height: 12px;
  background: var(--ink);
  border-radius: 50%;
  align-self: center;
  justify-self: center;
  opacity: 0;
}

.dice-face.f1 { transform: translateZ(45px); }
.dice-face.f2 { transform: rotateY(180deg) translateZ(45px); }
.dice-face.f3 { transform: rotateY(90deg) translateZ(45px); }
.dice-face.f4 { transform: rotateY(-90deg) translateZ(45px); }
.dice-face.f5 { transform: rotateX(90deg) translateZ(45px); }
.dice-face.f6 { transform: rotateX(-90deg) translateZ(45px); }

.dice-category-label {
  position: absolute;
  bottom: 14px;
  left: 0; right: 0;
  text-align: center;
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--ink);
  font-size: 0.9rem;
}

/* ---------- Envelope ---------- */

.envelope-wrap {
  width: 220px;
  height: 160px;
  position: relative;
  cursor: pointer;
}

.envelope-body {
  position: absolute;
  inset: 0;
  background: #FFEBD6;
  border: 4px solid var(--ink);
  border-radius: 10px;
}

.envelope-flap {
  position: absolute;
  top: -4px;
  left: -4px;
  right: -4px;
  height: 88px;
  background: #FFDAB3;
  border: 4px solid var(--ink);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  transform-origin: top center;
  transition: transform 0.6s ease;
  z-index: 2;
}

.envelope-wrap.open .envelope-flap {
  transform: rotateX(180deg);
}

.letter-paper {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 6px;
  height: 120px;
  background: var(--parchment);
  border: 3px solid var(--ink);
  border-radius: 6px;
  transform: translateY(10px);
  transition: transform 0.6s ease 0.3s;
  z-index: 1;
}

.envelope-wrap.open .letter-paper {
  transform: translateY(-90px);
}

/* ---------- Card / bucket ---------- */

.card-stack {
  position: relative;
  width: 140px;
  height: 190px;
}

.playing-card {
  position: absolute;
  inset: 0;
  border-radius: 14px;
  border: 4px solid var(--ink);
  backface-visibility: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.4rem;
  transition: transform 0.7s cubic-bezier(0.3, 0.8, 0.3, 1);
}

.card-back {
  background: repeating-linear-gradient(45deg, var(--teal), var(--teal) 8px, #279488 8px, #279488 16px);
}

.card-front {
  background: white;
  transform: rotateY(180deg);
}

.card-stack.flipped .card-back { transform: rotateY(180deg); }
.card-stack.flipped .card-front { transform: rotateY(0deg); }

/* ---------- Reveal badge ---------- */

.reveal-card {
  margin-top: 18px;
  text-align: center;
}

.reveal-card.hidden,
.empty-state.hidden,
.modal-backdrop.hidden,
.admin-panel-body.hidden {
  display: none;
}

.badge {
  background: white;
  border: 3px dashed var(--coral);
  border-radius: var(--radius-lg);
  padding: 22px 16px;
  transform: rotate(-1.5deg);
  animation: badgePop 0.4s ease;
}

@keyframes badgePop {
  from { transform: rotate(-1.5deg) scale(0.8); opacity: 0; }
  to { transform: rotate(-1.5deg) scale(1); opacity: 1; }
}

.badge-emoji { font-size: 3rem; }

.badge-title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.4rem;
  margin-top: 4px;
}

.badge-desc {
  margin-top: 6px;
  color: #574a6b;
  font-size: 0.95rem;
}

.badge-reward {
  margin-top: 10px;
  display: inline-block;
  background: var(--gold);
  padding: 4px 14px;
  border-radius: 999px;
  font-weight: 800;
  font-family: var(--font-display);
}

.reveal-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

.claim-btn {
  flex: 1;
  background: var(--sage);
  color: white;
  font-family: var(--font-display);
  font-weight: 700;
  padding: 14px;
  border-radius: var(--radius-md);
  box-shadow: 0 4px 0 #4CA858;
}

.claim-btn:active { transform: translateY(3px); box-shadow: none; }

.again-btn {
  background: white;
  border: 2px solid var(--line);
  color: var(--ink);
  font-weight: 700;
  padding: 14px;
  border-radius: var(--radius-md);
}

.empty-state {
  text-align: center;
  padding: 30px 10px;
  font-weight: 700;
  color: #574a6b;
}

/* ---------- Store ---------- */

.store-intro {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.1rem;
}

.store-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.store-item {
  background: white;
  border: 2px solid var(--line);
  border-radius: var(--radius-md);
  padding: 14px;
  text-align: center;
}

.store-item .item-emoji { font-size: 2rem; }

.store-item .item-name {
  font-family: var(--font-display);
  font-weight: 700;
  margin-top: 6px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.store-item .item-cost {
  color: var(--ink);
  font-weight: 800;
  margin: 6px 0;
}

.redeem-btn {
  width: 100%;
  background: var(--teal);
  color: white;
  font-weight: 700;
  padding: 10px;
  border-radius: var(--radius-md);
}

.redeem-btn:disabled {
  background: #d8d0c4;
  cursor: not-allowed;
}

/* ---------- Modals ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(43, 33, 64, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}

.modal {
  background: var(--parchment);
  border-radius: var(--radius-lg);
  padding: 24px;
  max-width: 420px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
}

.modal h2 {
  font-family: var(--font-display);
  margin: 0 0 6px;
}

.modal input,
.modal textarea {
  width: 100%;
  padding: 12px;
  border: 2px solid var(--line);
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: 1rem;
  margin-top: 10px;
  background: white;
  color: var(--ink);
}

.modal-error {
  color: var(--coral-dark);
  font-weight: 700;
  margin-top: 8px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.ghost-btn {
  background: transparent;
  border: 2px solid var(--line);
  color: var(--ink);
  padding: 10px 16px;
  border-radius: var(--radius-md);
  font-weight: 700;
}

.admin-modal { max-width: 560px; }

.admin-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.admin-tabs {
  display: flex;
  gap: 6px;
  margin: 12px 0;
}

.admin-tab {
  flex: 1;
  background: white;
  border: 2px solid var(--line);
  border-radius: var(--radius-md);
  padding: 8px;
  font-weight: 700;
  font-size: 0.85rem;
}

.admin-tab.active {
  background: var(--ink);
  color: var(--parchment);
  border-color: var(--ink);
}

.hint {
  font-size: 0.85rem;
  color: #574a6b;
}

.admin-form-row {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr auto;
  gap: 8px;
  align-items: start;
}

.admin-form-row input { margin-top: 0; }
.admin-form-row .claim-btn { flex: none; padding: 12px 16px; }

.admin-msg {
  font-weight: 700;
  min-height: 1.2em;
  color: var(--sage);
}

.admin-list {
  margin-top: 8px;
  max-height: 220px;
  overflow-y: auto;
  border: 2px solid var(--line);
  border-radius: var(--radius-md);
}

.admin-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  font-size: 0.9rem;
}

.admin-row:last-child { border-bottom: none; }

.admin-row .row-label {
  display: flex;
  gap: 6px;
  align-items: center;
  flex: 1;
}

.admin-row .row-tag {
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--parchment-dark);
}

.admin-row.done .row-label { opacity: 0.5; text-decoration: line-through; }

.mini-btn {
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 0.8rem;
  font-weight: 700;
}

/* ---------- Confetti ---------- */

#confettiLayer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 100;
  overflow: hidden;
}

.confetti-piece {
  position: absolute;
  top: -20px;
  width: 8px;
  height: 14px;
  opacity: 0.9;
  animation: confettiFall linear forwards;
}

@keyframes confettiFall {
  to {
    transform: translateY(110vh) rotate(540deg);
    opacity: 0.3;
  }
}
