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

:root {
  --primary: #222222;
  --primary-dark: #000000;
  --ticked-bg: #c8e6c9;
  --ticked-border: #81c784;
  --free-bg: #e0e0e0;
  --free-border: #9e9e9e;
  --winner-bg: #ffcdd2;
  --winner-border: #e57373;
  --bg: #ffffff;
  --surface: #f5f5f5;
  --cell-bg: #ffffff;
  --cell-border: #666666;
  --text: #111111;
  --text-muted: #666666;
  --gap: 4px;
}

html, body {
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Bebas Neue', -apple-system, BlinkMacSystemFont, sans-serif;
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

#app {
  display: flex;
  flex-direction: column;
  flex: 1;
  padding: 12px;
  max-width: 520px;
  margin: 0 auto;
  width: 100%;
}

header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 0 14px;
}

.logo-wrap {
  background: #000000;
  border-radius: 8px;
  padding: 4px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.logo {
  height: 48px;
  width: auto;
  display: block;
}

h1 {
  font-size: clamp(1.6rem, 7vw, 2rem);
  font-family: 'Bebas Neue', sans-serif;
  font-weight: 400;
  color: var(--text);
  letter-spacing: 0.06em;
  flex: 1;
}

.btn-new-game {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 9px 18px;
  font-family: 'Bebas Neue', sans-serif;
  font-size: 1rem;
  letter-spacing: 0.05em;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}

.btn-new-game:active {
  transform: scale(0.96);
  background: var(--primary-dark);
}

main {
  flex: 1;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

/* ---- Board Container ---- */
.board-container {
  position: relative;
  width: 100%;
}

/* ---- Board ---- */
.board {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: var(--gap);
  width: 100%;
}

.board-container.shaking {
  animation: board-shake 0.6s ease-out;
}

.cell {
  aspect-ratio: 1;
  background: var(--cell-bg);
  border: 1.5px solid var(--cell-border);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  overflow: hidden;
}

.cell:not(.free):active {
  transform: scale(0.93);
}

.cell-text {
  font-family: 'Bebas Neue', sans-serif;
  font-size: clamp(0.5rem, 2.1vw, 0.75rem);
  text-align: center;
  line-height: 1.2;
  word-break: break-word;
  hyphens: auto;
  color: var(--text);
  letter-spacing: 0.03em;
}

/* Ticked state */
.cell.ticked {
  background: var(--ticked-bg);
  border-color: var(--ticked-border);
}

.cell.ticked .cell-text {
  color: #2e7d32;
}

/* Free centre square */
.cell.free {
  background: var(--free-bg);
  border-color: var(--free-border);
  cursor: default;
}

.cell.free .cell-text {
  color: #444444;
  font-size: clamp(0.6rem, 2.6vw, 0.9rem);
  letter-spacing: 0.05em;
}

/* Winning line highlight */
.cell.winner {
  background: var(--winner-bg);
  border-color: var(--winner-border);
  animation: cell-pop 0.35s ease-out;
}

.cell.winner .cell-text {
  color: #c62828;
}

@keyframes cell-pop {
  0%   { transform: scale(1); }
  45%  { transform: scale(1.1); }
  100% { transform: scale(1); }
}

/* ---- BINGO Stamp ---- */
.bingo-stamp {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 10;
  font-family: 'Bebas Neue', sans-serif;
  font-size: clamp(4rem, 20vw, 7rem);
  letter-spacing: 0.12em;
  color: #cc0000;
  -webkit-text-stroke: 3px #880000;
  text-shadow: 3px 3px 0 rgba(0, 0, 0, 0.25);
  animation: stamp-in 0.5s cubic-bezier(0.22, 1, 0.36, 1) forwards;
  transform-origin: center;
}

.bingo-stamp.hidden {
  display: none;
}

@keyframes stamp-in {
  0%   { transform: scale(3) rotate(-8deg); opacity: 0; }
  60%  { transform: scale(0.92) rotate(3deg); opacity: 1; }
  80%  { transform: scale(1.06) rotate(-1.5deg); }
  100% { transform: scale(1) rotate(-2deg); opacity: 1; }
}

@keyframes board-shake {
  0%, 100% { transform: translateX(0) rotate(0); }
  10%      { transform: translateX(-10px) rotate(-1deg); }
  20%      { transform: translateX(10px) rotate(1deg); }
  30%      { transform: translateX(-8px) rotate(-0.8deg); }
  40%      { transform: translateX(8px) rotate(0.8deg); }
  50%      { transform: translateX(-5px) rotate(-0.4deg); }
  60%      { transform: translateX(5px) rotate(0.4deg); }
  70%      { transform: translateX(-3px); }
  80%      { transform: translateX(3px); }
  90%      { transform: translateX(-1px); }
}

/* ---- Win Overlay ---- */
.win-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.win-overlay.hidden {
  display: none;
}

.win-content {
  background: var(--surface);
  border-radius: 20px;
  padding: 40px 28px 32px;
  text-align: center;
  max-width: 320px;
  width: 100%;
  border: 2px solid var(--cell-border);
  animation: overlay-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes overlay-pop {
  from { transform: scale(0.65); opacity: 0; }
  to   { transform: scale(1);    opacity: 1; }
}

.win-title {
  font-family: 'Bebas Neue', sans-serif;
  font-size: clamp(2.4rem, 10vw, 3.2rem);
  font-weight: 400;
  color: var(--text);
  letter-spacing: 0.06em;
  margin-bottom: 8px;
}

.win-subtitle {
  color: var(--text-muted);
  font-size: 1rem;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  margin-bottom: 28px;
}

.btn-share {
  display: block;
  width: 100%;
  background: #111111;
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 15px;
  font-family: 'Bebas Neue', sans-serif;
  font-size: 1.1rem;
  letter-spacing: 0.05em;
  cursor: pointer;
  margin-bottom: 12px;
  transition: opacity 0.2s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.btn-share:active {
  opacity: 0.85;
  transform: scale(0.97);
}

.btn-play-again {
  display: block;
  width: 100%;
  background: transparent;
  color: var(--text-muted);
  border: 1.5px solid var(--cell-border);
  border-radius: 12px;
  padding: 13px;
  font-family: 'Bebas Neue', sans-serif;
  font-size: 1rem;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.btn-play-again:active {
  color: var(--text);
  border-color: var(--text);
  transform: scale(0.97);
}

/* Focus styles for keyboard accessibility */
.cell:focus-visible,
.btn-new-game:focus-visible,
.btn-share:focus-visible,
.btn-play-again:focus-visible {
  outline: 2px solid #444444;
  outline-offset: 2px;
}
