/* A familiar editor shell: horizontal menu bar, explorer, editor, panels.
   Two themes, because not everyone works in the dark. */

:root {
  --chrome: #323233;          /* barre de menus */
  --chrome-text: #cccccc;
  --chrome-hover: #4a4a4b;
  --side: #252526;            /* explorateur et panneaux */
  --side-text: #cccccc;
  --edit: #1e1e1e;            /* zone d'edition */
  --line: #3c3c3c;
  --accent: #0078d4;
  --status: #0078d4;
  --status-text: #ffffff;
  --text: #d4d4d4;
  --muted: #8b8b8b;
  --erreur: #f14c4c;
  --alerte: #cca700;
  --info: #3794ff;
  --ok: #89d185;
  --menu-bg: #2c2c2d;
  --shadow: rgba(0, 0, 0, .45);
  color-scheme: dark;
}

:root[data-theme="clair"] {
  --chrome: #dddddd;
  --chrome-text: #333333;
  --chrome-hover: #c8c8c8;
  --side: #f3f3f3;
  --side-text: #333333;
  --edit: #ffffff;
  --line: #d4d4d4;
  --accent: #005fb8;
  --status: #005fb8;
  --status-text: #ffffff;
  --text: #333333;
  --muted: #6a6a6a;
  --erreur: #e51400;
  --alerte: #bf8803;
  --info: #1a85ff;
  --ok: #388a34;
  --menu-bg: #ffffff;
  --shadow: rgba(0, 0, 0, .2);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--edit);
  color: var(--text);
  font: 13px/1.5 "Segoe UI", system-ui, -apple-system, sans-serif;
  overflow: hidden;
}

#app { display: flex; flex-direction: column; height: 100%; }

/* --- barre de menus ------------------------------------------------------------------------ */

#menubar {
  display: flex;
  align-items: center;
  gap: 2px;
  background: var(--chrome);
  color: var(--chrome-text);
  padding: 0 8px;
  height: 35px;
  flex: none;
  user-select: none;
}

.brand {
  font-weight: 600;
  font-size: 12px;
  letter-spacing: .02em;
  padding-right: 10px;
  margin-right: 4px;
  border-right: 1px solid var(--line);
  white-space: nowrap;
}
.brand span { color: var(--muted); font-weight: 400; }

.menu { position: relative; }

.menu > button {
  background: none;
  border: 0;
  color: inherit;
  font: inherit;
  padding: 5px 9px;
  border-radius: 4px;
  cursor: pointer;
}
.menu > button:hover,
.menu[open] > button { background: var(--chrome-hover); }

.menu .drop {
  position: absolute;
  top: calc(100% + 3px);
  left: 0;
  min-width: 270px;
  background: var(--menu-bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 6px 20px var(--shadow);
  padding: 4px;
  z-index: 50;
  display: none;
}
.menu[open] .drop { display: block; }

.drop button {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  width: 100%;
  background: none;
  border: 0;
  color: var(--chrome-text);
  font: inherit;
  text-align: left;
  padding: 6px 10px;
  border-radius: 4px;
  cursor: pointer;
}
.drop button:hover:not(:disabled) { background: var(--accent); color: #fff; }
.drop button:disabled { opacity: .4; cursor: default; }
.drop button kbd {
  font: 11px ui-monospace, Consolas, monospace;
  color: var(--muted);
  background: none;
}
.drop button:hover:not(:disabled) kbd { color: #dfe9f5; }
.drop hr { border: 0; border-top: 1px solid var(--line); margin: 4px 2px; }

.spacer { flex: 1; }

#menubar .pill {
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  white-space: nowrap;
}
.pill.absent { color: var(--alerte); }
.pill.present { color: var(--ok); }

/* --- corps ---------------------------------------------------------------------------------- */

#body {
  flex: 1;
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr) minmax(320px, 40%);
  min-height: 0;
}

#sidebar {
  background: var(--side);
  color: var(--side-text);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  padding: 10px 12px 6px;
  flex: none;
}

#filelist { flex: 1; overflow-y: auto; padding: 0 6px 8px; }

.file {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  background: none;
  border: 0;
  color: inherit;
  font: inherit;
  text-align: left;
  padding: 5px 8px;
  border-radius: 4px;
  cursor: pointer;
}
.file:hover { background: var(--chrome-hover); }
.file[aria-current="true"] { background: var(--accent); color: #fff; }
.file .dot { width: 7px; height: 7px; border-radius: 50%; flex: none; background: var(--ok); }
.file .dot.erreur { background: var(--erreur); }
.file .dot.alerte { background: var(--alerte); }
.file .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

#sidefoot { flex: none; padding: 8px 10px 12px; border-top: 1px solid var(--line); }
#sidefoot p { margin: 0 0 8px; font-size: 11px; color: var(--muted); line-height: 1.45; }

button.wide {
  width: 100%;
  padding: 6px 10px;
  border-radius: 4px;
  border: 1px solid var(--line);
  background: var(--chrome);
  color: var(--chrome-text);
  font: inherit;
  cursor: pointer;
}
button.wide:hover { background: var(--chrome-hover); }
button.wide.primary { background: var(--accent); border-color: var(--accent); color: #fff; }

/* --- editeur -------------------------------------------------------------------------------- */

#center { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--edit); }

#tabbar {
  flex: none;
  display: flex;
  align-items: center;
  height: 34px;
  background: var(--side);
  border-bottom: 1px solid var(--line);
  padding: 0 10px;
  font-size: 12px;
  gap: 10px;
}
#tabname { font-weight: 600; }
#tabnote { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

#editor { flex: 1; min-height: 0; }

/* --- panneau droit -------------------------------------------------------------------------- */

#right {
  display: flex;
  flex-direction: column;
  background: var(--side);
  border-left: 1px solid var(--line);
  min-width: 0;
  min-height: 0;
}

#screenwrap {
  flex: none;
  padding: 10px;
  border-bottom: 1px solid var(--line);
  position: relative;
}
#screen {
  position: relative;
  background: #000;
  border: 1px solid var(--line);
  aspect-ratio: 4 / 3;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
/* Scoped to #dosbox on purpose. As `#screen canvas` this rule outranked
   `.gwcanvas[hidden] { display: none }`, so the preview's own canvas stayed visible and painted
   solid black over the text. Only showed up in text mode, which is how it survived a while. */
#dosbox canvas {
  width: 100% !important;
  height: 100% !important;
  image-rendering: pixelated;
  display: block;
  outline: none;
}
#screenmsg {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 10px;
  text-align: center;
  padding: 18px;
  background: rgba(0, 0, 0, .82);
  color: #d4d4d4;
  font-size: 12px;
  line-height: 1.6;
}
#screenmsg[hidden] { display: none; }
#screenmsg strong { color: #fff; }
#screenmsg .why { color: #9aa4b1; font-size: 11px; max-width: 42ch; margin: 0 auto; }

#problems { flex: 1; overflow-y: auto; min-height: 0; }
#problems .empty { padding: 16px 14px; color: var(--muted); }

.finding {
  display: grid;
  grid-template-columns: 14px 1fr;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  background: none;
  border-left: 0;
  border-right: 0;
  border-top: 0;
  width: 100%;
  text-align: left;
  color: inherit;
  font: inherit;
}
.finding:hover { background: var(--chrome-hover); }
.finding .mark { font-weight: 700; line-height: 1.3; }
.finding.erreur .mark { color: var(--erreur); }
.finding.alerte .mark { color: var(--alerte); }
.finding.info .mark { color: var(--info); }
.finding .msg { margin: 0; }
.finding .hint { margin: 3px 0 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.finding .where { color: var(--muted); font-size: 11px; }

/* --- barre d'etat --------------------------------------------------------------------------- */

#status {
  flex: none;
  height: 24px;
  background: var(--status);
  color: var(--status-text);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 12px;
  font-size: 12px;
}
#status .grow { flex: 1; }
#status b { font-weight: 600; }

/* --- fenetre modale ------------------------------------------------------------------------- */

dialog {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--menu-bg);
  color: var(--text);
  padding: 0;
  max-width: 560px;
  width: calc(100% - 32px);
  box-shadow: 0 12px 40px var(--shadow);
}
dialog::backdrop { background: rgba(0, 0, 0, .5); }
dialog .head { padding: 14px 18px 0; font-weight: 600; }
dialog .content { padding: 10px 18px; line-height: 1.6; }
dialog .content p { margin: 0 0 10px; }
dialog .content code {
  font: 12px ui-monospace, Consolas, monospace;
  background: var(--side);
  padding: 1px 5px;
  border-radius: 3px;
}
dialog .content ul { margin: 0 0 10px; padding-left: 20px; }
dialog .content li { margin-bottom: 5px; }
dialog .foot { display: flex; justify-content: flex-end; gap: 8px; padding: 6px 18px 16px; }
dialog input[type="text"] {
  width: 100%;
  padding: 7px 9px;
  border-radius: 4px;
  border: 1px solid var(--line);
  background: var(--edit);
  color: var(--text);
  font: inherit;
}

/* --- ecrans etroits ------------------------------------------------------------------------- */

@media (max-width: 980px) {
  html, body { overflow: auto; }
  #body { grid-template-columns: 1fr; }
  #sidebar { border-right: 0; border-bottom: 1px solid var(--line); max-height: 220px; }
  #center { min-height: 55vh; }
  #right { border-left: 0; border-top: 1px solid var(--line); }
  #problems { max-height: 40vh; }
  .brand span { display: none; }
}

/* --- bandeau de l'ecran : choix du moteur ---------------------------------------------------- */

.panelhead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 0 8px;
}

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 5px; overflow: hidden; }
.seg button {
  background: var(--chrome);
  color: var(--chrome-text);
  border: 0;
  font: inherit;
  font-size: 11px;
  padding: 4px 10px;
  cursor: pointer;
}
.seg button + button { border-left: 1px solid var(--line); }
.seg button:hover { background: var(--chrome-hover); }
.seg button[aria-pressed="true"] { background: var(--accent); color: #fff; }

#preview, #dosbox { position: absolute; inset: 0; }
#preview[hidden], #dosbox[hidden] { display: none; }

/* En mode graphique, les pixels vont sur un canvas et les caracteres se posent par-dessus :
   pas besoin d'embarquer une police bitmap pour le texte d'un SCREEN 3. */
.gwcanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  display: block;
  background: #000;
}
.gwcanvas[hidden] { display: none !important; }
.gwscreen.over { background: transparent; position: absolute; inset: 0; }

/* L'ecran de l'apercu : une grille de caracteres, comme un vrai moniteur texte. */
.gwscreen {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  color: #aaa;
  font: 13px/1.18 Consolas, ui-monospace, monospace;
  padding: 6px 8px;
  white-space: pre;
  letter-spacing: 0;
}
@media (max-width: 1400px) { .gwscreen { font-size: 11px; } }

/* --- the machine selector ---------------------------------------------------------------- */

.machine {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  margin-right: 10px;
}
.machine select {
  font: inherit;
  font-size: 12px;
  color: var(--chrome-text);
  background: var(--chrome);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 3px 6px;
  cursor: pointer;
  max-width: 190px;
}
.machine select:hover { background: var(--chrome-hover); }

/* Shown while the program sits on an INPUT. Without it, a program that has printed its output
   and is quietly waiting for a keystroke reads as "nothing happened". */
#waiting {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 6px 10px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  text-align: center;
  cursor: text;
}
#waiting[hidden] { display: none; }

@media (max-width: 1100px) {
  .machine span { display: none; }
}
