/* Coding page */
body.code-page { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
.code-page .topbar { padding: 14px 22px; flex-shrink: 0; }

.module-pill {
  display: flex; align-items: center; gap: 14px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 999px; padding: 9px 18px; font-weight: 650; font-size: 14.5px; color: var(--ink-2); min-width: 0;
}
.module-pill .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 240px; }
.dots { display: flex; gap: 5px; align-items: center; }
.dots a { width: 8px; height: 8px; border-radius: 50%; background: #c9c9c0; display: block; }
.dots a.solved { background: var(--ink); }
.dots a.current { width: 16px; height: 16px; background: var(--lime); border: 2px solid var(--ink); }
.module-pill .lvl { color: var(--ink); font-weight: 800; white-space: nowrap; }

.workspace {
  flex: 1; display: grid; grid-template-columns: minmax(440px, 32%) 1fr; gap: 18px;
  padding: 0 22px 18px; min-height: 0;
}

/* ---------- left panel ---------- */
.brief { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.brief-tabs { display: flex; flex-wrap: wrap; gap: 2px; padding: 12px 10px; border-bottom: 1px solid var(--line); flex-shrink: 0; }
.brief-tabs button {
  border: 0; background: transparent; padding: 8px 9px; border-radius: 11px; font-weight: 700; font-size: 14px; white-space: nowrap;
  cursor: pointer; display: flex; align-items: center; gap: 5px; color: var(--ink);
}
.brief-tabs button:hover { background: var(--panel-2); }
.brief-tabs button.on { background: var(--dark); color: #fff; }
.brief-tabs .badge { background: var(--dark); color: #fff; border-radius: 7px; font-size: 11.5px; padding: 1px 6px; white-space: nowrap; }
.brief-tabs button.on .badge { background: var(--lime); color: var(--lime-ink); }
.brief-tabs svg { width: 14px; height: 14px; }
.brief-body { overflow-y: auto; padding: 26px 30px 30px; flex: 1; }
.brief-body .eyebrow { margin-bottom: 8px; }
.brief-body h1 { font-size: 36px; letter-spacing: -.03em; line-height: 1.1; margin: 0 0 16px; }
.meta { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 22px; }
.desc { font-size: 16.5px; line-height: 1.65; color: #2a2b33; }
.desc p { margin: 0 0 14px; }
.desc code, .hint code, .note code {
  font-size: .9em; background: var(--purple-soft); color: #4b32c9; padding: 1px 6px; border-radius: 6px;
}
.desc ul { margin: 0 0 14px; padding-left: 20px; }
.desc li { margin-bottom: 6px; }
.examples { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 20px 0 22px; }
.example { background: var(--dark); color: #e9e9f0; border-radius: 16px; padding: 16px 18px; min-width: 0; }
.example h4 { margin: 0 0 10px; color: var(--lime); font-size: 12.5px; letter-spacing: .08em; text-transform: uppercase; }
.example pre { margin: 0; white-space: pre-wrap; word-break: break-word; font-size: 13.5px; line-height: 1.6; color: #d7d8e2; }
.example .out { margin-top: 10px; display: flex; gap: 8px; align-items: flex-start; font-family: var(--mono); font-size: 13.5px; }
.example .out span.v { background: var(--lime); color: var(--lime-ink); padding: 2px 8px; border-radius: 7px; font-weight: 700; word-break: break-word; }
.rules h3 { font-size: 17px; margin: 0 0 8px; }
.rules ul { margin: 0 0 20px; padding-left: 20px; font-family: var(--mono); font-size: 13.5px; line-height: 1.9; color: var(--ink-2); }

.brief-tabs .badge:empty { display: none; }

/* AI tutor */
.tutor-teaser {
  display: flex; gap: 14px; align-items: center; width: 100%; text-align: left; cursor: pointer; font: inherit; color: inherit;
  border: 2px dashed #cfcfc5; background: transparent; border-radius: 18px; padding: 16px 18px; margin-top: 8px;
}
.tutor-teaser:hover { border-color: var(--ink); background: var(--panel-2); }
.tutor-teaser b { display: block; font-size: 16px; margin-bottom: 2px; }
.tutor-teaser span span { font-size: 13.5px; color: var(--ink-2); }
.tutor-teaser .go { margin-left: auto; flex-shrink: 0; }
.tutor-teaser .go svg { width: 20px; height: 20px; }
.bit { flex-shrink: 0; }
.tutor-teaser .bit svg, .msg .bit svg { width: 34px; height: 34px; display: block; }

.brief-body.chat-mode { display: flex; flex-direction: column; overflow: hidden; padding: 0; }
.chat-log { flex: 1; overflow-y: auto; padding: 22px 24px 12px; display: flex; flex-direction: column; gap: 12px; }
.msg { font-size: 15px; line-height: 1.55; max-width: 92%; }
.msg.me { align-self: flex-end; background: var(--dark); color: #fff; padding: 10px 14px; border-radius: 16px 16px 4px 16px; white-space: normal; word-break: break-word; }
.msg.bot { display: flex; gap: 10px; align-items: flex-start; }
.msg.bot .bubble { background: var(--panel-2); border: 1px solid var(--line); padding: 10px 14px; border-radius: 4px 16px 16px 16px; min-width: 0; }
.msg.bot .bubble p { margin: 0 0 8px; } .msg.bot .bubble p:last-child { margin-bottom: 0; }
.msg.bot .bubble ul { margin: 0 0 8px; padding-left: 20px; }
.msg.bot .bubble code { font-size: .9em; background: var(--purple-soft); color: #4b32c9; padding: 1px 6px; border-radius: 6px; }
.msg.bot .bubble pre { background: var(--dark); color: #e3e3ea; border-radius: 10px; padding: 10px 12px; font-size: 13px; overflow-x: auto; margin: 0 0 8px; }
.msg.err { align-self: center; background: var(--red-soft); color: #8a1c14; padding: 8px 12px; border-radius: 12px; font-size: 13.5px; text-align: center; }
.typing { display: flex; gap: 5px; padding: 14px 16px !important; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-3); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-left: 44px; }
.chips button { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 7px 12px; font: inherit; font-size: 13.5px; font-weight: 600; cursor: pointer; }
.chips button:hover { border-color: var(--ink); }
.chat-form { border-top: 1px solid var(--line); padding: 12px 16px 14px; display: grid; grid-template-columns: 1fr auto; gap: 8px 10px; align-items: end; flex-shrink: 0; }
.chat-form textarea {
  width: 100%; resize: none; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; font: inherit; font-size: 14.5px;
  outline: none; background: #fff; max-height: 140px;
}
.chat-form textarea:focus { border-color: var(--ink); }
.chat-form textarea:disabled { background: var(--panel-2); }
.chat-meta { grid-column: 1 / -1; font-size: 12.5px; color: var(--ink-3); font-weight: 600; }

.concept-example { background: var(--dark); color: #e9e9f0; border-radius: 16px; padding: 16px 18px; margin: 18px 0; }
.concept-example h4 { margin: 0 0 10px; color: var(--lime); font-size: 12.5px; letter-spacing: .08em; text-transform: uppercase; }
.concept-example pre { margin: 0; white-space: pre-wrap; word-break: break-word; font-size: 13.5px; line-height: 1.6; color: #d7d8e2; }
.concept-example p { margin: 10px 0 0; font-size: 12.5px; color: #9a9bab; }
.concept-next { color: var(--ink-2); font-size: 15px; }
.concept-next a { color: var(--purple); font-weight: 700; }
.hint { background: var(--panel-2); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; margin-bottom: 10px; font-size: 15px; }
.hint b { display: block; font-size: 12.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); margin-bottom: 4px; }
.locked { text-align: center; padding: 40px 10px; color: var(--ink-2); }
.locked .ic { width: 54px; height: 54px; border-radius: 16px; margin: 0 auto 14px; background: var(--panel-2); border: 1px solid var(--line); display: grid; place-items: center; }
.locked .ic svg { width: 24px; height: 24px; }
.solution-code { background: var(--dark); color: #e3e3ea; border-radius: 14px; padding: 16px; font-size: 13.5px; line-height: 1.6; overflow-x: auto; }
.history-item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; margin-bottom: 8px; font-size: 14px; background: #fff; }
.history-item .k { font-weight: 700; }
.history-item .when { color: var(--ink-3); font-size: 12.5px; }
.history-item .score { margin-left: auto; font-family: var(--mono); font-weight: 700; }
.history-item .score.ok { color: #17784a; } .history-item .score.bad { color: #b3261e; }

/* ---------- editor panel ---------- */
.ide {
  background: var(--dark-2); border-radius: 22px; display: flex; flex-direction: column; min-height: 0; overflow: hidden;
  color: #e6e6ee; border: 1px solid #101117;
}
.ide.fullscreen { position: fixed; inset: 10px; z-index: 50; }
.ide-bar { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--dark-line); flex-shrink: 0; }
.file-tab { display: flex; align-items: center; gap: 9px; background: var(--dark-3); padding: 9px 14px; border-radius: 12px; font-family: var(--mono); font-size: 14.5px; }
.lang-group { display: flex; background: var(--dark-3); padding: 4px; border-radius: 13px; }
.lang-group span { padding: 7px 16px; border-radius: 10px; font-weight: 700; font-size: 14.5px; color: #a8a9b8; }
.lang-group span.on { background: var(--lime); color: var(--lime-ink); }
.focus { font-family: var(--mono); font-size: 13.5px; color: #a8a9b8; display: flex; align-items: center; gap: 7px; }
.focus svg { width: 16px; height: 16px; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 12px; background: var(--dark-3); border: 0; display: grid; place-items: center;
  cursor: pointer; color: #d8d8e2; position: relative;
}
.icon-btn:hover { background: #333443; }
.icon-btn svg { width: 19px; height: 19px; }
.icon-btn.armed { background: var(--red); color: #fff; }
.popover {
  position: absolute; top: 52px; right: 0; background: var(--dark-3); border: 1px solid #3c3d4c; border-radius: 14px; padding: 12px;
  width: 220px; z-index: 20; box-shadow: 0 12px 30px rgba(0, 0, 0, .4); text-align: left; cursor: default;
}
.popover label { display: flex; justify-content: space-between; align-items: center; font-size: 13.5px; padding: 6px 2px; gap: 10px; }
.popover .size { display: flex; gap: 6px; align-items: center; }
.popover .size button { width: 30px; height: 30px; border-radius: 8px; border: 0; background: #3a3b4a; color: #fff; cursor: pointer; font-weight: 700; }

.editor-wrap { flex: 1; min-height: 0; position: relative; }
.editor-wrap .CodeMirror { position: absolute; inset: 0; height: auto; }

/* CodeMirror theme */
.cm-s-pq.CodeMirror { background: var(--dark-2); color: #e9e9f1; font-family: var(--mono); font-size: 15.5px; line-height: 1.75; }
.cm-s-pq .CodeMirror-gutters { background: var(--dark-2); border-right: 0; padding-right: 8px; }
.cm-s-pq .CodeMirror-linenumber { color: #5b5d6d; padding: 0 12px 0 14px; }
.cm-s-pq .CodeMirror-lines { padding: 18px 0; }
.cm-s-pq .CodeMirror-cursor { border-left: 2px solid var(--lime); }
.cm-s-pq .CodeMirror-activeline-background { background: #252632; }
.cm-s-pq .CodeMirror-activeline-gutter { background: #252632; box-shadow: inset 3px 0 0 var(--lime); }
.cm-s-pq .CodeMirror-activeline-gutter .CodeMirror-linenumber { color: #fff; }
.cm-s-pq .CodeMirror-selected, .cm-s-pq.CodeMirror-focused .CodeMirror-selected { background: #3a3d55; }
.cm-s-pq .cm-keyword { color: #c792ea; }
.cm-s-pq .cm-def { color: var(--lime); }
.cm-s-pq .cm-builtin { color: #82aaff; }
.cm-s-pq .cm-variable { color: #e9e9f1; }
.cm-s-pq .cm-variable-2 { color: #e9e9f1; }
.cm-s-pq .cm-property { color: #9cdcfe; }
.cm-s-pq .cm-string { color: #c3e88d; }
.cm-s-pq .cm-number { color: #f78c6c; }
.cm-s-pq .cm-comment { color: #6f7385; font-style: italic; }
.cm-s-pq .cm-operator { color: #89ddff; }
.cm-s-pq .cm-atom { color: #f78c6c; }
.cm-s-pq .cm-meta { color: #ffcb6b; }
.cm-s-pq .CodeMirror-matchingbracket { color: var(--lime) !important; text-decoration: underline; }
.cm-s-pq .cm-error-line { background: rgba(255, 93, 93, .16); }
.cm-s-pq .CodeMirror-gutter-wrapper .err-mark { color: var(--red); }

/* ---------- checkpoint area ---------- */
.dock { border-top: 1px solid var(--dark-line); background: #191a21; flex-shrink: 0; display: flex; flex-direction: column; max-height: 46%; }
.dock-tabs { display: flex; gap: 4px; padding: 12px 16px 0; }
.dock-tabs button { border: 0; background: transparent; color: #a8a9b8; padding: 10px 16px; border-radius: 11px; font-weight: 700; font-size: 14.5px; cursor: pointer; }
.dock-tabs button.on { background: var(--dark-3); color: #fff; }
.dock-tabs .badge { margin-left: 6px; background: var(--red); color: #fff; border-radius: 7px; padding: 0 6px; font-size: 11.5px; }
.dock-body { padding: 14px 20px 14px; overflow-y: auto; min-height: 150px; }

.trail { display: flex; align-items: flex-start; padding: 8px 6px 4px; }
.cp { display: flex; flex-direction: column; align-items: center; gap: 8px; cursor: pointer; background: none; border: 0; color: inherit; padding: 0; min-width: 64px; max-width: 150px; }
.cp .node {
  width: 46px; height: 46px; border-radius: 13px; border: 2px solid #4a4c5c; display: grid; place-items: center;
  font-weight: 800; font-size: 16px; background: var(--dark-2); transition: all .2s;
}
.cp .node svg { width: 18px; height: 18px; }
.cp .lbl { font-family: var(--sans); font-size: 12.5px; font-weight: 700; color: #c9cad6; text-align: center; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cp.sel .node { box-shadow: 0 0 0 3px rgba(212, 245, 60, .35); }
.cp.running .node { border-color: var(--lime); animation: pulse 1s infinite; }
.cp.pass .node { background: var(--lime); border-color: var(--lime); color: var(--lime-ink); box-shadow: 0 0 18px rgba(212, 245, 60, .35); }
.cp.fail .node, .cp.error .node, .cp.timeout .node { background: var(--red); border-color: var(--red); color: #fff; }
.trail .link { flex: 1; border-top: 2px dashed #4a4c5c; margin-top: 23px; min-width: 20px; }
.trail .link.lit { border-top-color: var(--lime); border-top-style: solid; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(212, 245, 60, .15); } }

.detail {
  margin-top: 12px; background: var(--dark-2); border-radius: 12px; padding: 12px 16px; font-family: var(--mono); font-size: 13.5px; color: #d6d7e1;
}
.detail .row { display: grid; grid-template-columns: 90px 1fr; gap: 10px; padding: 3px 0; }
.detail .row b { color: #8b8c9c; font-weight: 600; }
.detail pre { margin: 0; white-space: pre-wrap; word-break: break-word; font-family: var(--mono); }
.detail .good { color: var(--lime); } .detail .bad { color: #ff8a8a; }
.detail .note { font-family: var(--sans); color: #ffd28a; margin-top: 8px; font-size: 14px; }
.detail .note code { background: #3a3046; color: #ffd28a; }
.console { font-family: var(--mono); font-size: 13.5px; white-space: pre-wrap; word-break: break-word; margin: 0; color: #dcdde6; min-height: 100px; }
.console .err { color: #ff8a8a; }
.console .muted { color: #6f7385; }
.console .explain { color: #ffd28a; font-family: var(--sans); }

.helper-bar { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-top: 1px solid var(--dark-line); background: #191a21; flex-shrink: 0; }
.speech { flex: 1; background: var(--dark-3); border-radius: 14px; padding: 12px 16px; font-size: 14.5px; line-height: 1.45; min-height: 46px; display: flex; align-items: center; }
.speech code { background: #3a3b4a; padding: 0 5px; border-radius: 5px; font-size: .92em; }
.speech.good { background: #2c3a12; color: #eaffb0; }
.speech.bad { background: #3f2222; color: #ffd3d3; }
.helper-bar .btn { white-space: nowrap; }
.kbd-hint { font-size: 11.5px; color: #7b7c8c; }

.celebrate { position: fixed; inset: 0; pointer-events: none; z-index: 100; overflow: hidden; }
.celebrate i { position: absolute; width: 10px; height: 14px; top: -20px; border-radius: 3px; animation: fall 1.8s ease-in forwards; }
@keyframes fall { to { transform: translateY(105vh) rotate(540deg); opacity: .8; } }

.loading-py { display: inline-flex; gap: 8px; align-items: center; }
.spinner { width: 14px; height: 14px; border: 2px solid #555; border-top-color: var(--lime); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1100px) {
  body.code-page { height: auto; overflow: auto; }
  .workspace { grid-template-columns: 1fr; }
  .ide { min-height: 80vh; }
  .module-pill .dots, .focus { display: none; }
  .examples { grid-template-columns: 1fr; }
  .brief-body.chat-mode { height: 70vh; flex: none; }
}

/* ---------- dark theme (tokens live in base.css; these were hard-coded light colours) ---------- */
[data-theme="dark"] .desc { color: #d4d5df; }
[data-theme="dark"] .desc code, [data-theme="dark"] .hint code, [data-theme="dark"] .msg.bot .bubble code { color: #c4b5ff; }
[data-theme="dark"] .dots a { background: #44465a; }
[data-theme="dark"] .dots a.solved { background: var(--ink-2); }
[data-theme="dark"] .tutor-teaser { border-color: #3a3b4a; }
[data-theme="dark"] .chips button, [data-theme="dark"] .chat-form textarea, [data-theme="dark"] .history-item { background: var(--panel-2); color: var(--ink); }
[data-theme="dark"] .chat-form textarea:disabled { background: var(--panel); }
[data-theme="dark"] .msg.err { color: #ffb4ab; }
[data-theme="dark"] .history-item .score.ok { color: #6fdc9d; } [data-theme="dark"] .history-item .score.bad { color: #ff8f86; }
[data-theme="dark"] .brief-tabs button.on { background: var(--lime); color: var(--lime-ink); }
[data-theme="dark"] .brief-tabs button.on .badge { background: var(--lime-ink); color: var(--lime); }
[data-theme="dark"] .example, [data-theme="dark"] .concept-example, [data-theme="dark"] .solution-code, [data-theme="dark"] .msg.bot .bubble pre { background: #101116; border: 1px solid var(--line); }
[data-theme="dark"] .ide { border-color: var(--line); }
.code-page .theme-toggle { width: 46px; height: 46px; border-radius: 14px; }
