:root {
  --bg: #020604;
  --panel: rgba(6, 22, 12, 0.78);
  --phosphor: #39ff6a;
  --phosphor-dim: #1f8a3c;
  --line: rgba(57, 255, 106, 0.28);
  --amber: #ffb000;
  --red: #ff3b30;
  --defcon: #3b8bff;
  --mono: 'Share Tech Mono', ui-monospace, Consolas, monospace;
  --display: 'Orbitron', var(--mono);
}

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

body {
  min-height: 100vh;
  background:
    radial-gradient(ellipse at center, rgba(20, 60, 30, 0.35), transparent 70%),
    linear-gradient(rgba(57, 255, 106, 0.04) 1px, transparent 1px) 0 0 / 40px 40px,
    linear-gradient(90deg, rgba(57, 255, 106, 0.04) 1px, transparent 1px) 0 0 / 40px 40px,
    var(--bg);
  color: var(--phosphor);
  font-family: var(--mono);
  letter-spacing: 0.04em;
  text-shadow: 0 0 6px rgba(57, 255, 106, 0.45);
}

/* --- Effet écran cathodique ---------------------------------------------- */

.crt {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  background: repeating-linear-gradient(
    to bottom, rgba(0, 0, 0, 0.22) 0 1px, transparent 1px 3px);
  box-shadow: inset 0 0 160px rgba(0, 0, 0, 0.9);
  animation: flicker 6s infinite;
}

@keyframes flicker {
  0%, 96%, 100% { opacity: 1; }
  97% { opacity: 0.85; }
  98% { opacity: 0.95; }
}

/* --- Barre supérieure ------------------------------------------------------ */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.8rem 1.5rem;
  border-bottom: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.5);
}

.brand { font-family: var(--display); font-weight: 900; font-size: 1.3rem; letter-spacing: 0.2em; }
.brand small { font-family: var(--mono); font-weight: 400; font-size: 0.75rem; color: var(--phosphor-dim); letter-spacing: 0.1em; }

.beacon {
  display: inline-block;
  width: 10px; height: 10px;
  margin-right: 0.5rem;
  border-radius: 50%;
  background: var(--red);
  box-shadow: 0 0 10px var(--red);
  animation: blink 1.2s steps(1) infinite;
}

@keyframes blink { 50% { opacity: 0.15; } }

.clocks { display: flex; gap: 1.5rem; font-size: 0.9rem; color: var(--phosphor-dim); }
.clocks b { color: var(--phosphor); font-weight: 400; }

.classified {
  padding: 0.2rem 0.7rem;
  border: 1px solid var(--red);
  color: var(--red);
  text-shadow: 0 0 6px var(--red);
  font-size: 0.8rem;
}

/* --- Grille et panneaux ----------------------------------------------------- */

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-areas:
    'countdown countdown defcon'
    'briefing briefing risk'
    'threats threats threats'
    'history history history'
    'log log log';
  gap: 1rem;
  padding: 1rem 1.5rem;
}

.countdown { grid-area: countdown; }
.defcon { grid-area: defcon; }
.briefing { grid-area: briefing; }
.threats { grid-area: threats; }
.risk { grid-area: risk; }
.history { grid-area: history; }
.log { grid-area: log; }

.panel {
  position: relative;
  padding: 1.2rem 1.4rem;
  background: var(--panel);
  border: 1px solid var(--line);
}

/* Coins en équerre façon console militaire */
.panel::before, .panel::after {
  content: '';
  position: absolute;
  width: 14px; height: 14px;
  border: 2px solid var(--phosphor);
}
.panel::before { top: -2px; left: -2px; border-right: 0; border-bottom: 0; }
.panel::after { bottom: -2px; right: -2px; border-left: 0; border-top: 0; }

.panel h2 {
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px dashed var(--line);
  font-family: var(--display);
  font-size: 0.8rem;
  font-weight: 500;
  letter-spacing: 0.25em;
  color: var(--phosphor-dim);
}
.panel h2::before { content: '▶ '; color: var(--phosphor); }

/* --- Compte à rebours ------------------------------------------------------- */

.years {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  flex-wrap: wrap;
  font-family: var(--display);
  font-weight: 900;
  font-size: clamp(2.2rem, 6vw, 5rem);
  line-height: 1.1;
  text-shadow: 0 0 18px rgba(57, 255, 106, 0.7);
}
.years small { font-size: 0.3em; color: var(--phosphor-dim); }

.clock-row {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  margin: 1rem 0 1.4rem;
  font-family: var(--display);
  font-size: clamp(1.4rem, 3.4vw, 2.6rem);
}
.unit { display: flex; flex-direction: column; align-items: center; }
.unit small { font-family: var(--mono); font-size: 0.7rem; color: var(--phosphor-dim); margin-top: 0.2rem; }
.unit.ms { font-size: 0.5em; margin-left: 0.4rem; align-self: flex-end; color: var(--phosphor-dim); }
.unit.ms small { font-size: 0.6rem; }
.sep { animation: blink 1s steps(1) infinite; }

.meta {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  border-top: 1px dashed var(--line);
  padding-top: 1rem;
}
.meta dt { font-size: 0.7rem; color: var(--phosphor-dim); margin-bottom: 0.3rem; }
.meta dd { font-size: 1rem; }
.meta .warn { color: var(--amber); text-shadow: 0 0 6px var(--amber); }

.countdown.recalc { animation: recalc 1.2s ease-out; }
@keyframes recalc {
  0%, 30%, 60% { background: rgba(255, 59, 48, 0.25); border-color: var(--red); }
  15%, 45%, 100% { background: var(--panel); border-color: var(--line); }
}

/* --- DEFCON ---------------------------------------------------------------- */

.defcon-body { display: flex; gap: 1rem; align-items: center; }

.defcon-stack { flex: 1; display: flex; flex-direction: column; gap: 0.35rem; }

.defcon-row {
  padding: 0.45rem 0.8rem;
  border: 1px solid var(--line);
  font-family: var(--display);
  font-size: 0.8rem;
  letter-spacing: 0.2em;
  color: var(--phosphor-dim);
  opacity: 0.45;
  transition: all 0.4s;
}
.defcon-row b { font-size: 1.1rem; margin-right: 0.6rem; }
.defcon-row.active {
  opacity: 1;
  color: #000;
  text-shadow: none;
  background: var(--defcon);
  border-color: var(--defcon);
  box-shadow: 0 0 22px var(--defcon);
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse { 50% { box-shadow: 0 0 6px var(--defcon); } }

.defcon-label {
  margin-top: 1rem;
  min-height: 2.6em;
  color: var(--defcon);
  text-shadow: 0 0 8px var(--defcon);
  font-size: 0.9rem;
}
.defcon-index { margin-top: 0.5rem; font-size: 0.75rem; color: var(--phosphor-dim); }
.defcon-index b { color: var(--phosphor); font-weight: 400; }

.radar {
  position: relative;
  width: 120px; height: 120px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 1px solid var(--line);
  background:
    radial-gradient(circle, transparent 29%, var(--line) 30%, transparent 31%, transparent 59%, var(--line) 60%, transparent 61%),
    linear-gradient(transparent 49.5%, var(--line) 50%, transparent 50.5%),
    linear-gradient(90deg, transparent 49.5%, var(--line) 50%, transparent 50.5%);
  overflow: hidden;
}
.sweep {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: conic-gradient(from 0deg, rgba(57, 255, 106, 0.55), transparent 25%);
  animation: sweep 3s linear infinite;
}
@keyframes sweep { to { transform: rotate(360deg); } }

/* --- Vecteurs de menace ---------------------------------------------------- */

#threat-list { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1.2rem 1.6rem; }

.threat-head { display: flex; align-items: center; gap: 0.5rem; font-size: 0.85rem; }
.threat-label { flex: 1; }
.threat-weight { font-size: 0.7rem; color: var(--phosphor-dim); }
.threat-score { font-family: var(--display); font-size: 1.1rem; min-width: 2.2ch; text-align: right; }

.tag { font-size: 0.6rem; padding: 0.05rem 0.35rem; border: 1px solid currentColor; }
.tag-live { color: var(--phosphor); animation: blink 2s steps(1) infinite; }
.tag-stale { color: var(--amber); }
.tag-manual { color: var(--phosphor-dim); }
.tag-offline { color: var(--red); }

.bar { height: 10px; margin: 0.35rem 0; border: 1px solid var(--line); }
.bar-fill {
  height: 100%;
  background: repeating-linear-gradient(90deg, currentColor 0 6px, transparent 6px 8px);
  box-shadow: 0 0 8px currentColor;
  transition: width 1s ease-out;
}
.threat.low { color: var(--phosphor); }
.threat.mid { color: var(--amber); }
.threat.high { color: var(--red); }
.threat .threat-head, .threat .threat-detail { color: var(--phosphor); }
.threat.mid .threat-score { color: var(--amber); }
.threat.high .threat-score { color: var(--red); }
.threat-detail { font-size: 0.7rem; color: var(--phosphor-dim) !important; line-height: 1.4; }

/* --- Indice global ---------------------------------------------------------- */

.risk { text-align: center; display: flex; flex-direction: column; justify-content: center; }
.risk-value {
  font-family: var(--display);
  font-weight: 900;
  font-size: clamp(3rem, 7vw, 5.5rem);
  color: var(--amber);
  text-shadow: 0 0 20px var(--amber);
}
.risk-scale { color: var(--phosphor-dim); margin-bottom: 0.8rem; }
#risk-trend.up { color: var(--red); text-shadow: 0 0 6px var(--red); }
#risk-trend.down { color: var(--phosphor); }
.sys-status { margin-top: 1.5rem; font-size: 0.7rem; color: var(--phosphor-dim); }

/* --- Journal ---------------------------------------------------------------- */

#event-log {
  list-style: none;
  max-height: 320px;
  overflow-y: auto;
  font-size: 0.8rem;
  line-height: 1.7;
}
#event-log li { border-bottom: 1px solid rgba(57, 255, 106, 0.07); }
#event-log li::before { content: '> '; color: var(--phosphor-dim); }
#event-log time { color: var(--phosphor-dim); margin-right: 0.5rem; }
.ev-tag { color: var(--phosphor-dim); }
.ev-mid { color: var(--amber); text-shadow: 0 0 6px var(--amber); }
.ev-high { color: var(--red); text-shadow: 0 0 6px var(--red); }

#event-log::-webkit-scrollbar { width: 6px; }
#event-log::-webkit-scrollbar-thumb { background: var(--phosphor-dim); }

footer {
  padding: 1rem 1.5rem 1.5rem;
  font-size: 0.65rem;
  color: var(--phosphor-dim);
  text-align: center;
  line-height: 1.6;
}

/* --- Briefing ---------------------------------------------------------------- */

.situation-list { list-style: none; font-size: 0.85rem; line-height: 1.6; }
.situation-list li { padding: 0.15rem 0; animation: line-in 0.4s ease-out both; }
.situation-list li::before { content: '■ '; color: var(--phosphor-dim); }
.situation-list li:first-child { color: var(--amber); text-shadow: 0 0 6px var(--amber); }
@keyframes line-in { from { opacity: 0; transform: translateX(-6px); } }
.briefing-meta { margin-top: 1rem; font-size: 0.7rem; color: var(--phosphor-dim); }
.briefing-meta .err { color: var(--red); }
.blink { animation: blink 1s steps(1) infinite; }

.threat-parts { font-size: 0.68rem; color: var(--phosphor-dim) !important; margin-bottom: 0.2rem; }
.threat-parts b { color: var(--phosphor); font-weight: 400; }

/* --- Historique --------------------------------------------------------------- */

.panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; }
.panel-head h2 { flex: 1; }
.ranges { display: flex; gap: 0.3rem; }
.range-btn {
  padding: 0.2rem 0.6rem;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--phosphor-dim);
  font: inherit;
  font-size: 0.7rem;
  cursor: pointer;
}
.range-btn:hover { color: var(--phosphor); border-color: var(--phosphor-dim); }
.range-btn.active { color: #000; background: var(--phosphor); border-color: var(--phosphor); text-shadow: none; }

.chart-wrap { position: relative; min-height: 230px; }
.chart { display: block; overflow: visible; }
.chart .grid { stroke: rgba(57, 255, 106, 0.1); stroke-width: 1; }
.chart .axis { fill: var(--phosphor-dim); font-size: 11px; font-family: var(--mono); text-shadow: none; }
.chart .line {
  fill: none;
  stroke: var(--phosphor);
  stroke-width: 2;
  stroke-linejoin: round;
  filter: drop-shadow(0 0 4px rgba(57, 255, 106, 0.7));
}
.chart .last-dot { fill: var(--phosphor); filter: drop-shadow(0 0 6px var(--phosphor)); animation: blink 1.4s steps(1) infinite; }
.chart .cross-line { stroke: var(--phosphor-dim); stroke-dasharray: 3 3; }
.chart .cross-dot { fill: var(--bg); stroke: var(--phosphor); stroke-width: 2; }
.chart .hit { cursor: crosshair; }
.chart-tip {
  position: absolute;
  pointer-events: none;
  padding: 0.5rem 0.7rem;
  background: rgba(2, 10, 5, 0.95);
  border: 1px solid var(--phosphor-dim);
  font-size: 0.75rem;
  line-height: 1.5;
  white-space: nowrap;
}
.chart-tip .tip-time { color: var(--phosphor-dim); }
.chart-tip b { font-weight: 400; color: var(--phosphor); }
.chart-empty {
  display: grid;
  place-items: center;
  height: 230px;
  color: var(--phosphor-dim);
  font-size: 0.8rem;
  border: 1px dashed var(--line);
}

.history-data { margin-top: 0.8rem; font-size: 0.7rem; color: var(--phosphor-dim); }
.history-data summary { cursor: pointer; }
.history-data table { margin-top: 0.5rem; border-collapse: collapse; width: 100%; }
.history-data th, .history-data td { text-align: left; padding: 0.2rem 0.6rem; border-bottom: 1px solid rgba(57, 255, 106, 0.08); }
.history-data td { color: var(--phosphor); }

/* --- Journal : liens et prévisions -------------------------------------------- */

#event-log a { color: inherit; text-decoration: none; }
#event-log a:hover { text-decoration: underline; }
.ev-future { font-size: 0.6rem; padding: 0 0.3rem; border: 1px solid currentColor; color: #7fd8ff; }

body.link-lost .panel { border-color: rgba(255, 59, 48, 0.4); }
body.link-lost .sys-status { color: var(--red); }

/* --- Alerte maximale : l'interface vire au rouge ---------------------------- */

body[data-defcon='2'] .topbar,
body[data-defcon='1'] .topbar { border-bottom-color: var(--red); box-shadow: 0 0 30px rgba(255, 59, 48, 0.35); }
body[data-defcon='1'] .crt { background-color: rgba(255, 0, 0, 0.06); }

/* --- Responsive ------------------------------------------------------------- */

@media (max-width: 1200px) {
  #threat-list { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 900px) {
  .grid {
    grid-template-columns: 1fr;
    grid-template-areas: 'countdown' 'defcon' 'risk' 'briefing' 'threats' 'history' 'log';
  }
  #threat-list { grid-template-columns: 1fr; }
  .meta { grid-template-columns: 1fr; }
}
