/* ============================================================
   Py Quest - learn Python for kids
   ============================================================ */

:root {
    --ink: #33334d;
    --ink-soft: #6b6b85;
    --paper: #fffdf7;
    --gold: #ffc93c;
    --good: #35c26b;
    --good-soft: #dcf5e5;
    --bad: #ef6461;
    --bad-soft: #fde4e3;
    --blue: #5f8fc4;
    --blue-dark: #3f6c9e;
    --code-bg: #f3f1ea;
    --shadow: 0 6px 0 rgba(0, 0, 0, .09), 0 12px 26px rgba(70, 60, 120, .14);
    --mono: 'JetBrains Mono', ui-monospace, Menlo, Consolas, monospace;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Baloo 2', 'Trebuchet MS', sans-serif;
    color: var(--ink);
    background: linear-gradient(170deg, #e3f6e8 0%, #eef6ff 45%, #fff3d6 100%);
    background-attachment: fixed;
    min-height: 100vh;
    padding: 64px 14px 40px;
    font-size: 18px;
    line-height: 1.5;
}

main {
    max-width: 1180px;
    margin: 0 auto;
}

code {
    font-family: var(--mono);
    font-size: .88em;
    background: var(--code-bg);
    border-radius: 6px;
    padding: 1px 6px;
}

h2 {
    font-family: 'Fredoka One', 'Baloo 2', sans-serif;
    font-weight: 400;
    font-size: 26px;
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 8px;
}

p { margin-bottom: 10px; }

/* ---------- top bar ---------- */
.topbar {
    position: fixed;
    top: 10px;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    padding: 0 14px;
    z-index: 20;
    pointer-events: none;
}

.chip {
    pointer-events: auto;
    font: inherit;
    font-weight: 700;
    font-size: 17px;
    border-radius: 999px;
    padding: 6px 16px;
    background: #fff;
    color: var(--ink);
    box-shadow: var(--shadow);
    text-decoration: none;
}

.starcount .s { color: var(--gold); margin-right: 4px; }

/* ---------- cards & buttons ---------- */
.card {
    background: var(--paper);
    border-radius: 26px;
    padding: 22px;
    box-shadow: var(--shadow);
    margin-bottom: 18px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font: inherit;
    font-weight: 800;
    font-size: 19px;
    border: 0;
    border-radius: 16px;
    padding: 8px 20px;
    min-height: 50px;
    background: #e9eef8;
    color: var(--ink);
    box-shadow: 0 4px 0 rgba(0, 0, 0, .12);
    cursor: pointer;
    text-decoration: none;
    transition: transform .08s;
    margin: 6px 4px;
}

.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0, 0, 0, .12); }
.btn.primary { background: var(--blue); color: #fff; box-shadow: 0 4px 0 var(--blue-dark); }
.btn.small { font-size: 16px; min-height: 40px; padding: 4px 14px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn[hidden] { display: none; }

.link {
    font: inherit;
    font-weight: 800;
    background: none;
    border: 0;
    color: var(--blue-dark);
    cursor: pointer;
    text-decoration: underline;
}

.link.small { font-size: 15px; }
.row { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.small { font-size: 15px; color: var(--ink-soft); }
.center { text-align: center; }

/* ---------- home ---------- */
.hero {
    display: flex;
    align-items: center;
    gap: 18px;
}

.hero-snake {
    font-size: 72px;
    animation: bob 3s ease-in-out infinite;
}

@keyframes bob {
    50% { transform: translateY(-6px) rotate(-4deg); }
}

.game-title {
    font-family: 'Fredoka One', 'Baloo 2', sans-serif;
    font-weight: 400;
    font-size: clamp(42px, 7vw, 62px);
    line-height: 1;
    color: var(--blue-dark);
}

.game-title span { color: #ff9f1c; }
.tagline { font-size: 20px; margin: 6px 0 0; }

.world-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 18px;
    margin-bottom: 18px;
}

.world {
    background: var(--paper);
    border-radius: 26px;
    padding: 18px;
    box-shadow: var(--shadow);
    border-top: 8px solid var(--wc);
}

.world-head { display: flex; gap: 12px; align-items: center; margin-bottom: 10px; }
.world-emoji { font-size: 46px; line-height: 1; }
.world-name { font-family: 'Fredoka One', sans-serif; font-size: 24px; color: var(--wc); }
.world-blurb { font-size: 16px; color: var(--ink-soft); line-height: 1.35; }
.badge { margin-left: 6px; }

.world.soon { opacity: .6; text-align: center; }
.world.soon .world-emoji { filter: grayscale(.6); margin-bottom: 4px; }

.soon-tag {
    display: inline-block;
    margin-top: 8px;
    font-weight: 800;
    font-size: 14px;
    border-radius: 999px;
    padding: 2px 12px;
    background: #ece9f5;
}

.lesson-list { display: flex; flex-direction: column; gap: 8px; }

.lesson-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: 16px;
    background: #fff;
    border: 3px solid #e8e5f0;
    color: var(--ink);
    text-decoration: none;
    font-weight: 700;
    transition: border-color .15s, transform .1s;
}

.lesson-link:hover { border-color: var(--wc); transform: translateX(3px); }
.lesson-link.done { background: var(--good-soft); border-color: #bfe8cd; }

.lesson-num {
    width: 32px;
    height: 32px;
    flex: none;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: var(--wc);
    color: #fff;
    font-weight: 800;
}

.lesson-title { flex: 1; }
.lesson-stars { color: var(--gold); letter-spacing: 1px; font-size: 18px; }

.bonus {
    display: block;
    margin-top: 10px;
    text-align: center;
    font-weight: 800;
    color: var(--wc);
}

.extras { margin-bottom: 10px; }

/* ---------- lesson ---------- */
.lesson-head { margin: 4px 4px 14px; }
.crumb { font-weight: 800; color: var(--wc); }

.lesson-h1 {
    font-family: 'Fredoka One', sans-serif;
    font-weight: 400;
    font-size: clamp(34px, 5vw, 46px);
    line-height: 1.1;
}

.mission {
    font-size: 22px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 14px;
    border-left: 10px solid var(--gold);
}

.mission-tag {
    flex: none;
    background: var(--gold);
    border-radius: 999px;
    padding: 2px 14px;
    font-size: 15px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.learn p { max-width: 860px; }

.step-mark { color: #cfcbe0; font-size: 28px; }
.step-mark.done { color: var(--gold); }

.step.locked > *:not(h2):not(p) { opacity: .45; pointer-events: none; }

/* read-only code to type */
.code-block {
    font-family: var(--mono);
    font-size: 18px;
    line-height: 1.6;
    background: var(--code-bg);
    border-radius: 14px;
    padding: 10px 0;
    margin: 8px 0 14px;
    overflow-x: auto;
    user-select: none;
    -webkit-user-select: none;
}

.code-row { display: flex; padding: 0 14px; white-space: pre; transition: background .2s; }
.code-row .ln { width: 2.2em; flex: none; color: #b1adc2; text-align: right; margin-right: 14px; }
.code-row.ok { background: var(--good-soft); }
.code-row.ok .ln { color: var(--good); font-weight: 700; }

/* ---------- workbench ---------- */
.workbench {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 18px;
    align-items: start;
}

.workbench.has-turtle { grid-template-columns: minmax(0, 1fr) minmax(0, 500px); }

.wb-label {
    font-weight: 800;
    font-size: 15px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--ink-soft);
    margin: 0 0 4px 4px;
}

.editor {
    display: flex;
    border: 3px solid #d7d2e6;
    border-radius: 14px;
    background: #fff;
    overflow: hidden;
    height: 360px;
    resize: vertical;
}

.editor:focus-within { border-color: var(--blue); }

.gutter {
    flex: none;
    width: 3em;
    padding: 10px 8px 10px 0;
    text-align: right;
    font-family: var(--mono);
    font-size: 18px;
    line-height: 1.6;
    color: #b1adc2;
    background: #faf9fd;
    overflow: hidden;
    user-select: none;
}

.gutter .bad { color: #fff; background: var(--bad); border-radius: 0 6px 6px 0; }

.editor-body { position: relative; flex: 1; overflow: hidden; }

.err-line {
    position: absolute;
    left: 0;
    right: 0;
    background: var(--bad-soft);
    pointer-events: none;
}

.editor-text {
    position: relative;
    display: block;
    width: 100%;
    height: 100%;
    border: 0;
    outline: 0;
    resize: none;
    padding: 10px 12px;
    font-family: var(--mono);
    font-size: 18px;
    line-height: 1.6;
    color: var(--ink);
    background: transparent;
    white-space: pre;
    overflow: auto;
    tab-size: 4;
}

.run-row { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.run-row .btn { margin: 4px 0; }
.btn.run { background: var(--good); box-shadow: 0 4px 0 #239150; min-width: 130px; }
.btn.stop { background: var(--bad); color: #fff; box-shadow: 0 4px 0 #c24440; min-width: 130px; }
.run-status { font-weight: 700; color: var(--ink-soft); margin-left: 8px; }
.kbd-hint { margin-left: auto; }

.console {
    font-family: var(--mono);
    font-size: 17px;
    line-height: 1.55;
    background: #23233a;
    color: #e9f5ee;
    border-radius: 14px;
    padding: 12px 14px;
    min-height: 160px;
    max-height: 360px;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-word;
    margin-bottom: 12px;
}

.console-input {
    font: inherit;
    color: #ffe08a;
    background: #35355a;
    border: 0;
    border-bottom: 2px solid #ffe08a;
    outline: 0;
    padding: 0 4px;
    min-width: 8em;
    animation: glow 1.2s ease-in-out infinite alternate;
}

@keyframes glow { to { background: #45457a; } }

.turtle-box {
    background: #fff;
    border: 3px solid #d7d2e6;
    border-radius: 14px;
    overflow: hidden;
    aspect-ratio: 480 / 520;
    width: 100%;
}

.turtle-box canvas { width: 100% !important; height: auto !important; display: block; }
.turtle-box > div { width: 100% !important; height: auto !important; position: relative; }
.turtle-box > div canvas:not(:first-child) { position: absolute; left: 0; top: 0; }

.bug-helper {
    margin-top: 10px;
    background: var(--bad-soft);
    border: 3px solid #f6b9b6;
    border-radius: 14px;
    padding: 10px 14px;
    font-size: 18px;
}

.bug-title { font-weight: 800; color: #b23a36; }
.bug-raw { font-family: var(--mono); font-size: 13px; color: var(--ink-soft); margin-top: 6px; }

/* ---------- challenges & predict ---------- */
.challenges { list-style: none; display: flex; flex-direction: column; gap: 10px; }

.challenges li {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    background: #fff;
    border: 3px solid #e8e5f0;
    border-radius: 16px;
    padding: 10px 14px;
}

.challenges li.done { background: var(--good-soft); border-color: #bfe8cd; }
.ch-star { font-size: 26px; line-height: 1.1; color: #cfcbe0; }
.challenges li.done .ch-star { color: var(--gold); }

.hint-text {
    margin-top: 4px;
    background: #fff7dc;
    border-radius: 10px;
    padding: 6px 10px;
    font-size: 17px;
}

.options { display: flex; flex-wrap: wrap; gap: 4px; }
.btn.option { font-family: var(--mono); font-size: 17px; font-weight: 700; background: #fff; border: 3px solid #e8e5f0; }
.btn.option.right { background: var(--good); color: #fff; border-color: var(--good); opacity: 1; }
.btn.option.wrong { background: var(--bad-soft); border-color: #f6b9b6; text-decoration: line-through; }
.predict-feedback { margin-top: 8px; }
.right-text { font-weight: 700; color: #1f7a45; }
.wrong-text { font-weight: 700; color: #b23a36; }

/* ---------- parent guide ---------- */
.section-h { justify-content: center; margin-top: 24px; }
.answers summary { font-family: 'Fredoka One', sans-serif; font-size: 22px; cursor: pointer; }
.answer { margin-top: 12px; }
.answer-q { font-weight: 700; }
.answer .code-block { user-select: text; -webkit-user-select: text; font-size: 15px; margin: 6px 0; }

/* ---------- toast & overlay ---------- */
.toast {
    position: fixed;
    left: 50%;
    bottom: 26px;
    transform: translateX(-50%);
    background: var(--ink);
    color: #fff;
    font-weight: 800;
    font-size: 20px;
    border-radius: 999px;
    padding: 10px 24px;
    box-shadow: var(--shadow);
    z-index: 40;
    text-align: center;
    max-width: 92vw;
}

.toast.pop { animation: pop .35s ease-out; }

@keyframes pop {
    from { transform: translate(-50%, 30px) scale(.8); opacity: 0; }
}

.overlay {
    position: fixed;
    inset: 0;
    background: rgba(40, 36, 70, .45);
    display: grid;
    place-items: center;
    z-index: 50;
    padding: 16px;
}

.overlay[hidden] { display: none; }
.result-card { text-align: center; max-width: 440px; }
.result-card h2 { justify-content: center; }
.big-emoji { font-size: 76px; line-height: 1.1; }

.credits {
    max-width: 1180px;
    margin: 24px auto 0;
    text-align: center;
    font-size: 14px;
    color: var(--ink-soft);
}

.credits a { color: inherit; }

@media (max-width: 860px) {
    .workbench, .workbench.has-turtle { grid-template-columns: minmax(0, 1fr); }
    .kbd-hint { display: none; }
    .mission { flex-direction: column; align-items: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
    .hero-snake, .console-input, .toast.pop { animation: none; }
}
