:root {
  /* Palette: only these two solids; use rgba(var(--*-rgb), α) for transparency */
  --light: #ece9de;
  --dark: #4a0214;
  --light-rgb: 236, 233, 222;
  --dark-rgb: 74, 2, 20;
  --shadow: rgba(var(--dark-rgb), 0.35);
  --radius: 1.25rem;
  --font: "Cairo", system-ui, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
}

body.page-body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font);
  color: var(--light);
  background: var(--dark);
  position: relative;
  overflow-x: hidden;
  padding-bottom: calc(5.25rem + env(safe-area-inset-bottom, 0));
}

.bg-gradient {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 85% 55% at 20% 15%, rgba(var(--light-rgb), 0.08), transparent 55%),
    radial-gradient(ellipse 70% 50% at 85% 30%, rgba(var(--dark-rgb), 0.5), transparent),
    radial-gradient(ellipse 60% 45% at 50% 100%, rgba(var(--light-rgb), 0.04), transparent),
    linear-gradient(168deg, var(--dark) 0%, rgba(var(--dark-rgb), 0.92) 55%, var(--dark) 100%);
  z-index: -2;
}

/* Fixed bottom bar (replaces top header) */
.global-toolbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 900;
  padding: 0.65rem 1rem calc(0.65rem + env(safe-area-inset-bottom, 0));
  background: linear-gradient(0deg, rgba(var(--dark-rgb), 0.98), rgba(var(--dark-rgb), 0.9));
  border-top: 1px solid rgba(var(--light-rgb), 0.35);
  backdrop-filter: blur(12px);
  box-shadow: 0 -8px 32px var(--shadow);
}

.global-toolbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.5rem 0.75rem;
}

.btn-toolbar {
  padding: 0.55rem 1.15rem;
  font-size: 0.9rem;
  border-radius: 999px;
}

.home-centered {
  min-height: calc(100vh - 5.25rem - 3.5rem);
  min-height: calc(100dvh - 5.25rem - 3.5rem);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.25rem;
  padding: 1.5rem 1rem 2rem;
  text-align: center;
}

/* No solid fill — same .bg-gradient as rest of page (solid --dark looked darker than gradient) */
.home-brand {
  margin: 0;
  max-width: min(92vw, 440px);
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background: transparent;
  padding: 0.35rem 0;
  border: none;
  border-radius: 0;
  box-shadow: none;
}

.home-brand img {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: min(32vh, 200px);
  object-fit: contain;
  background: transparent;
}

.home-centered .hero-title {
  margin-bottom: 0;
}

.home-centered .hero-sub {
  margin-top: 0;
  max-width: 36rem;
}

.home-centered .game-grid {
  margin-top: 0.5rem;
  width: 100%;
  max-width: 900px;
}

/* Centered logo — transparent so page gradient matches (no darker strip) */
.game-page-logo {
  display: flex;
  justify-content: center;
  margin: 0 auto 1rem;
  max-width: min(92vw, 440px);
  background: transparent;
  padding: 0.35rem 0;
  border: none;
  border-radius: 0;
  box-shadow: none;
}

.game-page-logo img {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: min(26vh, 170px);
  object-fit: contain;
  background: transparent;
}

.main-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.65rem 1.35rem;
  border-radius: 999px;
  font-family: var(--font);
  font-weight: 700;
  font-size: 0.95rem;
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.2s, box-shadow 0.2s, background 0.2s;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--dark);
  color: var(--light);
  box-shadow: 0 6px 24px rgba(var(--dark-rgb), 0.45);
}

.btn-primary:hover {
  box-shadow: 0 8px 28px rgba(var(--dark-rgb), 0.55);
}

/* Spin wheel CTA — high contrast on dark page */
.btn-spin-wheel {
  background: linear-gradient(180deg, #ffb703 0%, #fb8500 100%);
  color: #1a0a0a;
  font-size: 1.05rem;
  padding: 0.85rem 1.75rem;
  border: 2px solid rgba(255, 255, 255, 0.55);
  box-shadow:
    0 4px 0 rgba(0, 0, 0, 0.2),
    0 12px 32px rgba(251, 133, 0, 0.45);
}

.btn-spin-wheel:hover:not(:disabled) {
  background: linear-gradient(180deg, #ffc933 0%, #ff9500 100%);
  box-shadow:
    0 4px 0 rgba(0, 0, 0, 0.18),
    0 14px 36px rgba(251, 133, 0, 0.55);
}

.btn-spin-wheel:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  box-shadow: none;
}

.btn-secondary {
  background: rgba(var(--light-rgb), 0.12);
  color: var(--light);
  border: 1px solid rgba(var(--light-rgb), 0.35);
}

.btn-ghost {
  background: rgba(var(--light-rgb), 0.08);
  color: var(--light);
  border: 1px solid rgba(var(--light-rgb), 0.22);
}

.btn-ghost:hover {
  background: rgba(var(--light-rgb), 0.14);
}

/* Cards — light panel on dark page */
.card {
  background:
    linear-gradient(165deg, rgba(var(--light-rgb), 0.45) 0%, transparent 42%),
    var(--light);
  border: 1px solid rgba(var(--dark-rgb), 0.15);
  border-radius: var(--radius);
  padding: 1.75rem;
  box-shadow:
    0 2px 0 rgba(var(--light-rgb), 0.5) inset,
    0 16px 40px rgba(var(--dark-rgb), 0.2);
  color: var(--dark);
}

.card h1,
.card h2 {
  margin-top: 0;
  color: var(--dark);
}

.card .form-control {
  background: var(--light);
  color: var(--dark);
  border: 1px solid rgba(var(--dark-rgb), 0.22);
}

.card .form-control::placeholder {
  color: rgba(var(--dark-rgb), 0.5);
}

/* Home tiles */
.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
  margin-top: 2rem;
}

.game-tile {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius);
  padding: 2rem 1.75rem;
  min-height: 220px;
  text-decoration: none;
  color: var(--light);
  background: linear-gradient(145deg, rgba(var(--dark-rgb), 0.95), var(--dark));
  border: 1px solid rgba(var(--light-rgb), 0.25);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.game-tile:hover {
  transform: translateY(-6px);
  box-shadow: 0 20px 50px var(--shadow);
}

.game-tile h2 {
  margin: 0 0 0.5rem;
  font-size: 1.5rem;
  color: var(--light);
}

.game-tile p {
  margin: 0;
  opacity: 0.9;
  line-height: 1.6;
}

.game-tile .tile-icon {
  position: absolute;
  top: 1.25rem;
  left: 1.25rem;
  font-size: 2.5rem;
  opacity: 0.35;
}

/* Forms */
.form-group {
  margin-bottom: 1.15rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.35rem;
  font-weight: 600;
  font-size: 0.9rem;
}

.form-control {
  width: 100%;
  padding: 0.75rem 1rem;
  border-radius: 0.75rem;
  border: 1px solid rgba(var(--light-rgb), 0.25);
  background: rgba(var(--light-rgb), 0.08);
  color: var(--light);
  font-family: var(--font);
  font-size: 1rem;
}

.form-control:focus {
  outline: 2px solid var(--light);
  outline-offset: 2px;
}

.form-errors {
  color: var(--dark);
  font-weight: 700;
  font-size: 0.9rem;
  margin-top: 0.25rem;
}

/* Scratch area */
.scratch-wrap {
  max-width: min(94vw, 520px);
  width: 100%;
  margin: 1.25rem auto 2rem;
  position: relative;
}

.scratch-stage {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  /* Wider card; a bit taller than 4:3 for a roomier scratch surface */
  aspect-ratio: 3/2;
  border: 3px solid rgba(var(--dark-rgb), 0.35);
  touch-action: none;
  transition: border-color 0.25s, box-shadow 0.35s ease;
  box-shadow:
    0 2px 4px rgba(var(--dark-rgb), 0.14),
    0 8px 24px rgba(var(--dark-rgb), 0.2),
    0 20px 48px rgba(var(--dark-rgb), 0.26),
    0 32px 64px rgba(var(--dark-rgb), 0.18),
    inset 0 1px 0 rgba(var(--light-rgb), 0.35);
}

.scratch-stage.scratch-scratching {
  border-color: var(--light);
  box-shadow:
    0 2px 8px rgba(var(--dark-rgb), 0.16),
    0 12px 32px rgba(var(--dark-rgb), 0.24),
    0 24px 56px rgba(var(--dark-rgb), 0.22),
    0 0 0 2px rgba(var(--light-rgb), 0.35),
    0 0 28px rgba(var(--light-rgb), 0.2);
  animation: none;
}

.scratch-loading {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  background: rgba(var(--dark-rgb), 0.88);
  color: var(--light);
  font-weight: 600;
}

.scratch-loading.is-show {
  display: flex;
}

.scratch-loading-spinner {
  position: relative;
  width: 48px;
  height: 48px;
  border: 4px solid rgba(var(--light-rgb), 0.2);
  border-top-color: #fff8e0;
  border-right-color: rgba(var(--light-rgb), 0.55);
  border-radius: 50%;
  animation: spin-load 0.5s linear infinite;
  box-shadow: 0 0 20px rgba(var(--light-rgb), 0.25);
}

@keyframes spin-load {
  to {
    transform: rotate(360deg);
  }
}

/* Scratch page — playful motion (respects reduced-motion below) */
.scratch-page {
  position: relative;
  padding: 0.25rem 0 0.5rem;
}

.scratch-page::before,
.scratch-page::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
  z-index: 0;
}

.scratch-page::before {
  width: min(260px, 52vw);
  height: min(260px, 52vw);
  top: -3.5rem;
  right: -4.5rem;
  background: radial-gradient(
    circle at 35% 40%,
    rgba(255, 236, 160, 0.35),
    rgba(var(--light-rgb), 0.2) 45%,
    transparent 68%
  );
  animation: scratch-deco-float 4.5s ease-in-out infinite;
  opacity: 0.75;
}

.scratch-page::after {
  width: min(200px, 42vw);
  height: min(200px, 42vw);
  bottom: -2.5rem;
  left: -3.5rem;
  background: radial-gradient(
    circle at 60% 55%,
    rgba(var(--light-rgb), 0.28),
    rgba(255, 200, 120, 0.12) 50%,
    transparent 72%
  );
  animation: scratch-deco-float 5.5s ease-in-out infinite reverse;
  opacity: 0.65;
}

.scratch-page > * {
  position: relative;
  z-index: 1;
}

@keyframes scratch-deco-float {
  0%,
  100% {
    transform: translate(0, 0) scale(1);
    opacity: 0.55;
  }
  33% {
    transform: translate(-16px, 14px) scale(1.14);
    opacity: 0.9;
  }
  66% {
    transform: translate(12px, -10px) scale(1.08);
    opacity: 0.7;
  }
}

@keyframes scratch-hero-in {
  from {
    opacity: 0;
    transform: translateY(18px) scale(0.94);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* “خربش واكسب” — entrance + soft glow pulse + shimmer (inner span; see scratch.html) */
@keyframes scratch-hero-line-in {
  from {
    opacity: 0;
    filter: blur(14px) brightness(1.65);
  }
  to {
    opacity: 1;
    filter: blur(0) drop-shadow(0 4px 22px rgba(var(--dark-rgb), 0.72))
      drop-shadow(0 0 32px rgba(var(--light-rgb), 0.45))
      drop-shadow(0 0 48px rgba(255, 220, 140, 0.25));
  }
}

@keyframes scratch-hero-line-pulse {
  0%,
  100% {
    transform: scale(1) rotate(0deg);
    text-shadow:
      0 3px 26px var(--shadow),
      0 0 14px rgba(var(--light-rgb), 0.22),
      0 0 36px rgba(255, 236, 180, 0.32);
  }
  15% {
    transform: scale(1.06) rotate(-2deg);
  }
  35% {
    transform: scale(1.18) rotate(1.8deg);
    text-shadow:
      0 5px 32px var(--shadow),
      0 0 44px rgba(var(--light-rgb), 0.65),
      0 0 72px rgba(255, 220, 140, 0.55),
      0 0 100px rgba(var(--light-rgb), 0.28);
  }
  55% {
    transform: scale(1.1) rotate(-1.2deg);
  }
  75% {
    transform: scale(1.14) rotate(1deg);
    text-shadow:
      0 4px 28px var(--shadow),
      0 0 38px rgba(var(--light-rgb), 0.48),
      0 0 64px rgba(255, 210, 120, 0.38);
  }
}

@keyframes scratch-hero-line-shimmer {
  0% {
    background-position: 165% 50%;
  }
  100% {
    background-position: -165% 50%;
  }
}

.scratch-hero-line {
  display: inline-block;
  background: linear-gradient(
    92deg,
    var(--light) 0%,
    #fff4d4 22%,
    #fff 45%,
    #fff 50%,
    #ffdc7a 52%,
    #fff8e8 65%,
    var(--light) 100%
  );
  background-size: 320% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
  animation:
    scratch-hero-line-in 0.28s cubic-bezier(0.18, 1.4, 0.28, 1) both,
    scratch-hero-line-pulse 0.62s cubic-bezier(0.42, 0, 0.58, 1) 0.12s infinite,
    scratch-hero-line-shimmer 0.95s linear 0.08s infinite;
}

.scratch-wrap-animate {
  animation: scratch-hero-in 0.72s 0.08s cubic-bezier(0.175, 0.885, 0.32, 1.18) both;
}

@keyframes scratch-card-breathe {
  0%,
  100% {
    transform: translateY(0) scale(1);
    border-color: rgba(var(--dark-rgb), 0.55);
    box-shadow:
      0 4px 8px rgba(var(--dark-rgb), 0.18),
      0 12px 32px rgba(var(--dark-rgb), 0.26),
      0 24px 56px rgba(var(--dark-rgb), 0.28),
      0 40px 80px rgba(var(--dark-rgb), 0.22),
      0 0 0 2px rgba(var(--light-rgb), 0.35),
      0 0 28px rgba(var(--light-rgb), 0.22),
      inset 0 1px 0 rgba(var(--light-rgb), 0.45),
      inset 0 0 48px rgba(var(--dark-rgb), 0.06);
  }
  50% {
    transform: translateY(-10px) scale(1.02);
    border-color: rgba(255, 236, 180, 0.55);
    box-shadow:
      0 8px 16px rgba(var(--dark-rgb), 0.2),
      0 18px 44px rgba(var(--dark-rgb), 0.3),
      0 32px 72px rgba(var(--dark-rgb), 0.32),
      0 48px 96px rgba(var(--dark-rgb), 0.24),
      0 0 0 4px rgba(var(--light-rgb), 0.55),
      0 0 48px rgba(var(--light-rgb), 0.42),
      0 0 80px rgba(255, 210, 120, 0.22),
      inset 0 1px 0 rgba(var(--light-rgb), 0.55),
      inset 0 0 56px rgba(var(--dark-rgb), 0.08);
  }
}

.scratch-stage.scratch-ready {
  animation: scratch-card-breathe 2.35s cubic-bezier(0.45, 0, 0.55, 1) infinite;
}

.scratch-loading-spinner::after {
  content: "";
  position: absolute;
  inset: -12px;
  border-radius: 50%;
  border: 2px solid transparent;
  border-right-color: rgba(255, 236, 160, 0.55);
  border-bottom-color: rgba(var(--light-rgb), 0.2);
  animation: spin-load 0.85s linear infinite reverse;
}

.scratch-actions .btn.btn-secondary:not(:disabled) {
  animation: scratch-btn-ready-pulse 1.15s ease-in-out infinite;
}

.scratch-actions .btn.scratch-btn--pop {
  animation:
    scratch-btn-ready-pulse 1.15s ease-in-out infinite,
    scratch-btn-pop 0.55s cubic-bezier(0.34, 1.6, 0.64, 1) both;
}

@keyframes scratch-btn-ready-pulse {
  0%,
  100% {
    box-shadow:
      0 2px 4px rgba(var(--dark-rgb), 0.14),
      0 8px 20px rgba(var(--dark-rgb), 0.22),
      0 0 0 rgba(255, 236, 160, 0);
  }
  50% {
    box-shadow:
      0 4px 10px rgba(var(--dark-rgb), 0.18),
      0 12px 28px rgba(var(--dark-rgb), 0.28),
      0 0 22px rgba(255, 236, 160, 0.45),
      0 0 40px rgba(var(--light-rgb), 0.2);
  }
}

@keyframes scratch-btn-pop {
  0% {
    transform: scale(1) translateY(0);
  }
  40% {
    transform: scale(1.14) translateY(-3px);
  }
  100% {
    transform: scale(1) translateY(0);
  }
}

.scratch-modal-img--in {
  animation: scratch-modal-img-in 0.48s 0.08s cubic-bezier(0.2, 1.5, 0.35, 1) both;
}

@keyframes scratch-modal-img-in {
  from {
    opacity: 0;
    transform: scale(0.45) rotate(-10deg);
    filter: blur(4px);
  }
  to {
    opacity: 1;
    transform: scale(1) rotate(0deg);
    filter: blur(0);
  }
}

.scratch-page--won .scratch-wrap-animate {
  animation: scratch-win-nudge 0.75s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

@keyframes scratch-win-nudge {
  0%,
  100% {
    transform: translateY(0) scale(1) rotate(0deg);
  }
  15% {
    transform: translateY(-10px) scale(1.06) rotate(-2deg);
  }
  30% {
    transform: translateY(4px) scale(1.04) rotate(2deg);
  }
  45% {
    transform: translateY(-6px) scale(1.05) rotate(-1deg);
  }
  60% {
    transform: translateY(3px) scale(1.02) rotate(1deg);
  }
}

#celebration-modal.modal-overlay.open .modal-box h2 {
  animation: scratch-modal-title 0.45s 0.04s cubic-bezier(0.22, 1.55, 0.36, 1) both;
}

@keyframes scratch-modal-title {
  from {
    opacity: 0;
    transform: scale(0.35) rotate(-6deg);
    text-shadow: none;
  }
  70% {
    transform: scale(1.08) rotate(2deg);
    text-shadow: 0 0 24px rgba(var(--light-rgb), 0.4);
  }
  to {
    opacity: 1;
    transform: scale(1) rotate(0deg);
    text-shadow: 0 2px 16px rgba(var(--dark-rgb), 0.2);
  }
}

/* Lighter motion for phones: less scale/offset (fewer layout jumps), still readable */
@keyframes scratch-deco-float-mobile {
  0%,
  100% {
    transform: translate(0, 0) scale(1);
    opacity: 0.48;
  }
  50% {
    transform: translate(-8px, 8px) scale(1.06);
    opacity: 0.72;
  }
}

@keyframes scratch-hero-line-pulse-mobile {
  0%,
  100% {
    transform: scale(1) rotate(0deg);
    text-shadow:
      0 2px 20px var(--shadow),
      0 0 12px rgba(var(--light-rgb), 0.18),
      0 0 28px rgba(255, 236, 180, 0.22);
  }
  50% {
    transform: scale(1.11) rotate(1.1deg);
    text-shadow:
      0 4px 26px var(--shadow),
      0 0 34px rgba(var(--light-rgb), 0.45),
      0 0 56px rgba(255, 220, 140, 0.35);
  }
}

@keyframes scratch-hero-line-shimmer-mobile {
  0% {
    background-position: 130% 50%;
  }
  100% {
    background-position: -130% 50%;
  }
}

@keyframes scratch-card-breathe-mobile {
  0%,
  100% {
    transform: translateY(0) scale(1);
    border-color: rgba(var(--dark-rgb), 0.55);
    box-shadow:
      0 2px 6px rgba(var(--dark-rgb), 0.16),
      0 8px 24px rgba(var(--dark-rgb), 0.22),
      0 16px 40px rgba(var(--dark-rgb), 0.24),
      0 0 0 2px rgba(var(--light-rgb), 0.3),
      0 0 20px rgba(var(--light-rgb), 0.16),
      inset 0 1px 0 rgba(var(--light-rgb), 0.42),
      inset 0 0 36px rgba(var(--dark-rgb), 0.05);
  }
  50% {
    transform: translateY(-6px) scale(1.008);
    border-color: rgba(255, 236, 180, 0.48);
    box-shadow:
      0 5px 12px rgba(var(--dark-rgb), 0.18),
      0 12px 32px rgba(var(--dark-rgb), 0.26),
      0 22px 48px rgba(var(--dark-rgb), 0.28),
      0 0 0 3px rgba(var(--light-rgb), 0.42),
      0 0 30px rgba(var(--light-rgb), 0.3),
      inset 0 1px 0 rgba(var(--light-rgb), 0.48),
      inset 0 0 44px rgba(var(--dark-rgb), 0.06);
  }
}

@keyframes scratch-win-nudge-mobile {
  0%,
  100% {
    transform: translateY(0) scale(1) rotate(0deg);
  }
  25% {
    transform: translateY(-5px) scale(1.03) rotate(-1deg);
  }
  50% {
    transform: translateY(3px) scale(1.02) rotate(0.8deg);
  }
  75% {
    transform: translateY(-3px) scale(1.02) rotate(-0.5deg);
  }
}

.scratch-stage.scratch-ready canvas {
  cursor: grab;
}

.scratch-stage.scratch-scratching canvas {
  cursor: grabbing;
}

@media (prefers-reduced-motion: reduce) {
  .scratch-page::before,
  .scratch-page::after,
  .scratch-hero-animate,
  .scratch-hero-line,
  .scratch-wrap-animate,
  .scratch-stage.scratch-ready,
  .scratch-loading-spinner,
  .scratch-loading-spinner::after,
  .scratch-actions .btn.btn-secondary:not(:disabled),
  .scratch-actions .btn.scratch-btn--pop,
  .scratch-modal-img--in,
  .scratch-page--won .scratch-wrap-animate,
  #celebration-modal.modal-overlay.open .modal-box h2 {
    animation: none !important;
  }

  .scratch-page::before,
  .scratch-page::after {
    transform: none;
  }

  .scratch-hero-line {
    color: var(--light);
    -webkit-text-fill-color: var(--light);
    background: none;
    filter: none;
    transform: none;
    text-shadow: 0 2px 20px var(--shadow);
  }
}

/* Scratch page — phones / narrow viewports */
@media (max-width: 639.98px) {
  .scratch-page {
    overflow-x: clip;
    max-width: 100%;
    padding-left: env(safe-area-inset-left, 0);
    padding-right: env(safe-area-inset-right, 0);
  }

  .scratch-wrap {
    max-width: 100%;
    width: min(100%, 36rem);
    margin-top: 0.85rem;
    margin-bottom: 1.5rem;
    padding-left: max(0.25rem, env(safe-area-inset-left, 0px));
    padding-right: max(0.25rem, env(safe-area-inset-right, 0px));
  }

  .scratch-stage {
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
  }

  .scratch-page::before {
    width: min(150px, 58vw);
    height: min(150px, 58vw);
    top: -1.75rem;
    right: -1.75rem;
  }

  .scratch-page::after {
    width: min(120px, 46vw);
    height: min(120px, 46vw);
    bottom: -1.25rem;
    left: -1.75rem;
  }

  /* Scroll the overlay (not only the card): centered tall modals were clipped on iOS */
  .modal-overlay {
    align-items: flex-start;
    justify-content: center;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding-top: max(1rem, env(safe-area-inset-top, 0px));
    padding-left: max(0.75rem, env(safe-area-inset-left));
    padding-right: max(0.75rem, env(safe-area-inset-right));
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
  }

  .modal-box {
    padding: 1.5rem 1rem 1.25rem;
    margin-top: auto;
    margin-bottom: auto;
    flex-shrink: 0;
    max-height: min(
      85vh,
      calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 2rem)
    );
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .scratch-actions .btn {
    min-height: 48px;
    min-width: min(100%, 220px);
  }
}

@media (max-width: 639.98px) and (prefers-reduced-motion: no-preference) {
  .scratch-page::before {
    animation: scratch-deco-float-mobile 5.5s ease-in-out infinite;
  }

  .scratch-page::after {
    animation: scratch-deco-float-mobile 6.5s ease-in-out infinite reverse;
  }

  .scratch-hero-line {
    animation:
      scratch-hero-line-in 0.28s cubic-bezier(0.18, 1.4, 0.28, 1) both,
      scratch-hero-line-pulse-mobile 0.88s ease-in-out 0.14s infinite,
      scratch-hero-line-shimmer-mobile 1.12s linear 0.08s infinite;
    max-width: 100%;
  }

  .scratch-stage.scratch-ready {
    animation: scratch-card-breathe-mobile 2.65s ease-in-out infinite;
  }

  .scratch-page--won .scratch-wrap-animate {
    animation: scratch-win-nudge-mobile 0.7s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
  }
}

.scratch-actions {
  text-align: center;
  margin-top: 1.25rem;
}

.scratch-actions .btn {
  min-width: 200px;
  box-shadow:
    0 2px 4px rgba(var(--dark-rgb), 0.12),
    0 6px 16px rgba(var(--dark-rgb), 0.18);
  transition: transform 0.2s, box-shadow 0.2s;
}

.scratch-actions .btn:not(:disabled):hover {
  box-shadow:
    0 4px 8px rgba(var(--dark-rgb), 0.14),
    0 10px 24px rgba(var(--dark-rgb), 0.22);
}

.scratch-actions .btn:not(:disabled):active {
  box-shadow: 0 2px 6px rgba(var(--dark-rgb), 0.16);
}

/* Canvas must sit above the prize layer so the silver coat covers text and image until scratched */
.scratch-stage canvas {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

.scratch-stage canvas.is-idle {
  visibility: hidden;
  pointer-events: none;
}

.scratch-prize-layer {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  text-align: center;
  background: linear-gradient(180deg, var(--light), var(--light));
  color: var(--dark);
  z-index: 0;
}

.scratch-prize-layer img {
  max-width: 70%;
  max-height: 45%;
  object-fit: contain;
  border-radius: 0.5rem;
}

/* Prize image stays in the layer under the canvas (canvas is opaque); avoid display:none/hidden so all browsers fetch the URL */
.prize-img-under-scratch.is-empty {
  display: none;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(var(--dark-rgb), 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-box {
  background: linear-gradient(165deg, var(--light), var(--light));
  color: var(--dark);
  border-radius: var(--radius);
  padding: 2.75rem 2.5rem;
  max-width: min(94vw, 580px);
  width: 100%;
  text-align: center;
  transform: scale(0.85);
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  border: 3px solid var(--dark);
  box-shadow: 0 24px 80px var(--shadow);
}

.modal-overlay.open .modal-box {
  transform: scale(1);
}

.modal-box h2 {
  color: var(--dark);
  margin-top: 0;
  font-size: clamp(1.75rem, 5vw, 2.35rem);
  margin-bottom: 0.75rem;
}

.modal-box p {
  font-size: clamp(1.15rem, 3.5vw, 1.45rem);
  font-weight: 700;
  line-height: 1.45;
  margin: 0.5rem 0 0;
}

.modal-box img {
  max-width: min(280px, 72vw) !important;
  width: auto;
  height: auto;
}

/* Prize / winning modals: never taller than viewport; tall images scale + scroll */
#celebration-modal .modal-box,
#result-modal .modal-box {
  max-height: min(88vh, 100dvh - 2.5rem);
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  align-items: center;
}

#celebration-modal #modal-prize-img,
#result-modal #modal-result-img {
  max-width: min(280px, 88vw) !important;
  max-height: min(50vh, 400px) !important;
  width: auto !important;
  height: auto !important;
  object-fit: contain;
  margin: 1rem auto !important;
  border-radius: 0.5rem;
  flex-shrink: 1;
  min-height: 0;
}

@media (max-width: 639.98px) {
  #celebration-modal .modal-box,
  #result-modal .modal-box {
    max-height: min(
      85vh,
      calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 2.5rem)
    );
  }

  #celebration-modal #modal-prize-img,
  #result-modal #modal-result-img {
    max-height: min(36vh, 240px) !important;
  }
}

.confetti {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 999;
}

/* Wheel */
.wheel-layout {
  display: grid;
  gap: 2rem;
  align-items: start;
}

@media (min-width: 900px) {
  .wheel-layout {
    grid-template-columns: 1fr 320px;
  }
}

.wheel-box {
  position: relative;
  width: min(100%, 420px);
  margin: 0 auto;
  aspect-ratio: 1;
}

.wheel-box canvas {
  width: 100%;
  height: auto;
  display: block;
  filter: drop-shadow(0 16px 40px var(--shadow));
  cursor: grab;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.wheel-box.is-wheel-dragging canvas {
  cursor: grabbing;
}

.wheel-pointer {
  position: absolute;
  top: -8px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 18px solid transparent;
  border-right: 18px solid transparent;
  border-top: 32px solid var(--light);
  z-index: 2;
  filter: drop-shadow(0 4px 6px rgba(var(--dark-rgb), 0.4));
}

.table-wrap {
  overflow-x: auto;
  border-radius: 0.75rem;
  border: 1px solid rgba(var(--dark-rgb), 0.18);
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

table.data-table th,
table.data-table td {
  padding: 0.65rem 0.85rem;
  text-align: right;
  border-bottom: 1px solid rgba(var(--dark-rgb), 0.12);
}

table.data-table th {
  background: rgba(var(--dark-rgb), 0.08);
  color: var(--dark);
  font-weight: 700;
}

table.data-table td {
  color: inherit;
}

table.data-table tr:hover td {
  background: rgba(var(--dark-rgb), 0.04);
}

.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
}

.badge-wait {
  background: rgba(var(--dark-rgb), 0.12);
  color: var(--dark);
}

.badge-done {
  background: rgba(var(--light-rgb), 0.35);
  color: var(--dark);
}

.hero-title {
  font-size: clamp(1.75rem, 5vw, 2.5rem);
  font-weight: 800;
  text-align: center;
  margin: 1rem 0 0.5rem;
  text-shadow: 0 2px 20px var(--shadow);
}

.hero-sub {
  text-align: center;
  opacity: 0.88;
  max-width: 36rem;
  margin: 0 auto;
  line-height: 1.7;
}

.link-inline {
  color: var(--light);
  text-decoration: underline;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
  margin: 1.5rem 0;
}

.stat-card {
  background: rgba(var(--light-rgb), 0.06);
  border-radius: 0.75rem;
  padding: 1rem;
  text-align: center;
  border: 1px solid rgba(var(--light-rgb), 0.2);
}

.stat-card strong {
  display: block;
  font-size: 1.75rem;
  color: var(--light);
}

.op-queue-live-hint {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  background: rgba(var(--light-rgb), 0.12);
  border: 1px solid rgba(var(--light-rgb), 0.28);
  color: var(--light);
  opacity: 0.95;
}

.op-queue-pending-flash {
  animation: opQueueFlash 0.75s ease-out 1;
}

@keyframes opQueueFlash {
  0% {
    box-shadow: 0 0 0 0 rgba(var(--light-rgb), 0.35);
  }
  100% {
    box-shadow: 0 0 0 14px transparent;
  }
}
