/* Overlay de trajet (fx/travel.js) — canvas pixel + HUD façon borne d'arcade 80s.
   Animations : transform / opacity uniquement. Ombres de texte statiques et dures (pas de flou animé). */

.tv {
  position: fixed; inset: 0; z-index: 100;
  background: var(--night, #0d0221);
  color: var(--text, #f4eaff);
  overflow: hidden; contain: strict;
  -webkit-user-select: none; user-select: none; touch-action: none;
  -webkit-tap-highlight-color: transparent;
  animation: tv-in .22s ease-out both;
}
.tv-cv {
  position: absolute; inset: 0; display: block;
  width: 100%; height: 100%;
  object-fit: cover;
  image-rendering: crisp-edges;
  image-rendering: pixelated;
}
/* scanlines CRT + vignette : un seul calque statique */
.tv-crt {
  position: absolute; inset: 0; pointer-events: none;
  background:
    repeating-linear-gradient(to bottom, rgba(0,0,0,0) 0 2px, rgba(0,0,0,.2) 2px 3px),
    radial-gradient(ellipse at 50% 45%, rgba(0,0,0,0) 58%, rgba(13,2,33,.55) 100%);
}

/* ---------------------------------------------------------------- HUD */
.tv-hud {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  pointer-events: none;
}
.tv-top {
  display: grid;
  grid-template-columns: minmax(0, auto) minmax(0, 1fr) minmax(0, auto);
  grid-template-areas: "time route speed";
  align-items: start; gap: 8px 12px;
}
.tv-time { grid-area: time; }
.tv-route { grid-area: route; }
.tv-speed { grid-area: speed; text-align: right; }

.tv-stat { display: flex; flex-direction: column; gap: 2px; line-height: 1; }
.tv-speed { align-items: flex-end; }
.tv-lbl {
  font-family: var(--f-pixel, 'Press Start 2P', monospace);
  font-size: clamp(7px, 1.5vw, 10px); letter-spacing: 1px;
  color: var(--pink, #ff2a6d);
  text-shadow: 1px 1px 0 #0d0221;
}
.tv-val {
  font-family: var(--f-lcd, 'VT323', monospace); font-weight: 400;
  font-variant-numeric: tabular-nums;
  line-height: .85;
}
.tv-time .tv-val {
  font-size: clamp(34px, 9vw, 64px);
  color: var(--yellow, #f9c80e);
  text-shadow: 2px 2px 0 #ff2a6d, 4px 4px 0 #0d0221;
}
.tv-time.hot .tv-val { color: #fff; animation: tv-blink .5s steps(1, end) infinite; }
.tv-spd { display: inline-flex; align-items: baseline; gap: 4px; }
.tv-speed .tv-val {
  font-size: clamp(28px, 7.5vw, 52px);
  color: var(--orange, #ff9e00);
  text-shadow: 2px 2px 0 #7b2cbf, 4px 4px 0 #0d0221;
  min-width: 2.2ch; text-align: right;
}
.tv-unit {
  font-family: var(--f-pixel, 'Press Start 2P', monospace);
  font-size: clamp(7px, 1.4vw, 9px); color: var(--cyan, #05d9e8);
  text-shadow: 1px 1px 0 #0d0221;
}

.tv-route { text-align: center; min-width: 0; padding-top: 2px; }
.tv-mode {
  display: inline-block;
  font-family: var(--f-pixel, 'Press Start 2P', monospace);
  font-size: clamp(7px, 1.4vw, 9px); letter-spacing: 2px;
  color: #0d0221; background: var(--cyan, #05d9e8);
  padding: 3px 6px 2px; margin-bottom: 6px;
  box-shadow: 2px 2px 0 #0d0221;
}
.tv-line {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center;
  gap: 4px 8px; min-width: 0;
}
.tv-from, .tv-to {
  font-family: var(--f-pixel, 'Press Start 2P', monospace);
  text-transform: uppercase; line-height: 1.25;
  overflow-wrap: anywhere; min-width: 0;
}
.tv-from { font-size: clamp(8px, 2vw, 12px); color: var(--muted, #a89bc9); text-shadow: 1px 1px 0 #0d0221; }
.tv-to {
  font-size: clamp(10px, 2.8vw, 17px); color: var(--pink, #ff2a6d);
  text-shadow: 2px 2px 0 #0d0221, 0 0 0 transparent;
}
/* horloge des cours sous la route ; « AVANT L'ARRIVÉE » quand les prix changent pendant le trajet */
.tv-px {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center;
  gap: 4px 8px; margin-top: 8px; line-height: 1;
}
.tv-px .tv-lbl { color: var(--cyan, #05d9e8); }
.tv-pxv {
  font-family: var(--f-lcd, 'VT323', monospace); font-weight: 400; font-variant-numeric: tabular-nums;
  font-size: clamp(20px, 4.5vw, 28px); line-height: .8;
  color: var(--cyan, #05d9e8); text-shadow: 2px 2px 0 #0d0221;
}
.tv-pxtag {
  display: none;
  font-family: var(--f-pixel, 'Press Start 2P', monospace);
  font-size: clamp(6px, 1.3vw, 8px); letter-spacing: 1px;
  color: #0d0221; background: var(--orange, #ff9e00);
  padding: 3px 5px 2px; box-shadow: 2px 2px 0 #0d0221;
}
.tv-px.soon .tv-pxv { color: var(--orange, #ff9e00); }
.tv-px.soon .tv-pxtag { display: inline-block; }
.tv-ico { color: var(--yellow, #f9c80e); font-size: clamp(14px, 3vw, 20px); line-height: 0; display: inline-flex; filter: drop-shadow(1px 1px 0 #0d0221); }
.tv-ico svg, .tv-mki svg { display: block; width: 1em; height: 1em; }

/* bulle du Professeur Satoshi, façon RPG 16 bits : fond bleu nuit, double bordure blanche, portrait pixel */
.tv-dlg {
  pointer-events: auto; position: relative; align-self: center;
  display: flex; align-items: flex-start; gap: 12px;
  width: min(96%, 640px); margin: 12px 0 0; padding: 10px 16px 14px 10px;
  font: inherit; color: #fff; text-align: left; cursor: pointer;
  background: linear-gradient(180deg, #2b3fbf 0%, #18238a 55%, #0d1255 100%);
  border: 3px solid #f4f4ff; border-radius: 8px;
  box-shadow: 0 0 0 3px #0a0d3a, 0 0 0 4px rgba(244, 244, 255, .28), 0 6px 0 rgba(0, 0, 0, .35);
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
.tv-dlg:focus-visible { outline: 2px dashed var(--yellow, #f9c80e); outline-offset: 6px; }
.tv-dlg-face {
  flex: none; box-sizing: content-box; width: 64px; height: 64px; /* 32 px × 2 : pixels nets (échelle entière) */
  image-rendering: crisp-edges; image-rendering: pixelated;
  background: radial-gradient(circle at 50% 40%, #4a60e0, #22309a);
  border: 2px solid #f4f4ff; border-radius: 4px; box-shadow: inset 0 0 0 2px #0a0d3a;
}
.tv-dlg-body { position: relative; display: block; flex: 1 1 auto; min-width: 0; }
.tv-dlg-name {
  display: block; margin: 2px 0 6px;
  font: 9px/1.2 var(--f-pixel, 'Press Start 2P', monospace); letter-spacing: .5px; text-transform: uppercase;
  color: var(--yellow, #f9c80e); text-shadow: 1px 1px 0 #0a0d3a;
}
.tv-dlg-text {
  display: block; height: calc(3em * 1.15); overflow: hidden;
  font-family: var(--f-lcd, 'VT323', monospace); font-size: clamp(18px, 2.6vw, 22px); line-height: 1.15;
  overflow-wrap: anywhere; text-shadow: 1px 1px 0 #0a0d3a;
}
.tv-dlg-meas { position: absolute; left: 0; right: 0; top: 0; height: auto; visibility: hidden; pointer-events: none; }
/* ▼ : il reste une page (toucher pour la suite) */
.tv-dlg-next {
  position: absolute; right: 10px; bottom: 6px; width: 0; height: 0;
  border-left: 6px solid transparent; border-right: 6px solid transparent; border-top: 8px solid #fff;
  opacity: 0;
}
.tv-dlg.more .tv-dlg-next { opacity: 1; animation: tv-dlg-bob .8s steps(2, jump-none) infinite; }
@keyframes tv-dlg-bob { 0% { transform: translateY(0); } 100% { transform: translateY(3px); } }
.tv-fillspace { flex: 1 1 auto; min-height: 8px; }

/* barre de progression façon compte-tours */
.tv-prog { width: min(100%, 720px); align-self: center; }
.tv-plbl {
  display: flex; justify-content: space-between; align-items: flex-end;
  font-family: var(--f-pixel, 'Press Start 2P', monospace);
  font-size: clamp(7px, 1.3vw, 9px); letter-spacing: 1px;
  color: var(--text, #f4eaff); text-shadow: 1px 1px 0 #0d0221;
  margin-bottom: 4px;
}
.tv-pct {
  font-family: var(--f-lcd, 'VT323', monospace); font-size: clamp(16px, 3vw, 22px);
  color: var(--green, #39ff14); line-height: .8;
}
.tv-track {
  position: relative; height: 14px;
  background: #1a0b3a;
  border: 2px solid var(--text, #f4eaff);
  box-shadow: 0 0 0 2px #0d0221, 3px 3px 0 2px #0d0221;
}
.tv-fill {
  position: absolute; inset: 0;
  background: linear-gradient(90deg, #39ff14 0%, #f9c80e 45%, #ff9e00 70%, #ff2a6d 100%);
  transform-origin: 0 50%; transform: scaleX(0);
  will-change: transform;
}
.tv-seg {
  position: absolute; inset: 0;
  background: repeating-linear-gradient(90deg, rgba(0,0,0,0) 0 7px, #0d0221 7px 9px);
}
.tv-mk {
  position: absolute; left: 0; top: 0; width: 100%; height: 100%;
  transform: translateX(0); will-change: transform;
}
.tv-mki {
  position: absolute; left: 0; bottom: 100%;
  transform: translate(-50%, -3px);
  color: var(--yellow, #f9c80e); font-size: 18px; line-height: 0;
  filter: drop-shadow(1px 1px 0 #0d0221);
}

/* bouton « MASQUER » (accès au chat pendant le trajet) : bouton arcade compact */
.tv-hide {
  pointer-events: auto;
  align-self: center;
  display: inline-flex; align-items: center; gap: 8px;
  margin-top: 10px; min-height: 34px; padding: 7px 14px 6px;
  font-family: var(--f-pixel, 'Press Start 2P', monospace);
  font-size: 9px; letter-spacing: 1px; line-height: 1; text-transform: uppercase;
  color: var(--text, #f4eaff); background: var(--line, #3a1f6e);
  border: 0; border-bottom: 2px solid #1d0f3a; border-radius: 4px;
  box-shadow: 2px 2px 0 #0d0221;
  cursor: pointer; touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.tv-hide:active { transform: translateY(2px); }
.tv-hide:focus { outline: none; }
.tv-hide:focus-visible { outline: 2px solid var(--cyan, #05d9e8); outline-offset: 2px; }
.tv-hide-ico { display: inline-flex; color: var(--cyan, #05d9e8); line-height: 0; }
.tv-hide-ico svg { display: block; width: 16px; height: 16px; }
.tv-arrived .tv-hide { visibility: hidden; }

/* ---------------------------------------------------------------- arrivée */
.tv-welcome {
  position: absolute; left: 0; right: 0; top: 50%;
  transform: translateY(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 16px 12px 18px;
  background: rgba(13, 2, 33, .72);
  border-top: 3px solid var(--pink, #ff2a6d);
  border-bottom: 3px solid var(--cyan, #05d9e8);
  text-align: center; pointer-events: none;
  opacity: 0; visibility: hidden;
}
.tv-w1 {
  font-family: var(--f-pixel, 'Press Start 2P', monospace);
  font-size: clamp(10px, 2.8vw, 16px); letter-spacing: 2px;
  color: var(--cyan, #05d9e8); text-shadow: 2px 2px 0 #0d0221;
}
.tv-w2 {
  font-family: var(--f-pixel, 'Press Start 2P', monospace); font-weight: 400;
  font-size: clamp(14px, 5vw, 44px); line-height: 1.2;
  text-transform: uppercase; overflow-wrap: anywhere; max-width: 100%;
  color: var(--yellow, #f9c80e);
  text-shadow: 3px 3px 0 #ff2a6d, 6px 6px 0 #0d0221;
}
.tv-arrived .tv-welcome { visibility: visible; opacity: 1; }
.tv-arrived .tv-w2 { animation: tv-pop .38s cubic-bezier(.2, 1.6, .4, 1) both; }
.tv-arrived .tv-w1 { animation: tv-pop .3s ease-out both; }
.tv-arrived .tv-hud { opacity: .35; }
.tv.tv-out { opacity: 0; transition: opacity .26s linear; }

@keyframes tv-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes tv-blink { 0% { opacity: 1; } 50% { opacity: .25; } }
@keyframes tv-pop {
  0% { transform: scale(.55); opacity: 0; }
  70% { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

/* ---------------------------------------------------------------- portrait : route sur sa ligne, chronos dessous */
@media (max-aspect-ratio: 1/1) {
  .tv-top { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-areas: "route route" "time speed"; }
  .tv-route { padding-top: 0; }
  .tv-dlg { margin-top: 12px; }
  .tv-prog { margin-bottom: 4px; }
}
/* paysage bas (téléphone couché) : HUD plus compact pour laisser voir la voiture */
@media (max-height: 430px) and (min-aspect-ratio: 1/1) {
  .tv-hud { padding-top: max(6px, env(safe-area-inset-top)); padding-bottom: max(6px, env(safe-area-inset-bottom)); }
  .tv-time .tv-val { font-size: 36px; }
  .tv-speed .tv-val { font-size: 30px; }
  .tv-mode { margin-bottom: 4px; }
  .tv-px { margin-top: 5px; }
  .tv-dlg { margin-top: 9px; padding: 6px 12px 14px 6px; width: min(82%, 640px); gap: 8px; }
  .tv-dlg-name { margin-bottom: 3px; font-size: 8px; }
  .tv-dlg-text { font-size: 17px; height: calc(2em * 1.15); }
  .tv-track { height: 10px; }
  .tv-plbl { margin-bottom: 2px; }
  .tv-hide { margin-top: 6px; min-height: 28px; padding: 5px 10px 4px; font-size: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  .tv, .tv-arrived .tv-w1, .tv-arrived .tv-w2, .tv-time.hot .tv-val, .tv-dlg.more .tv-dlg-next { animation: none; }
  .tv.tv-out { transition: none; }
}
