/* light theme by default, dark theme with .dark-theme on <html> (see theme.js).
   Light: warm greys, no pure white; the frame is darker than the editor, the lightest surface. */
:root {
  color-scheme: light;
  --bg: #e8e8e3; --panel: #f6f6f2; --panel-2: #efefea; --hover: #dededa;
  --line: #d4d4cd; --border: #c4c4bc;
  --text: #1c2027; --text-2: #3b4048; --muted: #5d6168; --icon: #50545b;
  --accent: #0e7470; --accent-soft: rgba(14, 116, 112, .13);
  --info: #1b66a3; --info-border: #8b9097; --info-hover: #0d4f85; --info-hover-bg: #dfe8ef;
  --code: #17663a; --code-bg: #e3ebe2;
  --stage: #d9d9d3; --danger: #d93d42;
  --shadow: 0 10px 30px rgba(40, 40, 30, .18); --overlay: rgba(232, 232, 227, .7);
  --cm-bg: #f7f7f3; --cm-gutter: #eeeee9; --cm-lineno: #8d9097; --cm-cursor: #1c2027;
  --cm-text: #1f2328; --cm-keyword: #8250df; --cm-number: #b5420e; --cm-string: #8a5b00; --cm-comment: #6e7781;
}
:root.dark-theme {
  color-scheme: dark;
  --bg: #0e0e14; --panel: #16161f; --panel-2: #12121a; --hover: #22222e;
  --line: #20202c; --border: #2a2a3a;
  --text: #e6e6ea; --text-2: #b9c2cc; --muted: #889; --icon: #9aa3ad;
  --accent: #7cc; --accent-soft: rgba(119, 204, 204, .12);
  --info: #9cf; --info-border: #4a5a6a; --info-hover: #bfe; --info-hover-bg: #17202c;
  --code: #9f9; --code-bg: #0b0b11;
  --stage: #000; --danger: #e5484d;
  --shadow: 0 10px 30px rgba(0, 0, 0, .5); --overlay: rgba(14, 14, 20, .7);
  --cm-text: #c6d0da; --cm-keyword: #c792ea; --cm-number: #f78c6c; --cm-string: #e5c07b; --cm-comment: #5b6b7a;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 14px system-ui, -apple-system, "Segoe UI", sans-serif; }
body { display: flex; flex-direction: column; }
header { padding: 10px 16px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px; }
header .logo { display: block; flex: none; line-height: 0; }
header .logo img { display: block; width: 56px; height: 56px; }
@media (max-width: 600px) { header .logo img { width: 46px; height: 46px; } }
h1 { margin: 0; font-size: 17px; }
h1 .x { color: var(--accent); }
header p { margin: 3px 0 0; color: var(--muted); font-size: 12.5px; }
.theme-toggle { flex: none; margin-left: auto; width: 36px; height: 36px; padding: 8px; border: 0; border-radius: 8px;
  background: transparent; color: var(--muted); cursor: pointer; }
.theme-toggle:hover { background: var(--hover); color: var(--text); }
.theme-toggle svg { display: block; width: 100%; height: 100%; fill: none; stroke: currentColor;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.info-i { display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; margin: 0 2px 0 6px; padding: 0; border-radius: 50%;
  border: 1px solid var(--info-border); background: transparent; color: var(--info); cursor: pointer;
  font: italic 700 11px Georgia, "Times New Roman", serif; vertical-align: middle; }
.info-i:hover { background: var(--info-hover-bg); border-color: var(--accent); color: var(--info-hover); }
.info-panel { margin: 8px 16px 0; padding: 10px 12px; max-width: 780px;
  background: var(--panel-2); border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: 8px; color: var(--text-2); font-size: 13px; line-height: 1.55; }
.info-panel code { font-family: "JetBrains Mono", monospace; font-variant-ligatures: none; color: var(--code);
  background: var(--code-bg); padding: 1px 5px; border-radius: 4px; }
.info-panel[hidden] { display: none; }
/* toolbar aligned on the two panes: Ouvrir, Nouveau, the menu and the title on the left;
   Télécharger and Exécuter pushed right, so that Exécuter sits on the editor/game seam
   and Télécharger does not move with the length of the title */
#bar { display: grid; grid-template-columns: 1fr 1fr; align-items: center;
  padding: 8px 16px; border-bottom: 1px solid var(--line); }
.bar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.bar-left #btnDownload { margin-left: auto; }
/* the logo's green, in both themes, and steady on hover */
#run, #btnResume { background: #3c9; color: #04120b; border: 0; border-radius: 7px;
  font: 600 14px system-ui; padding: 7px 18px; cursor: pointer; }

/* Ouvrir, Nouveau and the « Vos programmes / Exemples » menu */
.doc-btn { flex: none; width: 30px; height: 30px; padding: 6px; border: 0; border-radius: 7px;
  background: none; color: var(--icon); cursor: pointer; }
.doc-btn + .doc-btn { margin-left: -8px; }
.doc-btn:hover { background: var(--hover); color: var(--text); }
.doc-btn svg, .icon-btn svg { display: block; fill: none; stroke: currentColor;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.doc-btn svg { width: 100%; height: 100%; }
/* the program's emoji: the example's own, or the gamepad for the student's programs */
.mi-icon { flex: none; display: flex; align-items: center; justify-content: center; width: 30px; height: 30px;
  border-radius: 8px; background: var(--accent-soft); font-size: 17px; line-height: 1; }
.menu-wrap { position: relative; flex: none; margin-left: -6px; }
#btnExamples { display: block; border: 0; padding: 0; background: none; border-radius: 8px; cursor: pointer; }
#btnExamples:hover .mi-icon, #btnExamples[aria-expanded="true"] .mi-icon { box-shadow: inset 0 0 0 1.5px var(--accent); }
/* the program title, editable in place */
.doc-title { min-width: 0; flex: 0 1 300px; border: 1px solid transparent; background: transparent; border-radius: 6px;
  padding: 5px 8px; font: 14px system-ui; color: var(--text-2); }
@supports (field-sizing: content) {   /* the field fits the title */
  .doc-title { field-sizing: content; flex: 0 1 auto; max-width: 300px; min-width: 4em; }
}
.doc-title:hover { border-color: var(--border); }
.doc-title:focus { outline: none; border-color: var(--accent); color: var(--text); background: var(--panel); }
.menu { position: absolute; top: calc(100% + 6px); left: 0; z-index: 20; min-width: 300px; max-height: 70vh;
  overflow: auto; background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow); padding: 6px; }
#examplesMenu { min-width: 360px; }
.menu-title { font-size: 12px; color: var(--muted); padding: 4px 8px 6px; }
.menu-item { display: flex; flex-direction: column; align-items: flex-start; gap: 1px; width: 100%; border: 0;
  background: transparent; color: var(--text); font: 13px system-ui; text-align: left; padding: 7px 9px;
  border-radius: 7px; cursor: pointer; }
.menu-item:hover, .menu-item:focus-visible { background: var(--hover); outline: none; }
.menu-item.with-icon { flex-direction: row; align-items: center; gap: 12px; }
.mi-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.mi-label { font-weight: 600; }
.mi-sub { font-size: 12px; color: var(--muted); }
.menu-sep { height: 1px; background: var(--border); margin: 5px 4px; }
.menu-doc { display: flex; align-items: center; gap: 2px; }
.menu-doc .menu-item { flex: 1; min-width: 0; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; flex: none; width: 30px; height: 30px;
  border: 0; border-radius: 7px; background: transparent; color: var(--muted); cursor: pointer; }
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn svg { width: 16px; height: 16px; }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 50; background: var(--text);
  color: var(--bg); border-radius: 9px; padding: 9px 16px; box-shadow: var(--shadow);
  max-width: calc(100vw - 32px); font-size: 13px; }
.toast.error { background: var(--danger); color: #fff; }
.toast-action { margin-left: 14px; border: 0; background: transparent; color: inherit; cursor: pointer; font: inherit;
  font-weight: 700; text-decoration: underline; text-underline-offset: 3px; padding: 0; }
.pause-view { position: fixed; inset: 0; z-index: 70; display: flex; align-items: center; justify-content: center;
  background: var(--overlay); backdrop-filter: blur(3px); padding: 16px; }
.pause-box { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow);
  padding: 22px 24px; max-width: 440px; text-align: center; }
.pause-box h2 { margin: 0 0 8px; font-size: 18px; }
.pause-box p { margin: 0 0 16px; color: var(--muted); }
.menu[hidden], .toast[hidden], .pause-view[hidden] { display: none; }
main { flex: 1; display: grid; grid-template-columns: 1fr 1fr; min-height: 0; }
#editor-cell { min-height: 0; overflow: hidden; }
.CodeMirror { height: 100%; font: 13px/1.5 "JetBrains Mono", monospace; }
.CodeMirror pre.CodeMirror-line, .CodeMirror pre.CodeMirror-line-like { font-variant-ligatures: none; }

/* Sober palette: ONLY keywords, strings, comments and numbers are coloured.
   Everything else (variables, properties, operators, punctuation, builtins,
   defined names) stays neutral, so the signal stands out.
   The dark theme uses material-darker, the light theme CodeMirror's default theme. */
.cm-s-default.CodeMirror { background: var(--cm-bg); color: var(--cm-text); }
.cm-s-default .CodeMirror-gutters { background: var(--cm-gutter); border-right: 1px solid var(--line); }
.cm-s-default .CodeMirror-linenumber { color: var(--cm-lineno); }
.cm-s-default .CodeMirror-cursor { border-left-color: var(--cm-cursor); }
:is(.cm-s-default, .cm-s-material-darker) :is(span.cm-variable, span.cm-variable-2, span.cm-variable-3,
  span.cm-property, span.cm-operator, span.cm-punctuation, span.cm-bracket, span.cm-meta,
  span.cm-def, span.cm-builtin) { color: var(--cm-text); }
:is(.cm-s-default, .cm-s-material-darker) span.cm-keyword { color: var(--cm-keyword); }   /* def, class, if, for… */
:is(.cm-s-default, .cm-s-material-darker) :is(span.cm-atom, span.cm-number) { color: var(--cm-number); }   /* True / False / None */
:is(.cm-s-default, .cm-s-material-darker) :is(span.cm-string, span.cm-string-2) { color: var(--cm-string); }
:is(.cm-s-default, .cm-s-material-darker) span.cm-comment { color: var(--cm-comment); font-style: italic; }

#frame-wrap { position: relative; border-left: 1px solid var(--line); background: var(--stage); min-height: 0; }
/* color-scheme normal: otherwise, when the page is dark, Chrome paints an opaque white
   backdrop behind the about:blank iframe of a stopped game */
iframe { width: 100%; height: 100%; border: 0; display: block; background: var(--stage); color-scheme: normal; }
@media (max-width: 820px) {
  main { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
  #frame-wrap { border-left: 0; border-top: 1px solid var(--line); }
}
footer { padding: 8px 16px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12.5px; text-align: center; }
footer a { color: var(--muted); text-decoration: underline; text-underline-offset: 3px; }
/* lighting up on hover belongs to the dark theme; in the light theme the links simply show */
.dark-theme footer a { transition: color .2s; }
.dark-theme footer a:hover { color: var(--text); }
.dark-theme footer a img { opacity: .5; transition: opacity .2s; }
.dark-theme footer a:hover img { opacity: 1; }
