:root {
  --cream: #fffaf0;
  --green: #78c66f;
  --green-dark: #4c9f5c;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  min-height: 100%;
}

body {
  display: grid;
  place-items: center;
  overflow: hidden;
  isolation: isolate;
  background: #dff4f0;
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, sans-serif;
}

button, input { font: inherit; }

#game {
  position: relative;
  width: min(100vw, calc(100dvh * 9 / 16));
  height: min(100dvh, calc(100vw * 16 / 9));
  aspect-ratio: 9 / 16;
  overflow: hidden;
  isolation: isolate;
  background: #bfeaf1;
}


.start-screen,
.play-screen {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.start-screen {
  z-index: 50;
}

.start-button {
  appearance: none;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.start-button img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}

.start-button:focus-visible {
  outline: clamp(3px, .7vw, 6px) solid #2b7fc4;
  outline-offset: calc(clamp(3px, .7vw, 6px) * -1);
}

.play-screen[hidden],
.start-screen[hidden] {
  display: none;
}

.background {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 0;
}

.topbar {
  position: absolute;
  z-index: 10;
  top: max(2.5%, env(safe-area-inset-top));
  left: 4%;
  right: 4%;
  height: 7.5%;
  display: flex;
  align-items: center;
  gap: 3%;
}

.image-button {
  appearance: none;
  border: 0;
  padding: 0;
  margin: 0;
  background: transparent;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: transform 120ms ease, filter 120ms ease;
}

.image-button:active { transform: scale(.92); }
.image-button:focus-visible { outline: 3px solid #2b7fc4; outline-offset: 3px; border-radius: 18%; }

.image-button img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.home-button {
  width: 11.5%;
  aspect-ratio: 1;
  flex: 0 0 auto;
}

.progress {
  position: relative;
  flex: 1 1 auto;
  height: 27%;
  overflow: hidden;
  border: clamp(2px, .45vw, 5px) solid rgba(255, 250, 232, .95);
  border-radius: 999px;
  background: rgba(255,255,255,.72);
  box-shadow: inset 0 2px 5px rgba(80,120,80,.12), 0 2px 8px rgba(80,120,80,.12);
}

.progress-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(180deg, #a9df7f, #66b96f);
  box-shadow: inset 0 2px 3px rgba(255,255,255,.45);
  transition: width 350ms ease;
}

.score {
  position: relative;
  width: 15%;
  flex: 0 0 auto;
}

.score img { display: block; width: 100%; }
.score span {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: clamp(13px, 3.1vw, 24px);
  font-weight: 900;
  color: #805713;
  transform: translateY(1%);
}

.game-card {
  position: absolute;
  z-index: 5;
  left: 5%;
  width: 90%;
  top: 29%;
  height: 55%;
  transform-origin: center;
}

.card-background {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
  pointer-events: none;
}

.snail {
  position: absolute;
  z-index: 5;
  width: 34%;
  height: auto;
  top: -17%;
  left: 7%;
  transform-origin: 50% 100%;
  pointer-events: none;
}

.object-zone {
  position: relative;
  z-index: 2;
  left: 17%;
  top: 12%;
  width: 66%;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  overflow: hidden;
  isolation: isolate;
  border-radius: 17%;
  background: linear-gradient(180deg, rgba(216,248,250,.96), rgba(244,255,225,.96));
  box-shadow: inset 0 0 0 clamp(3px, .8vw, 7px) rgba(255,255,255,.82), 0 7px 16px rgba(56,121,70,.10);
}

.object-image {
  display: block;
  width: auto;
  height: auto;
  max-width: 68%;
  max-height: 68%;
  object-fit: contain;
  object-position: center;
  position: relative;
  z-index: 1;
  flex: none;
  filter: drop-shadow(0 8px 8px rgba(86,76,46,.08));
}

/*
 * Certains SVG exportés (notamment jardin et cartable) ont des dimensions
 * intrinsèques atypiques. Leur boîte d'affichage reste strictement centrée
 * et bornée, sans que l'image puisse passer devant les contrôles.
 */
.object-image[data-word="jardin"],
.object-image[data-word="cartable"] {
  width: 62%;
  height: 62%;
  max-width: none;
  max-height: none;
  object-fit: contain;
  object-position: center;
  overflow: hidden;
}

.object-image[data-word="jardin"] {
  width: 56%;
  height: 56%;
}

.audio-button {
  position: absolute;
  z-index: 10;
  width: 21%;
  aspect-ratio: 1;
  right: 10%;
  bottom: 25%;
}

.answer-zone {
  position: absolute;
  z-index: 3;
  left: 7%;
  right: 7%;
  bottom: 12%;
  height: 13%;
  display: flex;
  gap: 3%;
}

#answerInput {
  flex: 1 1 auto;
  min-width: 0;
  border: clamp(2px, .55vw, 6px) solid #b9d988;
  border-radius: 999px;
  padding: 0 7%;
  outline: none;
  background: rgba(255,253,248,.98);
  color: #43563d;
  text-align: center;
  font-size: clamp(18px, 4.5vw, 38px);
  font-weight: 800;
  caret-color: var(--green-dark);
  box-shadow: inset 0 2px 5px rgba(111,130,90,.08), 0 5px 12px rgba(70,110,67,.08);
}

#answerInput:focus {
  border-color: #83bc69;
  box-shadow: 0 0 0 clamp(2px, .5vw, 5px) rgba(131,188,105,.22);
}

.validate-button {
  height: 100%;
  aspect-ratio: 1;
  flex: 0 0 auto;
}

.image-button:disabled {
  cursor: default;
  pointer-events: none;
  filter: saturate(.75) brightness(.98);
}

#answerInput:disabled {
  opacity: 1;
  -webkit-text-fill-color: #43563d;
}

#answerInput::placeholder {
  color: #7d9c71;
  opacity: .9;
  letter-spacing: .08em;
}

#answerInput.revealed {
  border-color: #f0bc55;
  background: #fff8df;
  color: #73511c;
  -webkit-text-fill-color: #73511c;
  box-shadow: 0 0 0 clamp(2px, .5vw, 5px) rgba(240,188,85,.22);
}

.correct { animation: success 520ms ease; }
.wrong { animation: error 350ms ease; }
.snail-happy { animation: snailHappy 520ms ease; }

@keyframes success {
  0%,100% { transform: scale(1); }
  45% { transform: scale(1.025); }
}

@keyframes error {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-2.2%); }
  50% { transform: translateX(2.2%); }
  75% { transform: translateX(-1.1%); }
}

@keyframes snailHappy {
  0%,100% { transform: translateY(0) rotate(0); }
  45% { transform: translateY(-7%) rotate(-3deg); }
}

.end-panel {
  position: absolute;
  z-index: 30;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(84,142,114,.16);
  backdrop-filter: blur(4px);
}

.end-panel[hidden] { display: none; }

.end-card {
  width: 72%;
  padding: 10% 8%;
  border: 4px solid rgba(255,255,255,.85);
  border-radius: 12%;
  text-align: center;
  background: rgba(255,250,232,.95);
  box-shadow: 0 18px 40px rgba(55,97,73,.18);
}

.end-stars {
  color: #f7b71c;
  font-size: clamp(32px, 10vw, 72px);
  letter-spacing: .12em;
  margin-bottom: 12%;
}

#restartButton {
  border: 0;
  border-radius: 999px;
  padding: .75em 1.7em;
  background: linear-gradient(#92da77, #5eb96a);
  color: white;
  font-size: clamp(18px, 4.5vw, 34px);
  font-weight: 900;
  box-shadow: 0 7px 0 #469c58;
  cursor: pointer;
}

#restartButton:active { transform: translateY(4px); box-shadow: 0 3px 0 #469c58; }

@media (orientation: landscape) {
  #game {
    width: calc(100dvh * 9 / 16);
    height: 100dvh;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}
