:root {
  --bg: #08131f;
  --bg2: #0c1b2c;
  --card: #0f2134;
  --card2: #132a40;
  --line: #1e3f5c;
  --teal: #2ee6d6;
  --teal-d: #17a99e;
  --gold: #ffd23f;
  --red: #ff6b5e;
  --text: #e7f1ff;
  --muted: #8ea7c1;
  --code-bg: #091727;
  --radius: 18px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(46, 230, 214, 0.10), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(80, 120, 255, 0.10), transparent 60%),
    var(--bg);
  color: var(--text);
  font: 500 16px/1.55 "Nunito", system-ui, sans-serif;
  min-height: 100vh;
}
button { font: inherit; cursor: pointer; }
.page { max-width: 1320px; margin: 0 auto; padding: 22px 20px 40px; }

/* ---------- header ---------- */
.top { display: flex; align-items: center; justify-content: space-between; gap: 20px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 16px; }
.orb {
  width: 54px; height: 54px; border-radius: 50%; flex: none;
  background: radial-gradient(circle at 34% 30%, #b9fff8 0 10%, #2ee6d6 34%, #0f8f86 72%, #07514c 100%);
  box-shadow: 0 0 0 3px rgba(46, 230, 214, 0.18), 0 0 28px rgba(46, 230, 214, 0.45);
}
h1 { font: 700 40px/1.05 "Fredoka", sans-serif; margin: 0; letter-spacing: 0.3px; }
h1 span { color: var(--teal); }
.brand p { margin: 4px 0 0; color: #b8cbe0; font-size: 16px; }
.tags { display: flex; align-items: center; gap: 10px; padding: 7px 16px; border-radius: 999px; border: 1.5px solid rgba(46, 230, 214, 0.55); color: var(--teal); font-weight: 800; font-size: 14px; background: rgba(46, 230, 214, 0.06); }
.tags i { width: 5px; height: 5px; border-radius: 50%; background: var(--teal); }

/* ---------- level picker ---------- */
.levels { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; margin: 20px 0 18px; }
.lvl {
  display: flex; align-items: center; gap: 10px; text-align: left; padding: 10px 12px;
  border-radius: 14px; border: 1.5px solid var(--line); background: var(--card); color: var(--text);
  transition: border-color .15s, transform .15s, background .15s; min-width: 0;
}
.lvl:hover { border-color: rgba(46, 230, 214, 0.6); transform: translateY(-1px); }
.lvl.on { border-color: var(--teal); background: linear-gradient(180deg, rgba(46, 230, 214, 0.14), rgba(46, 230, 214, 0.04)); box-shadow: 0 0 22px rgba(46, 230, 214, 0.18); }
.lvl .num {
  flex: none; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  background: var(--card2); color: var(--teal); font: 700 18px "Fredoka", sans-serif; border: 1.5px solid var(--line);
}
.lvl.on .num, .lvl.won .num { background: var(--teal); color: #052a27; border-color: var(--teal); }
.lvl .txt { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.lvl b { font: 600 14px/1.2 "Fredoka", sans-serif; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lvl small { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stars { display: flex; gap: 1px; flex: none; align-self: flex-start; }
.stars i, .win-stars i {
  display: block; width: 11px; height: 11px; background: #2a4561;
  clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
}
.stars i.on { background: var(--gold); }

/* ---------- map ---------- */
.map-wrap {
  position: relative; border-radius: 12px; overflow: hidden;
  border: 2px solid rgba(46, 230, 214, 0.35); box-shadow: 0 0 30px rgba(46, 230, 214, 0.12);
  background: #1f2b57;
}
#map { display: block; width: 100%; height: 100%; image-rendering: pixelated; image-rendering: crisp-edges; }
.hud { position: absolute; top: 10px; left: 10px; right: calc(100% - var(--pw, 100%) + 10px); display: flex; gap: 8px; flex-wrap: wrap; pointer-events: none; }
.pill {
  background: rgba(7, 19, 33, 0.82); border: 1.5px solid rgba(46, 230, 214, 0.45); color: var(--text);
  border-radius: 10px; padding: 4px 10px; font: 600 14px "Fredoka", sans-serif; backdrop-filter: blur(4px);
}
.counters { display: flex; gap: 14px; align-items: center; }
.counters > span { display: flex; align-items: center; gap: 6px; }
.counters [hidden] { display: none; }
.ico { width: 14px; height: 14px; display: inline-block; }
.ico.coin { border-radius: 50%; background: radial-gradient(circle at 35% 35%, #fff5b8 0 18%, #ffd23f 22% 60%, #d4911a 64%); box-shadow: 0 0 0 1.5px #5a3a0a; }
.ico.gem { background: #2ee6d6; clip-path: polygon(20% 0, 80% 0, 100% 35%, 50% 100%, 0 35%); }
.ico.star { width: 14px; height: 14px; background: var(--gold); clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%); }
.ico.door { width: 11px; height: 14px; border-radius: 6px 6px 1px 1px; background: #8a5a32; box-shadow: 0 0 0 1.5px #ffd23f; }
.bubble.scroll { background: #f6e7c1; color: #4a2a12; border-color: #8a5a2a; font-family: "JetBrains Mono", monospace; font-size: 13px; }
.bubble.scroll::after { border-top-color: #8a5a2a; }

.bubble {
  position: absolute; transform: translate(-50%, -100%) scale(.6); opacity: 0; pointer-events: none;
  background: #fffdf4; color: #22180f; border: 2px solid #22180f; border-radius: 10px; padding: 5px 10px;
  font: 700 14px/1.3 "Nunito", sans-serif; max-width: 260px; text-align: center; transition: transform .15s, opacity .15s;
  margin-top: -8px; white-space: pre-wrap; z-index: 5;
}
.bubble::after { content: ""; position: absolute; left: 50%; bottom: -8px; margin-left: -6px; border: 6px solid transparent; border-top-color: #22180f; border-bottom: 0; }
.bubble.show { opacity: 1; transform: translate(-50%, -100%) scale(1); }
.bubble.alert { background: #2a0a10; color: #ffd9d4; border-color: var(--red); }
.bubble.alert::after { border-top-color: var(--red); }
.bubble.emote { font: 700 18px "Fredoka", sans-serif; padding: 1px 10px; }
.bubble.note { background: #0a2633; color: #c9fff8; border-color: var(--teal); box-shadow: 0 0 16px rgba(46, 230, 214, 0.5); font-family: "JetBrains Mono", monospace; font-size: 13px; }
.bubble.note::after { border-top-color: var(--teal); }
.bubble.note.bad { border-color: var(--red); color: #ffd9d4; box-shadow: 0 0 16px rgba(255, 90, 78, .5); }

.float {
  position: absolute; transform: translate(-50%, 0); font: 700 15px "Fredoka", sans-serif; color: var(--gold);
  text-shadow: 0 2px 0 #3a2400, 0 0 8px rgba(0, 0, 0, .5); pointer-events: none; animation: floatUp 1.1s ease-out forwards; white-space: nowrap;
}
.float.bad { color: var(--red); text-shadow: 0 2px 0 #3a0a0a; }
@keyframes floatUp { from { opacity: 1; margin-top: 0; } to { opacity: 0; margin-top: -40px; } }

.banner {
  position: absolute; left: calc(var(--pw, 100%) / 2); bottom: 12px; transform: translate(-50%, 20px); z-index: 4; opacity: 0; pointer-events: none;
  display: flex; flex-direction: column; gap: 2px; text-align: center; padding: 10px 16px; border-radius: 12px;
  background: rgba(7, 19, 33, 0.92); border: 1.5px solid var(--red); max-width: min(92%, 520px); transition: .2s;
}
.banner b { font: 700 16px "Fredoka", sans-serif; color: var(--red); }
.banner span { font-size: 14px; color: #dfe9f5; }
.banner.warn { border-color: var(--gold); }
.banner.warn b { color: var(--gold); }
.banner.ok { border-color: var(--teal); }
.banner.ok b { color: var(--teal); }
.banner.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- quest panel ---------- */
.quest { padding: 18px 8px 6px; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 24px; }
.quest-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.concept, .random { font: 700 12px "Nunito", sans-serif; letter-spacing: .4px; text-transform: uppercase; padding: 3px 10px; border-radius: 999px; }
.concept { color: #052a27; background: var(--teal); }
.random { color: var(--gold); border: 1.5px solid rgba(255, 210, 63, .5); }
.random[hidden] { display: none; }
.quest h2 { font: 700 26px/1.2 "Fredoka", sans-serif; margin: 10px 0 6px; }
.story { color: #b8cbe0; margin: 0 0 12px; }
.goal { display: flex; gap: 10px; align-items: flex-start; margin: 0 0 12px; padding: 10px 12px; border-radius: 12px; background: rgba(255, 210, 63, .07); border: 1.5px solid rgba(255, 210, 63, .25); font-weight: 700; }
.flag { flex: none; width: 14px; height: 18px; margin-top: 3px; background: linear-gradient(90deg, #8a6a3a 0 2px, transparent 2px), linear-gradient(var(--gold), var(--gold)) 2px 0 / 12px 10px no-repeat; }
.hint { margin-bottom: 14px; }
.hint #restoreBtn { margin-left: 6px; }
.hint p { margin: 8px 0 0; padding: 10px 12px; border-left: 3px solid var(--teal); background: rgba(46, 230, 214, .06); border-radius: 0 10px 10px 0; color: #cfe3f5; }
.hint p[hidden] { display: none; }
.ghost { background: none; border: 1.5px solid var(--line); color: var(--teal); border-radius: 10px; padding: 5px 12px; font-weight: 800; font-size: 14px; }
.ghost:hover { border-color: var(--teal); }
.quest h3 { font: 600 16px "Fredoka", sans-serif; margin: 0 0 8px; }
.quest h3 small { color: var(--muted); font: 500 13px "Nunito", sans-serif; margin-left: 6px; }
.api-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.api { display: flex; flex-direction: column; gap: 3px; text-align: left; padding: 9px 11px; border-radius: 11px; background: var(--code-bg); border: 1.5px solid var(--line); color: var(--muted); font-size: 13px; line-height: 1.35; }
.api:hover { border-color: var(--teal); }
.api code { color: var(--teal); font: 600 13px "JetBrains Mono", monospace; }

.ed-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-bottom: 1.5px solid var(--line); background: #0b1a2a; }
.tab { display: flex; align-items: center; gap: 8px; font: 13px "JetBrains Mono", monospace; color: var(--text); background: var(--code-bg); padding: 5px 12px; border-radius: 8px; border: 1px solid var(--line); }
.tab .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--gold); }
.py-status { font-size: 12px; font-weight: 800; display: flex; align-items: center; gap: 6px; color: var(--muted); }
.py-status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--gold); }
.py-status.loading::before { animation: pulse 1s infinite; }
.py-status.ready { color: var(--teal); }
.py-status.ready::before { background: var(--teal); box-shadow: 0 0 8px var(--teal); }
.py-status.fail { color: var(--red); }
.py-status.fail::before { background: var(--red); }
@keyframes pulse { 50% { opacity: .3; } }

.editor { display: flex; height: 340px; background: var(--code-bg); font: 14px/22px "JetBrains Mono", monospace; }
.editor.busy textarea { cursor: progress; }
.gutter { flex: none; width: 38px; padding: 12px 0; text-align: right; color: #44617d; overflow: hidden; user-select: none; border-right: 1px solid #13283d; }
.gutter div { padding-right: 10px; height: 22px; }
.gutter .cur { color: var(--gold); }
.gutter .err { color: var(--red); }
.code-area { position: relative; flex: 1; min-width: 0; }
.hl, #code { position: absolute; inset: 0; margin: 0; padding: 12px 14px; font: inherit; white-space: pre; overflow: auto; tab-size: 4; }
.hl { color: #d6e4f3; pointer-events: none; overflow: hidden; }
#code { color: transparent; caret-color: var(--teal); background: transparent; border: 0; outline: 0; resize: none; }
#code::selection { background: rgba(46, 230, 214, .25); }
.hl .ln { display: inline-block; min-width: 100%; }
.hl .ln.cur { background: rgba(255, 210, 63, .14); box-shadow: inset 3px 0 0 var(--gold); }
.hl .ln.err { background: rgba(255, 107, 94, .16); box-shadow: inset 3px 0 0 var(--red); }
.hl .c { color: #5f7d98; font-style: italic; }
.hl .s { color: #ffd479; }
.hl .n { color: #ff9e64; }
.hl .k { color: #ff8fc8; }
.hl .a { color: var(--teal); font-weight: 600; }
.hl .b { color: #8fb8ff; }
.hl .f { color: #c3e88d; }

.toolbar { display: flex; gap: 8px; padding: 12px 14px; border-top: 1.5px solid var(--line); border-bottom: 1.5px solid var(--line); flex-wrap: wrap; }
.run { white-space: nowrap;
  display: inline-flex; align-items: center; gap: 8px; padding: 9px 18px; border-radius: 11px; border: 0;
  background: linear-gradient(180deg, #4ff3e4, #1fc2b4); color: #042b27; font: 700 16px "Fredoka", sans-serif;
  box-shadow: 0 4px 0 #0f7d74, 0 0 22px rgba(46, 230, 214, .35); transition: transform .08s, box-shadow .08s;
}
.run:active { transform: translateY(3px); box-shadow: 0 1px 0 #0f7d74; }
.run.stop { background: linear-gradient(180deg, #ff8a7e, #e2463f); color: #fff; box-shadow: 0 4px 0 #8f2620; }
.run .ic { font-size: 13px; }
.tool { padding: 8px 12px; border-radius: 11px; border: 1.5px solid var(--line); background: var(--card2); color: var(--text); font-weight: 800; font-size: 14px; }
.tool:hover { border-color: var(--teal); }
.tool.small { min-width: 44px; }
.tool.sound { width: 44px; background: var(--card2) center / 20px no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%232ee6d6' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M11 5 6 9H2v6h4l5 4V5z'/%3E%3Cpath d='M15.5 8.5a5 5 0 0 1 0 7M19 5a10 10 0 0 1 0 14'/%3E%3C/svg%3E"); }
.tool.sound.off { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238ea7c1' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M11 5 6 9H2v6h4l5 4V5z'/%3E%3Cpath d='m23 9-6 6M17 9l6 6'/%3E%3C/svg%3E"); }

.console { height: 150px; overflow: auto; padding: 8px 14px 14px; font: 13px/1.6 "JetBrains Mono", monospace; }
.console .line { white-space: pre-wrap; word-break: break-word; }
.console .out { color: #e7f1ff; }
.console .info { color: var(--muted); }
.console .clue { color: var(--teal); }
.console .err { color: var(--red); }
.console .warn { color: var(--gold); }
.console .ok { color: #7dff8a; }

/* ---------- layout + floating editor ---------- */
.game { padding: 14px; }
.ide {
  position: absolute; z-index: 3; display: flex; flex-direction: column; overflow: hidden;
  top: 10px; right: 10px; width: max(calc(100% - var(--pw) - 20px), 286px); container-type: inline-size; max-width: calc(100% - 20px);
  background: rgba(6, 17, 30, 0.86); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  border: 1.5px solid rgba(46, 230, 214, 0.55); border-radius: 12px;
  box-shadow: 0 0 22px rgba(46, 230, 214, 0.2), 0 10px 26px rgba(0, 0, 0, 0.4);
}
.ide .ed-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; padding: 6px 6px 6px 8px; background: rgba(9, 23, 39, 0.7); }
.ide .tab { cursor: pointer; flex: none; padding: 4px 8px; gap: 6px; font-size: 12px; }
.ide .tab:hover { border-color: var(--teal); }
@container (max-width: 345px) { .ide .tab .name { display: none; } }
.ide .py-status { font-size: 0; }
.ide .py-status::before { width: 9px; height: 9px; }
.chev { width: 6px; height: 6px; border: solid var(--muted); border-width: 0 1.5px 1.5px 0; transform: rotate(45deg); margin: -3px 0 0 2px; transition: transform .15s; }
.ide.folded .chev { transform: rotate(-135deg); margin-top: 3px; }
.layout-bottom .chev { transform: rotate(-135deg); margin-top: 3px; }
.layout-bottom .ide.folded .chev { transform: rotate(45deg); margin-top: -3px; }
.ide .toolbar { display: flex; flex-wrap: nowrap; gap: 3px; padding: 0; border: 0; }
.ide .run { padding: 5px 11px; font-size: 14px; gap: 5px; box-shadow: 0 3px 0 #0f7d74, 0 0 14px rgba(46, 230, 214, .3); }
.ide .run.stop { box-shadow: 0 3px 0 #8f2620; }
.ide .run .ic { font-size: 10px; }
.ide .tool { padding: 4px 6px; font-size: 12px; border-radius: 9px; min-width: 30px; }
.ide #resetBtn { font-size: 15px; line-height: 1; }
.ide .tool.sound { width: 30px; background-size: 16px; }
.ide .tool.live { color: var(--muted); }
.ide .tool.live.on { color: #052a27; background: var(--teal); border-color: var(--teal); box-shadow: 0 0 10px rgba(46, 230, 214, .45); }
.ide-body { display: flex; flex-direction: column; border-top: 1.5px solid var(--line); }
.ide.folded .ide-body { display: none; }
.ide .editor { height: 190px; background: transparent; font-size: 13px; line-height: 20px; }
.ide .gutter { width: 32px; padding: 8px 0; }
.ide .gutter div { height: 20px; padding-right: 8px; }
.ide .hl, .ide #code { padding: 8px 10px; }
.ide .console { flex: none; height: 62px; border-top: 1.5px solid var(--line); padding: 5px 10px 8px; font-size: 12px; line-height: 1.5; }
.ide .console:empty { display: none; }
.layout-bottom .ide { width: auto; left: 8px; right: 8px; top: auto; bottom: 8px; max-height: calc(100% - 16px); }
.layout-bottom .ide .editor { height: 150px; flex: 0 1 auto; min-height: 60px; }
.layout-bottom .ide-body { flex: 1; min-height: 0; }
.layout-bottom .hud { right: 10px; }
.layout-bottom .banner { bottom: calc(100% - var(--ph) + 10px); }

/* ---------- win modal ---------- */
.modal { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(3, 9, 16, .7); backdrop-filter: blur(3px); opacity: 0; pointer-events: none; transition: opacity .2s; padding: 16px; z-index: 10; }
.modal.show { opacity: 1; pointer-events: auto; }
.modal-box { width: min(420px, 100%); text-align: center; padding: 26px 24px 22px; border-radius: 22px; background: linear-gradient(180deg, #13304a, #0d1f31); border: 2px solid var(--teal); box-shadow: 0 0 50px rgba(46, 230, 214, .35); transform: scale(.9); transition: transform .25s; }
.modal.show .modal-box { transform: scale(1); }
.modal-box h2 { font: 700 28px "Fredoka", sans-serif; margin: 8px 0 6px; }
.modal-box p { color: #c3d6ea; margin: 0 0 18px; }
.win-stars { display: flex; justify-content: center; gap: 8px; }
.win-stars i { width: 46px; height: 46px; }
.win-stars i.on { background: var(--gold); animation: pop .5s backwards; filter: drop-shadow(0 0 8px rgba(255, 210, 63, .8)); }
@keyframes pop { from { transform: scale(0) rotate(-40deg); } 70% { transform: scale(1.25); } }
.modal-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.modal-actions [hidden] { display: none; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .levels { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .quest { grid-template-columns: minmax(0, 1fr); gap: 4px; }
}
@media (max-width: 600px) {
  .page { padding: 14px 16px 30px; }
  h1 { font-size: 30px; }
  .orb { width: 42px; height: 42px; }
  .brand p { font-size: 14px; }
  .levels { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .lvl { flex-wrap: wrap; gap: 4px 8px; padding: 8px 10px; }
  .lvl .num { width: 28px; height: 28px; font-size: 15px; }
  .lvl .txt { flex-basis: 100%; order: 1; }
  .lvl b { white-space: normal; font-size: 13px; }
  .lvl .stars { margin-left: auto; align-self: center; }
  .game { padding: 8px; }
  .banner { padding: 7px 12px; }
  .banner b { font-size: 14px; }
  .banner span { font-size: 12px; }
  .pill { font-size: 12px; padding: 3px 8px; }
  .bubble { font-size: 12px; max-width: 180px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
