html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  padding: 0;
  overscroll-behavior: none;
  touch-action: none;
}

body {
  background: #0f0f0f;
  color: #eee;
  font-family: sans-serif;
  padding:
    env(safe-area-inset-top)
    env(safe-area-inset-right)
    env(safe-area-inset-bottom)
    env(safe-area-inset-left);
}

*, *::before, *::after {
  box-sizing: border-box;
}

* {
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* Numpad */
#root {
  position: absolute;
  inset: 0;
  padding: 5px;
  margin-right: 5px;
  height: 100dvh;
  touch-action: none;
  overflow: hidden;
}

.grid {
  display: grid;
  width: 100%;
  height: 100%;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 4px;
}

.cell {
  background: #222;
  border-radius: 6px;
  padding: 1px;
  position: relative;
  min-height: 0;
  min-width: 0;
}

.hiddencell {
  padding: 1px;
  position: relative;
  min-height: 0;
  min-width: 0;
}

.label, .back {
  position: absolute;
  width: 100%;
  height: 100%;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.25s ease;
  cursor: pointer;
}

.label-text {
  display: block;
  transition: opacity 0.25s ease;
  font-weight: bold;
  line-height: 1em;
}

.grid.level-0 { gap: 4px; margin: 2px; }
.grid.level-1 { gap: 2px; margin: 1px; }
.grid.level-2 { gap: 1px; }

.cell.level-1 { background: #333; }
.cell.level-0.full { background: #176638; }
.cell.level-1.full { background: #239954; }
.cell.level-2.full { background: #2ecc71; }
.cell.level-2.full.gold { background: #ffd700; }

.level-0 .label .label-text { opacity: 0.9; font-size: 140px; }
.level-1 .label .label-text { opacity: 0.1; font-size: 30px; }
.level-2 .label .label-text { opacity: 0.1; font-size: 6px; }

.level-1 .back { font-size: 30px; }
.level-2 .back { font-size: 6px; }

.level-0 .label { z-index: 3; }
.level-1 .label { z-index: 2; }

.cell.level-2 {
  z-index: 1;
  cursor: pointer;
  padding: 1px;
  background: #444;
}

.hiddencell.level-0 {
  background: #222;
  border-radius: 6px;
  padding: 4px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 16px;
  align-items: center;
}

/* Intro overlay */
#intro-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;

  display: flex;
  align-items: center;
  justify-content: center;

  padding: 0.8rem;

  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);

  transition: opacity 0.4s ease;
}

#intro-modal {
  background: #fff;
  color: #222;
  max-width: 420px;
  max-height: 100%;
  padding: 1.5rem;
  border-radius: 14px;
  text-align: center;
  box-shadow: 0 20px 40px rgba(0,0,0,0.3);
  overflow-y: auto;
  flex: 1;
  touch-action: auto;
}

#intro-modal button {
  margin-top: 0.5rem;
  padding: 0.6rem 1.2rem;
  font-size: 1rem;
  font-weight: bold;

  border: none;
  border-radius: 8px;
  cursor: pointer;

  background: #4CAF50;
  color: white;
}

#intro-modal button:hover {
  background: #43a047;
}

#intro-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.plate {
  display: flex;
  align-items: center;
  justify-content: space-between;

  width: 100%;
  min-width: 175px;
  max-width: 420px;
  aspect-ratio: 520 / 110;

  background: linear-gradient(#ffffff, #f4f4f4);
  border: 3px solid #000;
  border-radius: 8px;

  font-family: "Arial Black", "DIN", sans-serif;
  box-shadow: inset 0 0 0 2px #ccc;
}

.plate-left,
.plate-right {
  width: 14%;
  height: 100%;
  background: #003399;
  color: white;

  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.plate-number {
  flex: 1;
  text-align: center;
  font-size: clamp(1.2rem, 8vw, 2.0rem);
  letter-spacing: 0.15em;
  color: #000;
  white-space: nowrap;
}

.eu-stars {
  font-size: clamp(0.4rem, 5vw, 1.2rem);
  line-height: 1;
}

.country {
  font-size: clamp(0.4rem, 5vw, 1.2rem);
  font-weight: bold;
  margin-top: 0.2em;
}

.region {
  font-size: clamp(0.4rem, 5vw, 1.2rem);
  font-weight: bold;
  margin-top: 0.2em;
}

.region-logo {
  font-size: clamp(0.4rem, 5vw, 1.2rem);
}


/* Progress */
#progress {
  width: 100%;
  max-width: 400px;
  height: 30px;
  background-color: #ddd;
  border-radius: 15px;
  overflow: hidden;
  position: relative;
  display: block;
  margin: 5px auto;
}

#progress-bar {
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  width: 0%; /* dynamically updated */
  background-color: #4CAF50;
  transition: width 0.4s ease;
  border-radius: 15px 0 0 15px;
}

#progress-text {
  position: absolute;
  inset: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  font-weight: bold;
  color: white;
  user-select: none;
  text-shadow: 1px 1px 1px grey;
}

#progress-text.gold {
  color: #ffd700;
}


/* Trophies */
#trophies {
  width: 100%;
}

.trophy {
  display: inline-flex;
  align-items: baseline;
  gap: 0.4em;
  overflow: visible;
  width: 100%;
}

.trophy .emoji {
  transform-origin: center;
  animation: spin-smooth 2.0s cubic-bezier(0.12, 0.82, 0.18, 1) forwards;
  z-index: 100;
}
@keyframes spin-smooth {
  from {
    transform: rotate(0deg) scale(1.5);
  }
  to {
    transform: rotate(1800deg) scale(1);
  }
}


/* Confettis */
.confetti-container {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 9999;
}

.confetti {
  position: absolute;
  left: 50%;
  top: 50%;
  transform-origin: center;
  font-size: clamp(1.4rem, 4vw, 2.6rem);
  will-change: transform, opacity;
  animation-name: confetti-burst;
  animation-timing-function: cubic-bezier(.18,.65,.35,1);
}

@keyframes confetti-burst {
  0% {
    transform: translate(-50%, -50%) scale(0.4) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform:
      translate(var(--x), var(--y))
      scale(1)
      rotate(var(--r));
    opacity: 0;
  }
}


/* Smaller screens */
@media (max-width: 400px), (max-height: 500px) {
  .cell { border-radius: 4px; }
  .level-0.hiddencell { font-size: 13px; }
  .level-0 .label .label-text { font-size: 100px; }
  .level-1 .label .label-text { font-size: 22px; }
  .level-2 .label .label-text { font-size: 4px; }
  .level-1 .back { font-size: 22px; }
  .level-2 .back { font-size: 4px; }
}

@media (max-width: 280px), (max-height: 350px) {
  .cell { border-radius: 2px; }
  .level-0.hiddencell { font-size: 11px; }
  .level-0 .label .label-text { font-size: 70px; }
  .level-1 .label .label-text { font-size: 14px; }
  .level-2 .label .label-text { font-size: 2px; }
  .level-1 .back { font-size: 14px; }
  .level-2 .back { font-size: 2px; }
}

@media (max-height: 300px) {
  .cell { border-radius: 2px; }
  .level-0.hiddencell { font-size: 9px; }
  .level-0 .label .label-text { font-size: 40px; }
  .level-1 .label .label-text { font-size: 8px; }
  .level-2 .label .label-text { font-size: 1px; }
  .level-1 .back { font-size: 8px; }
  .level-2 .back { font-size: 1px; }
}

@media (max-height: 400px) {
  .hiddencell.level-0.left { flex-direction: row; }
}