[hidden] { display: none !important; }
:root {
  --bg: #eef1f5;
  --panel: #ffffff;
  --shell: #fbfbf8;
  --line: #d5dae2;
  --text: #1f2937;
  --muted: #6b7280;
  --accent: #2563eb;
  --run: #15803d;
  --stop: #b91c1c;
  --err: #c0262d;
  --font: 15px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "DejaVu Sans Mono", monospace;
  --vvh: 100dvh;
  --split: 58%;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text);
  font: 15px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
#app { position: fixed; left: 0; right: 0; top: 0; height: var(--vvh); display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left); }
button, label.tb { font: inherit; color: inherit; }
.spacer { flex: 1; }

/* ---------- barre du haut ---------- */
#topbar { display: flex; align-items: center; gap: 6px; padding: 6px 8px; border-bottom: 1px solid var(--line); background: var(--bg); min-height: 52px; }
.tb { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; min-width: 40px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--panel); cursor: pointer; user-select: none; -webkit-user-select: none;
  touch-action: manipulation; white-space: nowrap; }
.tb:active { filter: brightness(.92); }
.tb.small { min-height: 34px; padding: 0 10px; font-size: 14px; }
.tb.icon { padding: 0; font-size: 20px; }
.tb .ic { font-size: 16px; }
.tb.run { background: var(--run); color: #fff; border-color: var(--run); }
.tb.run2 { color: var(--run); border-color: var(--run); }
.tb.stop { color: var(--stop); }
.tb:disabled { opacity: .45; }
#tabs { display: flex; gap: 4px; overflow-x: auto; min-width: 0; scrollbar-width: none; }
#tabs::-webkit-scrollbar { display: none; }
.tab { display: flex; align-items: center; gap: 2px; height: 40px; padding: 0 4px 0 12px; border-radius: 10px; border: 1px solid transparent;
  background: transparent; cursor: pointer; white-space: nowrap; font-size: 14px; color: var(--muted); }
.tab.active { background: var(--panel); border-color: var(--line); color: var(--text); font-weight: 600; }
.tab .dirty { color: var(--accent); margin-left: 2px; }
.tab .x { width: 30px; height: 30px; border: 0; background: none; border-radius: 8px; color: var(--muted); font-size: 15px; }
.tab .x:active { background: var(--bg); }

/* ---------- zone principale ---------- */
#main { flex: 1; min-height: 0; display: flex; position: relative; }
#editor-pane { position: relative; min-width: 0; min-height: 0; background: var(--panel); flex: 0 0 var(--split); display: flex; }
#editor { flex: 1; min-width: 0; min-height: 0; }
#editor .cm-editor { height: 100%; font-size: var(--font); }
#editor .cm-editor.cm-focused { outline: none; }
#editor .cm-scroller { font-family: var(--mono); line-height: 1.5; }
#editor .cm-gutters { background: #f6f7f9; border-right: 1px solid #e6e8ec; color: #9aa1ab; }
#editor .cm-cellsep { border-top: 2px solid #9ec5a8; background: #f2f9f3; }
#editor .cm-cellsep, #editor .cm-cellsep * { font-weight: 600; }
#empty { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; color: var(--muted); }
#splitter { flex: 0 0 14px; display: flex; align-items: center; justify-content: center; background: var(--bg); cursor: col-resize; touch-action: none; }
#splitter span { width: 4px; height: 44px; border-radius: 2px; background: #b9c0cb; }
#shell-pane { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--shell); }
.shead { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-bottom: 1px solid var(--line); background: #f3f4f1; }
.stitle { font-weight: 600; }
#sstatus { font-size: 13px; color: var(--run); }
#sstatus.busy { color: #c27803; }
#shell-out { flex: 1; overflow: auto; padding: 8px 10px; font-family: var(--mono); font-size: var(--font); line-height: 1.4;
  white-space: pre-wrap; word-break: break-word; -webkit-overflow-scrolling: touch; user-select: text; -webkit-user-select: text; outline: none; }
#shell-out .err { color: var(--err); }
#shell-out .echo { color: #1d4ed8; }
#shell-out .info { color: var(--muted); font-style: italic; }
#shell-out img { display: block; max-width: 100%; max-height: 60vh; margin: 6px 0; border: 1px solid var(--line); border-radius: 8px; background: #fff; cursor: zoom-in; }
#shell-inrow { display: flex; align-items: flex-start; gap: 6px; padding: 6px 10px; border-top: 1px solid var(--line); background: #fff; }
#prompt { font-family: var(--mono); font-size: var(--font); color: var(--accent); padding-top: 6px; white-space: pre; }
#prompt.input { color: #b45309; }
#shell-in { flex: 1; resize: none; border: 0; outline: none; font-family: var(--mono); font-size: max(16px, var(--font)); line-height: 1.4;
  padding: 5px 0; background: transparent; max-height: 30vh; color: var(--text); }

/* portrait : empilé */
@media (orientation: portrait) {
  #main { flex-direction: column; }
  #editor-pane { flex-basis: var(--split); }
  #splitter { flex-basis: 14px; cursor: row-resize; }
  #splitter span { width: 44px; height: 4px; }
}

/* ---------- panneau fichiers ---------- */
#files { position: absolute; z-index: 20; left: 0; top: 0; bottom: 0; width: min(340px, 88vw); background: var(--panel);
  border-right: 1px solid var(--line); box-shadow: 4px 0 24px rgba(0,0,0,.12); display: flex; flex-direction: column; }
#files[hidden] { display: none; }
.fhead { display: flex; align-items: center; gap: 6px; padding: 8px; border-bottom: 1px solid var(--line); }
#crumbs { flex: 1; display: flex; flex-wrap: wrap; gap: 2px; font-size: 14px; }
#crumbs button { border: 0; background: none; color: var(--accent); padding: 6px 4px; font: inherit; cursor: pointer; }
.factions { display: flex; gap: 6px; padding: 8px; flex-wrap: wrap; }
#flist { list-style: none; margin: 0; padding: 0 0 8px; overflow: auto; flex: 1; }
#flist li { display: flex; align-items: center; gap: 10px; padding: 0 6px 0 12px; min-height: 46px; border-bottom: 1px solid #f0f1f4; cursor: pointer; }
#flist li:active { background: var(--bg); }
#flist .fi { width: 22px; text-align: center; }
#flist .fn { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#flist .fs { color: var(--muted); font-size: 12px; }
#flist .fm { width: 40px; height: 40px; border: 0; background: none; font-size: 18px; color: var(--muted); border-radius: 8px; }
.fhint { font-size: 12px; color: var(--muted); padding: 0 12px 12px; margin: 0; }

/* ---------- barre de touches tactile ---------- */
#keybar { display: flex; gap: 5px; overflow-x: auto; padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); background: #dfe3e9;
  border-top: 1px solid var(--line); scrollbar-width: none; flex: 0 0 auto; }
#keybar::-webkit-scrollbar { display: none; }
#keybar[hidden] { display: none; }
#keybar button { flex: 0 0 auto; min-width: 44px; height: 42px; padding: 0 10px; border: 0; border-radius: 8px; background: #fff;
  box-shadow: 0 1px 0 rgba(0,0,0,.18); font-family: var(--mono); font-size: 18px; color: var(--text); touch-action: manipulation; }
#keybar button.wide { font-family: inherit; font-size: 15px; }
#keybar button.run { background: var(--run); color: #fff; }
#keybar button:active { background: #c9ced6; }
#keybar .sep { flex: 0 0 8px; }

/* ---------- popups ---------- */
.popup { position: fixed; z-index: 50; background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,.18); padding: 6px; min-width: 220px; }
.popup button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 12px 14px; border-radius: 8px; font: inherit; cursor: pointer; }
.popup button:active { background: var(--bg); }
.popup button.danger { color: var(--stop); }
.popup hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
#viewer { position: fixed; inset: 0; z-index: 60; background: rgba(15,18,24,.92); display: flex; flex-direction: column; }
#viewer[hidden] { display: none; }
.vbar { display: flex; align-items: center; gap: 8px; padding: calc(8px + env(safe-area-inset-top)) 10px 8px; color: #fff; }
.vbar .tb { background: #2b313b; color: #fff; border-color: #3b4350; }
.vbody { flex: 1; overflow: auto; display: flex; align-items: center; justify-content: center; touch-action: pinch-zoom pan-x pan-y; }
.vbody img { max-width: 100%; max-height: 100%; background: #fff; }
