/* =====================================================================
   Code editor + console styles (IDE and Challenges)
   ===================================================================== */
:root {
  --code-bg: #FBFDFC; --code-gutter: #EEF5F1; --code-ink: #13211A;
  --tok-kw: #A6216B; --tok-str: #0F7A3D; --tok-num: #B4510B; --tok-com: #6F8478;
  --tok-fn: #1E5BB8; --tok-builtin: #6A3FC1; --tok-op: #44574C;
  --con-bg: #10201A; --con-ink: #DDF3E8; --con-dim: #8FB3A2; --con-in: #FFD779;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --code-bg: #0F1713; --code-gutter: #16211B; --code-ink: #E8F5EE;
    --tok-kw: #FF8FC6; --tok-str: #8BE0A4; --tok-num: #FFB870; --tok-com: #7D9488;
    --tok-fn: #8DBBFF; --tok-builtin: #C9B2FA; --tok-op: #B7CCC0;
    --con-bg: #0A110D;
  }
}
:root[data-theme="dark"] {
  --code-bg: #0F1713; --code-gutter: #16211B; --code-ink: #E8F5EE;
  --tok-kw: #FF8FC6; --tok-str: #8BE0A4; --tok-num: #FFB870; --tok-com: #7D9488;
  --tok-fn: #8DBBFF; --tok-builtin: #C9B2FA; --tok-op: #B7CCC0;
  --con-bg: #0A110D;
}

/* ---------- Editor ---------- */
.editor-box { border: 2px solid var(--line); border-radius: 14px; overflow: hidden; background: var(--code-bg); }
.CodeMirror {
  font-family: "JetBrains Mono", ui-monospace, Consolas, monospace; font-size: 16px; line-height: 1.55;
  height: auto; min-height: 320px; background: var(--code-bg); color: var(--code-ink);
}
.CodeMirror-scroll { min-height: 320px; }
.CodeMirror-gutters { background: var(--code-gutter); border-right: 1px solid var(--line); }
.CodeMirror-linenumber { color: var(--ink3); padding: 0 8px 0 4px; }
.CodeMirror-cursor { border-left: 2px solid var(--code-ink); }
.CodeMirror-selected, .CodeMirror-focused .CodeMirror-selected { background: rgba(59, 143, 230, .25) !important; }
.CodeMirror-matchingbracket { background: rgba(34, 179, 138, .25); color: inherit !important; outline: 1px solid var(--mint); }
.CodeMirror .cm-keyword { color: var(--tok-kw); font-weight: 700; }
.CodeMirror .cm-string, .CodeMirror .cm-string-2 { color: var(--tok-str); }
.CodeMirror .cm-number { color: var(--tok-num); }
.CodeMirror .cm-comment { color: var(--tok-com); font-style: italic; }
.CodeMirror .cm-def { color: var(--tok-fn); font-weight: 700; }
.CodeMirror .cm-builtin { color: var(--tok-builtin); }
.CodeMirror .cm-operator, .CodeMirror .cm-punctuation { color: var(--tok-op); }
.CodeMirror .cm-variable, .CodeMirror .cm-variable-2, .CodeMirror .cm-property { color: var(--code-ink); }
.cm-error-line { background: rgba(229, 72, 122, .22); }
.editor-tall .CodeMirror, .editor-tall .CodeMirror-scroll { min-height: 460px; }

/* ---------- Console ---------- */
.console {
  background: var(--con-bg); color: var(--con-ink); border-radius: 14px; padding: 12px 14px;
  font-family: "JetBrains Mono", ui-monospace, Consolas, monospace; font-size: 15px;
  min-height: 160px; max-height: 420px; overflow: auto; border: 2px solid var(--line);
}
.con-out { margin: 0; white-space: pre-wrap; word-break: break-word; font: inherit; }
.con-out:empty { display: none; }
.con-typed { color: var(--con-in); font-weight: 700; }
.con-note { font-family: "Nunito", system-ui, sans-serif; font-size: 14.5px; margin: 6px 0; color: var(--con-dim); }
.con-note.con-done { color: #7FE6C6; }
.con-note.con-stop { color: #FFD779; }
.con-error { background: #3A1724; color: #FFD3E1; border-left: 5px solid #E5487A; border-radius: 10px; padding: 10px 12px; }
.con-error .err-type { font-size: 15px; color: #FFA3C0; }
.con-error .err-line { margin-left: 6px; font: inherit; font-size: 13px; font-weight: 800; color: #3A1724; background: #FFA3C0; border: 0; border-radius: 999px; padding: 1px 10px; cursor: pointer; }
.con-error .err-msg { margin: 4px 0; font-size: 13.5px; opacity: .9; }
.con-error .err-hint { margin-top: 6px; color: #fff; font-size: 15px; }
.con-error code, .con-error kbd { background: rgba(255,255,255,.12); color: #fff; border-color: transparent; }
.con-ask { display: inline-flex; gap: 6px; margin: 2px 0; vertical-align: baseline; max-width: 100%; }
.con-ask input {
  font: inherit; font-weight: 700; color: var(--con-in); background: rgba(255,255,255,.08);
  border: 2px solid var(--con-in); border-radius: 8px; padding: 2px 8px; width: 220px; max-width: 55vw;
}
.con-ask .btn { padding: 2px 10px; font-size: 13px; box-shadow: none; }
.con-empty { color: var(--con-dim); font-family: "Nunito", system-ui, sans-serif; font-size: 14.5px; }

/* ---------- Turtle ---------- */
.turtle-box { background: #fff; border: 2px solid var(--line); border-radius: 14px; overflow: hidden; position: relative; }
.turtle-box > div, .turtle-stage { width: 100%; }
.turtle-stage { position: relative; aspect-ratio: 1 / 1; }
.turtle-stage canvas { width: 100% !important; height: auto !important; }
.turtle-stage canvas + canvas { position: absolute !important; top: 0; left: 0; margin-top: 0 !important; }

/* ---------- Toolbar ---------- */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 12px; }
.toolbar .spacer { flex: 1; }
.toolbar .btn { padding: 8px 13px; }
.btn.run { background: var(--mint); border-color: var(--mint); color: #fff; box-shadow: 0 3px 0 var(--mint-ink); font-size: 16px; }
.btn.run:hover { filter: brightness(1.05); background: var(--mint); }
.btn.sm { padding: 5px 10px; font-size: 13.5px; }
.status-dot { font-size: 13px; font-weight: 800; color: var(--ink3); }

/* ---------- Menus ---------- */
.pop { position: relative; display: inline-block; }
.pop-panel {
  display: none; position: absolute; z-index: 30; top: calc(100% + 6px); left: 0; min-width: 240px; max-height: 60vh; overflow: auto;
  background: var(--surface); border: 2px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); padding: 6px;
}
.pop.open .pop-panel { display: block; }
.pop-panel.right { left: auto; right: 0; }
.pop-panel button, .pop-panel a {
  display: flex; width: 100%; gap: 10px; align-items: center; text-align: left; background: none; border: 0; padding: 8px 10px;
  border-radius: 10px; cursor: pointer; font-weight: 700; font-size: 15px; text-decoration: none; color: var(--ink);
}
.pop-panel button:hover, .pop-panel a:hover { background: var(--sunk); }
.pop-panel .pop-h { font-size: 11.5px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--ink3); padding: 8px 10px 2px; }
.pop-panel small { color: var(--ink3); font-weight: 600; margin-left: auto; font-size: 12px; }

/* ---------- Dialog ---------- */
dialog.cl-dialog {
  border: 2px solid var(--line); border-radius: 18px; background: var(--surface); color: var(--ink);
  padding: 20px; width: min(520px, calc(100vw - 32px)); box-shadow: var(--shadow);
}
dialog.cl-dialog::backdrop { background: rgba(10, 20, 15, .55); }
dialog.cl-dialog h2 { font-size: 24px; margin-bottom: 8px; }
dialog.cl-dialog input[type="text"] { width: 100%; }
dialog.cl-dialog textarea { width: 100%; font-family: "JetBrains Mono", monospace; font-size: 13px; border-radius: 10px; border: 2px solid var(--line); background: var(--sunk); color: var(--ink); padding: 8px; }
.qr-box { display: flex; justify-content: center; margin: 12px 0; }
.qr-box img, .qr-box svg { width: 200px; height: 200px; background: #fff; padding: 8px; border-radius: 12px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; z-index: 100;
  background: var(--ink); color: var(--bg); font-weight: 800; padding: 10px 18px; border-radius: 999px;
  transition: opacity .2s, transform .2s; pointer-events: none; max-width: calc(100vw - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Files box ---------- */
.files { background: var(--surface); border: 2px solid var(--line); border-radius: 14px; padding: 10px 12px; }
.files-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.files-head .label { margin: 0; }
.files-head .spacer, .file-foot .spacer { flex: 1; }
.files-empty { margin: 8px 0 2px; font-size: 14px; color: var(--ink3); }
.file-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
.file-tab { border: 2px solid var(--line); background: var(--bg); border-radius: 999px; padding: 4px 11px; font-weight: 800; font-size: 13.5px; cursor: pointer; font-family: "JetBrains Mono", ui-monospace, monospace; }
.file-tab.on { background: var(--sky-soft); border-color: var(--sky); color: var(--sky-ink); }
.file-dot { color: var(--sun); }
.file-text { width: 100%; min-height: 110px; max-height: 260px; resize: vertical; font-family: "JetBrains Mono", ui-monospace, Consolas, monospace; font-size: 14px;
  border: 2px solid var(--line); border-radius: 10px; padding: 8px 10px; background: var(--code-bg); color: var(--code-ink); white-space: pre; }
.file-text[readonly] { background: var(--sunk); }
.file-foot { display: flex; align-items: center; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.file-foot small { color: var(--ink3); font-weight: 700; }

/* ---------- Help me debug / Ask Gemini ---------- */
.err-acts { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.err-btn { font: inherit; font-family: "Nunito", system-ui, sans-serif; font-size: 13.5px; font-weight: 800; cursor: pointer;
  background: rgba(255,255,255,.12); color: #fff; border: 2px solid rgba(255,255,255,.35); border-radius: 999px; padding: 3px 12px; }
.err-btn:hover { background: rgba(255,255,255,.22); }
.help-dlg { width: min(600px, calc(100vw - 32px)); max-height: calc(100vh - 40px); overflow: auto; }
.help-err { background: var(--berry-soft); color: var(--berry-ink); border-radius: 10px; padding: 8px 12px; font-size: 15px; margin: 0 0 8px; }
.help-sub { color: var(--ink2); margin: 0 0 8px; }
.help-steps { margin: 6px 0 0; padding-left: 22px; }
.help-steps li { margin: 8px 0; font-size: 15.5px; }
.help-steps label { display: flex; gap: 8px; align-items: flex-start; cursor: pointer; }
.help-steps input { margin-top: 5px; width: 18px; height: 18px; flex: none; }
.help-steps input:checked + span { color: var(--ink3); text-decoration: line-through; }
.help-lbl { display: block; font-weight: 800; font-size: 14.5px; margin: 10px 0 4px; }
dialog.help-dlg textarea { width: 100%; font: inherit; font-size: 15px; border-radius: 10px; border: 2px solid var(--line); background: var(--surface); color: var(--ink); padding: 8px 10px; resize: vertical; }
.help-note { font-size: 13.5px; color: var(--ink3); margin: 6px 0 0; }
.help-next { margin-top: 12px; background: var(--sky-soft); color: var(--sky-ink); border-radius: 12px; padding: 10px 14px; }
.help-next ol { margin: 4px 0; padding-left: 22px; }
.btn.gem { border-color: var(--grape); }
.btn.gem:not(.primary) { color: var(--grape-ink); }
.btn.primary.gem { background: var(--grape); border-color: var(--grape); color: #fff; box-shadow: 0 3px 0 var(--grape-ink); }
.stuck { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 6px; padding: 10px 12px; border-radius: 12px; background: var(--sun-soft); color: var(--sun-ink); }
