:root {
  color-scheme: dark;
  --bg: #12122a;
  --bg-glow: #2a2160;
  --surface: #23234a;
  --border: rgb(255 255 255 / 0.14);
  --text: #f4f4fb;
  --muted: #a6a6c8;
  --accent: #ff5a5f;
  --accent-dark: #b3262b;
  --gold: #ffc23d;
  --on-gold: #1d1606;
  --ball-size: min(62vw, 36vh, 300px);
  /* Replaced at runtime with the measured bar height (see app.js). */
  --bar-height: calc(89px + env(safe-area-inset-bottom, 0px));
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --gutter-left: max(16px, env(safe-area-inset-left, 0px));
  --gutter-right: max(16px, env(safe-area-inset-right, 0px));
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
}

html {
  background-color: var(--bg);
  /* Keeps pinch zoom but drops double-tap zoom, so fast taps never zoom the page. */
  touch-action: manipulation;
}

body {
  min-height: 100dvh;
  /* Not "fixed": iOS ignores it and it forces repaints while scrolling. */
  background: radial-gradient(circle at 20% -10%, var(--bg-glow), var(--bg) 55%) no-repeat;
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.4;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: 1.4rem;
}

h2 {
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

button,
select {
  min-height: 44px;
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: inherit;
  /* 16px or more stops iOS Safari from zooming in on focus. */
  font: inherit;
  font-size: 1rem;
  cursor: pointer;
}

button {
  transition: transform 0.1s;
}

button:active:not(:disabled) {
  transform: scale(0.96);
}

@media (hover: hover) {
  button:hover:not(:disabled),
  select:hover:not(:disabled) {
    border-color: rgb(255 255 255 / 0.35);
  }
}

button:focus-visible,
select:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}

button:disabled,
button[aria-disabled="true"],
select:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Classes below set "display", which would otherwise beat the hidden attribute. */
[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Top bar */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 1200px;
  margin: 0 auto;
  padding: calc(12px + var(--safe-top)) var(--gutter-right) 4px var(--gutter-left);
}

.toggles {
  display: flex;
  gap: 8px;
}

.toggles button {
  padding-inline: 0.85rem;
  white-space: nowrap;
}

#auto[aria-pressed="true"] {
  border-color: var(--gold);
  color: var(--gold);
}

/* Layout */

.app {
  display: grid;
  gap: 28px;
  max-width: 1200px;
  margin: 0 auto;
  /* Leave room for the fixed action bar on phones, with a clear gap under the last option. */
  padding: 8px var(--gutter-right) calc(var(--bar-height) + 40px) var(--gutter-left);
}

/* Caller: ball, actions, history */

.caller {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.ball {
  display: grid;
  place-items: center;
  width: var(--ball-size);
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, #ff9a9d, var(--accent) 42%, var(--accent-dark));
  box-shadow:
    inset -12px -16px 30px rgb(0 0 0 / 0.35),
    0 24px 48px rgb(0 0 0 / 0.45);
}

.ball-number {
  display: grid;
  place-items: center;
  width: 62%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff, #e9e9f2);
  color: #15152b;
  font-size: calc(var(--ball-size) * 0.3);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.ball.empty .ball-number {
  color: #b9b9cc;
}

.ball.rolling {
  animation: shake 0.18s linear infinite;
}

@keyframes shake {
  0%,
  100% {
    transform: rotate(0deg);
  }
  25% {
    transform: rotate(-10deg) translateX(-4px);
  }
  75% {
    transform: rotate(10deg) translateX(4px);
  }
}

.saying {
  margin: 0;
  color: var(--gold);
  font-size: 1.3rem;
  font-weight: 700;
  text-align: center;
  text-wrap: balance;
}

.card-news {
  margin: 0;
  padding: 10px 18px;
  border-radius: 14px;
  background: var(--gold);
  color: var(--on-gold);
  font-size: 1.2rem;
  font-weight: 800;
  text-align: center;
}

.status {
  margin: 0;
  min-height: 1.4em;
  color: var(--muted);
  text-align: center;
}

/* On phones the main buttons sit in a bar pinned to the bottom, within thumb reach. */
.actions {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 10;
  display: flex;
  gap: 8px;
  padding: 12px var(--gutter-right) calc(12px + var(--safe-bottom)) var(--gutter-left);
  border-top: 1px solid var(--border);
  background: rgb(18 18 42 / 0.92);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}

.actions .primary {
  flex: 1;
  min-height: 64px;
  border: none;
  background: var(--gold);
  color: var(--on-gold);
  font-size: 1.35rem;
  font-weight: 800;
}

.actions #repeat {
  min-height: 64px;
}

@media (hover: hover) {
  .actions .primary:hover:not(:disabled) {
    background: #ffd36f;
  }
}

/* Deshacer, ¡Línea!, ¡Bingo!: smaller than the main buttons, and away from the thumb bar. */
.tools {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.tools button {
  padding-inline: 0.9rem;
  font-size: 0.95rem;
}

.tools .claim {
  border-color: var(--gold);
  color: var(--gold);
  font-weight: 700;
}

.history {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.history-list {
  display: flex;
  gap: 8px;
  min-height: 48px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.history-list li {
  display: grid;
  place-items: center;
  width: 48px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* Cards with a line or bingo */

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

.cards-empty {
  margin: 0;
  color: var(--muted);
}

.cards-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.cards-label {
  color: var(--muted);
  font-weight: 600;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.chips li {
  min-width: 44px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

/* Cards from a set printed in several colors get a dot in their color. */
.chips li[style*="--card-color"]::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 6px;
  border: 1px solid rgb(255 255 255 / 0.6);
  border-radius: 50%;
  background: var(--card-color);
  vertical-align: baseline;
}

.chips.bingo li {
  border-color: var(--gold);
  background: var(--gold);
  color: var(--on-gold);
}

/* Board */

.board-wrap {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.count {
  margin-left: 8px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  letter-spacing: normal;
}

.board {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: 5px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.board li {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  border-radius: 8px;
  background: rgb(255 255 255 / 0.05);
  color: rgb(255 255 255 / 0.55);
  font-size: clamp(0.85rem, 3.6vw, 1.3rem);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  transition:
    background-color 0.3s,
    color 0.3s;
}

.board li.drawn {
  background: var(--gold);
  color: var(--on-gold);
  font-weight: 800;
}

.board li.last {
  background: #fff;
  color: #15152b;
  box-shadow: 0 0 0 3px var(--accent);
}

/* Options */

/* A list of label | control rows. The divider spans the full width, the rows at most 420px. */
.options {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 12px 14px;
  padding: 20px max(0px, calc((100% - 420px) / 2)) 0;
  border-top: 1px solid var(--border);
}

/* Each label spans both columns and puts its text and control in the columns of .options.
   justify-items pushes the label text to the right, next to its control. */
.field {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: subgrid;
  align-items: center;
  justify-items: end;
  color: var(--muted);
}

.field select {
  width: 100%;
  color: var(--text);
}

.options #reset {
  grid-column: 1 / -1;
  justify-self: center;
  margin-top: 4px;
}

.check {
  min-height: 44px;
  cursor: pointer;
}

.check input {
  justify-self: start;
  width: 22px;
  height: 22px;
  margin: 0;
  accent-color: var(--gold);
  cursor: pointer;
}

/* Wide screens: two columns, buttons back under the ball. */

@media (min-width: 900px) {
  .app {
    grid-template-columns: minmax(320px, 400px) 1fr;
    align-items: start;
    padding: 16px var(--gutter-right) calc(32px + var(--safe-bottom)) var(--gutter-left);
  }

  .actions {
    position: static;
    width: 100%;
    max-width: 400px;
    padding: 0;
    border: none;
    background: none;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }

  .options {
    grid-column: 1 / -1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ball.rolling {
    animation: none;
  }

  button,
  .board li {
    transition: none;
  }
}
