/* Scratch-off modal — below fixed navbar (72px), same idea as profiler_modal / card modal */

/* Scroll only inside .modal-body, not Bootstrap’s full-screen .modal (avoids background scroll / pull-to-refresh chaining) */
#scratchOffModal.modal {
  overflow-x: hidden;
  overflow-y: hidden;
  overscroll-behavior: none;
}

#scratchOffModal .modal-dialog.scratch-off-modal__dialog {
  --scratch-off-modal-top-offset: calc(72px + env(safe-area-inset-top));
  margin-top: calc(var(--scratch-off-modal-top-offset) + 0.5rem);
  margin-bottom: 0.5rem;
  margin-left: auto;
  margin-right: auto;
  max-width: min(42rem, calc(100vw - 1.5rem));
}

#scratchOffModal .modal-dialog.scratch-off-modal__dialog.modal-dialog-centered {
  align-items: flex-start;
  min-height: auto;
}

#scratchOffModal .modal-content.scratch-off-modal__content {
  max-height: calc(100dvh - var(--scratch-off-modal-top-offset) - 1.5rem);
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg-secondary, var(--bs-modal-bg));
  border: 1px solid var(--border-primary, rgba(255, 255, 255, 0.12));
  color: var(--text-primary, inherit);
  box-shadow: var(--shadow-xl, none);
}

#scratchOffModal .scratch-off-modal__header {
  flex-shrink: 0;
  padding-right: 3rem;
  z-index: 2;
  background: var(--bg-tertiary, var(--bs-modal-header-bg, var(--bs-modal-bg)));
  border-bottom: 1px solid var(--border-primary, rgba(255, 255, 255, 0.12));
  color: var(--text-primary, inherit);
}

#scratchOffModal .scratch-off-modal__header .modal-title {
  color: var(--text-primary, inherit);
}

#scratchOffModal .scratch-off-modal__header-meta {
  max-width: min(62vw, 26rem);
}

#scratchOffModal .scratch-off-modal__session-totals {
  color: var(--text-primary, inherit);
}

#scratchOffModal .scratch-off-modal__close {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  right: 0.75rem;
  margin: 0;
  filter: invert(1);
  opacity: 0.75;
}

#scratchOffModal .scratch-off-modal__close:hover {
  opacity: 1;
}

#scratchOffModal .scratch-off-modal__body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  background: var(--bg-secondary, transparent);
  color: var(--text-primary, inherit);
  padding-bottom: 0.25rem;
}

#scratchOffModal .scratch-off-modal__auto-start {
  position: sticky;
  bottom: 0;
  z-index: 12;
  display: flex;
  justify-content: flex-end;
  width: fit-content;
  max-width: 100%;
  margin-top: 0.75rem;
  margin-left: auto;
  margin-right: 0;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm, 0.375rem);
  background: color-mix(in srgb, var(--bg-elevated, #2f2f2f) 92%, transparent);
  border: 1px solid var(--border-primary, rgba(255, 255, 255, 0.12));
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.28);
  pointer-events: auto;
}

#scratchOffModal .scratch-off-modal__auto-start-label {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
  cursor: pointer;
  user-select: none;
}

#scratchOffModal .scratch-off-modal__auto-start-input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

#scratchOffModal .scratch-off-modal__auto-start-box {
  flex: 0 0 auto;
  width: 1.125rem;
  height: 1.125rem;
  border: 2px solid var(--accent-cyan, #06b6d4);
  border-radius: 0.3rem;
  background: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

#scratchOffModal .scratch-off-modal__auto-start-input:checked + .scratch-off-modal__auto-start-box {
  background: var(--accent-cyan, #06b6d4);
  border-color: var(--accent-cyan, #06b6d4);
}

#scratchOffModal .scratch-off-modal__auto-start-input:checked + .scratch-off-modal__auto-start-box::after {
  content: "";
  width: 0.3rem;
  height: 0.55rem;
  margin-top: -0.1rem;
  border: solid var(--bg-secondary, #1f1f1f);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

#scratchOffModal .scratch-off-modal__auto-start-input:focus-visible + .scratch-off-modal__auto-start-box {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-cyan, #06b6d4) 35%, transparent);
}

#scratchOffModal .scratch-off-modal__auto-start-text {
  color: var(--accent-cyan, #06b6d4);
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
}

.scratch-off-modal__body {
  /* Bootstrap .row uses negative margins; keep paint inside rounded modal */
  min-width: 0;
}

.scratch-off-modal__frame {
  min-width: 0;
}

/* Extra breathing room when the panel is inside the modal (full-page uses .container) */
.scratch-off-modal .scratch-off-panel {
  padding-left: 0.25rem;
  padding-right: 0.25rem;
}

.scratch-off-modal .scratch-off-header {
  padding-right: 0.25rem;
}

/* Scratch-off play page */
.scratch-off-page .scratch-off__cell {
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.06), rgba(0, 0, 0, 0.08));
  min-height: 7rem;
  transition: box-shadow var(--transition-base), border-color var(--transition-base);
}

/* Revealed cell (outcome pending or neutral) — subtle ring */
.scratch-off__cell.scratch-off__cell--done {
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.12);
  border-color: var(--border-primary, rgba(255, 255, 255, 0.18)) !important;
}

.scratch-off__cell--done .scratch-off__canvas {
  opacity: 0.48;
  transition: opacity 0.2s ease;
}

.scratch-off__prize {
  z-index: 0;
  pointer-events: none;
  color: var(--text-primary);
  font-size: clamp(1.85rem, 5vw, 2.35rem);
  line-height: 1.2;
  text-align: center;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.65);
  max-width: 100%;
  padding: 0 0.25rem;
}

.scratch-off__claim-title {
  font-weight: 600;
}

.scratch-off__claim-total {
  font-size: inherit;
  font-weight: 700;
  opacity: 0.95;
}

.scratch-off__grid-wrap {
  min-height: 0;
}

/* Unstarted ticket: grid stays sharp; matte veil handles dimming */
.scratch-off--awaiting-start .scratch-off__grid {
  pointer-events: none;
  user-select: none;
}

.scratch-off__start-gate {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  border-radius: var(--bs-border-radius, 0.375rem);
  isolation: isolate;
}

/* Flat matte cover — same palette as modals/cards, no blur or highlight sheen */
.scratch-off__start-gate::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: color-mix(in srgb, var(--bg-secondary) 78%, transparent);
  border: 1px solid var(--border-primary, rgba(255, 255, 255, 0.08));
}

.scratch-off__start-gate .btn {
  position: relative;
  z-index: 1;
  min-width: 11rem;
  box-shadow: var(--shadow-md, 0 4px 12px rgba(0, 0, 0, 0.35));
}

.scratch-off__start-gate[hidden] {
  display: none !important;
}

.scratch-off--awaiting-start .scratch-off__canvas {
  pointer-events: none;
}

.scratch-off__canvas {
  position: relative;
  z-index: 1;
  display: block;
  touch-action: none;
  pointer-events: auto;
  /* Do not set background-color: the silver layer is drawn in JS. A CSS background would sit
     under the bitmap and stay visible when destination-out clears pixels — hiding the prize. */
  background-color: transparent;
}

/* Scrollable modal body can steal touch scrolling; keep scratch gestures on the cells */
.scratch-off-modal .scratch-off__cell {
  touch-action: none;
}

/* Lightweight “up next” row — no scratch canvas until this play is first in the stack */
.scratch-off-stack-item--queued {
  background: var(--bg-tertiary, rgba(0, 0, 0, 0.2));
  border-style: dashed !important;
  border-color: var(--border-primary, rgba(255, 255, 255, 0.15)) !important;
  color: var(--text-secondary, var(--bs-secondary-color));
}

.scratch-off-stack-item--queued .text-body-secondary {
  color: var(--text-primary, inherit) !important;
}

.scratch-off-stack__session {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* Roulette Spinner: colored cell backgrounds show through foil while scratching */
.scratch-off--roulette-spinners .scratch-off__cell--has-foil-art {
  min-height: 7rem;
}

.scratch-off--roulette-spinners .scratch-off__cell--has-foil-art > .scratch-off__canvas {
  position: absolute;
  inset: 0;
  height: 7rem !important;
  width: 100%;
}

.scratch-off--roulette-spinners .scratch-off__foil-art {
  z-index: 2;
}

.scratch-off--roulette-spinners .scratch-off__foil-main {
  z-index: 3;
}

.scratch-off--roulette-spinners .scratch-off__cell--spin .scratch-off__prize {
  font-size: clamp(1.85rem, 5vw, 2.35rem);
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.scratch-off--roulette-spinners .scratch-off__cell--spin {
  background: linear-gradient(145deg, rgba(250, 204, 21, 0.45), rgba(180, 130, 20, 0.35)) !important;
}

.scratch-off--roulette-spinners .scratch-off__cell--roulette-red {
  background: linear-gradient(145deg, rgba(220, 38, 38, 0.72), rgba(127, 29, 29, 0.85)) !important;
}

.scratch-off--roulette-spinners .scratch-off__cell--roulette-black {
  background: linear-gradient(145deg, rgba(55, 65, 81, 0.88), rgba(17, 24, 39, 0.95)) !important;
}

.scratch-off--roulette-spinners .scratch-off__cell--roulette-green {
  background: linear-gradient(145deg, rgba(22, 163, 74, 0.72), rgba(21, 128, 61, 0.88)) !important;
}

.scratch-off--roulette-spinners .scratch-off__cell--roulette-red .scratch-off__prize,
.scratch-off--roulette-spinners .scratch-off__cell--roulette-black .scratch-off__prize,
.scratch-off--roulette-spinners .scratch-off__cell--roulette-green .scratch-off__prize,
.scratch-off--roulette-spinners .scratch-off__cell--spin .scratch-off__prize {
  color: #fff;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.75);
}

/* Done ring uses each cell's color (not default cyan) */
.scratch-off--roulette-spinners .scratch-off__cell--spin.scratch-off__cell--done {
  box-shadow: 0 0 0 2px rgba(250, 204, 21, 0.55);
  border-color: rgba(250, 204, 21, 0.65) !important;
}

.scratch-off--roulette-spinners .scratch-off__cell--roulette-red.scratch-off__cell--done {
  box-shadow: 0 0 0 2px rgba(248, 113, 113, 0.55);
  border-color: rgba(248, 113, 113, 0.75) !important;
}

.scratch-off--roulette-spinners .scratch-off__cell--roulette-black.scratch-off__cell--done {
  box-shadow: 0 0 0 2px rgba(107, 114, 128, 0.55);
  border-color: rgba(75, 85, 99, 0.8) !important;
}

.scratch-off--roulette-spinners .scratch-off__cell--roulette-green.scratch-off__cell--done {
  box-shadow: 0 0 0 2px rgba(74, 222, 128, 0.55);
  border-color: rgba(74, 222, 128, 0.65) !important;
}

/* Confirmed winners — green ring + full-strength prize text */
.scratch-off .scratch-off__cell--payout-win.scratch-off__cell--done {
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.75);
  border-color: var(--success) !important;
}

.scratch-off__cell--payout-win.scratch-off__cell--done .scratch-off__prize {
  opacity: 1;
  filter: none;
}

/* Confirmed misses — faded coins / emojis (no theme-colored “win” ring) */
.scratch-off__cell--payout-miss.scratch-off__cell--done {
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08);
  border-color: var(--border-primary, rgba(255, 255, 255, 0.12)) !important;
}

.scratch-off__cell--payout-miss.scratch-off__cell--done .scratch-off__prize {
  opacity: 0.38;
  filter: grayscale(0.5);
  transition: opacity 0.2s ease, filter 0.2s ease;
}

.scratch-off--suit-match .scratch-off__cell--suit-hearts {
  background: linear-gradient(145deg, rgba(220, 38, 38, 0.35), rgba(127, 29, 29, 0.45)) !important;
}

.scratch-off--suit-match .scratch-off__cell--suit-diamonds {
  background: linear-gradient(145deg, rgba(220, 38, 38, 0.28), rgba(100, 20, 20, 0.4)) !important;
}

.scratch-off--suit-match .scratch-off__cell--suit-spades,
.scratch-off--suit-match .scratch-off__cell--suit-clubs {
  background: linear-gradient(145deg, rgba(55, 65, 81, 0.55), rgba(17, 24, 39, 0.7)) !important;
}

.scratch-off--suit-match .scratch-off__prize {
  color: #fff;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.75);
}

.scratch-off-stack-item--session-done {
  background: rgba(25, 135, 84, 0.09);
  border-color: rgba(25, 135, 84, 0.4) !important;
}

/* Finished ticket stays visible above the next scratcher; interaction disabled via pointer-events */
.scratch-off-stack-item--finished {
  background: rgba(25, 135, 84, 0.06);
  border-color: rgba(25, 135, 84, 0.35) !important;
  pointer-events: none;
}

.scratch-off-stack-item--finished .scratch-off__canvas {
  pointer-events: none;
}

.scratch-off-stack-item--outline {
  border-color: var(--border-primary, rgba(255, 255, 255, 0.18)) !important;
  background: var(--bg-tertiary, rgba(0, 0, 0, 0.08));
}

/* Placeholder scratcher: same 2×3 layout as playable, non-interactive foil cells */
.scratch-off-modal .scratch-off__cell--placeholder,
.scratch-off-page .scratch-off__cell--placeholder {
  touch-action: auto;
  pointer-events: none;
  min-height: 7rem;
  filter: grayscale(0.2);
  opacity: 0.88;
}

.scratch-off__placeholder-surface {
  height: 7rem;
  background: linear-gradient(145deg, rgba(196, 200, 208, 0.55), rgba(148, 154, 168, 0.45));
  background-image:
    repeating-linear-gradient(
      -32deg,
      rgba(255, 255, 255, 0.07),
      rgba(255, 255, 255, 0.07) 3px,
      transparent 3px,
      transparent 7px
    ),
    linear-gradient(145deg, rgba(196, 200, 208, 0.65), rgba(130, 136, 150, 0.5));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.scratch-off__placeholder-lock {
  opacity: 0.45;
  font-size: clamp(1.25rem, 4vw, 1.65rem);
  filter: grayscale(1);
}

.scratch-off--placeholder {
  pointer-events: none;
}

.scratch-off-stack-item--done {
  opacity: 0.9;
}

.scratch-off-stack-item--done .scratch-off__canvas {
  pointer-events: none;
}

/* Scratcher themes — foil tint via --scratch-off-foil-fill (read in scratch_off_controller.js).
 * Rarity tiers match collection_cards.css / card_modal.css (C gray, U silver, R gold, SR red, L purple). */

.scratch-off--theme-classic {
  --scratch-off-foil-fill: #8a9099;
  --scratch-off-rarity-accent: var(--text-tertiary, #6b7280);
}

.scratch-off--theme-classic .scratch-off__cell {
  background: linear-gradient(145deg, rgba(107, 114, 128, 0.22), rgba(55, 65, 81, 0.32)) !important;
}

.scratch-off--theme-uncommon {
  --scratch-off-foil-fill: #b8b8b8;
  --scratch-off-rarity-accent: #d4d4d4;
}

.scratch-off--theme-uncommon .scratch-off__cell {
  background: linear-gradient(145deg, rgba(212, 212, 212, 0.2), rgba(115, 115, 115, 0.3)) !important;
}

.scratch-off--theme-rare {
  --scratch-off-foil-fill: #c9a227;
  --scratch-off-rarity-accent: #ffd700;
}

.scratch-off--theme-rare .scratch-off__cell {
  background: linear-gradient(145deg, rgba(255, 215, 0, 0.22), rgba(161, 98, 7, 0.34)) !important;
}

.scratch-off--theme-super_rare {
  --scratch-off-foil-fill: #c45c5c;
  --scratch-off-rarity-accent: #ef4444;
}

.scratch-off--theme-super_rare .scratch-off__cell {
  background: linear-gradient(145deg, rgba(239, 68, 68, 0.24), rgba(127, 29, 29, 0.36)) !important;
}

.scratch-off--theme-legendary {
  --scratch-off-foil-fill: #9b6bd4;
  --scratch-off-rarity-accent: #a855f7;
}

.scratch-off--theme-legendary .scratch-off__cell {
  background: linear-gradient(145deg, rgba(168, 85, 247, 0.24), rgba(88, 28, 135, 0.36)) !important;
}

.scratch-off--theme-crash {
  --scratch-off-foil-fill: #c49078;
}

.scratch-off--theme-crash .scratch-off__cell {
  background: linear-gradient(145deg, rgba(239, 68, 68, 0.22), rgba(127, 29, 29, 0.38)) !important;
}

.scratch-off--theme-underwater {
  --scratch-off-foil-fill: #6eb8c4;
}

.scratch-off--theme-underwater .scratch-off__cell {
  background: linear-gradient(145deg, rgba(6, 182, 212, 0.2), rgba(14, 116, 144, 0.34)) !important;
}

.scratch-off--theme-roulette {
  --scratch-off-foil-fill: #b8a0c8;
}

.scratch-off--theme-pk {
  --scratch-off-foil-fill: #4a8f5c;
}

.scratch-off--theme-pk .scratch-off__cell {
  background: linear-gradient(145deg, rgba(16, 185, 129, 0.22), rgba(6, 78, 59, 0.38)) !important;
}

.scratch-off--pk-kamin .scratch-off__prize {
  color: #ecfdf5;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
}
