/* Black Boat : consoles de bord.
   Ambre = ce qui est ordonné ou commandable. Cyan = ce qui est capté. Blanc = l’état réel. */
:root {
  --coque: #121D27;
  --console: #1A2833;
  --console-2: #223443;
  --rivet: #33495A;
  --lecture: #D9E1E7;
  --lecture-2: #8FA3B2;
  --ambre: #F0A63A;
  --ambre-sombre: #6B4A1C;
  --cyan: #86D5D8;
  --vert: #8FCB7E;
  --rouge: #E5493C;
  --wf-0: #0E1922;
  --wf-1: #2A7C88;
  --wf-2: #EAFBFF;
  --r-petit: 3px;
  --r-moyen: 6px;
  --police: "Barlow Semi Condensed", "Arial Narrow", "Roboto Condensed", system-ui, sans-serif;
  --police-titre: "Barlow Condensed", "Arial Narrow", "Roboto Condensed", system-ui, sans-serif;
  color-scheme: dark;
}

/* Éclairage de combat : tout le central passe au rouge */
body[data-eclairage="combat"] {
  --coque: #170B0A;
  --console: #241210;
  --console-2: #2F1815;
  --rivet: #552722;
  --lecture: #F3D3CC;
  --lecture-2: #B98A82;
  --ambre: #FF9D57;
  --ambre-sombre: #6E3218;
  --cyan: #FF8F7C;
  --vert: #E9B37C;
  --wf-0: #1B0907;
  --wf-1: #8E2B1F;
  --wf-2: #FFDCD2;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--coque);
  color: var(--lecture);
  font-family: var(--police);
  font-size: 15px;
  line-height: 1.4;
  font-variant-numeric: tabular-nums;
  transition: background-color 1.2s ease, color 1.2s ease;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

h1, h2, h3 { font-family: var(--police-titre); font-weight: 700; margin: 0; line-height: 1.1; }
h2 { font-size: 1.45rem; }
h3 { font-size: 1.1rem; color: var(--lecture-2); font-family: var(--police); font-weight: 600; }
p { margin: 0 0 .6em; }
.aide { color: var(--lecture-2); font-size: .9rem; }
[hidden] { display: none !important; }

button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea {
  background: var(--coque);
  border: 1px solid var(--rivet);
  border-radius: var(--r-petit);
  padding: .35rem .5rem;
  min-width: 0;
}
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, canvas:focus-visible, summary:focus-visible {
  outline: 2px solid var(--ambre);
  outline-offset: 2px;
}
label { display: grid; gap: .25rem; color: var(--lecture-2); font-size: .9rem; }

.btn {
  background: var(--console-2);
  border: 1px solid var(--rivet);
  border-radius: var(--r-petit);
  padding: .4rem .75rem;
  cursor: pointer;
  font-weight: 500;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--ambre); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-primaire { background: var(--ambre); color: #1A1206; border-color: var(--ambre); font-weight: 600; }
.btn-primaire:hover:not(:disabled) { filter: brightness(1.08); }
.btn-danger { border-color: var(--rouge); color: var(--rouge); }
.btn-danger.actif, .btn-danger:hover:not(:disabled) { background: var(--rouge); color: #fff; }
.btn.actif { border-color: var(--ambre); color: var(--ambre); background: var(--ambre-sombre); }
.btn-petit { padding: .15rem .45rem; font-size: .85rem; }
.btn-feu {
  background: var(--rouge); color: #fff; border: none; font-family: var(--police-titre);
  font-size: 1.5rem; letter-spacing: .02em; padding: .5rem 1.6rem; border-radius: var(--r-moyen);
}
.btn-feu:disabled { opacity: .35; cursor: not-allowed; }
.rangee { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; }

/* ---------- Carré (salle d’attente) ---------- */
.carre {
  max-width: 1080px; margin: 0 auto; padding: 3rem 1.5rem 4rem;
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 2.5rem; align-items: start;
}
.carre-titre h1 {
  font-size: clamp(3.6rem, 9vw, 7.5rem);
  letter-spacing: -.02em;
  line-height: .9;
  color: var(--lecture);
}
.silhouette { width: 100%; max-width: 420px; display: block; margin-bottom: 1.2rem; }
.silhouette path { fill: none; stroke: var(--ambre); stroke-width: 2; }
.silhouette line { stroke: var(--ambre); stroke-width: 2; }
.sous-titre { font-size: 1.15rem; color: var(--lecture-2); max-width: 30ch; margin-top: 1rem; }
.carte-carre { background: var(--console); border: 1px solid var(--rivet); border-radius: var(--r-moyen); padding: 1.4rem; }
#form-rejoindre { display: grid; gap: .9rem; margin-top: 1rem; }
.salle-entete { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
#salle-code { color: var(--ambre); letter-spacing: .08em; }
.liste-postes { display: grid; gap: .45rem; margin: 1rem 0; }
.poste-ligne {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .2rem 1rem; align-items: center;
  padding: .55rem .7rem; border: 1px solid var(--rivet); border-radius: var(--r-petit); background: var(--coque);
}
.poste-ligne.tenu { border-color: var(--ambre-sombre); }
.poste-ligne.moi { border-color: var(--ambre); }
.poste-ligne.ferme { opacity: .5; }
.poste-nom { font-weight: 600; }
.poste-desc { color: var(--lecture-2); font-size: .85rem; grid-column: 1; }
.poste-tenant { color: var(--ambre); font-size: .9rem; }
.salle-actions { display: flex; gap: .6rem; margin: .4rem 0 1rem; }
.briefing summary { cursor: pointer; font-weight: 600; margin-bottom: .5rem; }
.briefing ul { margin: .4rem 0; padding-left: 1.2rem; }

/* ---------- Bord ---------- */
.bord {
  display: grid; height: 100vh;
  grid-template-columns: minmax(0, 1fr) 340px;
  grid-template-rows: auto auto minmax(0, 1fr);
}
.bandeau {
  grid-column: 1 / -1;
  display: flex; flex-wrap: wrap; align-items: stretch;
  background: var(--console); border-bottom: 1px solid var(--rivet);
}
.repetiteur { padding: .35rem 1rem .4rem; border-right: 1px solid var(--rivet); min-width: 7.5rem; }
.repetiteur .nom { font-size: .78rem; color: var(--lecture-2); display: block; }
.repetiteur .val, .repetiteur .ord { display: block; }
.repetiteur .val { font-family: var(--police-titre); font-size: 1.65rem; font-weight: 700; line-height: 1.05; }
.repetiteur .ord { font-size: .82rem; color: var(--ambre); }
.repetiteur.alerte .val { color: var(--rouge); }
.bandeau .alarmes { display: flex; gap: .4rem; align-items: center; padding: 0 1rem; margin-left: auto; }
.voyant { padding: .2rem .55rem; border-radius: var(--r-petit); border: 1px solid var(--rivet); color: var(--lecture-2); font-size: .85rem; }
.voyant.on { border-color: var(--rouge); color: #fff; background: var(--rouge); }
.voyant.on.calme { background: var(--ambre-sombre); border-color: var(--ambre); color: var(--ambre); }

body.alerte-torpille .bandeau { animation: clignote 0.8s steps(2, end) infinite; }
@keyframes clignote { 50% { background: var(--rouge); } }

.postes { grid-column: 1 / -1; display: flex; gap: 0; border-bottom: 1px solid var(--rivet); overflow-x: auto; background: var(--coque); }
.onglet {
  background: none; border: none; border-bottom: 2px solid transparent; padding: .55rem 1rem; cursor: pointer; color: var(--lecture-2);
  font-weight: 600; white-space: nowrap;
}
.onglet[aria-selected="true"] { color: var(--lecture); border-bottom-color: var(--ambre); }
.onglet .pastille { display: inline-block; min-width: 1.2em; margin-left: .35rem; padding: 0 .3em; border-radius: 1em; background: var(--rouge); color: #fff; font-size: .75rem; }

.stations { overflow: auto; padding: 1rem; min-height: 0; }
.station { display: none; }
.station.visible { display: block; }

.comms { border-left: 1px solid var(--rivet); background: var(--console); display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.comms-bloc { padding: .7rem .8rem; border-bottom: 1px solid var(--rivet); display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.comms-bloc .fil { flex: 1 1 auto; }
.comms-bloc h3 { margin-bottom: .4rem; }
.comms-bloc.extensible { flex: 1 1 0; }
.fil { overflow-y: auto; display: flex; flex-direction: column; gap: .35rem; min-height: 3rem; }
.msg { border-left: 2px solid var(--rivet); padding: .2rem .5rem; font-size: .9rem; }
.msg .meta { color: var(--lecture-2); font-size: .78rem; }
.msg.a-traiter { border-left-color: var(--ambre); background: var(--console-2); }
.msg.statut-exécuté, .msg.statut-transmis { border-left-color: var(--vert); }
.msg .actions { display: flex; gap: .3rem; margin-top: .25rem; flex-wrap: wrap; }
.journal .msg { border-left-color: transparent; padding: .05rem .2rem; }
.journal .msg.warn { color: var(--ambre); }
.journal .msg.alarm { color: var(--rouge); font-weight: 600; }
.journal .msg.good { color: var(--vert); }
.cr-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .35rem; margin-top: .45rem; }
.cr-form select { grid-column: 1 / -1; }
.cr-rapides { display: flex; gap: .3rem; flex-wrap: wrap; margin-top: .35rem; }

/* ---------- Éléments de console ---------- */
.panneau { background: var(--console); border: 1px solid var(--rivet); border-radius: var(--r-moyen); padding: .9rem; }
.panneau > h3 { margin-bottom: .6rem; }
.grille-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1rem; }
.grille-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
.pile { display: grid; gap: 1rem; align-content: start; min-width: 0; }
.panneau { min-width: 0; }
.lecture-grande { font-family: var(--police-titre); font-size: 2.6rem; font-weight: 700; line-height: 1; }
.lecture-moyenne { font-family: var(--police-titre); font-size: 1.6rem; font-weight: 700; line-height: 1.05; }
.ordonne { color: var(--ambre); }
.capte { color: var(--cyan); }
.faible { color: var(--lecture-2); }
.ok { color: var(--vert); }
.danger { color: var(--rouge); }
.lampe { display: inline-flex; align-items: center; gap: .4rem; color: var(--lecture-2); }
.lampe::before { content: ""; width: .7rem; height: .7rem; border-radius: 50%; background: var(--rivet); }
.lampe.on { color: var(--rouge); }
.lampe.on::before { background: var(--rouge); box-shadow: 0 0 8px var(--rouge); }
.lampe.vert.on { color: var(--vert); }
.lampe.vert.on::before { background: var(--vert); box-shadow: 0 0 8px var(--vert); }
.jauge { height: .55rem; background: var(--coque); border: 1px solid var(--rivet); border-radius: 1rem; overflow: hidden; }
.jauge > i { display: block; height: 100%; background: var(--cyan); width: 0; transition: width .4s; }
.jauge.ambre > i { background: var(--ambre); }
.bandeau-info { padding: .5rem .7rem; border-radius: var(--r-petit); border: 1px solid var(--ambre); color: var(--ambre); background: var(--ambre-sombre); margin-bottom: .8rem; }
.bandeau-info.danger { border-color: var(--rouge); color: #fff; background: var(--rouge); }
table.tableau { width: 100%; border-collapse: collapse; font-size: .92rem; }
.tableau th { text-align: left; font-weight: 500; color: var(--lecture-2); padding: .3rem .4rem; border-bottom: 1px solid var(--rivet); font-size: .82rem; }
.tableau td { white-space: nowrap; padding: .3rem .4rem; border-bottom: 1px solid var(--console-2); vertical-align: middle; }
.tableau tr.choisi td { background: var(--console-2); }
.tableau tr.perdu td { color: var(--lecture-2); }
.tableau tr.menace td { color: var(--rouge); }
.tableau tr { cursor: default; }
.tableau-defile { overflow-x: auto; }
.vide { color: var(--lecture-2); font-size: .9rem; padding: .4rem 0; }

/* Timonier */
.barre-grille { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, .8fr) minmax(0, 1fr); gap: 1rem; }
.cadran { width: 100%; max-width: 280px; aspect-ratio: 1; display: block; margin: 0 auto .6rem; cursor: crosshair; }
.profondimetre { width: 100%; height: 360px; display: block; cursor: crosshair; }
.telegraphe { display: grid; gap: .3rem; }
.telegraphe .btn { text-align: left; display: flex; justify-content: space-between; }
.saisie-ordre { display: flex; gap: .3rem; align-items: center; flex-wrap: wrap; margin-top: .4rem; }
.saisie-ordre input { width: 5.2rem; }

/* Sonar */
.sonar-grille { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 1rem; }
.cascade-cadre { position: relative; }
.cascade { width: 100%; height: 320px; display: block; cursor: crosshair; background: var(--wf-0); border-radius: var(--r-petit); image-rendering: pixelated; }
.lofar { width: 100%; height: 200px; display: block; background: var(--wf-0); border-radius: var(--r-petit); }
.spectre { width: 100%; height: 90px; display: block; background: var(--wf-0); border-radius: var(--r-petit); margin-top: .4rem; }
.biblio { display: grid; gap: .4rem; margin-top: .6rem; }
.fiche { border: 1px solid var(--rivet); border-radius: var(--r-petit); padding: .4rem .55rem; font-size: .86rem; }
.fiche b { color: var(--lecture); }
.fiche .peigne { height: 14px; margin-top: .3rem; position: relative; background: var(--coque); border-radius: 2px; }
.fiche .peigne i { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--cyan); }
.transitoires { font-size: .88rem; display: grid; gap: .15rem; max-height: 9rem; overflow-y: auto; }

/* Armes */
.tubes { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .7rem; }
.tube { border: 1px solid var(--rivet); border-radius: var(--r-moyen); padding: .65rem; background: var(--coque); display: grid; gap: .35rem; }
.tube.selection { border-color: var(--ambre); box-shadow: inset 0 0 0 1px var(--ambre); }
.tube.pare { border-color: var(--rouge); }
.tube h4 { margin: 0; font-family: var(--police-titre); font-size: 1.25rem; display: flex; justify-content: space-between; align-items: baseline; }
.etat { display: flex; justify-content: space-between; font-size: .88rem; }
.etat span:first-child { color: var(--lecture-2); }
.tube .rangee .btn { flex: 1 1 auto; }
.conduite-tir { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .7rem; align-items: end; }
.torpilles { display: grid; gap: .6rem; }
.torpille { border: 1px solid var(--rivet); border-radius: var(--r-moyen); padding: .6rem .7rem; display: grid; gap: .4rem; }
.torpille.morte { opacity: .55; }
.torpille .ligne-haut { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; align-items: baseline; }
.torpille .mesures { display: flex; gap: 1.2rem; flex-wrap: wrap; font-size: .92rem; }

/* ESM */
.esm-grille { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 1rem; }
.mat-etat { font-family: var(--police-titre); font-size: 2rem; font-weight: 700; }
.conditions { display: grid; gap: .2rem; margin: .5rem 0; font-size: .92rem; }
.groupes { display: flex; flex-wrap: wrap; gap: .35rem; margin: .5rem 0; }
.groupe { border: 1px solid var(--rivet); border-radius: var(--r-petit); padding: .2rem .45rem; min-width: 3.2rem; text-align: center; background: var(--coque); cursor: pointer; }
.groupe .code { font-family: var(--police-titre); font-size: 1.2rem; display: block; }
.groupe .mot { font-size: .75rem; color: var(--cyan); min-height: 1em; display: block; }
.groupe.actif { border-color: var(--ambre); box-shadow: inset 0 0 0 1px var(--ambre); }
.groupe.trouve { border-color: var(--vert); }
.carnet { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: .25rem; max-height: 260px; overflow-y: auto; }
.carnet button { display: flex; justify-content: space-between; gap: .4rem; background: var(--coque); border: 1px solid var(--console-2); border-radius: var(--r-petit); padding: .2rem .4rem; cursor: pointer; font-size: .85rem; }
.carnet button:hover { border-color: var(--ambre); }
.carnet button .c { color: var(--lecture-2); }
.carnet button.raté { border-color: var(--rouge); animation: secoue .3s; }
@keyframes secoue { 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }

/* Commandement + table tactique */
.cmd-grille { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(280px, 1fr); gap: 1rem; }
.tac { display: flex; flex-direction: column; gap: .5rem; }
.tac-outils { display: flex; gap: .35rem; flex-wrap: wrap; align-items: center; }
.tac-cadre { position: relative; }
.tac-canvas { width: 100%; height: min(68vh, 640px); display: block; background: var(--coque); border: 1px solid var(--rivet); border-radius: var(--r-moyen); touch-action: none; }
.tac-info { position: absolute; left: .6rem; bottom: .5rem; font-size: .85rem; color: var(--lecture-2); pointer-events: none; }
.tac-pop {
  position: absolute; z-index: 5; background: var(--console); border: 1px solid var(--ambre); border-radius: var(--r-moyen);
  padding: .6rem; display: grid; gap: .45rem; width: 220px; box-shadow: 0 6px 24px rgba(0, 0, 0, .45);
}
.tac-pop .rangee input { width: 4.5rem; }
.situation { display: grid; gap: .5rem; font-size: .9rem; }
.situation .ligne { display: grid; grid-template-columns: 5.5rem minmax(0, 1fr); gap: .5rem; }
.situation .ligne > span:first-child { color: var(--lecture-2); }
.modeles { display: flex; flex-wrap: wrap; gap: .3rem; margin: .4rem 0; }
.compose { display: grid; gap: .45rem; }
.compose textarea { min-height: 3.4rem; resize: vertical; }

/* Fin de mission */
.fin {
  position: fixed; inset: 0; background: rgba(5, 9, 12, .82); display: grid; place-items: center; z-index: 50; padding: 1rem;
}
.fin-carte { background: var(--console); border: 1px solid var(--rivet); border-radius: var(--r-moyen); padding: 1.8rem; max-width: 560px; width: 100%; }
.fin-carte h2 { font-size: 2.6rem; margin-bottom: .4rem; }
.fin-carte.reussite h2 { color: var(--vert); }
.fin-carte.echec h2 { color: var(--rouge); }
.fin-carte dl { display: grid; grid-template-columns: auto 1fr; gap: .25rem 1rem; margin: 1rem 0; }
.fin-carte dt { color: var(--lecture-2); }
.fin-carte dd { margin: 0; }

.toasts { position: fixed; right: 1rem; bottom: 1rem; display: grid; gap: .4rem; z-index: 60; max-width: min(380px, 90vw); }
.toast { background: var(--console-2); border: 1px solid var(--rivet); border-radius: var(--r-petit); padding: .5rem .8rem; box-shadow: 0 4px 16px rgba(0, 0, 0, .4); }
.toast.err { border-color: var(--rouge); }
.toast.ok { border-color: var(--vert); }

@media (max-width: 1200px) {
  .barre-grille, .sonar-grille, .esm-grille, .cmd-grille { grid-template-columns: minmax(0, 1fr); }
  .tubes { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .carre { grid-template-columns: minmax(0, 1fr); padding-top: 1.5rem; }
  .bord { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto auto auto; height: auto; min-height: 100vh; }
  .comms { border-left: none; border-top: 1px solid var(--rivet); max-height: none; }
  .comms-bloc.extensible { flex: none; }
  .fil { max-height: 16rem; }
  .grille-2, .grille-3 { grid-template-columns: minmax(0, 1fr); }
}
