/* Police auto-hébergée (SIL OFL 1.1) : aucun appel externe */
@font-face {
  font-family: 'Share Tech Mono';
  font-style: normal; font-weight: 400; font-display: swap;
  src: url('fonts/share-tech-mono.woff2') format('woff2');
}

:root {
  --bg: #020617; --panel: #060a14; --panel-2: #0b1325; --side: #050811; --right: #070c18;
  --line: #0284c7; --line-soft: #1d4ed8; --accent: #38bdf8; --accent-2: #0284c7; --title: #7dd3fc;
  --text: #94a3b8; --white: #f8fafc; --ok: #34d399; --warn: #fbbf24; --bad: #f87171; --bad-strong: #ef4444;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  background-color: var(--bg);
  color: var(--accent);
  font-family: 'Share Tech Mono', ui-monospace, Menlo, Consolas, monospace;
  margin: 0;
  padding: 20px;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  transition: background-color 0.3s ease;
}
.noscript { color: var(--bad); }

/* Effet CRT & Scanlines légers */
.crt-overlay {
  position: absolute; inset: 0; pointer-events: none; z-index: 50;
  background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.25) 50%), linear-gradient(90deg, rgba(255, 0, 0, 0.03), rgba(0, 255, 0, 0.01), rgba(0, 0, 255, 0.03));
  background-size: 100% 4px, 6px 100%;
  border-radius: 8px;
}

body.panic { animation: panicFlash 1.5s infinite alternate; }
@keyframes panicFlash {
  0%   { background-color: #020617; box-shadow: inset 0 0 30px rgba(0,0,0,0.6); }
  100% { background-color: #2b0808; box-shadow: inset 0 0 60px rgba(239,68,68,0.3); }
}

.blackout-effect { border-color: #7f1d1d !important; }
.blackout-effect .sidebar, .blackout-effect #terminal { animation: blackoutBlink 1.2s infinite; filter: brightness(0.45) saturate(0.2); }
@keyframes blackoutBlink { 0%,100% { opacity: 1; } 50% { opacity: 0.7; } }

/* Vignette d'hypoxie */
.hypoxia-effect::after {
  content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 25;
  box-shadow: inset 0 0 90px 25px rgba(0,0,0,0.75);
  animation: hypoxiaPulse 3s infinite alternate;
}
@keyframes hypoxiaPulse { 0% { opacity: 0.35; } 100% { opacity: 1; } }

.glitch-effect .main-grid { position: relative; animation: textGlitch 0.4s infinite; }
/* left/top plutôt que transform : un transform casserait la boîte de crise fixée en bas sur mobile */
@keyframes textGlitch {
  0%   { left: 0; top: 0; }
  30%  { left: -1px; top: 0.5px; color: var(--bad); }
  60%  { left: 1px; top: -0.5px; }
  100% { left: 0; top: 0; }
}

.container {
  width: 100%; max-width: 950px; min-height: 580px;
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 0 40px rgba(2,132,199,0.25), inset 0 0 15px rgba(2,132,199,0.1);
  overflow: hidden;
  position: relative;
  transition: filter 0.3s ease, border-color 0.3s ease;
}

header {
  background: var(--panel-2);
  padding: 12px 20px;
  border-bottom: 2px solid var(--line);
  display: flex; justify-content: space-between; align-items: center; gap: 10px 20px; flex-wrap: wrap;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.05);
}
.head-left { display: flex; align-items: center; gap: 12px; }
.head-right { display: flex; gap: 10px 14px; align-items: center; font-size: 0.85rem; flex-wrap: wrap; }
.status-dot { width: 12px; height: 12px; background: var(--bad-strong); border-radius: 50%; box-shadow: 0 0 10px var(--bad-strong); border: 1px solid rgba(255,255,255,0.3); }
.game-title, h1 { margin: 0; font-size: 1.2rem; letter-spacing: 2px; color: var(--title); font-weight: 400; text-shadow: 0 0 8px rgba(125,211,252,0.4); }
.white { color: var(--white); }
.chrono-badge { background: rgba(2,132,199,0.1); border: 1px solid var(--line-soft); padding: 3px 8px; border-radius: 4px; }

.main-grid { display: grid; grid-template-columns: 320px 1fr; height: 580px; }

.sidebar {
  background: var(--side); border-right: 1px solid var(--line);
  padding: 15px; display: flex; flex-direction: column; justify-content: space-between; gap: 12px;
  overflow-y: auto;
}
.section-title { font-size: 0.75rem; color: var(--accent-2); text-transform: uppercase; border-bottom: 1px solid var(--line-soft); padding-bottom: 4px; margin-bottom: 8px; letter-spacing: 1px; }
.section-title-gap { margin-top: 10px; }

.metric-box { background: rgba(2,132,199,0.08); border: 1px solid rgba(2,132,199,0.3); padding: 10px 12px; border-radius: 6px; margin-bottom: 10px; box-shadow: inset 0 1px 3px rgba(0,0,0,0.3); }
.metric-label { font-size: 0.7rem; color: var(--text); letter-spacing: 0.5px; }
.metric-value { font-size: 1.15rem; font-weight: bold; color: var(--white); margin-top: 2px; }
.press { font-size: 0.75rem; color: var(--bad); }

.progress-container { margin-bottom: 10px; }
.progress-header { display: flex; justify-content: space-between; font-size: 0.7rem; margin-bottom: 3px; color: var(--text); }
.progress-bar-bg { background: var(--panel-2); height: 9px; border-radius: 5px; border: 1px solid var(--line-soft); overflow: hidden; position: relative; box-shadow: inset 0 2px 4px rgba(0,0,0,0.5); }
.progress-bar-fill { height: 100%; width: 100%; background: var(--ok); transition: width 0.2s, background-color 0.2s; box-shadow: 0 0 6px currentColor; }

/* Repères de seuil 35% et 65% sur les jauges */
.threshold-marker { position: absolute; top: 0; bottom: 0; width: 1px; background: rgba(255,255,255,0.3); z-index: 2; pointer-events: none; }
.t-35  { left: 35%; }
.t-65  { left: 65%; }
.t-co2-35 { left: 35%; } /* Inversé ou repères indicatifs CO2 */
.t-co2-65 { left: 65%; }

.controls { display: flex; flex-direction: column; gap: 6px; }
.control-panel-btn {
  background: var(--panel-2); border: 1px solid var(--accent-2); color: var(--accent);
  padding: 9px 10px; border-radius: 6px; cursor: pointer; font-family: inherit; font-size: 0.72rem;
  width: 100%; text-align: center; transition: all 0.2s; min-height: 44px; display: flex; align-items: center; justify-content: center;
  touch-action: manipulation; -webkit-user-select: none; user-select: none;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}
#btn-ballast { touch-action: none; font-weight: bold; letter-spacing: 0.5px; }
.control-panel-btn:hover:not(:disabled) { background: var(--line-soft); border-color: var(--accent); box-shadow: 0 0 10px rgba(56,189,248,0.3); }
.control-panel-btn:disabled { background: var(--bg); color: #334155; border-color: #0f172a; cursor: not-allowed; box-shadow: none; }
.control-panel-btn.active   { background: rgba(6, 95, 70, 0.4); border-color: var(--ok); color: var(--ok); box-shadow: inset 0 0 8px rgba(52,211,153,0.2); }
.control-panel-btn.inactive { background: rgba(127, 29, 29, 0.4); border-color: var(--bad); color: var(--bad); box-shadow: inset 0 0 8px rgba(248,113,113,0.2); }

.thermo { font-size: 0.72rem; color: var(--text); background: var(--bg); padding: 8px 10px; border-radius: 6px; border: 1px solid var(--line-soft); display: flex; justify-content: space-between; align-items: center; }
.thermo b { color: var(--ok); font-size: 0.8rem; }
.thermo b.warm { color: var(--warn); }
.thermo b.hot  { color: var(--bad-strong); text-shadow: 0 0 6px rgba(239,68,68,0.5); }

.right-panel { padding: 15px; display: flex; flex-direction: column; justify-content: space-between; background: var(--right); position: relative; min-height: 0; }

#terminal {
  background: var(--bg); border: 1px solid var(--line-soft); border-radius: 6px;
  flex: 1; min-height: 120px; padding: 12px; overflow-y: auto; font-size: 0.8rem; margin-bottom: 15px;
  display: flex; flex-direction: column; gap: 6px; box-shadow: inset 0 2px 6px rgba(0,0,0,0.5);
}
.log { color: var(--text); border-left: 3px solid var(--line); padding-left: 8px; line-height: 1.4; }
.log.warning { color: var(--warn); border-left-color: var(--warn); background: rgba(251,191,36,0.04); }
.log.danger  { color: var(--bad);  border-left-color: var(--bad); background: rgba(248,113,113,0.06); }
.log.success { color: var(--ok);   border-left-color: var(--ok); background: rgba(52,211,153,0.04); }

#event-box {
  background: var(--panel-2); border: 2px solid var(--bad-strong); border-radius: 8px; padding: 16px;
  position: relative; box-shadow: 0 0 25px rgba(239,68,68,0.4), inset 0 0 15px rgba(239,68,68,0.15);
  animation: pulseBox 1.2s infinite alternate;
}
@keyframes pulseBox { 0% { border-color: #ef4444; transform: scale(1); } 100% { border-color: #ff6b6b; transform: scale(1.003); } }
.event-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 8px; border-bottom: 1px solid rgba(239,68,68,0.3); padding-bottom: 6px; }
.event-title { color: var(--bad); font-size: 0.9rem; font-weight: bold; letter-spacing: 0.5px; }
.event-timer { font-size: 0.8rem; color: var(--bad); font-weight: bold; white-space: nowrap; background: rgba(239,68,68,0.15); padding: 2px 8px; border-radius: 4px; border: 1px solid rgba(239,68,68,0.4); }
.event-desc { font-size: 0.84rem; color: #e2e8f0; margin-bottom: 12px; line-height: 1.4; }

.choice-btn {
  display: flex; gap: 10px; align-items: baseline;
  background: #0f172a; color: var(--white); border: 1px solid #334155; padding: 11px 14px; width: 100%;
  text-align: left; border-radius: 6px; cursor: pointer; font-family: inherit; font-size: 0.82rem; margin-top: 6px;
  min-height: 44px; transition: all 0.2s; touch-action: manipulation; box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
.choice-btn:hover:not(:disabled) { background: #1e293b; border-color: var(--bad-strong); box-shadow: 0 0 10px rgba(239,68,68,0.25); }
.choice-btn:disabled { background: var(--bg); color: #475569; border-color: #0f172a; cursor: not-allowed; box-shadow: none; }
.choice-key { color: var(--warn); font-weight: bold; min-width: 15px; }
.choice-txt { line-height: 1.3; }

kbd { font: inherit; font-size: 0.85em; border: 1px solid var(--line-soft); border-bottom-width: 2px; border-radius: 4px; padding: 1px 6px; color: var(--title); background: rgba(2,132,199,0.1); }

/* Écrans superposés */
.overlay {
  position: absolute; inset: 0; z-index: 30;
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  padding: 20px; overflow-y: auto; background: rgba(2,6,23,0.95); backdrop-filter: blur(4px);
}

.start-panel-frame {
  background: var(--panel); border: 2px solid var(--line); border-radius: 10px; padding: 24px;
  max-width: 540px; width: 100%; box-shadow: 0 0 50px rgba(2,132,199,0.3), inset 0 0 20px rgba(2,132,199,0.1);
  display: flex; flex-direction: column; align-items: center;
}
.frame-danger { border-color: var(--bad-strong); box-shadow: 0 0 50px rgba(239,68,68,0.35); }
.frame-success { border-color: var(--ok); box-shadow: 0 0 50px rgba(52,211,153,0.35); }

.start-title { font-size: 1.5rem; letter-spacing: 3px; margin: 0 0 14px; text-shadow: 0 0 10px rgba(56,189,248,0.5); }
.briefing {
  font-size: 0.84rem; color: var(--text); line-height: 1.5; margin-bottom: 16px; text-align: left;
  background: rgba(2,6,23,0.7); padding: 14px 16px; border: 1px solid var(--line-soft); border-radius: 6px;
  box-shadow: inset 0 2px 5px rgba(0,0,0,0.4);
}
.briefing p { margin: 0 0 10px; }
.briefing p:last-child { margin-bottom: 0; }
.briefing .briefing-alert { color: var(--bad); font-weight: bold; letter-spacing: 0.5px; }
.best-line { font-size: 0.8rem; color: var(--warn); margin: 0 0 10px; font-weight: bold; }

.ov-title { font-size: 1.3rem; margin: 0 0 8px; font-weight: 400; letter-spacing: 2px; color: var(--title); }
.ov-title.danger { color: var(--bad); text-shadow: 0 0 10px rgba(239,68,68,0.5); } 
.ov-title.success { color: var(--ok); text-shadow: 0 0 10px rgba(52,211,153,0.5); }
.ov-text { color: var(--text); font-size: 0.82rem; max-width: 400px; margin: 0 0 12px; line-height: 1.4; }
.ov-stat { font-size: 0.8rem; color: var(--accent); margin-bottom: 14px; background: rgba(2,132,199,0.1); padding: 6px 12px; border-radius: 4px; border: 1px solid var(--line-soft); }

.pixel-canvas {
  image-rendering: pixelated; image-rendering: crisp-edges;
  width: 280px; max-width: 100%; height: auto; aspect-ratio: 280 / 120;
  border: 2px solid var(--line-soft); border-radius: 6px; background: #000; margin-bottom: 12px;
  box-shadow: 0 0 20px rgba(2,132,199,0.3), inset 0 0 10px rgba(0,0,0,0.8);
}

.btn-main {
  background: var(--accent-2); color: #fff; border: none; padding: 12px 24px; font-family: inherit; font-size: 0.88rem; font-weight: bold;
  border-radius: 6px; cursor: pointer; margin-top: 6px; transition: all 0.2s; min-height: 46px; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  box-shadow: 0 4px 12px rgba(2,132,199,0.4);
}
.btn-main:hover { background: var(--line-soft); box-shadow: 0 0 15px rgba(56,189,248,0.6); transform: translateY(-1px); }
.btn-icon { stroke: currentColor; }

.audio-btn {
  background: var(--panel-2); border: 1px solid var(--accent-2); color: var(--accent); padding: 6px 12px; border-radius: 4px;
  cursor: pointer; font-family: inherit; font-size: 0.75rem; transition: all 0.2s; min-height: 36px;
}
.audio-btn:hover { background: var(--line-soft); box-shadow: 0 0 8px rgba(56,189,248,0.3); }
#audio-txt { color: var(--ok); }
.audio-btn[aria-pressed="false"] #audio-txt { color: var(--warn); }

button:focus-visible { outline: 2px solid var(--white); outline-offset: 2px; }

/* Mobile / petits écrans */
@media (max-width: 760px) {
  body { padding: 8px; align-items: flex-start; }
  .container { min-height: 0; }
  .main-grid { grid-template-columns: 1fr; height: auto; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--line); overflow: visible; }
  .right-panel { padding: 12px; }
  #terminal { min-height: 150px; max-height: 180px; margin-bottom: 12px; }
  #event-box { position: fixed; left: 10px; right: 10px; bottom: 10px; z-index: 40; max-height: 60vh; overflow-y: auto; }
  .overlay { position: fixed; padding: 12px; justify-content: flex-start; padding-top: 20px; }
  .start-panel-frame { padding: 16px; margin-top: auto; margin-bottom: auto; }
  .start-title { font-size: 1.25rem; }
  .game-title { font-size: 1rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
/* ---- PANIQUE : retours visuels de danger ---- */
.damage-flash { position: absolute; inset: 0; pointer-events: none; z-index: 45; opacity: 0;
  background: radial-gradient(ellipse at center, rgba(239,68,68,0) 30%, rgba(239,68,68,0.6) 100%); }
.damage-flash.on { animation: dmgFlash 0.5s ease-out; }
@keyframes dmgFlash { 0% { opacity: 1; } 100% { opacity: 0; } }

.container.hit-s { animation: shakeS 0.3s linear; }
.container.hit-l { animation: shakeL 0.55s linear; }
@keyframes shakeS { 0%,100% { left: 0; top: 0; } 20% { left: -4px; top: 2px; } 40% { left: 4px; top: -2px; } 60% { left: -3px; top: 1px; } 80% { left: 2px; top: -1px; } }
@keyframes shakeL { 0%,100% { left: 0; top: 0; } 10% { left: -9px; top: 4px; } 25% { left: 8px; top: -5px; } 40% { left: -7px; top: 3px; } 55% { left: 6px; top: -3px; } 70% { left: -4px; top: 2px; } 85% { left: 3px; top: -1px; } }

/* Coque < 35 % : le cadre rougeoie en permanence */
.container.low-hull::before { content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 24;
  box-shadow: inset 0 0 70px rgba(239,68,68,0.5); animation: hullAlarm 0.9s infinite alternate; }
@keyframes hullAlarm { 0% { opacity: 0.25; } 100% { opacity: 1; } }
.container.low-hull .status-dot { animation: dotBlink 0.5s infinite alternate; }
@keyframes dotBlink { 0% { opacity: 0.2; } 100% { opacity: 1; } }

/* Jauge critique : libellé explicite (pas seulement la couleur) + pulsation */
.progress-container.critical .progress-header > span:first-child { color: var(--bad-strong); font-weight: bold; }
.progress-container.critical .progress-header > span:first-child::after { content: " \25B2 " var(--crit-txt, "CRITICAL"); }
.progress-container.critical .progress-bar-bg { border-color: var(--bad-strong); animation: critPulse 0.7s infinite alternate; }
@keyframes critPulse { 0% { box-shadow: 0 0 2px rgba(239,68,68,0.3); } 100% { box-shadow: 0 0 12px rgba(239,68,68,0.95); } }

/* Compte à rebours de crise */
.event-bar { height: 8px; background: rgba(239,68,68,0.15); border-radius: 4px; overflow: hidden; margin: 0 0 10px; border: 1px solid rgba(239,68,68,0.4); }
#ev-bar { height: 100%; width: 100%; background: var(--bad-strong); transition: width 1s linear; box-shadow: 0 0 8px rgba(239,68,68,0.8); }
#event-box.urgent { background: #2a0b10; animation: urgentBox 0.5s infinite alternate; }
@keyframes urgentBox { 0% { box-shadow: 0 0 20px rgba(239,68,68,0.4); } 100% { box-shadow: 0 0 45px rgba(239,68,68,0.95); } }
.event-timer.urgent { font-size: 1.05rem; color: #fff; background: var(--bad-strong); }

.lang-sel { background: var(--panel-2); border: 1px solid var(--accent-2); color: var(--accent); padding: 6px 8px; border-radius: 4px; font-family: inherit; font-size: 0.75rem; min-height: 36px; cursor: pointer; }
.lang-sel:hover { background: var(--line-soft); }

.start-lang { align-self: flex-end; margin: -6px -6px 6px 0; }
