/* ============================================================
   AETHEL DUST & ECHOES - theme "terminal militaire retro-futuriste".
   Ecran CRT, gris tres sombres, ambre et phosphore vert.

   Contraintes assumees :
   - Tout est en unites relatives et en clamp() : la meme feuille sert un
     ecran 4K et un telephone en 360 px de large.
   - Aucune police externe : sur un reseau degrade, un @font-face qui
     n'arrive pas laisse l'interface invisible plusieurs secondes.
   ============================================================ */

:root {
  /* Palette */
  --bg-void:      #07090a;
  --bg-deep:      #0d1113;
  --bg-panel:     #12181b;
  --bg-raised:    #1a2226;
  --line:         #24333a;
  --line-bright:  #35505c;

  --amber:        #ffb03a;
  --amber-dim:    #a86e1c;
  --phosphor:     #6ef0a0;
  --phosphor-dim: #2c7a4a;

  --hp:           #e04b42;
  --stamina:      #e8c545;
  --energy:       #4aa8e0;
  --rads:         #7dd87d;

  --text:         #c8d6dc;
  --text-dim:     #6b8189;
  --text-faint:   #3f5158;

  --danger:       #e04b42;
  --ok:           #6ef0a0;

  --radius: 3px;
  --mono: 'Courier New', 'DejaVu Sans Mono', monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg-void);
  color: var(--text);
  font-family: var(--mono);
  font-size: 15px;
  line-height: 1.5;
  overflow: hidden;
  /* Empeche le zoom par double-tap et le "pull to refresh" sur mobile,
     qui rendraient les commandes tactiles du jeu inutilisables. */
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* ── Effet CRT ────────────────────────────────────────────────
   Les scanlines sont un pseudo-element fixe et non-interactif. On les
   desactive sous 700 px : sur un ecran de telephone a forte densite, le
   motif de 3 px produit un moire desagreable et coute du fillrate. */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  background: repeating-linear-gradient(
    0deg,
    rgba(0, 0, 0, 0.16) 0px,
    rgba(0, 0, 0, 0.16) 1px,
    transparent 1px,
    transparent 3px
  );
  mix-blend-mode: multiply;
}
@media (max-width: 700px) {
  body::after { display: none; }
}

/* Vignettage : concentre le regard au centre de l'ecran. */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9998;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(0, 0, 0, 0.55) 100%);
}

/* ── Typographie ──────────────────────────────────────────── */
h1, h2, h3 {
  font-weight: normal;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--amber);
}
h1 { font-size: clamp(1.3rem, 4vw, 2rem); }
h2 { font-size: clamp(1rem, 3vw, 1.25rem); }
h3 { font-size: 0.95rem; color: var(--text-dim); }

a { color: var(--phosphor); text-decoration: none; }
a:hover { text-decoration: underline; }

.dim { color: var(--text-dim); }
.faint { color: var(--text-faint); }
.err { color: var(--danger); }
.ok { color: var(--ok); }

/* ── Ecrans plein page (accueil, creation) ────────────────── */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  overflow-y: auto;
  background:
    radial-gradient(ellipse at 50% 0%, #12191d 0%, var(--bg-void) 70%);
}
.screen[hidden] { display: none; }

.panel {
  width: 100%;
  max-width: 460px;
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: clamp(1.25rem, 4vw, 2rem);
  position: relative;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.6), 0 18px 50px rgba(0, 0, 0, 0.7);
}
.panel--wide { max-width: 880px; }

/* Coin ambre : signature visuelle du terminal. */
.panel::before {
  content: '';
  position: absolute;
  top: -1px; left: -1px;
  width: 22px; height: 22px;
  border-top: 2px solid var(--amber);
  border-left: 2px solid var(--amber);
}
.panel::after {
  content: '';
  position: absolute;
  bottom: -1px; right: -1px;
  width: 22px; height: 22px;
  border-bottom: 2px solid var(--amber);
  border-right: 2px solid var(--amber);
}

.brand {
  text-align: center;
  margin-bottom: 1.5rem;
}
.brand__title {
  font-size: clamp(1.4rem, 5vw, 2.1rem);
  color: var(--amber);
  letter-spacing: 0.2em;
  text-shadow: 0 0 18px rgba(255, 176, 58, 0.35);
}
.brand__sub {
  font-size: 0.72rem;
  color: var(--text-faint);
  letter-spacing: 0.3em;
  margin-top: 0.35rem;
}

/* ── Formulaires ──────────────────────────────────────────── */
.field { margin-bottom: 1rem; }
.field label {
  display: block;
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 0.35rem;
}
.field input,
.field select {
  width: 100%;
  padding: 0.7rem 0.8rem;
  background: var(--bg-void);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--mono);
  /* 16 px minimum : en dessous, iOS Safari zoome automatiquement sur le
     champ au focus et casse la mise en page. */
  font-size: 16px;
  transition: border-color 0.15s;
}
.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--amber);
  box-shadow: 0 0 0 1px rgba(255, 176, 58, 0.25);
}
.field input::placeholder { color: var(--text-faint); }

.hint {
  font-size: 0.7rem;
  color: var(--text-faint);
  margin-top: 0.3rem;
}

.btn {
  display: block;
  width: 100%;
  padding: 0.8rem 1rem;
  background: transparent;
  border: 1px solid var(--amber-dim);
  border-radius: var(--radius);
  color: var(--amber);
  font-family: var(--mono);
  font-size: 0.85rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  min-height: 44px; /* cible tactile confortable */
}
.btn:hover:not(:disabled) {
  background: rgba(255, 176, 58, 0.1);
  border-color: var(--amber);
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn--ghost { border-color: var(--line); color: var(--text-dim); }
.btn--ghost:hover:not(:disabled) { background: rgba(255,255,255,0.04); border-color: var(--line-bright); }

.row { display: flex; gap: 0.6rem; }
.row > * { flex: 1; }

.msg {
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius);
  font-size: 0.78rem;
  margin-bottom: 1rem;
  border: 1px solid;
}
.msg--err { border-color: var(--danger); color: var(--danger); background: rgba(224, 75, 66, 0.08); }
.msg--ok  { border-color: var(--ok); color: var(--ok); background: rgba(110, 240, 160, 0.08); }
.msg[hidden] { display: none; }

.switch-line {
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-dim);
  margin-top: 1.25rem;
}

/* ── Selection de classe ──────────────────────────────────── */
.class-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}
.class-card {
  background: var(--bg-void);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.9rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  text-align: left;
  font-family: var(--mono);
  color: var(--text);
}
.class-card:hover { border-color: var(--line-bright); }
.class-card.selected {
  border-color: var(--accent, var(--amber));
  background: rgba(255, 176, 58, 0.06);
}
.class-card__name {
  font-size: 0.95rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent, var(--amber));
}
.class-card__sub {
  font-size: 0.68rem;
  color: var(--text-faint);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin-bottom: 0.5rem;
}
.class-card__desc { font-size: 0.74rem; color: var(--text-dim); line-height: 1.45; }
.class-card__stats {
  margin-top: 0.6rem;
  font-size: 0.68rem;
  color: var(--text-faint);
  display: grid;
  gap: 0.15rem;
}
.class-card__stats b { color: var(--text-dim); font-weight: normal; }

.gender-row { display: flex; gap: 0.6rem; margin-bottom: 1rem; }
.gender-row .btn { flex: 1; }
.gender-row .btn.selected { background: rgba(255,176,58,0.14); border-color: var(--amber); }

/* ── Chargement ───────────────────────────────────────────── */
.loading {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  background: var(--bg-void);
}
.loading[hidden] { display: none; }
.loading__label {
  font-size: 0.75rem;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--amber);
}
.loading__bar {
  width: min(320px, 70vw);
  height: 2px;
  background: var(--line);
  overflow: hidden;
}
.loading__fill {
  height: 100%;
  width: 0%;
  background: var(--amber);
  transition: width 0.25s;
  box-shadow: 0 0 10px var(--amber);
}
.loading__detail { font-size: 0.7rem; color: var(--text-faint); }

/* ── Jeu ──────────────────────────────────────────────────── */
#renderCanvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  outline: none;
}

.hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 100;
  /* Respecte les encoches et la barre de geste des telephones. */
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.hud > * { pointer-events: none; }
.hud [data-interactive] { pointer-events: auto; }

/* Jauges circulaires - en bas a gauche */
.vitals {
  position: absolute;
  left: clamp(0.6rem, 2vw, 1.2rem);
  bottom: clamp(0.6rem, 2vw, 1.2rem);
  display: flex;
  gap: clamp(0.4rem, 1.5vw, 0.75rem);
  align-items: flex-end;
}
.gauge { position: relative; }
.gauge svg { display: block; transform: rotate(-90deg); }
.gauge__track { fill: none; stroke: rgba(255,255,255,0.07); }
.gauge__fill  { fill: none; stroke-linecap: round; transition: stroke-dashoffset 0.2s linear; }
.gauge__value {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.66rem;
  color: var(--text-dim);
}
.gauge__label {
  text-align: center;
  font-size: 0.55rem;
  letter-spacing: 0.14em;
  color: var(--text-faint);
  margin-top: 0.15rem;
  text-transform: uppercase;
}

/* Jauge de radiations - clignote au-dela du seuil */
.rads-bar {
  position: absolute;
  left: clamp(0.6rem, 2vw, 1.2rem);
  bottom: clamp(5.6rem, 14vw, 7rem);
  width: clamp(120px, 26vw, 190px);
}
.rads-bar__track {
  height: 4px;
  background: rgba(255,255,255,0.08);
  border: 1px solid var(--line);
  overflow: hidden;
}
.rads-bar__fill {
  height: 100%;
  width: 0%;
  background: var(--rads);
  box-shadow: 0 0 8px var(--rads);
  transition: width 0.3s;
}
.rads-bar__label {
  font-size: 0.58rem;
  letter-spacing: 0.16em;
  color: var(--text-faint);
  text-transform: uppercase;
  margin-bottom: 0.2rem;
  display: flex;
  justify-content: space-between;
}
.rads-bar.critical .rads-bar__fill { animation: rad-pulse 0.6s steps(2) infinite; }
.rads-bar.critical .rads-bar__label { color: var(--danger); }
@keyframes rad-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }

/* Mini-carte radar - en haut a droite */
.minimap {
  position: absolute;
  right: clamp(0.6rem, 2vw, 1.2rem);
  top: clamp(0.6rem, 2vw, 1.2rem);
  width: clamp(110px, 24vw, 180px);
  height: clamp(110px, 24vw, 180px);
  border: 1px solid var(--line-bright);
  border-radius: 50%;
  background: rgba(7, 9, 10, 0.78);
  overflow: hidden;
  box-shadow: inset 0 0 24px rgba(0, 0, 0, 0.9);
}
.minimap canvas { width: 100%; height: 100%; display: block; }
.minimap__ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  pointer-events: none;
  border: 1px solid rgba(110, 240, 160, 0.12);
}

.compass {
  position: absolute;
  right: clamp(0.6rem, 2vw, 1.2rem);
  top: calc(clamp(110px, 24vw, 180px) + clamp(1rem, 3vw, 1.7rem));
  width: clamp(110px, 24vw, 180px);
  text-align: center;
  font-size: 0.62rem;
  letter-spacing: 0.2em;
  color: var(--text-dim);
}

/* Bandeau d'information (ville, meteo, heure) */
.status-bar {
  position: absolute;
  top: clamp(0.6rem, 2vw, 1.2rem);
  left: clamp(0.6rem, 2vw, 1.2rem);
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  color: var(--text-dim);
}
.status-bar__row { display: flex; gap: 0.5rem; align-items: baseline; }
.status-bar__key { color: var(--text-faint); text-transform: uppercase; font-size: 0.6rem; }
.status-bar__val { color: var(--amber); }
.status-bar__val.safe { color: var(--phosphor); }
.status-bar__val.danger { color: var(--danger); }

/* Bandeau d'arrivee en ville */
.city-banner {
  position: absolute;
  top: 22%;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  opacity: 0;
  transition: opacity 0.6s;
}
.city-banner.show { opacity: 1; }
.city-banner__name {
  font-size: clamp(1.4rem, 5vw, 2.2rem);
  letter-spacing: 0.3em;
  color: var(--amber);
  text-shadow: 0 0 24px rgba(255, 176, 58, 0.4);
}
.city-banner__sub {
  font-size: 0.68rem;
  letter-spacing: 0.24em;
  color: var(--text-dim);
  text-transform: uppercase;
}

/* Debug reseau */
.netstat {
  position: absolute;
  left: clamp(0.6rem, 2vw, 1.2rem);
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.62rem;
  color: var(--text-faint);
  line-height: 1.7;
  white-space: pre;
}
.netstat[hidden] { display: none; }

/* ── Commandes tactiles (mobile) ──────────────────────────── */
.touch-controls { display: none; }
body.touch .touch-controls { display: block; }

.joystick {
  position: absolute;
  left: clamp(1rem, 6vw, 3rem);
  bottom: clamp(7rem, 18vw, 9rem);
  width: 128px;
  height: 128px;
  border: 1px solid var(--line-bright);
  border-radius: 50%;
  background: rgba(18, 24, 27, 0.4);
}
.joystick__knob {
  position: absolute;
  left: 50%; top: 50%;
  width: 52px; height: 52px;
  margin: -26px 0 0 -26px;
  border-radius: 50%;
  background: rgba(255, 176, 58, 0.22);
  border: 1px solid var(--amber-dim);
  transition: transform 0.05s;
}

.touch-buttons {
  position: absolute;
  right: clamp(1rem, 5vw, 2.5rem);
  bottom: clamp(6rem, 16vw, 8rem);
  display: grid;
  grid-template-columns: repeat(2, 60px);
  gap: 0.7rem;
}
.touch-btn {
  width: 60px; height: 60px;
  border-radius: 50%;
  border: 1px solid var(--line-bright);
  background: rgba(18, 24, 27, 0.55);
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 0.6rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  justify-content: center;
}
.touch-btn:active, .touch-btn.active {
  background: rgba(255, 176, 58, 0.2);
  border-color: var(--amber);
  color: var(--amber);
}

/* Sur un ecran bas (telephone en paysage), on remonte les jauges pour
   qu'elles ne passent pas sous le pouce qui tient l'appareil. */
@media (max-height: 480px) {
  .vitals { bottom: 0.4rem; }
  .rads-bar { bottom: 4.6rem; }
  .joystick { width: 104px; height: 104px; bottom: 5rem; }
}

/* ── Ecran de mort ────────────────────────────────────────── */
.death {
  position: fixed;
  inset: 0;
  z-index: 400;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  background: rgba(7, 9, 10, 0.9);
}
.death[hidden] { display: none; }
.death__title {
  font-size: clamp(1.8rem, 7vw, 3rem);
  letter-spacing: 0.35em;
  color: var(--danger);
  text-shadow: 0 0 30px rgba(224, 75, 66, 0.5);
}
.death__cause { font-size: 0.78rem; color: var(--text-dim); letter-spacing: 0.16em; }
.death .btn { width: auto; padding-inline: 2.5rem; pointer-events: auto; }
