        :root {
            --bg: #0f0d1a;
            --bg2: #1a1628;
            --card: #1e1a2e;
            --border: rgba(160, 130, 255, .18);
            --accent: #a78bfa;
            --accent2: #f59e0b;
            --green: #34d399;
            --red: #f87171;
            --blue: #38bdf8;
            --text: #e8e0ff;
            --muted: #8b80a8;
            --cell: 52px;
            --radius: 12px;
        }

        html[data-theme=light] {
            --bg: #f5f0ff;
            --bg2: #ede8ff;
            --card: #fff;
            --border: rgba(120, 90, 220, .2);
            --text: #1a1030;
            --muted: #7060a0;
        }

        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0
        }

        body {
            background: var(--bg);
            color: var(--text);
            font-family: 'Segoe UI', system-ui, sans-serif;
            min-height: 100vh
        }

        body::before {
            content: '';
            position: fixed;
            inset: 0;
            z-index: -1;
            background: radial-gradient(ellipse 70% 50% at 20% 10%, rgba(167, 139, 250, .08), transparent 60%),
                radial-gradient(ellipse 60% 40% at 80% 80%, rgba(245, 158, 11, .05), transparent 60%);
            pointer-events: none
        }

        /* ── Header ── */
        header {
            background: linear-gradient(135deg, rgba(30, 26, 46, .98), rgba(15, 13, 26, .98));
            border-bottom: 1px solid var(--border);
            padding: .5rem 1.5rem;
            display: flex;
            align-items: center;
            gap: 1rem;
            position: sticky;
            top: 0;
            z-index: 100;
            backdrop-filter: blur(12px)
        }

        .logo {
            font-size: 1.4rem;
            font-weight: 900;
            background: linear-gradient(135deg, #a78bfa, #f59e0b);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            white-space: nowrap
        }

        .theme-btn {
            background: rgba(167, 139, 250, .1);
            border: 1px solid var(--border);
            border-radius: 8px;
            padding: .35rem .65rem;
            cursor: pointer;
            color: var(--text);
            font-size: .85rem;
            margin-left: auto
        }

        /* ── Worlds Grid ── */
        .worlds-wrap {
            max-width: 1100px;
            margin: 0 auto;
            padding: 2rem 1rem
        }

        .worlds-hero {
            text-align: center;
            padding: 2rem 1rem 2.5rem;
            margin-bottom: 2rem;
            background: linear-gradient(135deg, rgba(167, 139, 250, .06), rgba(245, 158, 11, .04));
            border: 1px solid var(--border);
            border-radius: 18px
        }

        .worlds-hero h1 {
            font-size: 2rem;
            font-weight: 900
        }

        .worlds-hero h1 span {
            background: linear-gradient(135deg, #a78bfa, #f59e0b);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent
        }

        .worlds-hero p {
            color: var(--muted);
            margin-top: .5rem
        }

        .worlds-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
            gap: 1.2rem
        }

        .world-card {
            background: var(--card);
            border: 1px solid var(--border);
            border-radius: 18px;
            overflow: hidden;
            cursor: pointer;
            transition: all .2s
        }

        .world-card:hover {
            transform: translateY(-3px);
            box-shadow: 0 12px 40px rgba(167, 139, 250, .15)
        }

        .world-card.locked {
            opacity: .5;
            cursor: not-allowed
        }

        .world-header {
            padding: 1.2rem 1.5rem;
            border-bottom: 1px solid var(--border)
        }

        .world-icon {
            font-size: 2rem
        }

        .world-name {
            font-size: 1.05rem;
            font-weight: 800;
            margin-top: .3rem
        }

        .world-desc {
            font-size: .82rem;
            color: var(--muted);
            margin-top: .3rem;
            line-height: 1.5
        }

        .world-progress {
            padding: .8rem 1.5rem;
            display: flex;
            align-items: center;
            gap: .8rem
        }

        .progress-track {
            flex: 1;
            height: 6px;
            background: rgba(167, 139, 250, .15);
            border-radius: 3px;
            overflow: hidden
        }

        .progress-fill {
            height: 100%;
            border-radius: 3px;
            transition: width .5s
        }

        .world-stars {
            font-size: .82rem;
            color: var(--muted)
        }

        /* ── Level List ── */
        .level-list {
            max-width: 800px;
            margin: 0 auto;
            padding: 1.5rem 1rem
        }

        .level-back {
            display: flex;
            align-items: center;
            gap: .6rem;
            margin-bottom: 1.5rem;
            cursor: pointer;
            color: var(--muted);
            font-size: .88rem;
            font-weight: 600;
            width: fit-content
        }

        .level-back:hover {
            color: var(--text)
        }

        .level-item {
            background: var(--card);
            border: 1px solid var(--border);
            border-radius: 14px;
            padding: 1rem 1.3rem;
            margin-bottom: .7rem;
            cursor: pointer;
            transition: all .2s;
            display: flex;
            align-items: center;
            gap: 1rem
        }

        .level-item:hover:not(.locked) {
            border-color: var(--accent);
            background: rgba(167, 139, 250, .07);
            transform: translateX(4px)
        }

        .level-item.done {
            border-color: rgba(52, 211, 153, .35);
            background: rgba(52, 211, 153, .04)
        }

        .level-item.locked {
            opacity: .45;
            cursor: not-allowed
        }

        .level-item.boss {
            border-color: rgba(248, 113, 113, .4);
            background: rgba(248, 113, 113, .05)
        }

        .level-num {
            width: 36px;
            height: 36px;
            border-radius: 50%;
            background: rgba(167, 139, 250, .15);
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: .82rem;
            font-weight: 800;
            flex-shrink: 0
        }

        .level-item.done .level-num {
            background: rgba(52, 211, 153, .2);
            color: var(--green)
        }

        .level-item.boss .level-num {
            background: rgba(248, 113, 113, .2);
            color: var(--red)
        }

        .level-info {
            flex: 1
        }

        .level-name {
            font-size: .92rem;
            font-weight: 700
        }

        .level-meta {
            font-size: .74rem;
            color: var(--muted);
            margin-top: .2rem
        }

        .level-stars {
            font-size: 1rem;
            letter-spacing: 2px
        }

        .diff-badge {
            font-size: .65rem;
            font-weight: 700;
            padding: .1rem .45rem;
            border-radius: 4px;
            text-transform: uppercase
        }

        .diff-badge.easy {
            background: rgba(52, 211, 153, .15);
            color: var(--green)
        }

        .diff-badge.medium {
            background: rgba(245, 158, 11, .15);
            color: var(--accent2)
        }

        .diff-badge.hard {
            background: rgba(248, 113, 113, .15);
            color: var(--red)
        }

        /* ── Game Modal ── */
        .modal-overlay {
            display: none;
            position: fixed;
            inset: 0;
            z-index: 500;
            background: rgba(0, 0, 0, .75);
            backdrop-filter: blur(6px);
            align-items: flex-start;
            justify-content: center;
            padding: 1rem;
            overflow-y: auto
        }

        .modal-overlay.open {
            display: flex
        }

        .game-modal {
            background: var(--card);
            border: 1px solid var(--border);
            border-radius: 20px;
            width: min(1060px, 100%);
            margin: auto;
            box-shadow: 0 20px 60px rgba(0, 0, 0, .5)
        }

        .game-header {
            display: flex;
            align-items: center;
            gap: .8rem;
            padding: .9rem 1.2rem;
            border-bottom: 1px solid var(--border);
            background: linear-gradient(135deg, rgba(167, 139, 250, .06), transparent)
        }

        .game-title {
            font-size: .95rem;
            font-weight: 800;
            flex: 1
        }

        .btn-close {
            background: rgba(248, 113, 113, .1);
            border: 1px solid rgba(248, 113, 113, .3);
            border-radius: 8px;
            padding: .3rem .7rem;
            cursor: pointer;
            color: var(--red);
            font-size: .82rem
        }

        .btn-close:hover {
            background: rgba(248, 113, 113, .2)
        }

        .game-body {
            display: grid;
            grid-template-columns: 1fr 420px;
            gap: 0;
            min-height: 500px
        }

        .game-left {
            padding: 1rem;
            display: flex;
            flex-direction: column;
            gap: .7rem;
            border-right: 1px solid var(--border)
        }

        .game-right {
            padding: 1rem;
            display: flex;
            flex-direction: column;
            gap: .7rem;
            overflow-y: auto;
            max-height: 85vh
        }

        /* ── Aufgabe & API ── */
        .task-box {
            background: rgba(167, 139, 250, .06);
            border: 1px solid rgba(167, 139, 250, .2);
            border-left: 3px solid var(--accent);
            border-radius: 10px;
            padding: .7rem 1rem;
            font-size: .83rem;
            line-height: 1.6
        }

        .task-goal {
            background: rgba(52, 211, 153, .08);
            border: 1px solid rgba(52, 211, 153, .2);
            border-radius: 6px;
            padding: .35rem .7rem;
            font-size: .78rem;
            margin-top: .5rem;
            color: var(--green)
        }

        .api-list {
            display: flex;
            flex-wrap: wrap;
            gap: .35rem
        }

        .api-chip {
            background: rgba(167, 139, 250, .1);
            border: 1px solid rgba(167, 139, 250, .2);
            border-radius: 6px;
            padding: .2rem .5rem;
            font-size: .73rem;
            font-family: monospace;
            cursor: default
        }

        .api-chip:hover {
            background: rgba(167, 139, 250, .2)
        }

        .api-chip-desc {
            font-size: .66rem;
            color: var(--muted);
            display: block
        }

        /* ── Canvas ── */
        .canvas-wrap {
            position: relative;
            flex-shrink: 0
        }

        #adv-canvas {
            border-radius: 10px;
            border: 1px solid var(--border);
            display: block
        }

        /* ── Editor ── */
        .editor-label {
            font-size: .7rem;
            color: var(--muted);
            text-transform: uppercase;
            letter-spacing: .06em;
            font-weight: 700
        }

        .code-wrap {
            display: flex;
            border: 1px solid var(--border);
            border-radius: 10px;
            overflow: hidden;
            resize: both;
            min-height: 160px;
            background: rgba(0, 0, 0, .25)
        }

        .code-wrap:focus-within {
            border-color: var(--accent)
        }

        .line-nums {
            flex: 0 0 38px;
            background: rgba(0, 0, 0, .2);
            border-right: 1px solid var(--border);
            padding: .6rem 0;
            text-align: right;
            font-family: monospace;
            font-size: .82rem;
            line-height: 1.6em;
            color: var(--muted);
            opacity: .6;
            overflow: hidden;
            user-select: none;
            pointer-events: none
        }

        .line-nums span {
            display: block;
            padding-right: 6px;
            height: 1.6em
        }

        .code-editor {
            flex: 1 1 auto;
            width: 0;
            padding: .6rem .6rem .6rem 8px;
            background: transparent;
            color: var(--text);
            border: none;
            outline: none;
            resize: none;
            font-family: monospace;
            font-size: .82rem;
            line-height: 1.6em;
            tab-size: 4;
            white-space: pre;
            overflow: auto
        }

        /* ── Buttons ── */
        .btn {
            display: inline-flex;
            align-items: center;
            gap: .35rem;
            padding: .42rem .85rem;
            border-radius: 8px;
            font-size: .8rem;
            font-weight: 700;
            cursor: pointer;
            transition: all .2s;
            border: 1px solid var(--border);
            background: transparent;
            color: var(--text)
        }

        .btn:disabled {
            opacity: .4;
            cursor: not-allowed
        }

        .btn-run {
            background: linear-gradient(135deg, var(--accent), #7c3aed);
            color: #fff;
            border: none;
            box-shadow: 0 4px 15px rgba(167, 139, 250, .25)
        }

        .btn-run:hover:not(:disabled) {
            box-shadow: 0 8px 25px rgba(167, 139, 250, .4)
        }

        .btn-stop {
            background: linear-gradient(135deg, #f87171, #ef4444);
            color: #fff;
            border: none;
            display: none
        }

        .btn-stop.vis {
            display: inline-flex
        }

        .btn-hint {
            color: var(--accent2);
            border-color: rgba(245, 158, 11, .3)
        }

        .btn-reset {
            color: var(--muted)
        }

        .btn-sol {
            color: #fbbf24;
            border-color: rgba(251, 191, 36, .3)
        }

        .btn-sol:hover {
            background: rgba(251, 191, 36, .08)
        }

        .btn-next {
            background: linear-gradient(135deg, var(--green), #059669);
            color: #fff;
            border: none;
            font-weight: 800
        }

        .act-row {
            display: flex;
            gap: .4rem;
            flex-wrap: wrap
        }

        /* ── Output / Feedback ── */
        .output-box {
            background: rgba(0, 0, 0, .3);
            border: 1px solid var(--border);
            border-radius: 8px;
            padding: .55rem .8rem;
            font-family: monospace;
            font-size: .8rem;
            line-height: 1.5;
            white-space: pre-wrap;
            min-height: 32px;
            color: var(--green)
        }

        .err-box {
            background: rgba(248, 113, 113, .08);
            border: 1px solid rgba(248, 113, 113, .3);
            border-radius: 8px;
            padding: .55rem .8rem;
            font-size: .8rem;
            line-height: 1.6;
            display: none
        }

        .err-box.show {
            display: block
        }

        .err-type {
            font-weight: 800;
            color: var(--red)
        }

        .hint-box {
            background: rgba(245, 158, 11, .07);
            border: 1px solid rgba(245, 158, 11, .3);
            border-left: 3px solid var(--accent2);
            border-radius: 8px;
            padding: .6rem .8rem;
            font-size: .8rem;
            display: none
        }

        .hint-box.show {
            display: block
        }

        .sol-box {
            background: rgba(251, 191, 36, .06);
            border: 1px solid rgba(251, 191, 36, .3);
            border-left: 3px solid #fbbf24;
            border-radius: 8px;
            padding: .6rem .8rem;
            font-size: .8rem;
            display: none
        }

        .sol-box.show {
            display: block
        }

        .sol-box pre {
            font-family: monospace;
            font-size: .78rem;
            white-space: pre-wrap
        }

        .sol-nopt {
            color: var(--red);
            font-size: .72rem;
            margin-top: .35rem;
            font-style: italic
        }

        /* ── Result Banner ── */
        .result-banner {
            display: none;
            border-radius: 12px;
            padding: .8rem 1rem;
            border: 1px solid var(--border)
        }

        .result-banner.show {
            display: block
        }

        .result-banner.success {
            background: rgba(52, 211, 153, .08);
            border-color: rgba(52, 211, 153, .4)
        }

        .result-banner.partial {
            background: rgba(245, 158, 11, .08);
            border-color: rgba(245, 158, 11, .4)
        }

        .result-banner.fail {
            background: rgba(248, 113, 113, .08);
            border-color: rgba(248, 113, 113, .4)
        }

        .rb-top {
            display: flex;
            align-items: center;
            gap: .5rem;
            font-weight: 800;
            font-size: .92rem
        }

        .rb-stars {
            font-size: 1.2rem;
            letter-spacing: 2px
        }

        .rb-msg {
            font-size: .8rem;
            color: var(--muted);
            margin-top: .25rem
        }

        .rb-btns {
            margin-top: .7rem;
            display: flex;
            gap: .5rem;
            flex-wrap: wrap
        }

        .goals-list {
            display: flex;
            flex-direction: column;
            gap: .25rem;
            margin-top: .4rem
        }

        .goal-item {
            font-size: .77rem;
            display: flex;
            align-items: center;
            gap: .4rem
        }

        /* ── Run Indicator ── */
        .run-ind {
            display: none;
            align-items: center;
            gap: .4rem;
            font-size: .78rem;
            color: var(--accent);
            font-weight: 700
        }

        .run-ind.vis {
            display: flex
        }

        .spinner {
            width: 13px;
            height: 13px;
            border: 2px solid rgba(167, 139, 250, .2);
            border-top-color: var(--accent);
            border-radius: 50%;
            animation: spin .7s linear infinite
        }

        @keyframes spin {
            to {
                transform: rotate(360deg)
            }
        }

        /* ── Lösungs-Modal (Name-Dialog-Style) ── */
        #name-overlay {
            display: none;
            position: fixed;
            inset: 0;
            z-index: 9999;
            background: rgba(0, 0, 0, .7);
            backdrop-filter: blur(4px);
            align-items: center;
            justify-content: center
        }

        #name-overlay.show {
            display: flex
        }

        #name-dialog {
            background: var(--card);
            border: 1px solid var(--border);
            border-radius: 18px;
            padding: 1.8rem;
            width: min(400px, 92vw);
            box-shadow: 0 20px 60px rgba(0, 0, 0, .5)
        }

        #name-input {
            width: 100%;
            padding: .6rem .9rem;
            font-size: .95rem;
            border: 1px solid var(--border);
            border-radius: 8px;
            background: rgba(0, 0, 0, .2);
            color: var(--text);
            outline: none;
            margin-bottom: .2rem
        }

        #name-input:focus {
            border-color: var(--accent)
        }

        #name-err {
            color: var(--red);
            font-size: .78rem;
            min-height: 1.2em;
            margin-bottom: .5rem
        }

        /* ── Konfetti ── */
        .kfp {
            position: fixed;
            top: -10px;
            border-radius: 2px;
            pointer-events: none;
            z-index: 9997;
            animation: kfall 3s ease-in forwards
        }

        @keyframes kfall {
            to {
                transform: translateY(110vh) rotate(720deg);
                opacity: 0
            }
        }

        /* ── Toast ── */
        .toast {
            position: fixed;
            bottom: 1.5rem;
            left: 50%;
            transform: translateX(-50%);
            background: var(--card);
            border: 1px solid var(--border);
            border-radius: 30px;
            padding: .5rem 1.2rem;
            font-size: .85rem;
            font-weight: 700;
            z-index: 9998;
            box-shadow: 0 8px 30px rgba(0, 0, 0, .4);
            pointer-events: none
        }

        /* ── Speed-Slider ── */
        .speed-wrap {
            display: flex;
            align-items: center;
            gap: .4rem;
            font-size: .75rem;
            color: var(--muted)
        }

        .speed-wrap input {
            flex: 1;
            accent-color: var(--accent);
            cursor: pointer
        }

        /* ── Responsive ── */
        @media(max-width:700px) {
            .game-body {
                grid-template-columns: 1fr
            }

            .game-right {
                border-top: 1px solid var(--border);
                max-height: none
            }
        }

        html[data-theme=light] .code-editor {
            color: #1a1030
        }

        html[data-theme=light] .output-box {
            color: #059669;
            background: rgba(15, 23, 42, .03)
        }

        html[data-theme=light] .line-nums {
            background: rgba(15, 23, 42, .04)
        }

        html[data-theme=light] .code-wrap {
            background: rgba(15, 23, 42, .03)
        }
    
