/* Challenge roulette (GAME_SPEC §4.14): popup, wheel, chances, and the ticket
   box in the clear result. Detective-office card (2026-10-19 design): blue frame
   with gold lines on cream, a hat on the corner, blue title plate with paws,
   gold rim with studs, gold paw hub. Only roulette classes are styled here.
   Surface tokens (--cs-*) live in css/contentScreens.css. */
:root {
  --roulette-coins-0: #ffd25a;
  --roulette-coins-1: #ffbf2e;
  --roulette-shards-0: #9fe07a;
  --roulette-shards-1: #7fd05a;
  --roulette-hints-0: #8ec9ff;
  --roulette-hints-1: #6db6ff;
  /* Jackpot slice (looks only): deep navy with gold edges, unlike every light slice,
     and a faint gold light inside its own angle. */
  --roulette-jackpot: #1f3f94;
  --roulette-jackpot-glow: rgba(255, 214, 90, 0.16);
  --roulette-blue: #1f63d6;
  --roulette-blue-deep: #0d43a8;
  --roulette-gold-line: #ffd34e;
  /* Big wheel, but short screens keep the buttons and the list close. */
  --roulette-size: clamp(196px, min(72vw, 40vh), 312px);
}

/* The popup scrolls as a whole on very short screens (the hat sits outside the card). */
#popup-roulette.popup-overlay {
  overflow-y: auto;
  padding-top: calc(48px + var(--safe-top));
}

.popup-card.popup-card--roulette {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: min(92vw, 420px);
  max-width: 420px;
  margin: auto;
  padding: 30px 14px 14px;
  border: 7px solid var(--roulette-blue);
  border-radius: 28px;
  background: linear-gradient(180deg, #fffdf6 0%, #fbf3dd 60%, #f6e8c6 100%);
  box-shadow: inset 0 0 0 3px var(--roulette-gold-line), 0 0 0 3px var(--roulette-gold-line), 0 4px 0 3px var(--roulette-blue-deep), 0 18px 38px rgba(0, 0, 0, 0.45);
  box-sizing: border-box;
}

/* Detective hat resting on the top-left corner (a picture, no taps). */
.roulette-hat {
  position: absolute;
  z-index: 3;
  top: -38px;
  left: -30px;
  width: clamp(66px, 20vw, 96px);
  height: auto;
  transform: rotate(-10deg);
  filter: drop-shadow(0 4px 4px rgba(40, 20, 0, 0.35));
  pointer-events: none;
}

.popup-card--roulette .popup-close-btn {
  top: -18px;
  right: -16px;
  z-index: 3;
}

/* Title plate over the top edge: blue, gold border, a paw on each side. */
.roulette-title-plate {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  max-width: calc(100% - 40px);
  margin: -52px auto 0;
  padding: 6px 16px 7px;
  border: 3px solid var(--roulette-gold-line);
  border-radius: 20px;
  background: linear-gradient(180deg, #3b8bff 0%, var(--roulette-blue) 55%, var(--roulette-blue-deep) 100%);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.5), 0 4px 0 #0a3a94, 0 6px 10px rgba(0, 0, 0, 0.25);
}

.roulette-title-paw {
  flex: 0 0 auto;
  width: clamp(18px, 5vw, 26px);
  height: auto;
  filter: drop-shadow(0 1px 0 rgba(0, 0, 0, 0.3));
}

/* The shared popup h2 ribbon is replaced by the plate around it. */
.popup-card--roulette .roulette-title {
  max-width: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  box-shadow: none;
  color: #fff;
  font-size: clamp(22px, 6.6vw, 30px);
  line-height: 1.15;
  white-space: nowrap;
}

.roulette-tickets {
  margin: 0;
  font-size: 14px;
  font-weight: 800;
  color: var(--cs-brown-soft, #7a5a3a);
  text-align: center;
}

.roulette-stage {
  position: relative;
  width: var(--roulette-size);
  height: var(--roulette-size);
  flex: 0 0 auto;
  /* Room for the rim and the pointer above it, so the pointer never sits on the words. */
  margin: calc(var(--roulette-size) * 0.1 + 4px) 0 calc(var(--roulette-size) * 0.05 + 4px);
}

/* Gold rim around the wheel (still); the wheel turns inside it. */
.roulette-rim {
  position: absolute;
  inset: -5%;
  border-radius: 50%;
  background: linear-gradient(160deg, #fff1a8 0%, #f5c542 35%, #d99a1e 70%, #f8d66a 100%);
  box-shadow: inset 0 0 0 2px #fff6c9, inset 0 -3px 6px rgba(140, 80, 0, 0.45), 0 6px 14px rgba(60, 35, 0, 0.35);
}

.roulette-wheel {
  position: absolute;
  inset: 0;
  border: 3px solid #fff3c4;
  border-radius: 50%;
  box-sizing: border-box;
  box-shadow: inset 0 0 0 1px rgba(160, 100, 10, 0.5);
  transform: rotate(0deg);
}

.roulette-studs {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.roulette-stud {
  position: absolute;
  width: calc(var(--roulette-size) * 0.034);
  height: calc(var(--roulette-size) * 0.034);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fffbe0 0%, #ffd34e 45%, #b97a08 100%);
  box-shadow: 0 1px 1px rgba(80, 40, 0, 0.5);
  transform: translate(-50%, -50%);
  /* Pickable in UI Tool (they do nothing in the game). */
  pointer-events: auto;
}

.roulette-wheel--spinning {
  transition: transform 2.6s cubic-bezier(0.12, 0.7, 0.18, 1);
}

/* One slice label, turned to the middle of its slice. */
.roulette-seg {
  position: absolute;
  top: 0;
  left: 50%;
  width: 56px;
  height: 50%;
  margin-left: -28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding-top: 10%;
  box-sizing: border-box;
  transform-origin: 50% 100%;
  pointer-events: none;
}

.roulette-seg-icon {
  width: calc(var(--roulette-size) * 0.12);
  height: calc(var(--roulette-size) * 0.12);
  object-fit: contain;
}

.roulette-seg-label {
  font-size: calc(var(--roulette-size) * 0.054);
  font-weight: 900;
  line-height: 1;
  color: var(--cs-brown, #4a3220);
}

/* A narrow (5%) slice: a small icon close to the rim, where the slice is widest,
   and its number under it; sizes follow the wheel so they fit at every width. */
.roulette-seg[data-size="narrow"] {
  width: calc(var(--roulette-size) * 0.13);
  margin-left: calc(var(--roulette-size) * -0.065);
  gap: 1px;
  padding-top: 4%;
}

.roulette-seg[data-size="narrow"] .roulette-seg-icon {
  width: calc(var(--roulette-size) * 0.08);
  height: calc(var(--roulette-size) * 0.08);
}

.roulette-seg[data-size="narrow"] .roulette-seg-label {
  font-size: calc(var(--roulette-size) * 0.046);
}

/* Slice edges: a thin line from the centre to the rim on every boundary. */
.roulette-sep {
  position: absolute;
  top: 0;
  left: 50%;
  width: 2px;
  height: 50%;
  margin-left: -1px;
  background: rgba(255, 255, 255, 0.85);
  transform-origin: 50% 100%;
  pointer-events: none;
}

/* Jackpot edges: gold lines exactly on its two boundaries (they never widen the slice). */
.roulette-sep--jackpot {
  width: 3px;
  margin-left: -1.5px;
  background: linear-gradient(180deg, #fff6c4, #ffcf3a 40%, #c98a00);
  box-shadow: 0 0 4px rgba(255, 210, 74, 0.9);
}

.roulette-jackpot-glow {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  pointer-events: none;
}

/* The jackpot's sparkle at the rim (a still star picture, no motion). */
.roulette-seg-star {
  width: calc(var(--roulette-size) * 0.06);
  height: calc(var(--roulette-size) * 0.06);
  margin-top: -2%;
  object-fit: contain;
  filter: drop-shadow(0 0 3px rgba(255, 236, 140, 0.95));
}

.roulette-seg[data-jackpot="true"] .roulette-seg-label {
  color: #fff;
  -webkit-text-stroke: 3px #7a4a00;
  paint-order: stroke fill;
}

.roulette-pointer {
  position: absolute;
  z-index: 2;
  top: -9%;
  left: 50%;
  width: 0;
  height: 0;
  margin-left: -14px;
  border-left: 14px solid transparent;
  border-right: 14px solid transparent;
  border-top: 26px solid #e5432d;
  filter: drop-shadow(0 0 1px #fff6c9) drop-shadow(0 2px 2px rgba(0, 0, 0, 0.4));
}

/* Gold paw medallion in the middle (a picture; the wheel turns under it). */
.roulette-hub {
  position: absolute;
  z-index: 2;
  top: 50%;
  left: 50%;
  width: 26%;
  height: 26%;
  transform: translate(-50%, -50%);
  object-fit: contain;
  filter: drop-shadow(0 3px 4px rgba(60, 35, 0, 0.4));
}

/* Result line: the reward picture and the words on a cream pill. */
.roulette-result {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  max-width: 100%;
  margin: 0;
  padding: 6px 16px 6px 8px;
  border: 2px solid #f0cf7c;
  border-radius: 999px;
  background: #fff6dc;
  color: var(--cs-brown, #4a3220);
  font-size: 16px;
  font-weight: 900;
  text-align: center;
  box-sizing: border-box;
}

.roulette-result-icon {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  object-fit: contain;
}

.roulette-result-text {
  min-width: 0;
}

.roulette-result[data-jackpot="true"] {
  border-color: #ffc21a;
  background: linear-gradient(180deg, #fff6c8, #ffe58a);
  box-shadow: 0 0 0 2px rgba(255, 210, 74, 0.45);
}

.roulette-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  width: 100%;
}

.popup-card--roulette .roulette-spin,
.popup-card--roulette .roulette-ok {
  min-height: 52px;
  padding: 8px 20px;
  border-radius: 18px;
  font-size: clamp(18px, 5.4vw, 22px);
}

.roulette-spin { flex: 1 1 58%; }
.roulette-ok { flex: 1 1 34%; max-width: 62%; }

/* Chances: cream box with a gold edge and a title tab on its top border. */
.roulette-odds {
  position: relative;
  width: 100%;
  margin-top: 14px;
  padding: 20px 10px 10px;
  border: 2px solid #ecc15e;
  border-radius: 18px;
  background: rgba(255, 252, 240, 0.85);
  box-shadow: inset 0 2px 0 #fff;
  box-sizing: border-box;
}

.roulette-odds-head {
  position: absolute;
  top: -15px;
  left: 50%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 14px;
  border: 2px solid #ecc15e;
  border-radius: 999px;
  background: #fff8e4;
  transform: translateX(-50%);
  white-space: nowrap;
}

.roulette-odds-paw {
  width: 16px;
  height: auto;
  opacity: 0.85;
}

.roulette-odds-title {
  margin: 0;
  font-size: 14px;
  font-weight: 900;
  color: var(--cs-brown, #4a3220);
}

/* Two columns read top to bottom (best first), with a thin gold line between them. */
.roulette-odds-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: repeat(var(--odds-rows, 4), auto);
  grid-auto-flow: column;
  gap: 3px 16px;
  margin: 0;
  padding: 0;
  list-style: none;
  background: linear-gradient(rgba(226, 176, 74, 0.55), rgba(226, 176, 74, 0.55)) center / 2px 100% no-repeat;
}

.roulette-odds-row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 26px;
  padding: 2px 8px;
  border: 2px solid transparent;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.7);
  font-size: 13px;
  font-weight: 800;
  box-sizing: border-box;
}

/* Every other line: a very light blue tint (low contrast, not the jackpot gold). */
.roulette-odds-row--alt {
  background: rgba(31, 99, 214, 0.07);
}

.roulette-odds-icon {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  object-fit: contain;
}

.roulette-odds-name { flex: 1 1 auto; min-width: 0; white-space: nowrap; text-align: left; }

/* The jackpot row: a gold frame and a small star mark, not colour alone. */
.roulette-odds-row[data-jackpot="true"] {
  border-color: #ffc21a;
  background: #fff3c4;
}

.roulette-odds-jackpot {
  /* On the corner of the reward icon, so the name keeps the row's width. */
  position: absolute;
  top: -5px;
  left: 2px;
  width: 15px;
  height: 15px;
  object-fit: contain;
  filter: drop-shadow(0 0 2px rgba(255, 200, 40, 0.9));
}

.roulette-odds-pct {
  flex: 0 0 auto;
  min-width: 3ch;
  color: var(--cs-brown-soft, #7a5a3a);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.roulette-shard-note {
  margin: 8px 0 0;
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  color: var(--cs-brown-soft, #7a5a3a);
}

/* ---------- Win celebrations (display only) ----------
   Every win: the result pill's picture pops. Jackpot: a show over the stopped wheel
   (soft light, slow rays, stars, the prize growing, the word) that never covers the
   result line or the buttons; a tap skips it. The animated parts are their own
   elements, so UI Tool edits on the others are not overridden by the motion. */
.roulette-result.is-win .roulette-result-icon {
  animation: roulette-win-pop 520ms cubic-bezier(0.34, 1.5, 0.64, 1) both;
}

.roulette-result.is-win {
  animation: roulette-win-glow 900ms ease-out both;
}

@keyframes roulette-win-pop {
  0% { transform: scale(0.3) rotate(-12deg); }
  70% { transform: scale(1.18) rotate(4deg); }
  100% { transform: scale(1) rotate(0); }
}

@keyframes roulette-win-glow {
  0% { box-shadow: 0 0 0 0 rgba(255, 210, 74, 0.8); }
  100% { box-shadow: 0 0 0 10px rgba(255, 210, 74, 0); }
}

.roulette-jackpot-show {
  position: absolute;
  z-index: 4;
  inset: -6%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 248, 214, 0.96) 0%, rgba(255, 236, 160, 0.9) 48%, rgba(255, 220, 110, 0.55) 70%, rgba(255, 220, 110, 0) 72%);
  cursor: pointer;
  animation: roulette-jackpot-in 320ms ease-out both;
}

.roulette-jackpot-rays {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 110%;
  height: 110%;
  margin: -55% 0 0 -55%;
  opacity: 0.7;
  pointer-events: none;
  animation: roulette-jackpot-rays 2600ms linear both;
}

.roulette-jackpot-star {
  position: absolute;
  width: 15%;
  height: auto;
  pointer-events: none;
  animation: roulette-jackpot-star 900ms cubic-bezier(0.34, 1.5, 0.64, 1) both;
}

/* Stars beside the prize, clear of the word above it and the reward line below. */
#roulette-jackpot-star-1 { top: 38%; left: 9%; width: 13%; }
#roulette-jackpot-star-2 { top: 44%; right: 9%; width: 11%; animation-delay: 120ms; }
#roulette-jackpot-star-3 { bottom: 16%; left: 22%; width: 9%; animation-delay: 220ms; }
#roulette-jackpot-star-4 { bottom: 14%; right: 22%; width: 10%; animation-delay: 320ms; }

.roulette-jackpot-prize {
  position: relative;
  width: 40%;
  height: auto;
  filter: drop-shadow(0 6px 8px rgba(120, 70, 0, 0.35));
  animation: roulette-jackpot-prize 700ms cubic-bezier(0.34, 1.6, 0.64, 1) both;
}

.roulette-jackpot-title {
  position: relative;
  margin: 0 0 4px;
  order: -1;
  color: #ffd84a;
  font-size: clamp(28px, 9vw, 40px);
  font-weight: 900;
  line-height: 1;
  animation: roulette-jackpot-prize 600ms cubic-bezier(0.34, 1.6, 0.64, 1) 100ms both;
}

.roulette-jackpot-reward {
  position: relative;
  margin: 4px 0 0;
  color: #fff;
  font-size: clamp(16px, 5vw, 20px);
  font-weight: 900;
}

@keyframes roulette-jackpot-in {
  from { opacity: 0; transform: scale(0.85); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes roulette-jackpot-rays {
  from { transform: rotate(0deg); }
  to { transform: rotate(45deg); }
}

@keyframes roulette-jackpot-star {
  0% { opacity: 0; transform: scale(0.2); }
  100% { opacity: 1; transform: scale(1); }
}

@keyframes roulette-jackpot-prize {
  0% { transform: scale(0.2); }
  70% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

/* Ticket box in the clear result. */
.roulette-earned {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px 10px;
  margin: 6px 0;
  padding: 8px 10px;
  border: 2px solid var(--cs-gold, #e2b04a);
  border-radius: 16px;
  background: #fff6d6;
}

.roulette-earned-wheel {
  width: 34px;
  height: 34px;
  border: 3px solid var(--cs-gold, #e2b04a);
  border-radius: 50%;
  background: conic-gradient(var(--roulette-coins-0) 0 120deg, var(--roulette-shards-0) 120deg 240deg, var(--roulette-hints-0) 240deg 360deg);
  box-sizing: border-box;
}

.roulette-earned-title {
  flex: 1 1 160px;
  margin: 0;
  font-size: 14px;
  font-weight: 900;
  color: var(--cs-brown, #4a3220);
}

.roulette-earned-spin { flex: 1 1 100%; }

@media (prefers-reduced-motion: reduce) {
  .roulette-wheel--spinning { transition: none; }
  .roulette-result.is-win,
  .roulette-result.is-win .roulette-result-icon,
  .roulette-jackpot-show,
  .roulette-jackpot-rays,
  .roulette-jackpot-star,
  .roulette-jackpot-prize,
  .roulette-jackpot-title { animation: none; }
}

/* Narrow phones: one reward per row (best first), no middle line. */
@media (max-width: 360px) {
  .roulette-odds-list {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: none;
    grid-auto-flow: row;
    background: none;
  }
}

/* Companion ability line in the clear result (GAME_SPEC §4.15). */
.popup-ability {
  margin: 2px 0 0;
  font-size: 14px;
  font-weight: 900;
  color: #ffe27a;
}
