:root {
  --cobalt: #1d4596;
  --navy: #13265c;
  --tile: #f7f3ea;
  --glaze: #2f62c0;
  --gold: #d4a72c;
  --display: 'Rye', 'Georgia', serif;
  --text: 'Atkinson Hyperlegible', -apple-system, system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: max(14px, env(safe-area-inset-top)) 16px max(14px, env(safe-area-inset-bottom));
  background: var(--cobalt);
  color: var(--tile);
  font: 17px/1.4 var(--text);
  -webkit-text-size-adjust: 100%;
}

/* Header and progress */
.top { text-align: center; }

h1 {
  margin: 0;
  font: 400 22px/1.2 var(--display);
  letter-spacing: 0.01em;
}

.progress {
  margin-top: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.pips { display: flex; gap: 4px; }

.pip {
  width: 12px;
  height: 12px;
  border: 1.5px solid var(--gold);
  border-radius: 2px;
  transition: background-color 0.4s;
}

.pip.on { background: var(--gold); }

.count { color: var(--gold); font-weight: 700; font-size: 15px; }

/* The board: certificate tiles under azulejo covers */
.stage {
  flex: 1 1 auto;
  min-height: 240px;
  position: relative;
}

.board {
  position: absolute;
  inset: 0;
  margin: auto;
  height: 100%;
  max-width: 100%;
  aspect-ratio: 1125 / 2000;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(9, 1fr);
  background: var(--navy);
  border: 3px solid var(--gold);
  outline: 3px solid var(--navy);
}

.board.finished { cursor: zoom-in; }

.cell { position: relative; overflow: hidden; }

.cell img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.cover {
  position: absolute;
  inset: 0;
  background-color: var(--tile);
  background-image:
    radial-gradient(circle at 50% 50%, var(--gold) 0 7%, transparent 8%),
    radial-gradient(circle at 50% 30%, var(--glaze) 0 13%, transparent 14%),
    radial-gradient(circle at 70% 50%, var(--glaze) 0 13%, transparent 14%),
    radial-gradient(circle at 50% 70%, var(--glaze) 0 13%, transparent 14%),
    radial-gradient(circle at 30% 50%, var(--glaze) 0 13%, transparent 14%),
    radial-gradient(circle at 0 0, var(--navy) 0 24%, transparent 25%),
    radial-gradient(circle at 100% 0, var(--navy) 0 24%, transparent 25%),
    radial-gradient(circle at 0 100%, var(--navy) 0 24%, transparent 25%),
    radial-gradient(circle at 100% 100%, var(--navy) 0 24%, transparent 25%);
  box-shadow: inset 0 0 0 1px rgba(19, 38, 92, 0.35);
  transform-origin: center;
  transition: transform 0.55s cubic-bezier(0.55, 0, 0.75, 0.2), opacity 0.55s ease-in;
  transition-delay: calc(var(--i, 0) * 70ms);
  backface-visibility: hidden;
}

.cell.open .cover {
  transform: perspective(500px) rotateY(90deg) scale(0.92);
  opacity: 0;
}

.board.instant .cover { transition: none; }

/* Question card */
.card {
  background: var(--tile);
  color: var(--navy);
  border-radius: 12px;
  padding: 12px 14px 14px;
}

.card .label { margin: 0; font-size: 15px; opacity: 0.75; }

.card .question { margin: 2px 0 10px; font-size: 19px; line-height: 1.35; font-weight: 700; }

.answer { display: flex; gap: 8px; }

.answer input {
  font-size: 18px; /* 16px or more, or iOS Safari zooms in on focus */
  font-family: var(--text);
  flex: 1;
  min-width: 0;
  height: 48px;
  padding: 0 12px;
  color: var(--navy);
  background: #fff;
  border: 2px solid var(--navy);
  border-radius: 8px;
}

button {
  height: 48px;
  padding: 0 18px;
  font: 700 17px var(--text);
  color: var(--navy);
  background: var(--gold);
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

button:disabled { opacity: 0.6; }

input:focus-visible,
button:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}

.card.shake { animation: shake 0.4s; }

@keyframes shake {
  20%, 60% { transform: translateX(-8px); }
  40%, 80% { transform: translateX(8px); }
}

.status {
  margin: 0;
  min-height: 1.4em;
  text-align: center;
  font-weight: 700;
  color: var(--gold);
}

/* Finish */
.done { text-align: center; }

.done h2 {
  margin: 0 0 4px;
  font: 400 30px/1.15 var(--display);
  color: var(--gold);
}

.done-actions { display: flex; justify-content: center; gap: 10px; margin-top: 10px; }

body.locked { overflow: hidden; }

/* Full-screen reveal: opens by itself after the last tiles flip */
.reveal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  background: var(--cobalt);
}

.reveal[hidden] { display: none; }

.reveal h2 {
  margin: 0;
  font: 400 30px/1.15 var(--display);
  color: var(--gold);
  text-align: center;
}

.reveal .frame {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: flex;
  justify-content: center;
}

.reveal img {
  height: 100%;
  width: auto;
  max-width: 100%;
  object-fit: contain;
  border: 3px solid var(--gold);
  outline: 3px solid var(--navy);
}

.reveal.show img { animation: pop 0.7s cubic-bezier(0.2, 0.9, 0.3, 1.2); }
.reveal.show h2 { animation: pop 0.7s 0.15s cubic-bezier(0.2, 0.9, 0.3, 1.2) both; }

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

.reveal-actions { display: flex; gap: 10px; }

button.quiet {
  color: var(--tile);
  background: transparent;
  border: 2px solid var(--tile);
}

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

@media (prefers-reduced-motion: reduce) {
  .cover { transition: opacity 0.3s; transition-delay: 0s; }
  .cell.open .cover { transform: none; }
  .card.shake { animation: none; }
  .reveal.show img, .reveal.show h2 { animation: none; }
}
