:root {
  --bg: #fff;
  --ink: #111;
  --muted: #6e6e73;
  --field: #f2f2f4;
  --line: #1d1d1f;
  --accent: #b4f200;
  --ui: "Avenir Next Condensed", "Helvetica Neue", Arial, sans-serif;
  --ease: cubic-bezier(.25, .1, .25, 1);
  --ease-out: cubic-bezier(.2, .7, .2, 1);
  --vvh: 100vh;
  --vvt: 0px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--ui);
  -webkit-text-size-adjust: 100%;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

body { position: fixed; inset: 0; }

/* Hauteur réelle visible (clavier compris), mise à jour en JS via visualViewport */
#app {
  position: fixed;
  left: 0; right: 0;
  top: var(--vvt);
  height: var(--vvh);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: max(28px, env(safe-area-inset-top)) 6vw max(24px, env(safe-area-inset-bottom));
  overflow: hidden;
  background: var(--bg);
}

.logo { flex: 0 0 auto; width: min(64vw, 560px); margin: 4vh 0 3vh; transition: width .4s var(--ease), margin .4s var(--ease); }
.logo img { display: block; width: 100%; height: auto; }

/* La casquette garde la même taille et la même place entre l'accueil et le formulaire.
   Elle ne rétrécit que si la place manque (clavier ouvert). */
.cap {
  flex: 0 1 36vh;
  min-height: 0;
  width: 100%;
  max-width: 820px;
}
.cap svg { width: 100%; height: 100%; display: block; }
.is-home .cap { cursor: pointer; }

/* Accueil et formulaire superposés dans la même cellule : la zone a toujours la hauteur du formulaire */
.stage {
  flex: 1 0 auto;
  display: grid;
  align-content: start;
  justify-items: center;
  width: 100%;
  max-width: 640px;
}
.stage > * { grid-area: 1 / 1; }

.home-hint {
  margin: 3vh 0 0;
  font-size: clamp(22px, 3.4vw, 34px);
  font-weight: 400;
  letter-spacing: -0.01em;
  transition: opacity .5s var(--ease), visibility 0s;
}
.is-form .home-hint { opacity: 0; visibility: hidden; transition: opacity .3s var(--ease), visibility 0s .3s; }

.order { width: 100%; visibility: hidden; transition: visibility 0s .4s; }
.order > * { opacity: 0; transform: translateY(12px); transition: opacity .3s var(--ease), transform .3s var(--ease); }
.is-form .order { visibility: visible; transition: none; }
.is-form .order > * { opacity: 1; transform: none; transition: opacity .55s var(--ease), transform .7s var(--ease-out); }
.is-form .order > :nth-child(2) { transition-delay: .06s; }
.is-form .order > :nth-child(3) { transition-delay: .12s; }
.is-form .order > :nth-child(4) { transition-delay: .18s; }

/* Choix de police */
.fonts { display: flex; gap: 4%; margin: 0 0 2.5vh; }
.font-btn {
  flex: 1;
  height: 72px;
  border: 1.5px solid transparent;
  border-radius: 10px;
  background: none;
  color: var(--ink);
  font-size: 30px;
  transition: border-color .3s var(--ease), height .4s var(--ease), font-size .4s var(--ease), transform .15s var(--ease);
}
.font-btn.is-on { border-color: var(--line); }
.font-btn:active { transform: scale(.98); }

.field { display: block; margin-bottom: 2vh; text-align: center; }
.field-label { display: block; font-size: 20px; color: var(--muted); margin-bottom: 8px; transition: font-size .4s var(--ease); }
.field-label small { font-size: 15px; opacity: .7; }

.field input {
  width: 100%;
  height: 64px;
  border: 0;
  border-radius: 10px;
  background: var(--field);
  color: var(--ink);
  text-align: center;
  font-size: 26px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  -webkit-user-select: text;
  user-select: text;
  box-shadow: inset 0 0 0 1.5px transparent;
  transition: box-shadow .25s var(--ease), background-color .25s var(--ease), height .4s var(--ease);
}
.field input:focus { background: #fff; box-shadow: inset 0 0 0 1.5px var(--line); }
.field input.initials { font-size: 36px; text-transform: uppercase; }
.field input.name { font-family: var(--ui); }

.submit {
  display: block;
  width: 62%;
  margin: 3vh auto 0;
  height: 64px;
  border: 0;
  border-radius: 10px;
  background: var(--ink);
  color: #fff;
  font-family: var(--ui);
  font-size: 22px;
  letter-spacing: .04em;
  text-transform: uppercase;
  transition: background-color .3s var(--ease), color .3s var(--ease), transform .15s var(--ease), height .4s var(--ease);
}
.submit:disabled { background: #e8e8ed; color: #a1a1a6; }
.submit:active:not(:disabled) { transform: scale(.98); }

/* Clavier ouvert : on compacte le haut, la casquette se réduit d'elle-même */
.kb .logo { width: min(40vw, 320px); margin: 0 0 1vh; }
.kb .fonts { margin: 1vh 0 1vh; }
.kb .font-btn { height: 52px; font-size: 24px; }
.kb .field { margin-bottom: 1vh; }
.kb .field-label { font-size: 16px; margin-bottom: 4px; }
.kb .field-label small { display: none; }
.kb .field input { height: 50px; }
.kb .submit { margin-top: 1.2vh; height: 54px; }

/* Changement de police dans l'aperçu */
.swap { animation: swap .35s var(--ease); }
@keyframes swap { from { opacity: 0; } }

/* Calques : confirmation et remerciement */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity .4s var(--ease), visibility 0s .4s;
}
.overlay.is-open { opacity: 1; visibility: visible; transition: opacity .4s var(--ease); }
.overlay > * { transform: translateY(10px) scale(.985); transition: transform .5s var(--ease-out); }
.overlay.is-open > * { transform: none; }

.confirm { background: rgba(255, 255, 255, .82); -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px); }
.confirm-box { width: min(86vw, 560px); }
.confirm h2, .thanks h2 { font-size: 40px; font-weight: 600; margin: 0 0 24px; }
.confirm-initials { font-size: 84px; line-height: 1.1; margin-bottom: 8px; }
.confirm-name { font-size: 26px; color: var(--muted); margin-bottom: 24px; }
.confirm p { font-size: 20px; color: var(--muted); margin: 0 0 32px; }
.confirm-actions { display: flex; gap: 16px; }
.confirm-actions > * { flex: 1; width: auto; margin: 0; }
.btn-ghost {
  height: 64px;
  border: 1.5px solid var(--ink);
  border-radius: 10px;
  background: none;
  color: var(--ink);
  font-family: var(--ui);
  font-size: 22px;
  text-transform: uppercase;
  letter-spacing: .04em;
  transition: transform .15s var(--ease);
}
.btn-ghost:active { transform: scale(.98); }

.thanks { background: var(--bg); padding: 0 10vw; }
.thanks-inner { display: flex; flex-direction: column; align-items: center; }
.thanks-logo { width: min(50vw, 420px); margin-bottom: 8vh; }
.thanks p { font-size: 26px; max-width: 560px; margin: 0 0 40px; }
.thanks-number { font-size: 22px; color: var(--muted); letter-spacing: .08em; text-transform: uppercase; }
.thanks-number b { display: block; font-size: 64px; color: var(--ink); letter-spacing: 0; }

/* Témoin discret pour l'équipe : commandes en attente d'envoi */
.queue-dot { position: absolute; right: 14px; bottom: 14px; width: 10px; height: 10px; border-radius: 50%; background: #e0a100; }

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