/* Python Quest — style.css */
:root {
  --bg: #0f1220;
  --bg2: #171b2e;
  --panel: #1c2138;
  --panel2: #232a47;
  --text: #e8eaf6;
  --muted: #9aa3c0;
  --accent: #6c8cff;
  --green: #2ec27e;
  --red: #ff6b6b;
  --yellow: #ffd166;
  --radius: 12px;
  --mono: ui-monospace, "JetBrains Mono", "Fira Code", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  min-height: 100vh;
}
.hidden { display: none !important; }
#app { max-width: 1180px; margin: 0 auto; padding: 0 16px; }

/* ── top bar ── */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 4px; gap: 16px;
}
.logo { font-size: 20px; font-weight: 700; }
.player-stats { display: flex; align-items: center; gap: 12px; }
.stat { font-weight: 600; font-size: 14px; color: var(--text); }
.stat.small { color: var(--muted); font-size: 12px; }
.xp-wrap { display: flex; flex-direction: column; gap: 2px; }
.xp-bar {
  width: 160px; height: 8px; border-radius: 6px; background: var(--panel2); overflow: hidden;
}
.xp-bar.small { width: 120px; }
#xp-fill, #lesson-xp-fill {
  height: 100%; width: 0;
  background: linear-gradient(90deg, var(--accent), #9a6cff);
  border-radius: 6px; transition: width .4s ease;
}

/* ── home ── */
.home-main { padding: 24px 4px 40px; }
h1 { font-size: 34px; margin: 8px 0 4px; }
h1 em { color: var(--accent); font-style: normal; }
.tagline { color: var(--muted); margin-top: 0; }
.pyodide-status {
  margin: 14px 0; padding: 10px 14px; border-radius: var(--radius);
  background: var(--panel); font-size: 14px; color: var(--muted);
}
.pyodide-status.ready { color: var(--green); }
.pyodide-status.error { color: var(--red); }
.level-heading {
  margin: 34px 0 14px; font-size: 15px; letter-spacing: .04em;
  display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap;
  border-bottom: 1px solid var(--panel2); padding-bottom: 10px;
}
.lvl-badge {
  font-size: 16px; font-weight: 800; text-transform: uppercase; letter-spacing: .1em;
  padding: 4px 12px; border-radius: 8px; color: #fff;
}
.lvl-blurb { color: var(--muted); font-size: 14px; flex: 1; letter-spacing: 0; }
.lvl-count { color: var(--muted); font-size: 12.5px; letter-spacing: 0; }
.level-section { border-radius: var(--radius); padding: 4px 14px 18px; margin: 0 -14px; }
.level-section.lvl-beginner { background: linear-gradient(180deg, rgba(46, 194, 126, .07), transparent 70%); }
.level-section.lvl-intermediate { background: linear-gradient(180deg, rgba(108, 140, 255, .07), transparent 70%); }
.level-section.lvl-advanced { background: linear-gradient(180deg, rgba(224, 123, 57, .08), transparent 70%); }
.level-section.lvl-beginner .lvl-badge { background: var(--green); }
.level-section.lvl-intermediate .lvl-badge { background: var(--accent); }
.level-section.lvl-advanced .lvl-badge { background: #e07b39; }
.course-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; }
.course-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; }
.course-card {
  background: var(--panel); border: 1px solid var(--panel2); border-radius: var(--radius);
  padding: 16px;
}
.course-card { border-left: 4px solid var(--accent); }
.course-head { display: flex; align-items: center; gap: 10px; }
.course-icon { font-size: 22px; }
.course-title { font-weight: 700; flex: 1; }
.course-xp { font-size: 12px; color: var(--muted); }
.course-desc { color: var(--muted); font-size: 14px; margin: 8px 0 12px; }
.course-bar { height: 6px; background: var(--panel2); border-radius: 4px; overflow: hidden; margin-bottom: 12px; }
.course-bar > div { height: 100%; background: var(--green); transition: width .4s; }
.course-lessons { display: flex; flex-wrap: wrap; gap: 6px; }
.pill {
  font-size: 12.5px; padding: 5px 10px; border-radius: 999px; cursor: pointer;
  background: var(--panel2); color: var(--text); text-decoration: none; border: 1px solid transparent;
}
.pill:hover { border-color: var(--accent); }
.pill.done { background: rgba(46, 194, 126, .15); color: var(--green); }
.foot { color: var(--muted); font-size: 12.5px; padding: 20px 0 40px; text-align: center; }

/* ── lesson ── */
.lesson-topbar { gap: 10px; }
.lesson-title { flex: 1; font-weight: 700; font-size: 15px; text-align: center; }
.lesson-main {
  display: grid; grid-template-columns: minmax(300px, 440px) 1fr;
  gap: 16px; align-items: start; padding-bottom: 40px;
}
@media (max-width: 900px) { .lesson-main { grid-template-columns: 1fr; } }
.lesson-left, .lesson-right { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.crumbs { display: flex; gap: 6px; flex-wrap: wrap; }
.crumb {
  width: 30px; height: 30px; border-radius: 8px; display: inline-flex;
  align-items: center; justify-content: center; cursor: pointer;
  background: var(--panel); color: var(--muted); font-size: 13px; font-weight: 600;
  text-decoration: none;
}
.crumb.active { background: var(--accent); color: #fff; }
.crumb.done { color: var(--green); }
.lesson-card { background: var(--panel); border: 1px solid var(--panel2); border-radius: var(--radius); padding: 18px; }
.instructions { font-size: 14.5px; line-height: 1.65; }
.instructions .isec {
  margin: 14px 0 6px; font-size: 11.5px; font-weight: 700; letter-spacing: .12em;
  text-transform: uppercase; color: var(--accent);
}
.instructions .isec:first-child { margin-top: 0; }
.instructions code.block {
  display: block; margin: 6px 0; padding: 9px 12px; line-height: 1.5;
  border-left: 3px solid var(--accent); border-radius: 0 4px 4px 0; overflow-x: auto;
}
.instructions code, .result code {
  font-family: var(--mono); background: var(--panel2); padding: 1px 5px; border-radius: 4px;
  font-size: 13px; white-space: pre-wrap; display: inline-block; max-width: 100%;
}
.hint-box {
  margin-top: 12px; padding: 10px 12px; border-radius: 8px; font-size: 13.5px;
  background: rgba(255, 209, 102, .08); border: 1px solid rgba(255, 209, 102, .25);
}
.lesson-actions { margin-top: 12px; }
.test-results { font-size: 14px; }
.result { padding: 12px 14px; border-radius: var(--radius); white-space: pre-wrap; }
.result.pass { background: rgba(46, 194, 126, .12); border: 1px solid rgba(46, 194, 126, .4); color: var(--green); }
.result.fail { background: rgba(255, 107, 107, .1); border: 1px solid rgba(255, 107, 107, .4); color: var(--red); }

/* editor + console */
.editor-header {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel2); border-radius: var(--radius) var(--radius) 0 0; padding: 8px 12px;
}
.dot { width: 10px; height: 10px; border-radius: 50%; }
.dot.r { background: #ff5f57; } .dot.y { background: #febc2e; } .dot.g { background: #28c840; }
.editor-file { color: var(--muted); font-size: 13px; margin-left: 6px; flex: 1; }
.editor-buttons { display: flex; gap: 8px; }
#editor {
  min-height: 260px; padding: 14px; background: #12162a;
  font-family: var(--mono); font-size: 14px; line-height: 1.55;
  color: #d6e2ff; outline: none; white-space: pre-wrap; tab-size: 4;
  border: 1px solid var(--panel2); border-top: none;
  border-radius: 0;
}
#editor:focus { border-color: var(--accent); }
.console-header {
  background: var(--panel2); padding: 6px 12px; font-size: 12px; letter-spacing: .1em;
  text-transform: uppercase; color: var(--muted);
  border-radius: 0;
}
.console {
  margin: 0; background: #0b0e1c; color: #cfd6ff;
  font-family: var(--mono); font-size: 13px; line-height: 1.5;
  padding: 12px 14px; min-height: 120px; max-height: 320px; overflow: auto;
  border: 1px solid var(--panel2); border-top: none; border-radius: 0 0 var(--radius) var(--radius);
  white-space: pre-wrap;
}
.console .out { color: #d6e2ff; }
.console .err { color: var(--red); }
.console .meta { color: var(--muted); font-size: 11.5px; }

/* interactive input() prompt rendered inside the console */
.inline-input { display: flex; align-items: baseline; }
.inline-input .prompt-label { color: #d6e2ff; white-space: pre-wrap; }
.inline-input input {
  flex: 1; min-width: 40px; background: transparent; border: 0; outline: 0;
  color: #8ab4f8; font-family: var(--mono); font-size: 13px; caret-color: #8ab4f8;
}
.console .echo { color: #8ab4f8; }

/* buttons */
.btn {
  border: none; border-radius: 8px; padding: 9px 16px; font-size: 14px; font-weight: 600;
  cursor: pointer; color: var(--text); background: var(--panel2); transition: filter .15s;
}
.btn:hover { filter: brightness(1.15); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.green { background: var(--green); color: #04150c; }
.btn.ghost { background: transparent; border: 1px solid var(--panel2); color: var(--muted); }
.btn.ghost:hover { color: var(--text); }
.btn.small { padding: 6px 11px; font-size: 13px; }

/* shortcut keys */
.shortcuts-bar {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  padding: 8px 12px; background: var(--panel); border: 1px solid var(--panel2);
  border-radius: var(--radius); font-size: 12.5px; color: var(--muted);
}
.sc { display: inline-flex; align-items: center; gap: 5px; }
.kbd {
  font-family: var(--mono); font-size: 11.5px; font-weight: 700;
  background: var(--panel2); color: var(--text);
  border: 1px solid #3a4370; border-bottom-width: 2px;
  border-radius: 5px; padding: 2px 7px; white-space: nowrap;
}

/* toast */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(10px);
  background: var(--panel2); border: 1px solid var(--accent); color: var(--text);
  padding: 10px 18px; border-radius: 999px; font-size: 14px; font-weight: 600;
  opacity: 0; transition: all .25s ease; z-index: 50; pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.hidden { opacity: 0; }

/* ── progress code bar + modal ── */
.code-bar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin-top: 10px; padding: 7px 12px;
  background: var(--panel); border: 1px solid var(--panel2); border-radius: var(--radius);
  font-size: 12.5px; color: var(--muted);
}
.code-label { font-weight: 700; letter-spacing: .03em; white-space: nowrap; }
.code-preview {
  font-family: var(--mono); font-size: 12.5px; font-weight: 700; color: var(--yellow);
  letter-spacing: .07em; cursor: pointer; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; max-width: 42vw; min-width: 3ch;
}
.code-preview:hover { color: #ffe08a; text-decoration: underline dotted; }
.code-count { font-size: 11.5px; white-space: nowrap; }
.code-actions { margin-left: auto; display: flex; gap: 6px; }
.code-bar.updated { animation: codePulse 1.1s ease; }
@keyframes codePulse {
  0%   { border-color: var(--yellow); box-shadow: 0 0 0 4px rgba(255, 209, 102, .28); }
  100% { border-color: var(--panel2); box-shadow: 0 0 0 4px transparent; }
}

.modal-backdrop {
  position: fixed; inset: 0; z-index: 60; padding: 16px;
  background: rgba(5, 7, 16, .72);
  display: flex; align-items: center; justify-content: center;
}
.code-modal {
  background: var(--panel); border: 1px solid var(--panel2); border-radius: var(--radius);
  width: min(620px, 100%); padding: 20px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, .5);
}
.code-modal-title {
  font-weight: 800; font-size: 15px; letter-spacing: .12em; text-transform: uppercase;
  color: var(--yellow); margin-bottom: 14px;
}
.code-modal-section { margin-bottom: 16px; }
.code-modal-label { font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.code-full {
  display: block; font-family: var(--mono); font-size: 13px; line-height: 1.7;
  background: #0b0e1c; border: 1px solid var(--panel2); border-radius: 8px;
  padding: 10px 12px; color: #ffe08a; word-break: break-all;
  max-height: 170px; overflow: auto; margin-bottom: 8px; user-select: all;
}
.code-toggle {
  display: block; background: none; border: none; padding: 0;
  font-family: inherit; font-size: 12px; font-weight: 600;
  color: var(--muted); cursor: pointer;
  text-decoration: underline dotted; text-underline-offset: 3px;
}
.code-toggle:hover { color: var(--text); }
#code-full-wrap { margin-top: 10px; }
.code-input {
  width: 100%; font-family: var(--mono); font-size: 14px; text-transform: uppercase;
  letter-spacing: .05em; background: #0b0e1c; color: var(--text);
  border: 1px solid var(--panel2); border-radius: 8px; padding: 10px 12px; outline: none;
}
.code-input:focus { border-color: var(--accent); }
.code-input-error { margin-top: 6px; color: var(--red); font-size: 13px; }
.code-modal-actions { display: flex; gap: 8px; margin-top: 10px; }
.code-modal-note { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
@media (max-width: 640px) {
  .code-preview { max-width: 38vw; }
  .code-actions { margin-left: 0; }
  .code-actions .btn { padding: 5px 8px; }
}

/* Worked-solution reveal (after 3 failed submits). */
.solution-box { margin-top: 10px; padding: 10px 12px; background: var(--panel2); border-radius: var(--radius); }
.solution-head { font-size: 13px; color: var(--text); margin-bottom: 8px; }
.solution-note { font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.solution-code {
  margin: 0; padding: 10px 12px; background: #0b0e1c; color: #cfd6ff;
  font-family: var(--mono); font-size: 13px; line-height: 1.5;
  border-radius: 8px; overflow: auto; max-height: 260px; white-space: pre-wrap;
}
.playground-row { margin-top: 14px; }
