/* ===== Reset / base ===== */
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body {
  height: 100%;
  overflow: hidden;
  background: #050a18;
  color: #e8eefc;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  user-select: none;
  -webkit-user-select: none;
}
body {
  background:
    radial-gradient(ellipse at top, #112a55 0%, #0a1530 45%, #050a18 100%);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

/* ===== Écrans ===== */
.screen {
  display: none;
  flex-direction: column;
  flex: 1;
  width: 100%;
  height: 100%;
  min-height: 100dvh;
  position: absolute;
  inset: 0;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}
.screen.active { display: flex; }

.hidden { display: none !important; }

/* ===== Top bar ===== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  gap: 12px;
  border-bottom: 1px solid rgba(80, 140, 255, 0.15);
  background: rgba(10, 21, 48, 0.6);
  backdrop-filter: blur(8px);
}
.screen-title { font-size: 16px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; }
.btn-back {
  background: rgba(255,255,255,0.05);
  color: #e8eefc;
  border: 1px solid rgba(255,255,255,0.1);
  font-size: 14px;
  padding: 8px 12px;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
}

.streak {
  background: linear-gradient(135deg, #ff8a00, #ff3d00);
  color: white;
  font-weight: 800;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 14px;
  box-shadow: 0 0 12px rgba(255, 100, 30, 0.4);
}

/* ===== Energon bar ===== */
.energon-wrap { flex: 1; max-width: 220px; }
.energon-label {
  font-size: 9px;
  letter-spacing: 2px;
  color: #5aa8ff;
  font-weight: 800;
  text-align: right;
}
.energon-bar {
  position: relative;
  height: 10px;
  background: rgba(20, 40, 80, 0.6);
  border: 1px solid rgba(90, 168, 255, 0.4);
  border-radius: 6px;
  overflow: hidden;
  margin-top: 4px;
}
.energon-bar.small { height: 6px; }
.energon-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #00d4ff, #5aa8ff, #b388ff);
  box-shadow: 0 0 12px #00d4ff;
  transition: width 0.6s cubic-bezier(.2,.8,.2,1);
}
.energon-pct {
  font-size: 11px;
  text-align: right;
  margin-top: 2px;
  color: #9bc4ff;
  font-weight: 700;
}
.energon-mini { width: 80px; }
.cycle-counter {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 1px;
  color: #9bc4ff;
}

/* ===== HOME ===== */
.home-main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 24px max(24px, env(safe-area-inset-bottom));
  gap: 18px;
  text-align: center;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.optimus-badge {
  width: 140px;
  height: 140px;
  border-radius: 50%;
  background: radial-gradient(circle, #1e3a8a, #0a1530);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 3px solid #c8102e;
  box-shadow:
    0 0 40px rgba(200, 16, 46, 0.4),
    inset 0 0 30px rgba(0, 212, 255, 0.2);
  animation: pulse 3s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 30px rgba(200, 16, 46, 0.3), inset 0 0 30px rgba(0, 212, 255, 0.2); }
  50% { box-shadow: 0 0 50px rgba(200, 16, 46, 0.6), inset 0 0 40px rgba(0, 212, 255, 0.4); }
}

/* Logo Autobot (forme stylisée) */
.autobot-logo {
  width: 80px;
  height: 80px;
  background:
    linear-gradient(180deg, #e8eefc 0%, #9bc4ff 100%);
  -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><path d='M50 5 L20 25 L20 55 Q20 80 50 95 Q80 80 80 55 L80 25 Z M50 20 L35 30 L35 50 L42 50 L42 65 L58 65 L58 50 L65 50 L65 30 Z' fill='black'/></svg>") center/contain no-repeat;
          mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><path d='M50 5 L20 25 L20 55 Q20 80 50 95 Q80 80 80 55 L80 25 Z M50 20 L35 30 L35 50 L42 50 L42 65 L58 65 L58 50 L65 50 L65 30 Z' fill='black'/></svg>") center/contain no-repeat;
  filter: drop-shadow(0 0 8px rgba(0, 212, 255, 0.6));
}
.autobot-logo.big { width: 120px; height: 120px; }

.title {
  font-size: 32px;
  font-weight: 900;
  letter-spacing: 1px;
  background: linear-gradient(180deg, #ffffff, #9bc4ff);
  -webkit-background-clip: text;
          background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 2px 12px rgba(0, 212, 255, 0.2);
}
.title.gold {
  background: linear-gradient(180deg, #fff7ad, #ffb800);
  -webkit-background-clip: text;
          background-clip: text;
  -webkit-text-fill-color: transparent;
}
.speech {
  font-size: 16px;
  line-height: 1.5;
  color: #c9d6ee;
  max-width: 320px;
}
.speech strong { color: #fff; }

/* ===== Boutons ===== */
.btn {
  border: none;
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.5px;
  transition: transform 0.1s ease, box-shadow 0.2s ease;
  padding: 14px 20px;
  border-radius: 14px;
  font-size: 16px;
}
.btn:active { transform: scale(0.97); }
.btn-primary {
  background: linear-gradient(135deg, #c8102e, #8b0a20);
  color: white;
  box-shadow: 0 4px 20px rgba(200, 16, 46, 0.4), inset 0 1px 0 rgba(255,255,255,0.2);
}
.btn-primary.big {
  padding: 18px 28px;
  font-size: 18px;
  border-radius: 16px;
  min-width: 240px;
}
.btn-secondary {
  background: linear-gradient(135deg, #1e3a8a, #0a1f5a);
  color: #e8eefc;
  border: 1px solid rgba(90, 168, 255, 0.3);
}
.btn-tertiary {
  background: transparent;
  color: #9bc4ff;
  border: 1px solid rgba(155, 196, 255, 0.3);
  padding: 10px 16px;
  font-size: 14px;
  border-radius: 10px;
  margin-top: 8px;
}
.done-today {
  color: #6effb0;
  font-weight: 700;
  font-size: 14px;
  text-align: center;
}

/* ===== Vidéo (explication) ===== */
.video-main {
  flex: 1;
  min-height: 0;            /* essentiel pour que le flex calcule la hauteur */
  display: flex;
  flex-direction: column;
  padding: 12px 12px max(12px, env(safe-area-inset-bottom));
  gap: 12px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.video-frame {
  position: relative;
  flex: 1;
  min-height: 220px;
  border-radius: 20px;
  overflow: hidden;
  background: #000;
  border: 2px solid rgba(90, 168, 255, 0.4);
  box-shadow:
    0 10px 40px rgba(0, 0, 0, 0.6),
    0 0 30px rgba(0, 212, 255, 0.25),
    inset 0 0 0 1px rgba(255, 255, 255, 0.05);
}
.video-frame::before,
.video-frame::after {
  content: '';
  position: absolute;
  width: 24px;
  height: 24px;
  border: 2px solid #c8102e;
  pointer-events: none;
  z-index: 2;
}
.video-frame::before {
  top: 8px; left: 8px;
  border-right: none; border-bottom: none;
  border-top-left-radius: 12px;
}
.video-frame::after {
  bottom: 8px; right: 8px;
  border-left: none; border-top: none;
  border-bottom-right-radius: 12px;
}
#video-explain {
  width: 100%;
  height: 100%;
  display: block;
  background: #000;
  object-fit: contain;
}
#btn-go-mission {
  flex-shrink: 0;     /* le bouton reste toujours visible */
  align-self: center;
}

/* ===== MISSION (respiration) ===== */
.mission-main {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.video-stage {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.phase-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.12s linear;
}
.phase-video.active { opacity: 1; }

/* voile sombre pour lisibilité */
.video-stage::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(5,10,24,0.5) 0%, rgba(5,10,24,0.3) 50%, rgba(5,10,24,0.7) 100%);
  pointer-events: none;
}

.phase-overlay {
  position: relative;
  z-index: 2;
  text-align: center;
  pointer-events: none;
}
.phase-label {
  font-size: 56px;
  font-weight: 900;
  letter-spacing: 3px;
  text-shadow: 0 0 20px currentColor, 0 4px 30px rgba(0,0,0,0.8);
  color: #00d4ff;
  transition: color 0.4s ease;
}
.phase-label.expire { color: #ffb800; }
.phase-instr {
  font-size: 16px;
  margin-top: 8px;
  letter-spacing: 1px;
  color: #e8eefc;
  text-shadow: 0 2px 10px rgba(0,0,0,0.8);
}
.countdown {
  font-size: 80px;
  font-weight: 900;
  margin-top: 12px;
  color: #fff;
  text-shadow: 0 4px 24px rgba(0,212,255,0.6);
  font-variant-numeric: tabular-nums;
}

.breath-ring {
  position: absolute;
  width: 220px;
  height: 220px;
  border-radius: 50%;
  border: 3px solid rgba(0, 212, 255, 0.6);
  box-shadow: 0 0 30px rgba(0, 212, 255, 0.4), inset 0 0 30px rgba(0, 212, 255, 0.2);
  pointer-events: none;
  z-index: 1;
  transform: scale(0.6);
  transition: transform 3s cubic-bezier(.45,.05,.55,.95),
              border-color 0.4s ease,
              box-shadow 0.4s ease;
}
.breath-ring.inspire {
  transform: scale(1.2);
  border-color: rgba(0, 212, 255, 0.9);
  box-shadow: 0 0 50px rgba(0, 212, 255, 0.7), inset 0 0 50px rgba(0, 212, 255, 0.4);
}
.breath-ring.expire {
  transform: scale(0.6);
  border-color: rgba(255, 184, 0, 0.9);
  box-shadow: 0 0 30px rgba(255, 184, 0, 0.5), inset 0 0 30px rgba(255, 184, 0, 0.2);
}

/* ===== SUCCÈS ===== */
.success-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  gap: 16px;
  text-align: center;
  animation: fadeUp 0.6s ease;
}
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}
.success-logo {
  width: 180px;
  height: 180px;
  border-radius: 50%;
  background: radial-gradient(circle, #ffb800, #c8102e);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 60px rgba(255, 184, 0, 0.6);
  animation: spin 6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.success-logo .autobot-logo { animation: spin 6s linear infinite reverse; }

.energon-gain {
  display: inline-block;
  margin-top: 8px;
  font-size: 36px;
  font-weight: 900;
  color: #00d4ff;
  text-shadow: 0 0 20px rgba(0, 212, 255, 0.6);
}
.streak-result {
  font-size: 20px;
  font-weight: 800;
  padding: 10px 20px;
  border-radius: 999px;
  background: linear-gradient(135deg, #ff8a00, #ff3d00);
  box-shadow: 0 0 20px rgba(255, 100, 30, 0.4);
}
.optimus-quote {
  font-style: italic;
  font-size: 14px;
  color: #9bc4ff;
  max-width: 320px;
  line-height: 1.5;
  margin-top: 8px;
}

/* ===== Petits écrans ===== */
@media (max-height: 700px) {
  .optimus-badge { width: 110px; height: 110px; }
  .autobot-logo { width: 64px; height: 64px; }
  .title { font-size: 26px; }
  .speech { font-size: 14px; }
  .phase-label { font-size: 44px; }
  .countdown { font-size: 64px; }
  .breath-ring { width: 180px; height: 180px; }
  .success-logo { width: 140px; height: 140px; }
}
