:root {
  --vert: #00ff66;
  --vert-doux: rgba(0,255,102,.35);
  --vert-fond: rgba(0,255,102,.05);
  --vert-trait: rgba(0,255,102,.18);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
}

body {
  background:
    radial-gradient(ellipse at 50% 45%, rgba(0,255,102,.12), transparent 62%),
    #000;
  color: var(--vert);
  font-family: 'Courier New', monospace;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
}

/* quadrillage discret en fond */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;

  background-image:
    linear-gradient(rgba(0,255,102,.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0,255,102,.05) 1px, transparent 1px);
  background-size: 44px 44px;

  -webkit-mask-image: radial-gradient(ellipse at center, #000 20%, transparent 75%);
  mask-image: radial-gradient(ellipse at center, #000 20%, transparent 75%);
}

/* fines lignes d'écran par-dessus tout */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 5;
  pointer-events: none;

  background: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent 2px,
    rgba(0,0,0,.28) 3px
  );
  opacity: .35;
}

.hud {
  position: relative;
  z-index: 1;

  height: 100dvh;
  max-width: 1500px;
  margin: 0 auto;

  padding:
    env(safe-area-inset-top)
    28px
    env(safe-area-inset-bottom);

  display: flex;
  flex-direction: column;
}

/* EN-TÊTE */

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 0 14px;

  border-bottom: 1px solid transparent;
  border-image: linear-gradient(90deg, var(--vert-doux), transparent 80%) 1;
}

.titre {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.logo {
  font-size: 1.5rem;
  letter-spacing: 12px;

  text-shadow:
    0 0 14px var(--vert),
    0 0 34px var(--vert-doux);
}

.sous-logo {
  font-size: .6rem;
  letter-spacing: 5px;
  opacity: .5;
}

.entete-droite {
  display: flex;
  align-items: center;
  gap: 16px;
}

/* BOUTON VOIX / ÉCRIT */

#mode {
  width: 42px;
  height: 36px;

  display: flex;
  align-items: center;
  justify-content: center;

  background: none;
  border: 1px solid var(--vert-doux);
  border-radius: 4px;
  color: var(--vert);

  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background .3s, box-shadow .3s;
}

#mode:hover,
body.ecrit #mode {
  background: var(--vert-fond);
  box-shadow: 0 0 10px var(--vert-doux);
}

#voyant {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1px solid var(--vert-doux);
}

body.actif #voyant,
body.ecoute #voyant,
body.parle #voyant {
  background: var(--vert);
  box-shadow: 0 0 10px var(--vert);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  50% {
    opacity: .35;
  }
}

/* SCÈNE : panneau gauche | sphère | panneau droit */

.scene {
  flex: 1;
  min-height: 0;

  display: grid;
  grid-template-columns: 280px 1fr 280px;
  gap: 24px;
  align-items: stretch;

  padding: 18px 0 6px;
}

.panneau {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
}

/* CARTES */

.carte {
  position: relative;

  border: 1px solid var(--vert-trait);
  border-radius: 2px;
  padding: 14px 16px;

  background:
    linear-gradient(160deg, rgba(0,255,102,.09), rgba(0,255,102,.02) 60%);

  box-shadow: inset 0 0 24px rgba(0,255,102,.04);
}

/* quatre coins lumineux façon écran de contrôle */
.carte::before {
  content: '';
  position: absolute;
  inset: -1px;
  pointer-events: none;

  background:
    linear-gradient(var(--vert), var(--vert)) top left / 14px 2px no-repeat,
    linear-gradient(var(--vert), var(--vert)) top left / 2px 14px no-repeat,
    linear-gradient(var(--vert), var(--vert)) top right / 14px 2px no-repeat,
    linear-gradient(var(--vert), var(--vert)) top right / 2px 14px no-repeat,
    linear-gradient(var(--vert), var(--vert)) bottom left / 14px 2px no-repeat,
    linear-gradient(var(--vert), var(--vert)) bottom left / 2px 14px no-repeat,
    linear-gradient(var(--vert), var(--vert)) bottom right / 14px 2px no-repeat,
    linear-gradient(var(--vert), var(--vert)) bottom right / 2px 14px no-repeat;
}

.carte h2 {
  display: flex;
  align-items: center;
  gap: 10px;

  font-size: .68rem;
  letter-spacing: 4px;
  font-weight: normal;
  opacity: .75;
  margin-bottom: 12px;
}

/* trait qui prolonge le titre */
.carte h2::after {
  content: '';
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, var(--vert-doux), transparent);
}

.num {
  font-size: .6rem;
  letter-spacing: 1px;
  padding: 1px 5px;
  border: 1px solid var(--vert-doux);
  border-radius: 2px;
  opacity: .8;
}

.grand {
  font-size: 1.9rem;
  letter-spacing: 3px;
  text-shadow: 0 0 12px var(--vert-doux);
}

.moyen {
  font-size: 1.1rem;
  letter-spacing: 3px;
  text-shadow: 0 0 10px var(--vert-doux);
}

.petit {
  font-size: .8rem;
  opacity: .7;
  margin-top: 6px;
  text-transform: capitalize;
}

.bientot {
  font-size: .8rem;
  opacity: .45;
  font-style: italic;
}

.carte-journal,
.carte-fichiers {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* JOURNAL */

#journal {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#journal li {
  font-size: .75rem;
  line-height: 1.4;
  opacity: .85;
  word-break: break-word;

  padding-left: 8px;
  border-left: 1px solid var(--vert-doux);
}

#journal li.toi {
  color: #b8ffd2;
  opacity: .6;
  border-left-color: rgba(184,255,210,.35);
}

#journal li.vide {
  opacity: .4;
  font-style: italic;
  border-left: none;
  padding-left: 0;
}

/* ZONE INTERACTIVE (SPHÈRE) */

#zone {
  min-height: 0;
  overflow: visible;

  background: none;
  border: none;

  display: flex;
  align-items: center;
  justify-content: center;

  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: filter .4s;
}

body.ecoute #zone {
  filter: drop-shadow(0 0 20px var(--vert-doux));
}

body.parle #zone {
  filter: drop-shadow(0 0 30px var(--vert));
}

/* SPHÈRE LUMINEUSE */

.sphere-container {
  width: min(58dvh, 44vw, 520px);
  aspect-ratio: 1;

  display: flex;
  align-items: center;
  justify-content: center;

  position: relative;
  transform-origin: center;

  filter:
    drop-shadow(0 0 12px rgba(0,255,102,.25));
}

#sphere {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

/* anneaux HUD autour de la sphère */
.sphere-container::before,
.sphere-container::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
}

/* anneau extérieur en pointillés, tourne lentement */
.sphere-container::before {
  inset: -9%;
  border: 1px dashed var(--vert-doux);
  animation: tourne 60s linear infinite;
}

/* anneau d'arcs lumineux, tourne en sens inverse */
.sphere-container::after {
  inset: -18%;
  border: 2px solid transparent;
  border-top-color: var(--vert);
  border-bottom-color: var(--vert-doux);
  opacity: .55;
  animation: tourne-inverse 18s linear infinite;
}

@keyframes tourne {
  to {
    transform: rotate(360deg);
  }
}

@keyframes tourne-inverse {
  to {
    transform: rotate(-360deg);
  }
}

/* les anneaux accélèrent quand MOYA écoute ou parle */
body.ecoute .sphere-container::after {
  animation-duration: 8s;
  opacity: .8;
}

body.parle .sphere-container::before {
  animation-duration: 25s;
}

body.parle .sphere-container::after {
  animation-duration: 3s;
  opacity: 1;
}

/* MOYA ACTIVE */

body.actif .sphere-container {
  animation: respiration 4s ease-in-out infinite;
}

/* MOYA ÉCOUTE */

body.ecoute .sphere-container {
  animation: ecoute 2.4s ease-in-out infinite;
}

/* MOYA PARLE */

body.parle .sphere-container {
  animation: parole .7s ease-in-out infinite alternate;

  filter:
    drop-shadow(0 0 20px rgba(0,255,102,.6));
}

@keyframes respiration {
  0%, 100% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.04);
  }
}

@keyframes ecoute {
  0%, 100% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.06);
  }
}

@keyframes parole {
  from {
    transform: scale(.96);
  }

  to {
    transform: scale(1.08);
  }
}

/* STATUT */

#statut {
  text-align: center;
  font-size: .8rem;
  letter-spacing: 6px;
  opacity: .85;
  padding: 8px 0 12px;

  text-shadow: 0 0 10px var(--vert-doux);
}

/* SOUS-TITRES */

#sous-titres {
  min-height: 14dvh;
  max-height: 20dvh;

  overflow-y: auto;
  padding: 14px 0 18px;

  text-align: center;

  display: flex;
  flex-direction: column;
  gap: 10px;

  width: min(900px, 100%);
  margin: 0 auto;

  border-top: 1px solid transparent;
  border-image: linear-gradient(90deg, transparent, var(--vert-doux), transparent) 1;

  scrollbar-width: thin;
  scrollbar-color: var(--vert-doux) transparent;
}

#vous {
  font-size: .9rem;
  color: #b8ffd2;
  opacity: .65;
}

#reponse {
  font-size: 1.15rem;
  line-height: 1.5;

  text-shadow: 0 0 10px var(--vert-doux);
}

#reponse a {
  color: inherit;
  text-decoration: underline;
}

/* MODE ÉCRIT : barre de saisie en bas de l'écran */

body.ecrit .hud {
  /* suit la hauteur réellement visible (clavier ouvert sur téléphone) */
  height: var(--vh-visible, 100dvh);
}

body.ecrit .sphere-container {
  width: min(40dvh, 44vw, 380px);
}

#barre-ecrite {
  display: flex;
  gap: 10px;

  width: min(900px, 100%);
  margin: 0 auto;
  padding: 0 0 14px;
}

#barre-ecrite[hidden] {
  display: none;
}

#saisie {
  flex: 1;
  min-width: 0;

  background: var(--vert-fond);
  border: 1px solid var(--vert-doux);
  border-radius: 4px;
  color: #b8ffd2;

  font-family: inherit;
  font-size: 16px; /* 16px minimum : évite le zoom automatique sur iPhone */

  padding: 12px 14px;
  outline: none;

  -webkit-appearance: none;
  appearance: none;

  /* sans cela, on ne peut pas taper dans le champ sur iPhone */
  -webkit-user-select: text;
  user-select: text;
}

#saisie:focus {
  border-color: var(--vert);
  box-shadow: 0 0 12px var(--vert-doux);
}

#saisie::placeholder {
  color: var(--vert);
  opacity: .4;
}

#envoyer-ecrit {
  width: 48px;

  display: flex;
  align-items: center;
  justify-content: center;

  background: var(--vert-fond);
  border: 1px solid var(--vert-doux);
  border-radius: 4px;
  color: var(--vert);

  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

#envoyer-ecrit:hover,
#envoyer-ecrit:active {
  border-color: var(--vert);
  box-shadow: 0 0 10px var(--vert-doux);
}

/* PETIT ÉCRAN : on cache les panneaux */

@media (max-width: 900px) {
  .scene {
    grid-template-columns: 1fr;
  }

  .panneau {
    display: none;
  }

  .sphere-container {
    width: min(70vw, 340px);
  }

  body.ecrit .sphere-container {
    width: min(46vw, 210px);
  }

  .hud {
    padding-left: 18px;
    padding-right: 18px;
  }

  .logo {
    letter-spacing: 9px;
  }

  .sous-logo {
    display: none;
  }
}

/* respecte les réglages « réduire les animations » */
@media (prefers-reduced-motion: reduce) {
  .sphere-container::before,
  .sphere-container::after {
    animation: none;
  }
}