* { margin:0; padding:0; box-sizing:border-box; -webkit-tap-highlight-color:transparent; }
body{
  font-family:"Courier New", monospace;
  background:#111;
  min-height:100vh;
  display:flex;
  align-items:center;
  justify-content:center;
  padding:14px;
  overflow:auto;
  color:#ddd;
}

/* App centered */
.app{
  width: min(900px, 96vw);
  display:flex;
  flex-direction:column;
  align-items:center;
}

/* Topbar */
.topbar { display:none; }

.status{
  padding:6px 10px;
  border-radius:8px;
  border:1px solid #333;
  background:#000;
  display:flex;
  gap:10px;
  align-items:center;
}

.dot{
  width:10px; height:10px; border-radius:50%;
  background:#a00;
  box-shadow:0 0 8px rgba(255,0,0,0.2);
}
.dot.on{
  background:#0f0;
  box-shadow:0 0 10px rgba(0,255,0,0.35);
}

.controls{ display:flex; gap:8px; align-items:center; }

.btn{
  background:#222;
  color:#ddd;
  border:1px solid #444;
  border-radius:8px;
  padding:6px 10px;
  cursor:pointer;
  user-select:none;
}
.btn:active{ transform:translateY(1px); }
.btn.toggled{ border-color:#0f0; color:#0f0; }

/* CDU stage centered + responsive */
.cdu-stage{
  position:relative;
  width: min(640px, 96vw);
  max-height: calc(100vh - 120px);
  aspect-ratio:826 / 1351;
  background:#0b0b0b;
  border-radius:16px;
  box-shadow:0 10px 40px rgba(0,0,0,0.55);
  overflow:hidden;
}

.cdu-overlay{
  position:absolute;
  inset:0;
  width:100%;
  height:100%;
  object-fit:contain;
  pointer-events:none;
  image-rendering:auto;
}

/* LED overlays — above night mask and backlight so they glow at night */
.cdu-led{
  display:none;
  z-index:5;
}
.cdu-led.active{
  display:block;
}

/* Lighting overlays — opacity controlled by JS */
.cdu-night-mask{
  background:#000;
  opacity:0;
  z-index:3;
  width:100%;
  height:100%;
}
.cdu-lighting{
  opacity:0;
  z-index:4;
}
.cdu-flood-mask{
  background:rgba(255,240,210,1);
  opacity:0;
  z-index:5;
  width:100%;
  height:100%;
}

/* Screen anchor — z-index above night/flood masks so screen stays readable */
.cdu-display{
  position:absolute;
  overflow:hidden;
  pointer-events:none;
  z-index:6;
}
.debug .cdu-display{
  pointer-events:auto;
  cursor:pointer;
}
.debug .cdu-display::after{
  content:"";
  position:absolute;
  inset:0;
  border:2px dashed rgba(255,255,0,0.65);
  border-radius:6px;
  pointer-events:none;
  box-sizing:border-box;
}
.debug .cdu-display.selected::after{
  border:3px solid rgba(255,255,0,1);
  box-shadow: 0 0 0 2px rgba(255,255,0,0.25) inset;
}

/* --- CDU Display container --- */
.cdu-display-inner{
  position:absolute;
  inset:0;
  background:#080810;
  border:1px solid rgba(60,60,80,0.6);
  border-radius:4px;

  /* padding piloté par JS (en px écran) */
  padding: var(--cdu-pad, 8px);
  overflow:hidden;
}

/* --- Multi-layer CDU display (14 visual rows) --- */
.cdu-row {
  position: relative;
  height: var(--cdu-cell-h, 14px);
}

.cdu-layer {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(24, 1fr);
  pointer-events: none;
}

.cdu-layer span {
  font-family: "Lucida Console", Consolas, monospace;
  font-size: var(--cdu-font, 16px);
  font-weight: bold;
  line-height: var(--cdu-cell-h, 14px);
  text-align: center;
  white-space: pre;
  user-select: none;
}

/* Spaces are transparent — lower layers show through */
.cdu-layer span.space {
  color: transparent;
}

/* Color layers — matched to Zibo in-sim CDU */
.layer-grey    { color: #E0E0E0; }
.layer-green   { color: #00DD00; }
.layer-magenta { color: #FF40FF; }
.layer-cyan    { color: #00CCEE; }

/* Small text rows: inherit color from layer class, reduce font */
.cdu-row-sm .cdu-layer span {
  font-size: calc(var(--cdu-font, 16px) * 0.72);
}

/* Legacy small-layer classes (for Line00_S which is on a large row) */
.layer-sm-grey span  { font-size: calc(var(--cdu-font, 16px) * 0.72); }
.layer-sm-green span { font-size: calc(var(--cdu-font, 16px) * 0.72); }
.layer-sm-grey  { color: #E0E0E0; }
.layer-sm-green { color: #00DD00; }

/* Invert layers */
.layer-invert span.inv {
  background: #E0E0E0;
  color: #000000;
}
.layer-sm-invert span {
  font-size: calc(var(--cdu-font, 16px) * 0.72);
}
.layer-sm-invert span.inv {
  background: #E0E0E0;
  color: #000000;
}

/* Debug: highlight selected row */
.cdu-row.row-selected {
  outline: 1px solid rgba(255, 255, 0, 0.5);
  background: rgba(255, 255, 0, 0.08);
}

/* EXEC LED glow */
.hit.led-on {
  box-shadow: 0 0 12px 4px rgba(110, 233, 112, 0.6);
  background: rgba(110, 233, 112, 0.25) !important;
}

/* Hit layer doesn't catch clicks, only .hit does */
.hit-layer{
  position:absolute;
  inset:0;
  pointer-events:none;
}

.hit{
  position:absolute;
  border-radius:6px;
  background:rgba(0,255,0,0.0);
  border:1px solid rgba(0,255,0,0.0);
  cursor:pointer;
  user-select:none;
  pointer-events:auto;
}
.hit.round{ border-radius:999px; }

/* Debug visualization */
.debug .hit{
  background:rgba(0,255,0,0.10);
  border-color:rgba(0,255,0,0.35);
}

/* Debug label */
.hit .lbl{
  display:none;
  position:absolute;
  left:4px; top:2px;
  font-size:10px;
  color:#0f0;
  text-shadow:0 1px 2px rgba(0,0,0,0.8);
  pointer-events:none;
  white-space:nowrap;
}
.debug .hit .lbl{ display:block; }

/* Selected */
.hit.selected{
  outline:2px solid rgba(255,255,0,0.85);
  outline-offset:-2px;
}
.debug .hit.selected{
  background:rgba(255,255,0,0.12);
  border-color:rgba(255,255,0,0.55);
}

/* Debug panel OVERLAY on CDU */
.dbg-panel{
  position:absolute;
  left:50%;
  transform:translateX(-50%);
  width:min(560px, calc(100% - 20px));
  max-height: 48%;
  overflow:auto;

  background: rgba(0,0,0,0.85);
  border: 1px solid #2a2a2a;
  border-radius: 12px;
  padding: 10px;
  color: #ddd;
  z-index: 60;
  backdrop-filter: blur(6px);
}

/* Two positions */
.dbg-panel.pos-top{ top:10px; bottom:auto; }
.dbg-panel.pos-bottom{ bottom:10px; top:auto; }

.dbg-title{
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:10px;
  margin-bottom:8px;
  font-size:12px;
}
.dbg-grid{
  display:grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 8px;
}
.dbg-grid label:first-child{ grid-column: 1 / span 2; }
.dbg-grid label:nth-child(2){ grid-column: 3; }

.dbg-grid label{
  display:flex;
  flex-direction:column;
  gap:4px;
  font-size:11px;
  opacity:0.95;
}
.dbg-grid input{
  background:#111;
  color:#ddd;
  border:1px solid #444;
  border-radius:8px;
  padding:6px 8px;
  outline:none;
}
.dbg-row{
  display:flex;
  flex-wrap:wrap;
  gap:6px;
  align-items:center;
  margin-bottom:6px;
  font-size:11px;
}
.dbg-row span{
  opacity:0.7;
  width:56px;
}
.dbg-hint{
  font-size:10px;
  opacity:0.6;
  margin-top:4px;
}

.dbg-code{
  width:100%;
  height:160px;
  margin-top:8px;
  background:#0b0b0b;
  color:#ddd;
  border:1px solid #333;
  border-radius:10px;
  padding:8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Courier New", monospace;
  font-size:11px;
  display:none;
  white-space:pre;
}

/* STATUT indicator: visible even in non-debug */
.hit.status-indicator{
  background: rgba(255,0,0,0.85);   /* default = disconnected */
  border: 1px solid rgba(0,0,0,0.35);
}

.hit.status-indicator.connected{
  background: rgba(0,255,0,0.85);
}

.hit.status-indicator.disconnected{
  background: rgba(255,0,0,0.85);
}

/* En debug, on garde aussi une bordure lisible */
.debug .hit.status-indicator{
  border-color: rgba(255,255,255,0.25);
}

/* Widget container: le CDU remplit son conteneur parent (FlightDeck) */
.widget-container .cdu-stage {
  width: 100%;
  height: 100%;
  max-height: none;
  aspect-ratio: 826 / 1351;
}

/* FlightDeck: hitbox layer must be on top and clickable */
.cdu-hit-layer {
  position: absolute;
  inset: 0;
  z-index: 50;
  pointer-events: none;
}
