/* ============================================================
   Le raconteur de territoire
   Charte Thibaut Loubère (teal / lime / mint / rose, Bricolage + Inter)
   Pensé pour l'iPhone tenu à une main : la question en haut, le micro sous le pouce.
   ============================================================ */
:root {
  --tl-teal: #0F3B40; --tl-teal-deep: #0B2E32;
  --tl-cream: #F5F1E8;
  --tl-lime: #D9F26A; --tl-mint: #3DE0B4; --tl-pink: #F5B6CC; --tl-pink-strong: #F58FB0;
  --tl-on-dark-70: rgba(245, 241, 232, 0.70); --tl-on-dark-55: rgba(245, 241, 232, 0.55);
  --tl-line: rgba(245, 241, 232, 0.16);
  --font-title: 'Bricolage Grotesque', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --radius: 16px; --radius-pill: 999px;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --glow:
    radial-gradient(ellipse 90% 50% at 10% 0%, rgba(61, 224, 180, 0.14), transparent),
    radial-gradient(ellipse 70% 45% at 95% 100%, rgba(217, 242, 106, 0.10), transparent);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; height: 100%; }
body {
  margin: 0; min-height: 100%; min-height: 100dvh;
  font-family: var(--font-body); font-size: 16px; line-height: 1.5; color: var(--tl-cream);
  background-color: var(--tl-teal); background-image: var(--glow); background-attachment: fixed;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
button, input, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--tl-lime); outline-offset: 3px; }
h1:focus { outline: none; }

.app {
  display: flex; flex-direction: column;
  min-height: 100vh; min-height: 100dvh; max-width: 520px; margin: 0 auto;
  padding: calc(14px + env(safe-area-inset-top)) calc(22px + env(safe-area-inset-right)) calc(18px + env(safe-area-inset-bottom)) calc(22px + env(safe-area-inset-left));
}

/* ---------- En-tête ---------- */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--tl-on-dark-70); }
.brand img { width: 30px; height: 30px; border-radius: 8px; }
.brand span { font-size: 11px; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; line-height: 1.35; }
.brand b { font-weight: 600; color: var(--tl-lime); }
.count { font-size: 13px; font-weight: 600; color: var(--tl-on-dark-55); font-variant-numeric: tabular-nums; }
.bar { height: 3px; margin-top: 14px; border-radius: 3px; background: var(--tl-line); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; border-radius: 3px; background: var(--tl-lime); transition: width 500ms var(--ease-out); }

/* ---------- Écrans ---------- */
.screen { flex: 1; display: flex; flex-direction: column; min-height: 0; padding-top: 26px; animation: in 420ms var(--ease-out); }
.screen--center { justify-content: center; align-items: flex-start; gap: 14px; padding-bottom: 12vh; }
@keyframes in { from { opacity: 0; transform: translateY(10px); } }
.status { margin: auto 0; color: var(--tl-on-dark-70); }

.intro { margin: 0 0 18px; font-size: 14px; color: var(--tl-on-dark-70); }
.q { margin: 0; font-family: var(--font-title); font-weight: 700; font-size: clamp(28px, 8.2vw, 38px); line-height: 1.08; letter-spacing: -0.02em; text-wrap: balance; }
.hint { margin: 12px 0 0; font-size: 15px; color: var(--tl-on-dark-70); text-wrap: pretty; }

/* ---------- Réponse ---------- */
.answer {
  flex: 1 1 auto; display: block; width: 100%; min-height: 84px; margin: 20px 0 0; padding: 0 0 0 16px; resize: none;
  background: transparent; border: 0; border-left: 3px solid var(--tl-line); border-radius: 0;
  font-size: 18px; line-height: 1.5; color: var(--tl-cream); caret-color: var(--tl-lime);
  transition: border-color 300ms var(--ease-out);
}
.answer::placeholder { color: var(--tl-on-dark-55); opacity: 1; }
.answer:focus { outline: none; border-left-color: var(--tl-lime); }
.is-listening .answer { border-left-color: var(--tl-mint); }
.answer.has-text { border-left-color: var(--tl-mint); }

/* ---------- Micro ---------- */
.mic-zone { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 18px 0 20px; }
.mic {
  position: relative; width: 124px; height: 124px; border-radius: 50%; border: 0; padding: 0; cursor: pointer;
  background: var(--tl-lime); color: var(--tl-teal);
  box-shadow: 0 18px 44px rgba(217, 242, 106, 0.22);
  transition: transform 250ms var(--ease-out), background 250ms var(--ease-out), box-shadow 250ms var(--ease-out);
  touch-action: manipulation;
}
.mic:active { transform: scale(0.95); }
.mic__icon { position: absolute; inset: 0; margin: auto; width: 52px; height: 52px; fill: currentColor; transition: opacity 200ms, transform 300ms var(--ease-out); }
.mic__icon--stop { opacity: 0; transform: scale(0.6); }
.mic__ring { position: absolute; inset: 0; border-radius: 50%; border: 2px solid var(--tl-pink); opacity: 0; pointer-events: none; }
.is-listening .mic { background: var(--tl-pink); box-shadow: 0 18px 44px rgba(245, 143, 176, 0.28); }
.is-listening .mic__icon--mic { opacity: 0; transform: scale(0.6); }
.is-listening .mic__icon--stop { opacity: 1; transform: none; }
.is-listening .mic__ring { animation: ring 1.8s var(--ease-out) infinite; }
.is-listening .mic__ring--2 { animation-delay: 0.9s; }
@keyframes ring { from { opacity: 0.7; transform: scale(1); } to { opacity: 0; transform: scale(1.55); } }
.mic-label { margin: 0; min-height: 1.5em; font-size: 14px; font-weight: 500; text-align: center; color: var(--tl-on-dark-70); }
.is-listening .mic-label { color: var(--tl-pink); }
.no-speech .mic { width: 84px; height: 84px; }
.no-speech .mic__icon { width: 36px; height: 36px; }

/* ---------- Boutons ---------- */
.nav { display: flex; gap: 10px; }
.btn {
  flex: 1; display: inline-flex; align-items: center; justify-content: center; min-height: 52px; padding: 0 22px;
  font-size: 16px; font-weight: 600; line-height: 1; border-radius: var(--radius-pill); border: 1.5px solid transparent; cursor: pointer;
  transition: transform 250ms var(--ease-out), background 250ms var(--ease-out), border-color 250ms var(--ease-out), opacity 250ms;
  touch-action: manipulation;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: wait; }
.btn--mint { background: var(--tl-mint); color: var(--tl-teal); }
.btn--ghost { flex: 0 0 auto; background: transparent; color: var(--tl-cream); border-color: rgba(245, 241, 232, 0.28); }
.btn--quiet { background: transparent; color: var(--tl-cream); border-color: rgba(245, 241, 232, 0.28); }
.link { align-self: center; margin-top: 16px; padding: 8px; background: none; border: 0; font-size: 13px; color: var(--tl-on-dark-55); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }

/* ---------- Choix du type ---------- */
.chips { flex: 1; display: flex; flex-direction: column; gap: 10px; margin: 24px 0 20px; }
.chip {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; min-height: 58px; padding: 12px 18px; text-align: left;
  font-size: 17px; font-weight: 600; color: var(--tl-cream); background: rgba(245, 241, 232, 0.06);
  border: 1.5px solid var(--tl-line); border-radius: var(--radius); cursor: pointer;
  transition: background 250ms var(--ease-out), border-color 250ms var(--ease-out), color 250ms, transform 250ms var(--ease-out);
  touch-action: manipulation;
}
.chip::after { content: '→'; color: var(--tl-on-dark-55); transition: transform 300ms var(--ease-out), color 250ms; }
.chip:active { transform: scale(0.98); }
.chip[aria-pressed="true"] { background: var(--tl-lime); border-color: var(--tl-lime); color: var(--tl-teal); }
.chip[aria-pressed="true"]::after { color: var(--tl-teal); transform: translateX(3px); }

/* ---------- Envoi ---------- */
.end { flex: 1; display: flex; flex-direction: column; margin-top: 26px; }
.field { display: block; }
.field__label { display: block; margin-bottom: 8px; font-size: 14px; font-weight: 500; color: var(--tl-on-dark-70); }
.field__label em { font-style: normal; color: var(--tl-on-dark-55); }
.field__input {
  display: block; width: 100%; min-height: 52px; padding: 0 16px; font-size: 17px; color: var(--tl-cream);
  background: rgba(245, 241, 232, 0.06); border: 1.5px solid var(--tl-line); border-radius: var(--radius);
}
.field__input::placeholder { color: var(--tl-on-dark-55); opacity: 1; }
.field__input:focus { outline: none; border-color: var(--tl-lime); }
.check { display: flex; gap: 12px; align-items: flex-start; margin: 20px 0 0; font-size: 15px; line-height: 1.45; color: var(--tl-cream); cursor: pointer; }
.check input { flex: 0 0 auto; width: 24px; height: 24px; margin: 0; accent-color: var(--tl-lime); }
.trap { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.error { margin: 16px 0 0; padding: 12px 14px; font-size: 14px; color: var(--tl-teal); background: var(--tl-pink); border-radius: 12px; }
.end .nav { margin-top: auto; padding-top: 24px; }

/* ---------- Merci ---------- */
.done-mark { display: grid; place-items: center; width: 72px; height: 72px; border-radius: 50%; background: var(--tl-lime); color: var(--tl-teal); margin-bottom: 6px; }
.done-mark svg { width: 38px; height: 38px; }
#s-done .btn { flex: 0 0 auto; margin-top: 14px; }

@media (max-height: 640px) {
  .screen { padding-top: 18px; }
  .intro { margin-bottom: 12px; }
  .mic { width: 104px; height: 104px; }
  .mic-zone { padding: 12px 0 14px; }
  .answer { min-height: 64px; margin-top: 14px; }
}
@media (min-width: 700px) {
  .app { padding-top: 40px; padding-bottom: 40px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .is-listening .mic__ring { opacity: 0.5; transform: scale(1.2); }
}
