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

:root {
  --page-bg: #F5F5F2;
  --header-bg: #FFFFFF;
  --text-primary: #1A1A1A;
  --text-secondary: #6B6B6B;
  --accent: #2563EB;
  --border: #E2E2DE;
  --shadow-sm: rgba(0, 0, 0, 0.06);
  --shadow-md: rgba(0, 0, 0, 0.12);
  --reset-red: #EF4444;
  --reset-red-hover: #DC2626;
  --check-green: #22C55E;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--page-bg);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
}

/* ── HEADER ─────────────────────────────────────────── */

header {
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
  padding: 16px 24px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 10px var(--shadow-sm);
}

.header-content {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

h1 {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  line-height: 1.2;
}

.tagline {
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin-top: 3px;
}

.header-stats {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 5px;
  flex-shrink: 0;
}

.counter {
  line-height: 1;
}

#count {
  font-size: 2.2rem;
  font-weight: 900;
  color: var(--accent);
  letter-spacing: -0.03em;
}

.counter-denom {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.counter-label {
  font-size: 0.7rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.progress-bar-wrap {
  width: 120px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.35s ease;
}

#reset-btn {
  background: none;
  border: 1.5px solid var(--border);
  color: var(--text-secondary);
  padding: 4px 14px;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
  margin-top: 2px;
}

#reset-btn:hover {
  border-color: var(--reset-red);
  color: var(--reset-red);
}

/* ── AD SLOTS ────────────────────────────────────────── */

.ad-slot {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #EEEEED;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  color: #BBBBBB;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.ad-banner {
  width: 100%;
  height: 90px;
}

.ad-banner::before {
  content: 'Advertisement';
}

/* Desktop: fills grid cell beside How to Play */
.ad-rectangle {
  grid-area: ad;
  border-top: none;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  padding: 24px 16px;
}

.ad-rectangle::before {
  content: 'Advertisement';
}

/* ── CONTENT LAYOUT (grid wrapper) ──────────────────── */

.content-layout {
  max-width: 1200px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr 300px;
  grid-template-areas:
    "htp  ad"
    "main main";
}

/* ── MAIN + GRID ─────────────────────────────────────── */

main {
  grid-area: main;
  padding: 32px 24px 0;
}

.plate-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
  gap: 14px;
}

/* ── PLATE TILE ──────────────────────────────────────── */

.plate {
  position: relative;
  background: var(--plate-bg, #FFFFFF);
  color: var(--plate-text, #003087);
  border-radius: 7px;
  aspect-ratio: 2 / 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  box-shadow:
    inset 0 0 0 4px rgba(0, 0, 0, 0.10),
    0 2px 6px var(--shadow-sm),
    0 1px 2px var(--shadow-sm);
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.25s ease;
  outline: none;
}

/* Inner frame line */
.plate::before {
  content: '';
  position: absolute;
  inset: 6px;
  border: 1px solid rgba(128, 128, 128, 0.18);
  border-radius: 3px;
  pointer-events: none;
}

/* Bolt decorations */
.plate::after {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle 3px at 10px 50%, rgba(0,0,0,0.12) 100%, transparent 100%),
    radial-gradient(circle 3px at calc(100% - 10px) 50%, rgba(0,0,0,0.12) 100%, transparent 100%);
  border-radius: 7px;
  pointer-events: none;
}

.plate:hover {
  transform: translateY(-2px);
  box-shadow:
    inset 0 0 0 4px rgba(0, 0, 0, 0.10),
    0 8px 20px var(--shadow-md),
    0 2px 6px var(--shadow-sm);
}

.plate:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.plate:active {
  transform: translateY(0);
}

.plate-abbr {
  font-size: 2rem;
  font-weight: 900;
  letter-spacing: 0.06em;
  line-height: 1;
}

.plate-name {
  font-size: 0.52rem;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  margin-top: 6px;
  opacity: 0.8;
}

/* ── SPOTTED STATE ───────────────────────────────────── */

.plate.spotted {
  filter: grayscale(100%) opacity(0.32);
}

.plate.spotted:hover {
  filter: grayscale(80%) opacity(0.48);
  transform: translateY(-1px);
}

.check-badge {
  position: absolute;
  top: 5px;
  right: 7px;
  width: 20px;
  height: 20px;
  background: var(--check-green);
  border-radius: 50%;
  display: none;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
  z-index: 1;
}

.check-badge svg {
  width: 11px;
  height: 11px;
  stroke: #FFFFFF;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.plate.spotted .check-badge {
  display: flex;
}

/* ── HOW TO PLAY ─────────────────────────────────────── */

.how-to-play {
  grid-area: htp;
  padding: 24px 24px 28px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.how-to-play h2 {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 10px;
  color: var(--text-primary);
}

.how-to-play p {
  font-size: 0.875rem;
  color: var(--text-secondary);
  max-width: 660px;
  line-height: 1.75;
}

.how-to-play p + p {
  margin-top: 8px;
}

/* ── FOOTER ──────────────────────────────────────────── */

footer {
  text-align: center;
  padding: 20px 24px;
  font-size: 0.78rem;
  color: var(--text-secondary);
  border-top: 1px solid var(--border);
}

/* ── MODAL ───────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

.modal-overlay[hidden] {
  display: none;
}

.modal {
  background: #FFFFFF;
  border-radius: 14px;
  padding: 28px 32px 24px;
  max-width: 360px;
  width: calc(100% - 48px);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.22);
}

.modal h3 {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.modal p {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: 24px;
  line-height: 1.6;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.modal-actions button {
  padding: 9px 20px;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background 0.15s;
}

#modal-cancel {
  background: #F0F0EE;
  color: var(--text-primary);
}

#modal-cancel:hover {
  background: #E4E4E2;
}

.btn-danger {
  background: var(--reset-red);
  color: #FFFFFF;
}

.btn-danger:hover {
  background: var(--reset-red-hover);
}

/* ── RESPONSIVE ──────────────────────────────────────── */

@media (max-width: 640px) {
  h1 {
    font-size: 1.05rem;
  }

  .tagline {
    display: none;
  }

  #count {
    font-size: 1.8rem;
  }

  .progress-bar-wrap {
    width: 90px;
  }

  .content-layout {
    grid-template-columns: 1fr;
    grid-template-areas:
      "htp"
      "main"
      "ad";
  }

  .how-to-play {
    padding: 20px 16px 24px;
    border-right: none;
  }

  /* Mobile: centered rectangle below the plate grid */
  .ad-rectangle {
    width: 336px;
    height: 280px;
    max-width: calc(100% - 28px);
    margin: 32px auto;
    border: 1px dashed #D0D0CE !important;
    border-radius: 4px;
  }

  main {
    padding: 20px 14px 0;
  }

  .plate-grid {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 10px;
  }

  .plate-abbr {
    font-size: 1.65rem;
  }

  .plate-name {
    font-size: 0.48rem;
  }
}

@media (max-width: 400px) {
  .plate-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  header {
    padding: 12px 16px;
  }
}
