:root {
  color-scheme: dark;
  --bg: #12122a;
  --bg-glow: #2a2160;
  --surface: #23234a;
  --sheet-bg: #17173a;
  --border: rgb(255 255 255 / 0.14);
  --text: #f4f4fb;
  --muted: #a6a6c8;
  --accent: #ff5a5f;
  --gold: #ffc23d;
  --on-gold: #1d1606;
  --wood: #f1d29a;
  /* Replaced at runtime with the measured bar height (see app.js). */
  --bar-height: calc(140px + 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));
  --content-width: 720px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
}

html {
  background-color: var(--bg);
  /* iOS Safari enlarges text in landscape unless told not to. */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  /* 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 {
  display: flex;
  align-items: center;
  gap: 10px;
  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 {
  opacity: 0.45;
  cursor: not-allowed;
}

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

/* Top bar */

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

.logo {
  width: 32px;
  height: 32px;
  border-radius: 8px;
}

#undo {
  padding-inline: 0.85rem;
  white-space: nowrap;
}

/* Layout */

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

.game {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.banner {
  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;
  text-wrap: balance;
}

.next {
  align-self: center;
  min-height: 52px;
  padding-inline: 1.6rem;
  border-color: var(--gold);
  color: var(--gold);
  font-size: 1.15rem;
  font-weight: 800;
}

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

/* Board: one column per team, with its points and its matches. */

.board {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  /* Boxes per column, plus room for the «Buenas» divider. */
  --rows: 6.6;
  /* The boxes shrink on short screens, so the whole game fits above the score bar. */
  --box: clamp(34px, calc((100dvh - 430px) / var(--rows)), 64px);
}

.board[data-boxes="3"] {
  --rows: 3.2;
}

.team {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 0;
  padding: 6px 6px 14px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--sheet-bg);
}

.team h2 {
  width: 100%;
  color: var(--text);
  font-size: inherit;
  letter-spacing: normal;
  text-transform: none;
}

/* Tap a name to change it. */
.team-name {
  display: block;
  width: 100%;
  overflow: hidden;
  padding: 4px 6px;
  border: none;
  border-radius: 12px;
  background: none;
  font-size: 1.1rem;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.team-name::after {
  content: " ✎";
  color: var(--muted);
  font-size: 0.8em;
  font-weight: 400;
}

.games {
  margin: 0;
  color: var(--gold);
  font-size: 0.9rem;
  font-weight: 700;
}

.points {
  margin: 4px 0 0;
  font-size: 3rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.points.won {
  color: var(--gold);
}

.stage {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.stage.buenas {
  color: var(--gold);
}

.tally {
  display: flex;
  flex-direction: column;
  align-items: center;
  align-self: stretch;
  gap: 2px;
  margin-top: 8px;
}

.box {
  display: block;
  width: var(--box);
  height: var(--box);
}

.frame {
  fill: none;
  stroke: rgb(255 255 255 / 0.12);
  stroke-dasharray: 20 16;
  stroke-width: 8;
}

.stick {
  stroke: var(--wood);
  stroke-linecap: round;
  stroke-width: 26;
}

.head {
  fill: var(--accent);
}

.match {
  opacity: 0;
  transition: opacity 0.2s;
}

.match.on {
  opacity: 1;
}

.divider {
  width: 80%;
  margin: 2px 0;
  padding-top: 2px;
  border-top: 1px dashed var(--gold);
  color: var(--gold);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-align: center;
  text-transform: uppercase;
}

/* Score bar: pinned to the bottom, one half per team, within thumb reach. */

.actions {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 10px max(var(--gutter-right), calc((100% - var(--content-width)) / 2 + 16px)) calc(10px + var(--safe-bottom))
    max(var(--gutter-left), calc((100% - var(--content-width)) / 2 + 16px));
  border-top: 1px solid var(--border);
  background: rgb(18 18 42 / 0.92);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}

.side {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.small {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.small button {
  padding: 0;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

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

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

/* Options */

/* A list of label | control rows, like the options of the bingo caller. */
.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);
}

.options h2,
.option-buttons {
  grid-column: 1 / -1;
}

.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);
}

.option-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 4px;
}

/* A phone on its side: one row of buttons per team, so the bar leaves room for the board. */
@media (orientation: landscape) and (max-height: 500px) {
  .side {
    flex-direction: row;
  }

  .small {
    flex: 3;
  }

  .actions .primary {
    flex: 2;
    min-height: 44px;
    font-size: 1.3rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  button,
  .match {
    transition: none;
  }
}
