:root {
  color-scheme: light;
  --navy: #071a3d;
  --blue: #1728c9;
  --red: #ed1717;
  --gold: #ffd84a;
  --ink: #101010;
  --paper: #fffdf7;
  --muted: #5f6878;
  --line: #111;
  --shadow: 0 18px 50px rgb(0 0 0 / 20%);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  min-height: 100%;
  background: var(--navy);
}

body {
  min-height: 100dvh;
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 50% -10%, #244882 0, transparent 44%),
    linear-gradient(180deg, #071a3d 0%, #0a224b 100%);
}

button {
  font: inherit;
}

.app-shell {
  width: min(100%, 880px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}

.app-header {
  text-align: center;
  color: white;
}

.app-header h1 {
  margin: 0;
  font-family: "Comic Sans MS", "Trebuchet MS", sans-serif;
  font-size: clamp(2.15rem, 8vw, 4.8rem);
  line-height: 1;
  letter-spacing: -0.05em;
  text-shadow: 0 3px 0 rgb(0 0 0 / 18%);
}

.app-header h1 span:first-child {
  color: #ff3030;
}

.app-header h1 span:last-child {
  color: #5a72ff;
}

.subtitle {
  margin: 7px 0 12px;
  color: #dce7ff;
  font-size: clamp(0.83rem, 2.6vw, 1rem);
}

.toolbar {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 0 auto 10px;
  flex-wrap: wrap;
}

.control {
  min-height: 42px;
  padding: 9px 15px;
  border: 1px solid rgb(255 255 255 / 32%);
  border-radius: 999px;
  color: white;
  background: rgb(255 255 255 / 10%);
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
}

.control:hover,
.control:focus-visible {
  background: rgb(255 255 255 / 19%);
}

.control:focus-visible,
.tile:focus-visible,
.dialog-close:focus-visible {
  outline: 4px solid #7ad7ff;
  outline-offset: 2px;
}

.control.primary {
  border-color: #ff6262;
  background: var(--red);
}

.control.install {
  border-color: #f8cf2e;
  color: #17203a;
  background: var(--gold);
}

.icon-control {
  width: 42px;
  padding-inline: 0;
  font-size: 1.2rem;
}

.status {
  min-height: 27px;
  margin: 0 auto 7px;
  color: #e6edff;
  text-align: center;
  font-size: 0.9rem;
  font-weight: 700;
}

.status.bingo {
  color: #ffe36c;
  font-size: 1.05rem;
  animation: celebrate 650ms ease both;
}

.bingo-board {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  width: min(96vw, 760px);
  margin: 0 auto;
  overflow: hidden;
  border: clamp(4px, 0.75vw, 8px) solid var(--line);
  border-radius: 8px;
  background: var(--line);
  box-shadow: var(--shadow);
}

.tile {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  min-width: 0;
  margin: 0;
  padding: clamp(4px, 1.4vw, 13px);
  border: 0;
  border-right: clamp(2px, 0.38vw, 4px) solid var(--line);
  border-bottom: clamp(2px, 0.38vw, 4px) solid var(--line);
  border-radius: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: Impact, "Arial Black", sans-serif;
  font-size: clamp(0.66rem, 1.9vw, 1.1rem);
  line-height: 1.08;
  text-align: center;
  overflow-wrap: anywhere;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  transition: background-color 130ms ease, color 130ms ease, transform 80ms ease;
}

.tile.tile-short {
  font-size: clamp(0.88rem, 2.55vw, 1.5rem);
}

.tile.tile-medium {
  font-size: clamp(0.76rem, 2.2vw, 1.3rem);
}

.tile.tile-long {
  font-size: clamp(0.66rem, 1.9vw, 1.1rem);
}

.tile:nth-child(5n) {
  border-right: 0;
}

.tile:nth-last-child(-n + 5) {
  border-bottom: 0;
}

.tile:active:not(.center) {
  transform: scale(0.965);
}

.tile.marked {
  color: #061533;
  background: #ffe26e;
}

.tile.marked:not(.center)::after {
  content: "✓";
  position: absolute;
  right: 5px;
  bottom: 1px;
  color: rgb(7 26 61 / 35%);
  font-family: Arial, sans-serif;
  font-size: clamp(1.1rem, 5vw, 2.1rem);
  font-weight: 900;
}

.tile.winner {
  color: white;
  background: var(--red);
  animation: winner-pulse 700ms ease both;
}

.tile.center {
  cursor: default;
  background: linear-gradient(145deg, #fff7b8, #ffd84a);
}

.tile.center img {
  width: 63%;
  height: 63%;
  object-fit: contain;
  filter: drop-shadow(0 3px 2px rgb(0 0 0 / 22%));
}

.tile.center::after {
  content: "FREE";
  position: absolute;
  bottom: 4%;
  color: #1d2d4e;
  font-family: Arial, sans-serif;
  font-size: clamp(0.42rem, 1.6vw, 0.78rem);
  font-weight: 900;
  letter-spacing: 0.12em;
}

.hint {
  margin: 11px 0 0;
  color: #b9c7e6;
  text-align: center;
  font-size: 0.78rem;
}

dialog {
  width: min(90vw, 470px);
  padding: 0;
  border: 0;
  border-radius: 22px;
  color: var(--ink);
  background: white;
  box-shadow: 0 25px 80px rgb(0 0 0 / 45%);
}

dialog::backdrop {
  background: rgb(0 10 30 / 72%);
  backdrop-filter: blur(3px);
}

.dialog-content {
  position: relative;
  padding: 28px;
}

.dialog-content h2 {
  margin: 0 0 12px;
  color: var(--navy);
}

.dialog-content p {
  line-height: 1.5;
}

.dialog-content .primary {
  display: block;
  margin: 18px auto 0;
}

.dialog-close {
  position: absolute;
  top: 9px;
  right: 12px;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 50%;
  color: #4e596e;
  background: #edf0f5;
  font-size: 1.5rem;
  cursor: pointer;
}

@keyframes winner-pulse {
  50% { transform: scale(1.04); }
}

@keyframes celebrate {
  from { opacity: 0; transform: translateY(5px) scale(0.95); }
  to { opacity: 1; transform: none; }
}

@media (max-width: 430px) {
  .app-shell {
    padding-inline: 7px;
  }

  .toolbar {
    gap: 6px;
  }

  .control {
    min-height: 38px;
    padding: 7px 11px;
    font-size: 0.78rem;
  }

  .icon-control {
    width: 38px;
  }

  .tile {
    aspect-ratio: auto;
    min-height: clamp(76px, 21.5vw, 92px);
    padding: 2px;
    line-height: 0.98;
    letter-spacing: -0.015em;
  }

  .tile.tile-short {
    font-size: clamp(0.86rem, 4.35vw, 1.15rem);
  }

  .tile.tile-medium {
    font-size: clamp(0.75rem, 3.75vw, 1rem);
  }

  .tile.tile-long {
    font-size: clamp(0.69rem, 3.25vw, 0.86rem);
  }
}

@media (orientation: landscape) and (max-height: 650px) {
  .app-shell {
    display: grid;
    grid-template-columns: minmax(170px, 1fr) auto;
    grid-template-rows: auto auto auto 1fr;
    gap: 4px 10px;
    align-items: center;
    width: 100%;
    min-height: 100dvh;
    padding: max(6px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  }

  .app-header,
  .toolbar,
  .status,
  .hint {
    grid-column: 1;
  }

  .bingo-board {
    grid-column: 2;
    grid-row: 1 / 5;
    align-self: center;
    justify-self: end;
    width: min(92vh, calc(100vw - 190px), 650px);
    aspect-ratio: 1;
  }

  .app-header h1 {
    font-size: clamp(1.75rem, 5.2vw, 3.35rem);
  }

  .subtitle {
    margin: 4px 0 6px;
  }

  .toolbar {
    gap: 5px;
    margin-bottom: 2px;
  }

  .control {
    min-height: 36px;
    padding: 6px 10px;
    font-size: 0.78rem;
  }

  .icon-control {
    width: 36px;
  }

  .status {
    min-height: 20px;
    margin: 0;
    font-size: 0.78rem;
  }

  .hint {
    align-self: end;
    margin: 0;
    font-size: 0.7rem;
  }

  .tile {
    min-height: 0;
    aspect-ratio: 1;
    padding: 2px;
    line-height: 0.94;
    overflow: hidden;
  }

  .tile.tile-short {
    font-size: clamp(0.72rem, 2.6vw, 1.15rem);
  }

  .tile.tile-medium {
    font-size: clamp(0.64rem, 2.15vw, 0.95rem);
  }

  .tile.tile-long {
    font-size: clamp(0.58rem, 1.85vw, 0.82rem);
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
