*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: #F8FAFC;
  color: #111827;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow-x: hidden;
}

[hidden] { display: none !important; }

.app {
  max-width: 480px;
  margin: 0 auto;
  padding: 12px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

h1 { margin: 0; font-size: 1.5rem; font-weight: 800; }

.btn {
  min-height: 48px;
  min-width: 48px;
  padding: 0 16px;
  border-radius: 12px;
  font: inherit;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}
.btn-primary { background: #1D4ED8; color: #fff; border: 2px solid #1D4ED8; }
.btn-primary:active { background: #1E40AF; border-color: #1E40AF; }
.btn-secondary { background: #fff; color: #1D4ED8; border: 2px solid #1D4ED8; }
.btn-secondary:active { background: #EFF6FF; }

button:focus-visible { outline: 3px solid #1D4ED8; outline-offset: 2px; }

.notice {
  margin: 0;
  padding: 8px 12px;
  border-radius: 10px;
  background: #FEF3C7;
  color: #78350F;
  font-size: 0.875rem;
  font-weight: 600;
}

.status {
  margin: 0;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 1.125rem;
  font-weight: 600;
}
.bingo-status { color: #166534; font-weight: 800; }

.card {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  width: 100%;
  max-width: min(100%, 70vh, 480px);
  max-width: min(100%, 70dvh, 480px);
  margin: 0 auto;
}

.square {
  position: relative;
  aspect-ratio: 1 / 1;
  min-width: 0;
  min-height: 44px;
  padding: 3px 2px;
  border: 2px solid #1F2937;
  border-radius: 10px;
  background: #FFFFFF;
  color: #111827;
  font: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  overflow: hidden;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: transform 80ms ease-out;
}
.square:active:not([aria-disabled="true"]) { transform: scale(0.96); }

.square .icon { font-size: clamp(1.1rem, 6vw, 1.75rem); line-height: 1; }
.square .name {
  font-size: clamp(0.6875rem, 2.6vw, 0.875rem);
  font-weight: 700;
  line-height: 1.1;
  text-align: center;
  overflow-wrap: anywhere;
  hyphens: auto;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.square .name.long { font-size: clamp(0.6875rem, 2.2vw, 0.75rem); }

.square.marked { background: #15803D; color: #fff; }
.square.marked::after {
  content: "✓";
  position: absolute;
  top: 1px;
  right: 4px;
  font-size: 0.875rem;
  font-weight: 800;
}
.square.free { cursor: default; }
.square.win { background: #166534; color: #fff; border: 4px solid #FACC15; }

.stats { margin: 0; font-size: 0.9375rem; font-weight: 500; color: #374151; text-align: center; }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 10;
}
.overlay-clear { background: rgba(0, 0, 0, 0.25); z-index: 20; }

.dialog {
  background: #fff;
  color: #111827;
  border-radius: 12px;
  padding: 24px;
  max-width: 360px;
  width: 100%;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}
.dialog h2 { margin: 0 0 8px; font-size: 1.25rem; }
.dialog p { margin: 0 0 16px; font-size: 1rem; }
.dialog-buttons { display: flex; gap: 12px; justify-content: flex-end; flex-wrap: wrap; }

.banner { text-align: center; }
.bingo-title { font-size: 3rem !important; font-weight: 800; margin: 0 0 8px !important; color: #166534; }
.bingo-time { font-size: 1.25rem !important; font-weight: 600; }

.confetti {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 30;
}

@media (prefers-reduced-motion: reduce) {
  .square { transition: none; }
  .square:active:not([aria-disabled="true"]) { transform: none; }
}
