/* Game engine UIs (media/games/*.js). The stage is dark, so engine text is light.
   Side controls and the rules panel sit on the page and inherit its colours. */

/* The host sizes the stage (16:9 on wide screens, content height on phones);
   the engine root only needs to fill it. */
.av-stage[data-stage] { display: flex; }

.av-eng {
  --av-pad: 8px;
  flex: 1;
  width: 100%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 16px;
  color: #fff;
  -webkit-tap-highlight-color: transparent;
}

.av-eng img { user-select: none; -webkit-user-drag: none; }

/* ---------- Reels (video and classic) ---------- */

.av-reels {
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--av-cols, 5), minmax(0, 1fr));
  width: min(100%, 620px);
  padding: var(--av-pad);
  border-radius: var(--av-r);
  background: rgba(5, 12, 30, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
}

.av-reels-classic { width: min(100%, 420px); }

.av-reel {
  position: relative;
  overflow: hidden;
  aspect-ratio: 1 / 3;
}

.av-reel + .av-reel { border-left: 1px solid rgba(255, 255, 255, 0.1); }

.av-reel-strip {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  will-change: transform;
}

.av-cell {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  padding: 7%;
}

.av-cell img {
  display: block;
  width: 100%;
  height: auto;
  transition: transform 0.2s ease-out;
}

.av-cell.av-hit {
  background: radial-gradient(circle, color-mix(in srgb, var(--av-hue, #1f6feb) 45%, transparent) 0%, transparent 70%);
}

.av-cell.av-hit img { transform: scale(1.06); }

.av-lines {
  position: absolute;
  inset: var(--av-pad);
  width: calc(100% - 2 * var(--av-pad));
  height: calc(100% - 2 * var(--av-pad));
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s ease-out;
}

.av-lines.av-on { opacity: 1; }

.av-lines polyline {
  fill: none;
  stroke: var(--av-acc);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.av-lines polyline:nth-child(2n) { stroke: #fff; }

.av-eng-banner.av-off { visibility: hidden; }

.av-eng-banner {
  margin: 0;
  padding: 6px 16px;
  border-radius: 999px;
  background: var(--av-acc);
  color: #fff;
  font: 600 15px/1.3 var(--av-font-h);
  text-align: center;
}

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

.av-wheel {
  position: relative;
  width: min(100%, 380px);
  aspect-ratio: 1;
  padding-top: 10px;
  /* The turning square disc would otherwise widen the page at its diagonals. */
  overflow: clip;
}

.av-wheel-disc {
  width: 100%;
  height: 100%;
  will-change: transform;
}

.av-wheel-svg { display: block; width: 100%; height: 100%; }

.av-seg path { stroke: rgba(5, 12, 30, 0.9); stroke-width: 1; }
.av-seg-a path { fill: var(--av-hue, #1f6feb); }
.av-seg-b path { fill: color-mix(in srgb, var(--av-hue, #1f6feb) 50%, #0b1630); }
.av-seg-0 path { fill: #0e1a33; }
.av-seg-top path { fill: var(--av-acc); }

.av-seg text {
  fill: #fff;
  font: 700 13px var(--av-font-m);
  stroke: rgba(0, 0, 0, 0.55);
  stroke-width: 2.5px;
  paint-order: stroke;
}

.av-seg-on path { fill: #fff; }
.av-seg-on text { fill: #0b1630; stroke: none; }

.av-wheel-rim { fill: none; stroke: rgba(255, 255, 255, 0.4); stroke-width: 2; }
.av-wheel-hub { fill: #0b1630; stroke: var(--av-hue, #1f6feb); stroke-width: 4; }

.av-wheel-pointer {
  position: absolute;
  top: 0;
  left: 50%;
  width: 40px;
  height: 40px;
  transform: translateX(-50%);
  fill: var(--av-acc);
  stroke: #fff;
  stroke-width: 2;
}

/* ---------- Scratch card ---------- */

.av-scratch {
  position: relative;
  width: min(100%, 360px);
  aspect-ratio: 1;
  border-radius: var(--av-r);
  overflow: hidden;
  background: rgba(5, 12, 30, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.16);
}

.av-scratch-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  width: 100%;
  height: 100%;
}

.av-scratch-cell {
  display: grid;
  place-items: center;
  padding: 12%;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.av-scratch-cell img { width: 100%; height: auto; display: block; }
.av-scratch-cell.av-hit { background: color-mix(in srgb, var(--av-hue, #1f6feb) 40%, transparent); }

.av-scratch-foil {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}

/* ---------- Peg drop ---------- */

.av-drop { width: min(100%, 520px); }
.av-drop-svg { display: block; width: 100%; height: auto; }

.av-peg { fill: rgba(255, 255, 255, 0.55); }
.av-peg-on { fill: var(--av-acc); }

.av-bin rect { fill: rgba(255, 255, 255, 0.1); }
.av-bin-up rect { fill: color-mix(in srgb, var(--av-hue, #1f6feb) 55%, transparent); }
.av-bin-on rect { fill: var(--av-acc); }
.av-bin text { fill: #fff; font: 700 11px var(--av-font-m); }

.av-ball { fill: #fff; stroke: var(--av-acc); stroke-width: 3; }

/* ---------- Radar tiles ---------- */

.av-radar {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  width: min(100%, 400px);
}

.av-tile {
  appearance: none;
  aspect-ratio: 1;
  padding: 10%;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 10px;
  background: radial-gradient(circle, rgba(31, 111, 235, 0.3), rgba(5, 12, 30, 0.7));
  cursor: pointer;
  transition: transform 0.15s ease-out, opacity 0.2s ease-out;
}

.av-tile:disabled { cursor: default; }
.av-tile:disabled:not(.av-tile-crate):not(.av-tile-storm) { opacity: 0.6; }
.av-tile:not(:disabled):hover { transform: translateY(-2px); }
.av-tile:not(:disabled):active { transform: scale(0.95); }
.av-tile:focus-visible { outline: 3px solid var(--av-sky); outline-offset: 2px; }
.av-tile img { display: block; width: 100%; height: auto; animation: av-pop 0.22s ease-out; }
.av-tile-crate { background: color-mix(in srgb, var(--av-hue, #1f6feb) 35%, rgba(5, 12, 30, 0.7)); }
.av-tile-storm { background: color-mix(in srgb, var(--av-acc) 40%, rgba(5, 12, 30, 0.7)); }
.av-tile.av-tile-dim { opacity: 0.5; }

@keyframes av-pop {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

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

.av-dice-face {
  margin: 0;
  font: 700 clamp(48px, 9vw, 88px) / 1 var(--av-font-m);
  font-variant-numeric: tabular-nums;
}

.av-dice-face.av-dice-hit { text-shadow: 0 0 24px var(--av-hue, #1f6feb), 0 0 2px #fff; }

.av-dice-track {
  position: relative;
  width: min(100%, 560px);
  height: 14px;
  margin-top: 16px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  /* The moving rail is as wide as the track; clip it sideways only. */
  overflow-x: clip;
  overflow-clip-margin: 4px;
}

.av-dice-zone {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: var(--av-hue, #1f6feb);
  transition: transform 0.2s ease-out;
}

.av-dice-rail { position: absolute; inset: -8px 0; pointer-events: none; will-change: transform; }

.av-dice-marker {
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 30px;
  margin-left: -2px;
  border-radius: 2px;
  background: #fff;
  box-shadow: 0 0 0 2px var(--av-acc);
}

.av-dice-scale {
  display: flex;
  justify-content: space-between;
  width: min(100%, 560px);
  font: 12px var(--av-font-m);
  color: rgba(255, 255, 255, 0.75);
}

/* ---------- Cards (higher or lower) ---------- */

.av-hilo-table { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.av-hilo-slot { display: grid; place-items: center; min-height: 10px; }

.av-playcard {
  position: relative;
  width: clamp(110px, 22vw, 150px);
  aspect-ratio: 5 / 7;
  border-radius: 12px;
  background: #f7f5ef;
  color: #141a26;
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.4);
  transition: transform 0.22s ease-out, opacity 0.22s ease-out;
}

.av-playcard-in { opacity: 0; transform: translateY(-10px) scale(0.95); }
.av-still .av-playcard { transition: none; }
.av-playcard-red { color: #b4232a; }

.av-playcard-back {
  border: 5px solid #f7f5ef;
  background: repeating-linear-gradient(45deg, var(--av-hue, #1f6feb) 0 8px, #0b1630 8px 16px);
}

.av-playcard-corner {
  position: absolute;
  top: 8px;
  left: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font: 700 20px / 1 var(--av-font-h);
}

.av-playcard-corner svg { width: 16px; height: 16px; fill: currentColor; }
.av-playcard-corner-end { top: auto; left: auto; bottom: 8px; right: 10px; transform: rotate(180deg); }
.av-playcard-pip { position: absolute; inset: 0; display: grid; place-items: center; }
.av-playcard-pip svg { width: 46%; fill: currentColor; }

.av-playcard-sm { width: 44px; border-radius: 6px; box-shadow: none; }
.av-playcard-sm .av-playcard-corner { top: 4px; left: 5px; font-size: 13px; }
.av-playcard-sm .av-playcard-corner svg { width: 11px; height: 11px; }
.av-playcard-sm .av-playcard-pip, .av-playcard-sm .av-playcard-corner-end { display: none; }

.av-hilo-trail { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; min-height: 62px; }

.av-hilo-ladder {
  margin: 0;
  font: 600 16px var(--av-font-m);
  color: rgba(255, 255, 255, 0.85);
}

/* ---------- Keno ---------- */

.av-keno {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 6px;
  width: min(100%, 560px);
}

.av-keno-cell {
  appearance: none;
  aspect-ratio: 1;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 10px;
  background: rgba(5, 12, 30, 0.6);
  color: #fff;
  font: 600 clamp(12px, 2.4vw, 16px) var(--av-font-m);
  cursor: pointer;
  transition: transform 0.12s ease-out;
}

.av-keno-cell:not(:disabled):hover { transform: translateY(-1px); }
.av-keno-cell:not(:disabled):active { transform: scale(0.95); }
.av-keno-cell:disabled { cursor: default; }
.av-keno-cell:focus-visible { outline: 3px solid var(--av-sky); outline-offset: 2px; }
.av-keno-cell.av-pick { background: var(--av-sky); border-color: transparent; }
.av-keno-cell.av-drawn { box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.8); }
.av-keno-cell.av-pick.av-hit { background: var(--av-acc); box-shadow: inset 0 0 0 2px #fff; }

/* ---------- Side controls (next to the primary button) ---------- */

.av-eng-field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

.av-eng-field select,
.av-eng-field input[type="range"] {
  font: inherit;
  accent-color: var(--av-acc);
}

.av-eng-field select {
  min-height: 40px;
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid currentColor;
  background: transparent;
  color: inherit;
}

.av-eng-field select option { color: #141a26; }
.av-eng-out { min-width: 2.5ch; font-family: var(--av-font-m); }

.av-eng-toggle { display: inline-flex; gap: 6px; }

.av-eng-btn {
  appearance: none;
  min-height: 44px;
  padding: 8px 16px;
  border: 2px solid currentColor;
  border-radius: 999px;
  background: transparent;
  color: inherit;
  font: 600 15px var(--av-font-h);
  cursor: pointer;
  transition: transform 0.12s ease-out;
}

.av-eng-btn:not(:disabled):active { transform: scale(0.96); }
.av-eng-btn:focus-visible { outline: 3px solid var(--av-sky); outline-offset: 2px; }
.av-eng-btn[aria-pressed="true"] { background: var(--av-sky); border-color: var(--av-sky); color: #fff; }
.av-eng-btn:disabled { opacity: 0.45; cursor: not-allowed; }

@media (hover: hover) {
  .av-eng-btn:not(:disabled):hover { background: color-mix(in srgb, currentColor 10%, transparent); }
  .av-eng-btn[aria-pressed="true"]:not(:disabled):hover { background: var(--av-sky); }
}

.av-eng-readout { margin: 0; font: 14px / 1.4 var(--av-font-m); }

/* ---------- Rules panel tables ---------- */

.av-eng-table {
  width: 100%;
  margin: 8px 0 14px;
  border-collapse: collapse;
  font-size: 14px;
}

.av-eng-table caption { text-align: left; font-weight: 600; padding-bottom: 6px; }

.av-eng-table th,
.av-eng-table td {
  padding: 6px 8px;
  text-align: left;
  border-bottom: 1px solid color-mix(in srgb, currentColor 15%, transparent);
}

.av-eng-table td { font-family: var(--av-font-m); }
.av-eng-table img { display: inline-block; vertical-align: middle; width: 28px; height: 28px; margin-right: 6px; }
.av-eng-table-wrap { overflow-x: auto; }
.av-eng-table-wide th, .av-eng-table-wide td { padding: 5px 6px; white-space: nowrap; }

/* ---------- Small screens and reduced motion ---------- */

/* On wide screens the stage is a fixed 16:9 box, so each engine is capped by
   width as a share of the stage (its height is 56.25% of its width). */
@media (min-width: 761px) {
  .av-reels { width: min(100%, 620px, calc(93.75% - 110px)); }
  .av-reels-classic { width: min(100%, 420px, calc(56.25% - 14px)); }
  .av-wheel { width: min(100%, 380px, calc(56.25% - 24px)); }
  .av-scratch { width: min(100%, 360px, calc(56.25% - 14px)); }
  .av-drop { width: min(100%, 520px, calc(51.9% - 13px)); }
  .av-radar { width: min(100%, 400px, calc(56.25% - 14px)); }
  .av-keno { width: min(100%, 560px, calc(90% - 22px)); }
}

@media (max-width: 640px) {
  .av-eng { --av-pad: 5px; gap: 10px; padding: 12px 8px; }
  .av-radar, .av-keno { gap: 4px; }
  .av-keno-cell, .av-tile { border-radius: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  .av-eng *,
  .av-eng-btn {
    transition: none !important;
    animation: none !important;
  }
}
