:root {
  --bg-page: #e9e9e9;
  --card-bg: #fffdf8;
  --border-soft: #ece6d8;

  --amber: #e8971d;
  --amber-dark: #c97c0f;
  --red: #E12905;
  --blue: #0864F3;
  --green: #1E882D;
  --yellow: #FBBC04;

  --ink: #1c1c1c;
  --ink-soft: #6b6b6b;

  --radius-lg: 20px;
  --radius-md: 12px;
  --radius-sm: 8px;

  --ease: cubic-bezier(.22, 1, .36, 1);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg-page);
  font-family: "Inter", "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 16px;
}

.page {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.page[hidden] {
  display: none;
}

#resultsPage {
  max-width: none;
  width: 100%;
  height: calc(100dvh - 32px);
  min-height: 0;
}

.keno-widget {
  display: flex;
  gap: 20px;
  max-width: 1160px;
  width: 100%;
  height: calc(100dvh - 72px);
  min-height: 0;
}

/* ---------- LEFT PANEL ---------- */

.left-panel {
  display: flex;
  flex-direction: column;
  width: 340px;
  flex-shrink: 0;
  align-self: flex-start;
  height: fit-content;
  background: var(--card-bg);
  border: 1.5px solid var(--amber);
  border-radius: var(--radius-lg);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.04);
  min-height: 0;
  overflow: hidden;
}

.header-card {
  flex: 0 0 auto;
  padding: 16px 18px 14px;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  border-bottom: 1px solid var(--border-soft);
  perspective: 700px;
  /* gives the forward/back reveal actual depth */
}

.keno-title {
  margin: 0;
  font-size: 30px;
  font-weight: 900;
  letter-spacing: 4px;
  background: linear-gradient(180deg, #ffd35c 0%, var(--amber) 55%, var(--amber-dark) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.08);
}

.current-ball {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: #fff;
  border: 4px solid var(--amber);
  box-shadow: 0 0 0 4px rgba(232, 151, 29, 0.15), 0 4px 14px rgba(232, 151, 29, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-weight: 800;
  color: var(--ink);
  transition: transform 0.35s var(--ease);
}

/* ball comes toward the viewer, then settles back into place */
.current-ball.ball-forward-back {
  animation: ballForwardBack 0.9s var(--ease);
  transform-style: preserve-3d;
}

@keyframes ballForwardBack {
  0% {
    transform: translateZ(-120px) scale(0.6);
    opacity: 0;
    box-shadow: 0 0 0 0 rgba(232, 151, 29, 0);
  }

  45% {
    transform: translateZ(70px) scale(1.35);
    opacity: 1;
    box-shadow: 0 0 0 14px rgba(232, 151, 29, 0.25), 0 10px 24px rgba(232, 151, 29, 0.45);
  }

  75% {
    transform: translateZ(-10px) scale(0.94);
    box-shadow: 0 0 0 4px rgba(232, 151, 29, 0.15), 0 4px 14px rgba(232, 151, 29, 0.25);
  }

  100% {
    transform: translateZ(0) scale(1);
    box-shadow: 0 0 0 4px rgba(232, 151, 29, 0.15), 0 4px 14px rgba(232, 151, 29, 0.25);
  }
}

.progress-block {
  grid-column: 1 / -1;
  width: 100%;
  margin-top: 12px;
}

.progress-labels {
  display: flex;
  justify-content: flex-end;
  align-items: baseline;
  font-weight: 700;
  margin-bottom: 6px;
}

.progress-count {
  font-size: 18px;
}

.progress-total {
  font-size: 14px;
  color: var(--ink-soft);
  font-weight: 600;
}

.progress-left {
  font-size: 15px;
  color: var(--ink-soft);
  font-weight: 600;
}

.progress-track {
  height: 6px;
  border-radius: 6px;
  background: #f1ecdd;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--amber-dark), var(--amber));
  transition: width 0.5s var(--ease);
}

/* ---------- STATS CARD ---------- */

.stats-card {
  flex: 0 0 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 12px;
  align-content: stretch;
}

.stats-section {
  min-height: 0;
  border-radius: var(--radius-md);
  padding: 10px;
  display: flex;
  flex-direction: column;
}

.stats-section--color {
  background: #fdecee;
}

.stats-section--quarter {
  background: #eaf2fb;
}

.stats-section--exotic {
  background: #eaf8ef;
}

.stats-section-title {
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--ink);
  margin-bottom: 6px;
}

.tile-grid {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.tile {
  border-radius: var(--radius-sm);
  padding: 7px 9px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  justify-content: center;
  transition: background-color 0.3s var(--ease);
}

/* By Color tiles: tinted with the ball's own color */
.tile-red {
  background: rgba(219, 47, 63, 0.10);
}

.tile-green {
  background: rgba(28, 157, 85, 0.10);
}

.tile-blue {
  background: rgba(36, 81, 232, 0.10);
}

.tile-yellow {
  background: rgba(224, 144, 15, 0.10);
}

/* By Quarter tiles: tinted to match each quadrant's badge color */
.tile-q1 {
  background: rgba(31, 182, 201, 0.12);
}

.tile-q2 {
  background: rgba(58, 166, 85, 0.12);
}

.tile-q3 {
  background: rgba(224, 168, 60, 0.14);
}

.tile-q4 {
  background: rgba(138, 99, 210, 0.12);
}

/* Exotic Results tiles: neutral lavender tint (no per-item color identity) */
.tile-exotic {
  background: rgba(147, 112, 219, 0.10);
}

.tile-top {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.stat-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot-red {
  background: var(--red);
}

.dot-blue {
  background: var(--blue);
}

.dot-green {
  background: var(--green);
}

.dot-yellow {
  background: var(--yellow);
}

.tile-label {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* quarter badges: spatial grid quadrants, colors distinct from the
   ball color-zone palette since this is a different categorization */
.q-badge {
  flex-shrink: 0;
  min-width: 26px;
  padding: 3px 6px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 800;
  color: #fff;
  text-align: center;
}

.q-badge-1 {
  background: #1fb6c9;
}

/* top-left: cyan */
.q-badge-2 {
  background: #3aa655;
}

/* top-right: green */
.q-badge-3 {
  background: #e0a83c;
}

/* bottom-left: gold */
.q-badge-4 {
  background: #8a63d2;
}

/* bottom-right: purple */

.tile-value {
  font-size: 16px;
  font-weight: 900;
  color: var(--ink);
  transition: transform 0.2s var(--ease);
}

.tile-value.bump {
  animation: statBump 0.4s var(--ease);
}

@keyframes statBump {
  0% {
    transform: scale(1);
  }

  40% {
    transform: scale(1.18);
  }

  100% {
    transform: scale(1);
  }
}

/* ---------- GRID PANEL ---------- */

.grid-panel {
  flex: 1;
  align-self: flex-start;
  height: fit-content;
  background: var(--card-bg);
  border: 1px solid var(--amber);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.04);
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.ball-grid {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 8px;
  position: relative;
}

/* quadrant divider lines */
.ball-grid::before,
.ball-grid::after {
  content: "";
  position: absolute;
  background: var(--ink);
  opacity: 0.55;
}

.ball-grid::before {
  /* vertical divider between col 5 and 6 */
  left: 50.6%;
  top: 0;
  bottom: 0;
  width: 1px;
  transform: translateX(-4px);
}

.ball-grid::after {
  /* horizontal divider between row 4 and 5 */
  top: 50.7%;
  left: 0;
  right: 0;
  height: 1px;
  transform: translateY(-4px);
}

.ball {
  aspect-ratio: 1 / 1;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border-soft);
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
  transition: background-color 0.3s var(--ease), color 0.3s var(--ease),
    border-color 0.3s var(--ease), transform 0.3s var(--ease),
    box-shadow 0.3s var(--ease);
}

/* every cell keeps a border tinted to its zone, even before it's drawn */
.ball.zone-red {
  border-color: var(--red);
}

.ball.zone-green {
  border-color: var(--green);
}

.ball.zone-blue {
  border-color: var(--blue);
}

.ball.zone-yellow {
  border-color: var(--yellow);
}

.ball.drawn-red {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}

.ball.drawn-blue {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}

.ball.drawn-green {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

.ball.drawn-yellow {
  background: var(--yellow);
  border-color: var(--yellow);
  color: #fff;
}

.ball.current-hit {
  animation: ballLand 0.55s var(--ease);
}

@keyframes ballLand {
  0% {
    transform: scale(0.5);
    box-shadow: 0 0 0 0 rgba(0, 0, 0, 0);
  }

  55% {
    transform: scale(1.25);
    box-shadow: 0 0 16px 4px rgba(232, 151, 29, 0.55);
  }

  100% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(0, 0, 0, 0);
  }
}

/* ---------- DEV CONTROLS (remove in production) ---------- */

.dev-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--ink-soft);
}

.dev-controls button {
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border-soft);
  background: #fff;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
}

.dev-controls button:hover {
  background: #f6f2e6;
}

/* ---------- RESPONSIVE ---------- */

@media (max-width: 860px) {
  .keno-widget {
    height: calc(100dvh - 72px);
    flex-direction: column;
  }

  .left-panel {
    width: 100%;
    flex: 0 1 48%;
    align-self: stretch;
  }

  .grid-panel {
    flex: 1 1 52%;
    align-self: stretch;
  }

  .ball {
    font-size: 13px;
  }
}

/* ---------- GRID PAGE: LEFT PANEL LAYOUT AT <=960px ----------
   - drop the big current-ball circle from the header
   - move the progress bar up next to the KENO title instead
   - stretch the left panel to match the grid panel's height
     (rather than shrink-wrapping to its own content) */
@media (max-width: 960px) {
  .keno-widget {
    align-items: stretch;
  }

  .left-panel,
  .grid-panel {
    align-self: stretch;
    height: auto;
  }

  .current-ball {
    display: none;
  }

  .header-card {
    grid-template-columns: auto 1fr;
    column-gap: 18px;
  }

  .progress-block {
    grid-column: 2 / 3;
    margin-top: 0;
    align-self: center;
  }

  .stats-card {
    flex: 1 1 auto;
  }
}

@media (prefers-reduced-motion: reduce) {

  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

/* =========================================================
   RESULTS PAGE
   ---------------------------------------------------------
   Two structurally independent containers side by side: the
   grid card (draw id + number balls) and the badges card
   (the 4 majority badges). They are kept in visual sync — same
   width proportions top-to-bottom, same row heights — purely
   through shared CSS variables, not by nesting them in one
   shared grid, so they can never bleed into each other.
   ========================================================= */

:root {
  --results-gap: 20px;
  /* gap between the two cards, and between the two top-row halves */
  --badges-track-width: clamp(340px, 30vw, 480px);
  /* badges card / header width — same var used in both rows so they always line up */
  --mini-ball-size: 40px;
  /* ball diameter */
  --result-row-height: 85px;
  /* FIXED height shared by every grid row AND badge row — this is what keeps them locked to the same Y position row-by-row, since a shared min-height alone lets each row grow to fit its own tallest child independently (the 2-line draw-id-card vs. a single badge chip), causing drift over many rows */
  --badges-columns: repeat(4, minmax(60px, 1fr));
  /* 4 equal badge columns, shared by the header row and every badge row */
}

/* ---- top row: logo+timer (left) / header badges (right) ---- */

.results-top-row {
  display: flex;
  align-items: center;
  gap: var(--results-gap);
  width: 100%;
  flex-shrink: 0;
}

.results-top-left {
  display: flex;
  align-items: center;
  gap: 16px;
  flex: 1 1 auto;
  min-width: 0;
}

.results-top-right {
  display: grid;
  grid-template-columns: var(--badges-columns);
  gap: 10px;
  align-items: center;
  flex: 0 0 var(--badges-track-width);
  min-width: 0;
}

.keno-logo-box {
  flex-shrink: 0;
  background: #111;
  color: #f5c518;
  font-weight: 900;
  font-size: 24px;
  letter-spacing: 3px;
  padding: 14px 20px;
  border-radius: 14px;
}

.countdown-bar {
  flex: 1;
  min-width: 0;
  background: linear-gradient(180deg, #ffdd66, #f0a92c);
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 26px;
  gap: 12px;
  box-shadow: 0 3px 10px rgba(201, 124, 15, 0.3);
}

.countdown-side-label {
  font-weight: 800;
  font-size: 13px;
  color: #3a2a05;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

.countdown-unit {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 46px;
}

.countdown-digit {
  font-size: 26px;
  font-weight: 900;
  color: #1c1c1c;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.countdown-unit-label {
  font-size: 10px;
  font-weight: 700;
  color: #4a3a10;
  text-transform: uppercase;
  margin-top: 2px;
}

.countdown-divider {
  font-size: 20px;
  font-weight: 700;
  color: #3a2a05;
}

.header-badge {
  justify-self: center;
  width: fit-content;
  max-width: 100%;
  min-width: 0;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 10.5px;
  font-weight: 800;
  color: #fff;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-badge-color {
  background: #E12905;
}

.header-badge-quarter {
  background: #704B00;
}

.header-badge-parity {
  background: #0059B2;
}

.header-badge-half {
  background: #00007F;
}

/* ---- body row: the two independent white cards ---- */
/* A single shared scroller wraps both cards, so scrolling the
   list moves both cards together as one action — there's no
   separate scrollbar per card to fall out of sync. */

.results-body-scroll {
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

.results-body {
  display: flex;
  align-items: flex-start;
  gap: var(--results-gap);
  width: 100%;
}

.grid-card,
.badges-card {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
  overflow: hidden;
  /* clip to the rounded corners; the shared
                        scroller above handles all scrolling now */
  min-width: 0;
}

.grid-card {
  flex: 1 1 auto;
  padding: 8px 12px 12px;
}

.badges-card {
  flex: 0 0 var(--badges-track-width);
  padding: 8px 12px 12px;
}

.results-loading {
  text-align: center;
  padding: 24px;
  color: var(--ink-soft);
  font-weight: 600;
}

/* ---- grid card rows: draw id + number balls ---- */

.grid-row {
  display: flex;
  align-items: center;
  gap: 20px;
  height: var(--result-row-height);
  padding: 0 10px;
  border-bottom: 1px solid var(--border-soft);
}

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

.draw-id-card {
  flex: 0 0 clamp(84px, 9vw, 120px);
  background: #fdf3d8;
  border: 1px solid #f0dfa4;
  border-radius: 8px;
  padding: 7px 10px;
  min-width: 0;
  overflow: hidden;
}

.draw-id-line {
  font-size: 11.5px;
  font-weight: 800;
  color: var(--ink);
}

.draw-date-line {
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-soft);
  margin-top: 2px;
}

/* Outer wrapper: a plain block element that reliably takes exactly
   its flex share of the row and hard-clips anything past it — this
   is what stops balls from ever bleeding past the grid card's own
   edge, regardless of how many numbers a draw has. */
.draw-balls-wrap {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
}

.draw-balls {
  display: flex;
  gap: 18px;
  width: 100%;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.draw-balls::-webkit-scrollbar {
  display: none;
}

.mini-ball {
  flex-shrink: 0;
  width: var(--mini-ball-size);
  height: var(--mini-ball-size);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 800;
  font-size: 15px;
}

.mini-ball-red {
  background: var(--red);
}

.mini-ball-blue {
  background: var(--blue);
}

.mini-ball-green {
  background: var(--green);
}

.mini-ball-yellow {
  background: var(--yellow);
}

/* ---- badges card rows: the 4 majority badges ---- */

.badge-row {
  display: grid;
  grid-template-columns: var(--badges-columns);
  gap: 10px;
  align-items: center;
  height: var(--result-row-height);
  padding: 0 10px;
  border-bottom: 1px solid var(--border-soft);
}

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

.badge {
  justify-self: center;
  width: fit-content;
  max-width: 100%;
  min-width: 0;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 800;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.badge-color-red {
  background: #FFD0C7;
  color: #E12905;
  border: 1px solid #E12905;
}

.badge-color-green {
  background: #B2FFBD;
  color: #1E882D;
  border: 1px solid #1E882D;
}

.badge-color-blue {
  background: #D9E8FF;
  color: #0864F3;
  border: 1px solid #0864F3;
}

.badge-color-yellow {
  background: #FFEDB9;
  color: #B98A00;
  border: 1px solid #B98A00;
}

.badge-quarter-q1 {
  background: #FEEECD;
  color: #704B00;
  border: 1px solid #704B00;
}

.badge-quarter-q2 {
  background: #FED98C;
  color: #704B00;
  border: 1px solid #704B00;
}

.badge-quarter-q3 {
  background: #CE8B00;
  color: #FEEECD;
  border: 1px solid #FEEECD;
}

.badge-quarter-q4 {
  background: #704B00;
  color: #FEEECD;
  border: 1px solid #FEEECD;
}

.badge-parity-odd {
  background: #DAE7F4;
  color: #0080FF;
  border: 1px solid #0080FF;
}

.badge-parity-even {
  background: #0059B2;
  color: #DAE7F4;
  border: 1px solid #DAE7F4;
}

.badge-half-lower {
  background: #00007F;
  color: #fff;
  border: 1px solid #00007F;
}

.badge-half-upper {
  background: #E3DEFE;
  color: #2800FF;
  border: 1px solid #2800FF;
}

/* ---- graduated shrink for mid-size / laptop screens ----
   The badges track width and mini-ball size are both CSS
   variables, so overriding them here keeps the grid card, the
   badges card, and their headers all shrinking in lockstep —
   nothing can drift out of alignment between breakpoints. */
@media (max-width: 1300px) {
  :root {
    --badges-track-width: clamp(300px, 30vw, 420px);
  }

  .badge,
  .header-badge {
    font-size: 10px;
    padding: 5px 8px;
  }

  .draw-id-line {
    font-size: 11px;
  }

  .draw-date-line {
    font-size: 10px;
  }
}

@media screen and (min-width: 1100px) and (max-width: 1300px) {
  :root {
    --mini-ball-size: 34px;
    --result-row-height: 60px;
    --badges-track-width: clamp(260px, 30vw, 360px);
  }

  .badge,
  .header-badge {
    font-size: 9.5px;
    padding: 5px 7px;
  }

  .grid-row,
  .badge-row,
  .results-top-row,
  .results-body {
    gap: 6px;
  }

  .draw-balls {
    gap: 2px;
  }
}


@media (max-width: 960px) {
  body {
    padding: 6px;
    gap: 6px;
  }

  .page {
    gap: 6px;
  }

  :root {
    --mini-ball-size: 28px;
    --result-row-height: 45px;
    --badges-track-width: 210px;
    --badges-columns: repeat(4, minmax(38px, 1fr));
    --results-gap: 8px;
  }

  .results-top-left {
    gap: 8px;
  }

  .keno-logo-box {
    font-size: 13px;
    letter-spacing: 1px;
    padding: 5px 8px;
    border-radius: 5px;
    height: 30px;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .countdown-bar {
    padding: 4px 10px;
    gap: 4px;
    border-radius: 5px;
    height: 30px;
  }

  .countdown-unit {
    min-width: 24px;
  }

  .countdown-digit {
    font-size: 13px;
  }

  .countdown-unit-label {
    font-size: 6px;
  }

  .countdown-divider {
    font-size: 9px;
  }

  .countdown-side-label {
    font-size: 10.5px;
  }

  .header-badge {
    white-space: normal;
    font-size: 7.5px;
    padding: 3px 5px;
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 30px;
  }

  .badge {
    font-size: 7.5px;
    padding: 3px 5px;
    border-radius: 12px;
  }

  .grid-card,
  .badges-card {
    padding-left: 10px;
    padding-right: 10px;
  }

  .results-top-right {
    padding-left: 10px;
    padding-right: 10px;
  }

  .grid-row,
  .badge-row {
    gap: 2px;
    padding: 0;
  }

  .draw-id-card {
    flex: 0 0 clamp(50px, 8vw, 70px);
    padding: 3px 5px;
  }

  .draw-id-line {
    font-size: 8.5px;
  }

  .draw-date-line {
    font-size: 7.5px;
    margin-top: 1px;
  }

  .tile-value {
    font-size: 12px;
  }

  .keno-widget {
    height: 95dvh;
  }

  .draw-balls {
    gap: 4px;
  }

  #gridPage {
    position: relative;
    /* so the overlay's inset:0 anchors to this page, not the viewport */
  }

  .grid-loading-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.25);
    z-index: 500;
  }

  .grid-loading-overlay[hidden] {
    display: none;
  }

  .loading-box {
    background: #fff;
    padding: 16px 26px;
    border-radius: 14px;
    font-weight: 700;
    font-size: 18px;
    color: var(--ink);
    box-shadow: 0 12px 35px rgba(0, 0, 0, 0.18);
  }

  .grid-blurred {
    filter: blur(6px);
    pointer-events: none;
    user-select: none;
  }

  .dots span {
    animation: loadingDotBlink 1.4s infinite;
    opacity: 0;
  }

  .dots span:nth-child(2) {
    animation-delay: 0.2s;
  }

  .dots span:nth-child(3) {
    animation-delay: 0.4s;
  }

  @keyframes loadingDotBlink {

    0%,
    20% {
      opacity: 0;
    }

    50% {
      opacity: 1;
    }

    100% {
      opacity: 0;
    }
  }

}

@media (max-width: 900px) {
  :root {
    --mini-ball-size: 30px;
    --result-row-height: 48px;
  }

  .draw-balls {
    gap: 6px;
  }
}

@media (max-width: 700px) {
  .results-top-row {
    flex-direction: column;
    align-items: stretch;
  }

  .results-top-right {
    flex-basis: auto;
  }

  .results-body {
    flex-direction: column;
  }

  .grid-card,
  .badges-card {
    flex-basis: auto;
  }

  .countdown-bar {
    padding: 8px 14px;
    gap: 6px;
  }

  /* the second "Next Draw In" label is purely decorative — drop it
     on narrow screens so the bar's content actually fits */
  .countdown-side-label:last-child {
    display: none;
  }

  .countdown-digit {
    font-size: 20px;
  }

  .countdown-unit-label {
    font-size: 9px;
  }

  .countdown-divider {
    font-size: 16px;
  }
}


.draw-animation-layer {
  position: fixed;
  inset: 0;
  z-index: 9999;
  pointer-events: none;
  overflow: hidden;
  display: none;
}

.draw-animation-layer.active {
  display: block;
}

.animated-draw-ball {
  position: fixed;

  width: 140px;
  height: 140px;

  border-radius: 50%;

  display: flex;
  align-items: center;
  justify-content: center;

  background: #fff;
  border: 6px solid var(--amber);

  color: var(--ink);
  font-size: 72px;
  font-weight: 900;

  box-shadow:
    0 0 0 8px rgba(232, 151, 29, 0.18),
    0 12px 35px rgba(0, 0, 0, 0.28);

  transform: translate(-50%, -50%) scale(1);

  will-change: left, top, transform, opacity;

  left: 50%;
  top: 50%;

  opacity: 0;
}

/* Going from grid -> center */
.animated-draw-ball.fly-to-center {
  animation: flyBallToCenter 650ms cubic-bezier(.22, 1, .36, 1) forwards;
}

/* Staying large in center */
.animated-draw-ball.center-hold {
  animation: centerBallHold 550ms ease-in-out forwards;
}

/* Going from center -> grid */
.animated-draw-ball.fly-back {
  animation: flyBallBack 650ms cubic-bezier(.22, 1, .36, 1) forwards;
}


/* ---------------------------------------------------------
   GRID -> CENTER
   --------------------------------------------------------- */

@keyframes flyBallToCenter {

  0% {
    opacity: 0;
    transform:
      translate(-50%, -50%) scale(0.35);
  }

  20% {
    opacity: 1;
  }

  65% {
    transform:
      translate(-50%, -50%) scale(1.45);
  }

  100% {
    opacity: 1;
    transform:
      translate(-50%, -50%) scale(1.65);
  }
}


/* ---------------------------------------------------------
   CENTER HOLD
   --------------------------------------------------------- */

@keyframes centerBallHold {

  0% {
    opacity: 1;
    transform:
      translate(-50%, -50%) scale(1.65);
  }

  50% {
    opacity: 1;
    transform:
      translate(-50%, -50%) scale(1.75);
  }

  100% {
    opacity: 1;
    transform:
      translate(-50%, -50%) scale(1.65);
  }
}


/* ---------------------------------------------------------
   CENTER -> GRID
   --------------------------------------------------------- */

@keyframes flyBallBack {

  0% {
    opacity: 1;
    transform:
      translate(-50%, -50%) scale(1.65);
  }

  65% {
    transform:
      translate(-50%, -50%) scale(1.05);
  }

  100% {
    opacity: 0;
    transform:
      translate(-50%, -50%) scale(0.85);
  }
}

/* =========================================================
   RESPONSIVE RANGES — GRID PAGE + RESULTS PAGE
   ---------------------------------------------------------
   How this works (so the six range blocks stay tiny):

   1. TWO ENGINES hold all the real rules, written once:
        - COMPACT engine  769–960px : your tuned 960x540 TV
          layout, scaled DOWN smoothly (unit --cu).
          At exactly 960x540 it matches your existing design.
        - MAIN engine     961px +   : your 1920x1080 design,
          scaled UP/DOWN smoothly (unit --u).
      --u = 1 design pixel at 1920x1080. It is the smaller of
      (width/1920, height/1080), so the layout always fits.

   2. RESULTS BALLS ARE SIZED FROM THE SPACE AVAILABLE, not
      hand-picked. Before this, all 20 balls only fit at
      exactly 960px and 1920px wide; every other width cut the
      last balls off. Now the ball size is calculated from the
      width left over, so they always fit (with ~5% to spare
      for a scrollbar).

   3. THE SIX RANGE BLOCKS at the bottom only set a few knobs
      (badge card width, ball density, row height) per range.

   Your 1920x1080 block (further below) is untouched and still
   wins at exactly that size.
   ========================================================= */


/* ---------------------------------------------------------
   SHARED (all widths): grid loading overlay
   This used to exist only inside the <=960px and 1920px
   blocks, so at any width in between it was unstyled.
   --------------------------------------------------------- */
#gridPage {
  position: relative;
}

.grid-loading-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.25);
  z-index: 500;
}

.grid-loading-overlay[hidden] {
  display: none;
}

.loading-box {
  background: #fff;
  padding: 16px 26px;
  border-radius: 14px;
  font-weight: 700;
  font-size: 18px;
  color: var(--ink);
  box-shadow: 0 12px 35px rgba(0, 0, 0, 0.18);
}

.grid-blurred {
  filter: blur(6px);
  pointer-events: none;
  user-select: none;
}

.dots span {
  animation: loadingDotBlink 1.4s infinite;
  opacity: 0;
}

.dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes loadingDotBlink {

  0%,
  20% {
    opacity: 0;
  }

  50% {
    opacity: 1;
  }

  100% {
    opacity: 0;
  }
}


/* =========================================================
   COMPACT ENGINE — 769px to 960px
   --cu = 1px at 960x540 (your tuned TV size), smaller below.
   Every number below is your existing 960 value x --cu.
   ========================================================= */
@media (min-width: 769px) and (max-width: 960px) {

  :root {
    --cu: min(1px, calc(100vw / 960), calc(100vh / 540));

    --results-gap: calc(8 * var(--cu));
    --badges-track-width: calc(210 * var(--cu));
    --badges-columns: repeat(4, minmax(0, 1fr));
    --result-row-height: calc(45 * var(--cu));

    /* ball sized from the strip: 638 design-px available, 20 balls
       + 19 gaps need 612, leaving ~4% spare for a scrollbar */
    --mini-ball-size: calc(27 * var(--cu));
  }

  /* ---------- RESULTS PAGE ---------- */

  body {
    padding: calc(6 * var(--cu));
    gap: calc(6 * var(--cu));
  }

  .page {
    gap: calc(6 * var(--cu));
  }

  .results-top-left {
    gap: calc(8 * var(--cu));
  }

  .results-top-right {
    gap: calc(10 * var(--cu));
    padding-left: calc(10 * var(--cu));
    padding-right: calc(10 * var(--cu));
  }

  .keno-logo-box {
    font-size: calc(13 * var(--cu));
    letter-spacing: calc(1 * var(--cu));
    padding: calc(5 * var(--cu)) calc(8 * var(--cu));
    height: calc(30 * var(--cu));
  }

  .countdown-bar {
    padding: calc(4 * var(--cu)) calc(10 * var(--cu));
    gap: calc(4 * var(--cu));
    height: calc(30 * var(--cu));
  }

  .countdown-unit {
    min-width: calc(24 * var(--cu));
  }

  .countdown-digit {
    font-size: calc(13 * var(--cu));
  }

  .countdown-unit-label {
    font-size: calc(6 * var(--cu));
  }

  .countdown-divider {
    font-size: calc(9 * var(--cu));
  }

  .countdown-side-label {
    font-size: calc(10.5 * var(--cu));
  }

  .header-badge {
    font-size: calc(7.5 * var(--cu));
    padding: calc(3 * var(--cu)) calc(5 * var(--cu));
    height: calc(30 * var(--cu));
  }

  .badge {
    font-size: calc(7.5 * var(--cu));
    padding: calc(3 * var(--cu)) calc(5 * var(--cu));
  }

  .grid-card,
  .badges-card {
    padding-left: calc(10 * var(--cu));
    padding-right: calc(10 * var(--cu));
  }

  .grid-row,
  .badge-row {
    gap: calc(2 * var(--cu));
    padding: 0;
  }

  .draw-id-card {
    flex: 0 0 calc(70 * var(--cu));
    padding: calc(3 * var(--cu)) calc(5 * var(--cu));
  }

  .draw-id-line {
    font-size: calc(8.5 * var(--cu));
  }

  .draw-date-line {
    font-size: calc(7.5 * var(--cu));
    margin-top: calc(1 * var(--cu));
  }

  .draw-balls {
    gap: calc(3.8 * var(--cu));
  }

  .mini-ball {
    font-size: calc(var(--mini-ball-size) * 0.55);
  }
}

/* ---------- GRID PAGE, compact, landscape only ----------
   (portrait phones/tablets keep your existing stacked layout) */
@media (min-width: 769px) and (max-width: 960px) and (min-aspect-ratio: 1/1) {

  .keno-widget {
    gap: calc(20 * var(--cu));
  }

  .left-panel {
    flex: 0 0 auto;
    width: calc(340 * var(--cu));
    border-radius: calc(20 * var(--cu));
  }

  .grid-panel {
    flex: 1 1 0;
    padding: calc(20 * var(--cu));
    border-radius: calc(20 * var(--cu));
  }

  .header-card {
    padding: calc(16 * var(--cu)) calc(18 * var(--cu)) calc(14 * var(--cu));
    column-gap: calc(18 * var(--cu));
  }

  .keno-title {
    font-size: calc(30 * var(--cu));
    letter-spacing: calc(4 * var(--cu));
  }

  .progress-labels {
    margin-bottom: calc(6 * var(--cu));
  }

  .progress-count {
    font-size: calc(18 * var(--cu));
  }

  .progress-total {
    font-size: calc(14 * var(--cu));
  }

  .progress-left {
    font-size: calc(15 * var(--cu));
  }

  .progress-track {
    height: calc(6 * var(--cu));
  }

  .stats-card {
    padding: calc(12 * var(--cu));
    gap: calc(8 * var(--cu));
  }

  .stats-section {
    padding: calc(10 * var(--cu));
    border-radius: calc(12 * var(--cu));
  }

  .stats-section-title {
    font-size: calc(10 * var(--cu));
    margin-bottom: calc(6 * var(--cu));
  }

  .tile-grid {
    gap: calc(6 * var(--cu));
  }

  .tile {
    padding: calc(7 * var(--cu)) calc(9 * var(--cu));
    border-radius: calc(8 * var(--cu));
  }

  .tile-top {
    gap: calc(6 * var(--cu));
  }

  .stat-dot {
    width: calc(11 * var(--cu));
    height: calc(11 * var(--cu));
  }

  .tile-label {
    font-size: calc(12.5 * var(--cu));
  }

  .tile-value {
    font-size: calc(12 * var(--cu));
  }

  .q-badge {
    min-width: calc(26 * var(--cu));
    padding: calc(3 * var(--cu)) calc(6 * var(--cu));
    font-size: calc(11 * var(--cu));
    border-radius: calc(6 * var(--cu));
  }

  .ball-grid {
    gap: calc(8 * var(--cu));
  }

  .ball {
    font-size: calc(16 * var(--cu));
    border-radius: calc(8 * var(--cu));
  }

  .ball-grid::before {
    transform: translateX(calc(-4 * var(--cu)));
  }

  .ball-grid::after {
    transform: translateY(calc(-4 * var(--cu)));
  }
}


/* =========================================================
   MAIN ENGINE — 961px and up
   --u = 1px at 1920x1080. Every number is a 1920 design value
   x --u, so 2560x1440 is 1.33x and 3840x2160 is 2x.
   ========================================================= */
@media (min-width: 961px) {

  :root {
    --u: min(calc(100vw / 1920), calc(100vh / 1080));

    /* knobs — the range blocks below override these (design px at 1920) */
    --bw: 480;
    /* badges card width */
    --ball-div: 30.1;
    /* ball size = free strip width / this */
    --ball-gapk: 0.45;
    /* ball gap as a fraction of ball size */
    --ball-fs: 0.375;
    /* ball number size as a fraction of ball size */
    --rh: 85;
    /* result row height */

    --idw: max(70px, calc(120 * var(--u)));
    /* draw-id card width */
    --results-gap: calc(20 * var(--u));
    --badges-track-width: calc(var(--bw) * var(--u));
    --badges-columns: repeat(4, minmax(0, 1fr));
    --result-row-height: calc(var(--rh) * var(--u));

    /* free strip width = 1808 design-px - badges card - id card */
    --mini-ball-size: calc(((1808 - var(--bw)) * var(--u) - var(--idw)) / var(--ball-div));
    --ball-gap: calc(var(--mini-ball-size) * var(--ball-gapk));
  }

  /* ---------- RESULTS PAGE ---------- */

  body {
    padding: calc(16 * var(--u));
    gap: calc(12 * var(--u));
  }

  .page {
    gap: calc(16 * var(--u));
  }

  #resultsPage {
    height: calc(100vh - 32 * var(--u));
  }

  .results-top-row,
  .results-body {
    gap: var(--results-gap);
  }

  .results-top-left {
    gap: calc(16 * var(--u));
  }

  /* inset = card padding + row padding, so header columns sit exactly above the badge columns */
  .results-top-right {
    gap: calc(10 * var(--u));
    padding-left: calc(20 * var(--u));
    padding-right: calc(20 * var(--u));
  }

  .keno-logo-box {
    font-size: max(12px, calc(24 * var(--u)));
    letter-spacing: calc(3 * var(--u));
    padding: calc(14 * var(--u)) calc(20 * var(--u));
    border-radius: calc(14 * var(--u));
  }

  .countdown-bar {
    padding: calc(4 * var(--u)) calc(10 * var(--u));
    gap: calc(4 * var(--u));
    border-radius: calc(20 * var(--u));
  }

  .countdown-side-label {
    font-size: max(8px, calc(13 * var(--u)));
    letter-spacing: calc(0.5 * var(--u));
  }

  .countdown-unit {
    min-width: calc(46 * var(--u));
  }

  .countdown-digit {
    font-size: max(13px, calc(26 * var(--u)));
  }

  .countdown-unit-label {
    font-size: max(6.5px, calc(10 * var(--u)));
    margin-top: calc(2 * var(--u));
  }

  .countdown-divider {
    font-size: max(10px, calc(20 * var(--u)));
  }

  .header-badge {
    white-space: normal;
    font-size: max(7.5px, calc(12 * var(--u)));
    padding: calc(3 * var(--u)) calc(5 * var(--u));
    border-radius: calc(8 * var(--u));
    display: flex;
    justify-content: center;
    align-items: center;
    height: max(26px, calc(30 * var(--u)));
  }

  .badge {
    font-size: max(7.5px, calc(15 * var(--u)));
    padding: calc(3 * var(--u)) calc(5 * var(--u));
    border-radius: calc(12 * var(--u));
  }

  .grid-card,
  .badges-card {
    padding: calc(8 * var(--u)) calc(10 * var(--u)) calc(12 * var(--u));
    border-radius: calc(16 * var(--u));
  }

  .grid-row {
    gap: calc(20 * var(--u));
    padding: 0 calc(10 * var(--u));
  }

  .badge-row {
    gap: calc(10 * var(--u));
    padding: 0 calc(10 * var(--u));
  }

  .draw-id-card {
    flex: 0 0 var(--idw);
    padding: calc(7 * var(--u)) calc(10 * var(--u));
    border-radius: calc(8 * var(--u));
  }

  .draw-id-line {
    font-size: max(8.5px, calc(11.5 * var(--u)));
  }

  .draw-date-line {
    font-size: max(7.5px, calc(11 * var(--u)));
    margin-top: calc(2 * var(--u));
  }

  .draw-balls {
    gap: var(--ball-gap);
  }

  .mini-ball {
    font-size: max(9px, calc(var(--mini-ball-size) * var(--ball-fs)));
  }

  /* ---------- GRID PAGE ---------- */

  .keno-widget {
    --k-cell: calc(116 * var(--u));
    --k-cgap: calc(10 * var(--u));
    --k-pad: calc(24 * var(--u));

    max-width: none;
    width: 100%;
    height: min(calc(100vh - 32 * var(--u)), calc(1048 * var(--u)));
    gap: calc(28 * var(--u));
    justify-content: center;
    align-items: stretch;
  }

  .left-panel {
    width: calc(520 * var(--u));
    align-self: stretch;
    height: auto;
    border-width: calc(2 * var(--u));
    border-radius: calc(20 * var(--u));
  }

  .header-card {
    padding: calc(28 * var(--u)) calc(30 * var(--u)) calc(22 * var(--u));
  }

  .keno-title {
    font-size: calc(54 * var(--u));
    letter-spacing: calc(7 * var(--u));
  }

  .current-ball {
    width: calc(140 * var(--u));
    height: calc(140 * var(--u));
    border-width: calc(6 * var(--u));
    font-size: calc(44 * var(--u));
  }

  .progress-block {
    margin-top: calc(18 * var(--u));
  }

  .progress-labels {
    margin-bottom: calc(6 * var(--u));
  }

  .progress-count {
    font-size: calc(30 * var(--u));
  }

  .progress-total {
    font-size: calc(22 * var(--u));
  }

  .progress-left {
    font-size: calc(24 * var(--u));
  }

  .progress-track {
    height: calc(10 * var(--u));
    border-radius: calc(10 * var(--u));
  }

  .progress-fill {
    border-radius: calc(10 * var(--u));
  }

  .stats-card {
    flex: 1 1 auto;
    padding: calc(20 * var(--u));
    gap: calc(14 * var(--u));
  }

  .stats-section {
    padding: calc(18 * var(--u));
    border-radius: calc(16 * var(--u));
  }

  .stats-section-title {
    font-size: calc(16 * var(--u));
    letter-spacing: calc(1 * var(--u));
    margin-bottom: calc(10 * var(--u));
  }

  .tile-grid {
    gap: calc(10 * var(--u));
  }

  .tile {
    padding: calc(10 * var(--u)) calc(16 * var(--u));
    border-radius: calc(12 * var(--u));
    gap: calc(2 * var(--u));
  }

  .tile-top {
    gap: calc(10 * var(--u));
  }

  .stat-dot {
    width: calc(16 * var(--u));
    height: calc(16 * var(--u));
  }

  .tile-label {
    font-size: calc(19 * var(--u));
  }

  .tile-value {
    font-size: calc(28 * var(--u));
  }

  .q-badge {
    min-width: calc(40 * var(--u));
    padding: calc(4 * var(--u)) calc(9 * var(--u));
    font-size: calc(16 * var(--u));
    border-radius: calc(8 * var(--u));
  }

  .grid-panel {
    flex: 0 0 auto;
    width: calc((10 * var(--k-cell)) + (9 * var(--k-cgap)) + (2 * var(--k-pad)) + 2px);
    align-self: stretch;
    height: auto;
    padding: var(--k-pad);
    border-radius: calc(20 * var(--u));
  }

  .ball-grid {
    grid-template-columns: repeat(10, var(--k-cell));
    grid-auto-rows: var(--k-cell);
    gap: var(--k-cgap);
  }

  .ball {
    font-size: calc(40 * var(--u));
    border-width: 2px;
    border-radius: calc(14 * var(--u));
  }

  .ball-grid::before {
    left: 50%;
    transform: translateX(-0.5px);
  }

  .ball-grid::after {
    top: 50%;
    transform: translateY(-0.5px);
  }

  .animated-draw-ball {
    width: calc(140 * var(--u));
    height: calc(140 * var(--u));
    border-width: calc(6 * var(--u));
    font-size: calc(72 * var(--u));
  }

  .loading-box {
    padding: calc(16 * var(--u)) calc(26 * var(--u));
    border-radius: calc(14 * var(--u));
    font-size: calc(18 * var(--u));
  }
}


/* =========================================================
   THE SIX RANGES
   Each block only sets the knobs for its range. Everything
   else (sizes, fonts, spacing) scales automatically from
   --u / --cu above.
   ========================================================= */

/* Small screens / compact TV browser viewport */
@media screen and (min-width: 769px) and (max-width: 900px) {

  /* Compact layout
     Your <=860px rule stacks the grid page vertically (built for phones).
     On a landscape TV viewport that squashes the 10x8 grid, so keep the
     left panel and grid side by side whenever the screen is landscape.
     Sizes come from the compact engine above. */
  @media (min-aspect-ratio: 1/1) {
    .keno-widget {
      flex-direction: row;
    }
  }
}

/* Medium screens
   769-960 is covered by the compact engine (your 960 TV design, scaled).
   From 961 the main engine takes over; here its balls are packed a bit
   tighter and the badges card is slimmer so more of the screen goes to
   the numbers. */
@media screen and (min-width: 901px) and (max-width: 1100px) {
  :root {
    --bw: 440;
    --ball-div: 26;
    --ball-gapk: 0.20;
    --ball-fs: 0.45;
    --rh: 90;
  }
}

/* Large screens (1280x720, 1366x768 laptops/TVs) */
@media screen and (min-width: 1101px) and (max-width: 1400px) {
  :root {
    --bw: 450;
    --ball-div: 27.2;
    --ball-gapk: 0.28;
    --ball-fs: 0.42;
    --rh: 88;
  }
}

/* Full HD and larger viewports (1440x810, 1536x864, 1600x900) */
@media screen and (min-width: 1401px) and (max-width: 1600px) {
  :root {
    --bw: 460;
    --ball-div: 28.4;
    --ball-gapk: 0.36;
    --ball-fs: 0.40;
    --rh: 86;
  }
}

/* Large TV viewports (1680x945, 1707x960, 1800x1012) */
@media screen and (min-width: 1601px) and (max-width: 1800px) {
  :root {
    --bw: 470;
    --ball-div: 29.2;
    --ball-gapk: 0.41;
    --ball-fs: 0.385;
    --rh: 85;
  }
}

/* Extra-large / 4K browser viewports
   These are exactly your 1920x1080 design values. 2560x1440 scales up
   1.33x and 3840x2160 scales up 2x automatically through --u. */
@media screen and (min-width: 1801px) {
  :root {
    --bw: 480;
    --ball-div: 30.1;
    --ball-gapk: 0.45;
    --ball-fs: 0.375;
    --rh: 85;
  }
}


/* =========================================================
   GRID PAGE — 1920 x 1080 ONLY
   ---------------------------------------------------------
   Scoped to a 1920x1080 screen so it can't affect any other
   resolution (the 960px / laptop rules above are untouched).

   Sizing is derived from the screen instead of hard-coded:
   the 10x8 ball grid is made as large as the viewport height
   allows, then the left stats panel takes a fixed width beside
   it. Both panels stretch to the same full height.

   Height budget for the grid panel (1080 tall screen):
     1080 - 32 (body padding) - 2 (panel border)
          - 48 (panel padding) - 70 (7 row gaps) = 928
     928 / 8 rows = 116px per ball cell
   Width: 10 cells + 9 gaps + padding + border = 1300px
   Left panel 520 + gap 28 + grid 1300 = 1848 (fits in 1888)
   ========================================================= */
@media (min-width: 1800px) and (max-width: 2000px) and (min-height: 900px) and (max-height: 1100px) {

  .keno-widget {
    --k-left: 520px;
    /* left stats panel width */
    --k-gap: 28px;
    /* gap between left panel and grid panel */
    --k-pad: 24px;
    /* grid panel inner padding */
    --k-cgap: 10px;
    /* gap between ball cells */

    /* cell size = whichever is smaller: what fits the height, or what fits the width */
    --k-cell: min(calc((100dvh - 32px - 2px - (2 * var(--k-pad)) - (7 * var(--k-cgap))) / 8),
        calc((100vw - 32px - var(--k-left) - var(--k-gap) - 2px - (2 * var(--k-pad)) - (9 * var(--k-cgap))) / 10));

    max-width: none;
    width: 100%;
    height: calc(100dvh - 32px);
    gap: var(--k-gap);
    justify-content: center;
    align-items: stretch;
  }

  /* ---------- LEFT PANEL: same height as the grid, bigger type ---------- */

  .left-panel {
    width: var(--k-left);
    align-self: stretch;
    height: auto;
    border-width: 2px;
  }

  .header-card {
    padding: 28px 30px 22px;
  }

  .keno-title {
    font-size: 54px;
    letter-spacing: 7px;
  }

  .current-ball {
    width: 140px;
    height: 140px;
    border-width: 6px;
    font-size: 44px;
  }

  .progress-block {
    margin-top: 18px;
  }

  .progress-count {
    font-size: 30px;
  }

  .progress-total {
    font-size: 22px;
  }

  .progress-left {
    font-size: 24px;
  }

  .progress-track {
    height: 10px;
    border-radius: 10px;
  }

  .progress-fill {
    border-radius: 10px;
  }

  /* stats fill the rest of the panel, three equal sections */
  .stats-card {
    flex: 1 1 auto;
    padding: 20px;
    gap: 14px;
  }

  .stats-section {
    padding: 18px;
    border-radius: 16px;
  }

  .stats-section-title {
    font-size: 16px;
    letter-spacing: 1px;
    margin-bottom: 10px;
  }

  .tile-grid {
    gap: 10px;
  }

  .tile {
    padding: 10px 16px;
    border-radius: 12px;
    gap: 2px;
  }

  .tile-top {
    gap: 10px;
  }

  .stat-dot {
    width: 16px;
    height: 16px;
  }

  .tile-label {
    font-size: 19px;
  }

  .tile-value {
    font-size: 28px;
  }

  .q-badge {
    min-width: 40px;
    padding: 4px 9px;
    font-size: 16px;
    border-radius: 8px;
  }

  /* ---------- GRID PANEL: sized from the cell size above ---------- */

  .grid-panel {
    flex: 0 0 auto;
    width: calc((10 * var(--k-cell)) + (9 * var(--k-cgap)) + (2 * var(--k-pad)) + 2px);
    align-self: stretch;
    height: auto;
    padding: var(--k-pad);
  }

  .ball-grid {
    grid-template-columns: repeat(10, var(--k-cell));
    grid-auto-rows: var(--k-cell);
    gap: var(--k-cgap);
  }

  .ball {
    font-size: 40px;
    border-width: 2px;
    border-radius: 14px;
  }

  /* quadrant divider lines: with equal gaps, the middle of the gap between
     col 5/6 and row 4/5 is exactly 50%, so no offset tuning is needed here */
  .ball-grid::before {
    left: 50%;
    transform: translateX(-0.5px);
  }

  .ball-grid::after {
    top: 50%;
    transform: translateY(-0.5px);
  }

  .header-badge {
    white-space: normal;
    font-size: 12px;
    padding: 3px 5px;
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 30px;
  }

  .badge {
    font-size: 15px;
    padding: 3px 5px;
    border-radius: 12px;
  }

  .grid-card,
  .badges-card {
    padding-left: 10px;
    padding-right: 10px;
  }

  .results-top-right {
    padding-left: 10px;
    padding-right: 10px;
  }

  .countdown-bar {
    padding: 4px 10px;
    gap: 4px;
    border-radius: 20px;
  }

  .animated-draw-ball {
    position: fixed;

    width: 140px;
    height: 140px;

    border-radius: 50%;

    display: flex;
    align-items: center;
    justify-content: center;

    background: #fff;
    border: 6px solid var(--amber);

    color: var(--ink);
    font-size: 72px;
    font-weight: 900;

    box-shadow:
      0 0 0 8px rgba(232, 151, 29, 0.18),
      0 12px 35px rgba(0, 0, 0, 0.28);

    transform: translate(-50%, -50%) scale(1);

    will-change: left, top, transform, opacity;

    left: 50%;
    top: 50%;

    opacity: 0;
  }

  #gridPage {
    position: relative;
    /* so the overlay's inset:0 anchors to this page, not the viewport */
  }

  .grid-loading-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.25);
    z-index: 500;
  }

  .grid-loading-overlay[hidden] {
    display: none;
  }

  .loading-box {
    background: #fff;
    padding: 16px 26px;
    border-radius: 14px;
    font-weight: 700;
    font-size: 18px;
    color: var(--ink);
    box-shadow: 0 12px 35px rgba(0, 0, 0, 0.18);
  }

  .grid-blurred {
    filter: blur(6px);
    pointer-events: none;
    user-select: none;
  }

  .dots span {
    animation: loadingDotBlink 1.4s infinite;
    opacity: 0;
  }

  .dots span:nth-child(2) {
    animation-delay: 0.2s;
  }

  .dots span:nth-child(3) {
    animation-delay: 0.4s;
  }

  @keyframes loadingDotBlink {

    0%,
    20% {
      opacity: 0;
    }

    50% {
      opacity: 1;
    }

    100% {
      opacity: 0;
    }
  }

}