:root {
  --bg: #f6f7f9; --panel: #ffffff; --text: #1f2937; --muted: #6b7280; --border: #dfe3e8;
  --bar: #ffffff; --accent: #2563eb; --ok: #16a34a; --danger: #dc2626;
  --btn: #f1f3f6; --btn-hover: #e6e9ef; --code-bg: #f1f3f6; --radius: 8px;
}
:root[data-theme='dark'] {
  --bg: #15181e; --panel: #1b1e26; --text: #e5e7eb; --muted: #9ca3af; --border: #2c313c;
  --bar: #20242d; --accent: #60a5fa; --btn: #2a2f3a; --btn-hover: #343a47; --code-bg: #262b36;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { display: flex; flex-direction: column; font: 14px/1.4 system-ui, 'Segoe UI', sans-serif; color: var(--text); background: var(--bg); }
#topbar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--bar); border-bottom: 1px solid var(--border); }
.brand { font-size: 16px; }
.spacer { flex: 1; }
#status { font-size: 12px; color: var(--muted); min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#topbar button { white-space: nowrap; }
button, select { font: inherit; color: var(--text); padding: 6px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--btn); cursor: pointer; transition: background .12s; }
button:hover:not(:disabled), select:hover { background: var(--btn-hover); }
button.ghost { background: transparent; }
button.primary { background: var(--ok); border-color: var(--ok); color: #fff; font-weight: 600; }
button.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
button.danger:hover:not(:disabled) { background: var(--danger); color: #fff; }
button:disabled { opacity: .5; cursor: default; }
[hidden] { display: none !important; }

#layout { flex: 1; min-height: 0; display: grid; grid-template-columns: 340px minmax(0, 1fr); }
#layout.no-tuto { grid-template-columns: minmax(0, 1fr); }
#layout > #ms-pane { grid-column: 2; }
#layout.no-tuto > #ms-pane { grid-column: 1; }
#layout.no-tuto #tuto-panel { display: none; }
.pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--panel); border-left: 1px solid var(--border); }
.pane-head { display: flex; justify-content: space-between; align-items: center; min-height: 28px; padding: 4px 10px; font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); background: var(--bar); border-bottom: 1px solid var(--border); }

#tuto-panel { display: flex; flex-direction: column; overflow: auto; background: var(--panel); }
.tuto-bar { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px; border-bottom: 1px solid var(--border); }
.tuto-bar select { flex: 1 1 100%; }
/* couleur des tutoriels par chapitre (liste et sélection) */
.tuto-bar .chap-0 { background-color: #dbeafe; color: #1f2937; }
.tuto-bar .chap-1 { background-color: #d9f2d0; color: #1f2937; }
.tuto-bar .chap-2 { background-color: #ffe0c2; color: #1f2937; }
.tuto-bar .chap-3 { background-color: #ffd6d6; color: #1f2937; }
.tuto-view { padding: 0 16px 16px; overflow: auto; }
.tuto-view code { background: var(--code-bg); padding: 1px 5px; border-radius: 4px; }
.tuto-view pre { position: relative; background: var(--code-bg); padding: 12px; border-radius: var(--radius); white-space: pre-wrap; overflow-wrap: anywhere; margin: 6px 0 4px; }
.tuto-view pre code { padding: 0; background: none; }
/* encadré du bouton ? : mêmes couleurs que l'aide de microStudio */
.tuto-view .aide-ms { background: hsl(30,100%,90%); color: hsl(20,20%,20%); border: 2px solid hsl(30,80%,70%); border-radius: var(--radius); padding: 2px 12px; margin: 10px 0; }
/* encadré « Voir les axes » : crème, comme celui du bouton ? */
.tuto-view .aide-axes { background: hsl(30,100%,90%); color: hsl(20,20%,20%); border: 2px solid hsl(30,80%,70%); border-radius: var(--radius); padding: 2px 12px; margin: 10px 0; }
.tuto-view .aide-axes code { background: rgba(0,0,0,.08); color: inherit; }
.tuto-view .aide-ms code { background: rgba(0,0,0,.08); color: inherit; }
.tuto-view blockquote { margin-left: 0; padding-left: 12px; border-left: 3px solid var(--accent); color: var(--muted); }
.tuto-view blockquote ul { padding-left: 18px; }
.solution-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 24px 0 8px; padding: 10px; border-top: 2px solid var(--border); }
.solution-bar strong { flex: 1 1 100%; }
.solution-bar button { padding: 2px 10px; font-size: 12px; }
.insert-bar { display: flex; gap: 6px; margin: 4px 0 12px; }
.insert-bar button { padding: 2px 10px; font-size: 12px; }
.tuto-edit { flex: 1; min-height: 300px; margin: 10px; padding: 8px; font: 13px/1.5 ui-monospace, monospace; resize: none; color: var(--text); background: var(--code-bg); border: 1px solid var(--border); border-radius: var(--radius); }

.edtabs { display: flex; align-items: center; gap: 4px; padding: 6px 8px 0; background: var(--bar); border-bottom: 1px solid var(--border); }
.edtabs span { padding: 6px 14px; border-radius: 6px 6px 0 0; color: var(--muted); font-size: 12px; cursor: pointer; }
.edtabs span:hover { color: var(--text); }
.edtabs span.on { background: var(--panel); color: var(--text); font-weight: 600; border: 1px solid var(--border); border-bottom-color: var(--panel); margin-bottom: -1px; cursor: default; }
.actbar { display: flex; align-items: center; gap: 6px; padding: 6px 10px; background: var(--panel); border-bottom: 1px solid var(--border); flex-wrap: wrap; min-height: 45px; }
.actbar button { padding: 4px 10px; font-size: 12px; }
.actbar .grow { flex: 1; }
.actbar .saved { color: var(--ok); font-size: 12px; }
.actbar .saved.pending { color: var(--muted); }
.actbar .info { color: var(--muted); font: 12px ui-monospace, monospace; }
#ms-wrap { position: relative; flex: 1; min-height: 0; background: var(--bg); }
#ms { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
#ms-loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); background: var(--bg); pointer-events: none; transition: opacity .2s; }
#ms-loading.done { opacity: 0; }

.tuto-empty { text-align: center; color: var(--muted); padding: 32px 8px; }
.tuto-view details { margin: 8px 0; border: 1px solid var(--border); border-radius: var(--radius); padding: 0 10px; background: var(--bg); }
.tuto-view details[open] { padding-bottom: 6px; }
.tuto-view summary { cursor: pointer; font-weight: 600; padding: 6px 0; color: var(--accent); }
.tuto-view img { max-width: 100%; image-rendering: pixelated; }

/* ---- clignotement d'un élément désigné par un tutoriel ---- */
@keyframes ecg-blink { 0%, 100% { box-shadow: inset 0 0 0 0 rgba(255,140,0,0), 0 0 0 0 rgba(255,140,0,0); } 50% { box-shadow: inset 0 0 0 3px rgba(255,140,0,1), 0 0 0 3px rgba(255,140,0,.9); } }
.ecg-blink { animation: ecg-blink .6s ease-in-out 4 !important; }
/* mot d'un tutoriel qui fait clignoter un bouton (survol ou clic) */
.tuto-view .montre { cursor: pointer; font-weight: 600; color: var(--accent); border-bottom: 2px dotted var(--accent); white-space: nowrap; }
.tuto-view .montre:hover { background: rgba(255,140,0,.15); }

#hero { display: inline-flex; align-items: center; gap: 6px; font-size: .9em; opacity: .85; white-space: nowrap; }
#hero a { color: inherit; }

/* Mes projets */
#my-projects { max-width: 22ch; overflow: hidden; text-overflow: ellipsis; }
#projects-dialog { width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 64px); border: 1px solid var(--border); border-radius: 10px; padding: 18px 20px; background: var(--bar); color: inherit; }
#projects-dialog::backdrop { background: rgba(0, 0, 0, .45); }
#projects-dialog h2 { margin: 0; font-size: 1.2rem; }
#projects-dialog h3 { margin: 18px 0 8px; font-size: 1rem; }
#projects-dialog .muted { opacity: .7; font-size: .9em; }
#projects-dialog a.button { display: inline-block; padding: 6px 12px; border-radius: 6px; text-decoration: none; }
#projects-dialog a.button.primary { background: var(--ok); color: #fff; font-weight: 600; }
.pd-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.pd-quota { display: grid; gap: 6px; font-size: .9em; }
.pd-meter { height: 8px; border-radius: 4px; background: var(--border); overflow: hidden; }
.pd-meter span { display: block; height: 100%; background: var(--ok); }
.pd-meter.warn span { background: #d97706; }
.warn-text { color: #d97706; }
.pd-list { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 6px; }
.pd-list li { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; }
.pd-list li.open { border-color: var(--ok); }
.pd-name { display: grid; flex: 1; min-width: 0; }
.pd-name strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pd-badge { font-size: .85em; color: var(--ok); }
.pd-new { display: flex; flex-wrap: wrap; gap: 8px; }
.pd-new input { flex: 1 1 220px; min-width: 0; }
#projects-dialog input, #projects-dialog select { padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--panel); color: inherit; font: inherit; }

/* Explorer */
#explorer-dialog { width: min(980px, calc(100vw - 32px)); max-height: calc(100vh - 48px); border: 1px solid var(--border); border-radius: 10px; padding: 18px 20px; background: var(--bar); color: inherit; }
#explorer-dialog::backdrop { background: rgba(0, 0, 0, .55); }
#explorer-dialog h2 { margin: 0; font-size: 1.2rem; }
#explorer-dialog .muted { opacity: .7; font-size: .9em; }
#explorer-dialog .grow { flex: 1; }
#explorer-dialog input { padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--panel); color: inherit; font: inherit; }
.ex-bar { display: flex; flex-wrap: wrap; gap: 10px; justify-content: space-between; margin-bottom: 14px; }
.ex-tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.ex-tabs button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.ex-search { display: flex; gap: 6px; flex: 1 1 260px; max-width: 420px; }
.ex-search input { flex: 1; min-width: 0; }
.ex-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }
.ex-card { display: grid; grid-template-rows: auto 1fr auto; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--panel); }
.ex-pic { aspect-ratio: 16 / 10; display: grid; place-items: center; background: var(--bg); cursor: pointer; overflow: hidden; }
.ex-pic img { width: 100%; height: 100%; object-fit: contain; image-rendering: pixelated; }
.ex-letter { font-size: 2.6rem; font-weight: 700; opacity: .45; }
.ex-info { display: grid; gap: 2px; padding: 8px 10px 4px; min-width: 0; }
.ex-info strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ex-actions { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 10px 10px; }
.ex-like.on { color: var(--danger); border-color: var(--danger); }
.ex-more { grid-column: 1 / -1; justify-self: center; }
.ex-player { display: block; width: 100%; aspect-ratio: 16 / 9; max-height: calc(100vh - 160px); border: 0; border-radius: 8px; background: #000; }
