#game-root {
    --rb-accent: #10B981;
    --rb-accent-dark: #0c8d64;
    --rb-accent-light: #e3f9ef;
    --rb-accent-border: #a7f3d0;
    --rb-glass-bg: rgba(255, 255, 255, .7);
    --rb-glass-border: rgba(255, 255, 255, .5);
    --rb-text: var(--kw-text, #2D2A32);
    /* Command-block colors, one per kind of block (like Scratch's). */
    --rb-move: #3B82F6;
    --rb-move-dark: #1d4ed8;
    --rb-tool: #8B5CF6;
    --rb-tool-dark: #6d28d9;
    --rb-loop: #F59E0B;
    --rb-loop-dark: #b45309;
    --rb-sense: #EC4899;
    --rb-sense-dark: #be185d;
}

/*
 * The kwi-* modifier classes game.js passes to KidWorldIcons.svg() are only
 * ever *named* by the shared icon helper, never defined by it, so the
 * tier/status colors are given real values here, scoped to this game.
 */
#game-root .kwi-accent { color: var(--rb-accent); }
#game-root .kwi-success { color: #10B981; }
#game-root .kwi-danger { color: #EF4444; }
#game-root .kwi-trophy { color: #F59E0B; }
#game-root .kwi-muted { color: #cbd5e1; }

.kwg-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: 14px;
}

.rb-wrap {
    max-width: 1100px;
    margin: 0 auto;
}

.rb-wrap-mid {
    max-width: 760px;
}

.rb-wrap-narrow {
    max-width: 480px;
}

.rb-glyph {
    width: 1.15em;
    height: 1.15em;
    flex: 0 0 auto;
    vertical-align: -0.2em;
}

.rb-loading,
.rb-error {
    text-align: center;
    padding: 48px 16px;
}

.rb-loading-icon,
.rb-error-icon {
    font-size: 40px;
    margin-bottom: 10px;
}

.rb-loading-icon {
    animation: rb-pulse-kf 1.2s ease-in-out infinite;
}

.rb-loading-text {
    font-size: 15px;
    color: #fff;
    text-shadow: 0 1px 3px rgba(0, 0, 0, .2);
}

.rb-error-text {
    font-size: 15px;
    font-weight: 700;
    color: #fff;
    background: #EF4444;
    display: inline-block;
    padding: 6px 16px;
    border-radius: 999px;
}

/* ---- level picker ---- */

.rb-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 18px;
}

.rb-header-icon {
    display: flex;
    font-size: 30px;
    line-height: 1;
}

.rb-header-icon img {
    display: block;
    height: 38px;
    width: auto;
}

.rb-header-title {
    font-size: 22px;
    font-weight: 800;
    color: #fff;
    text-shadow: 0 1px 3px rgba(0, 0, 0, .2);
}

.rb-levels {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
}

.rb-level-card {
    display: flex;
    flex-direction: column;
    border: 1px solid var(--rb-glass-border);
    border-radius: var(--kw-radius, 12px);
    background: var(--rb-glass-bg);
    backdrop-filter: blur(14px) saturate(160%);
    -webkit-backdrop-filter: blur(14px) saturate(160%);
    padding: 0;
    cursor: pointer;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .12);
    transition: transform .15s ease, box-shadow .15s ease;
}

.rb-level-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 10px 18px rgba(0, 0, 0, .14);
}

.rb-level-thumb {
    margin-top: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 70px;
    font-size: 36px;
    background: linear-gradient(135deg, var(--rb-accent-light), var(--rb-accent-border));
    background-size: 70px 70px;
    background-repeat: no-repeat;
    background-position: center;
}

.rb-level-body {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 12px 10px 16px;
}

.rb-level-name {
    font-size: 17px;
    font-weight: 800;
    color: var(--rb-text);
    text-align: center;
}

.rb-level-age {
    font-size: 14px;
    font-weight: 700;
    color: var(--rb-accent-dark);
    background: var(--rb-accent-light);
    padding: 2px 10px;
    border-radius: 999px;
}

.rb-level-count {
    font-size: 12px;
    font-weight: 700;
    color: #64748b;
}

.rb-level-row {
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.rb-level-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: var(--rb-accent-light);
    color: var(--rb-accent-dark);
    border-radius: 999px;
    padding: 6px 12px;
    font-weight: 700;
    font-size: 12px;
}

.rb-level-pill-icon {
    display: inline-flex;
    line-height: 1;
}

.rb-level-pill-icon img {
    display: block;
    width: 14px;
    height: 14px;
    object-fit: cover;
    border-radius: 50%;
}

.rb-change-level-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    border: 1px solid var(--rb-glass-border);
    background: var(--rb-glass-bg);
    color: var(--rb-accent-dark);
    border-radius: 999px;
    font-weight: 700;
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
    padding: 6px 12px 6px 10px;
}

.rb-change-level-btn svg {
    width: 12px;
    height: 12px;
}

/* ---- shared buttons ---- */

.rb-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: none;
    background: #fff;
    color: var(--rb-accent-dark);
    border-radius: 999px;
    padding: 9px 16px;
    min-height: 40px;
    font-weight: 800;
    font-size: 14px;
    cursor: pointer;
    box-shadow: 0 2px 0 rgba(0, 0, 0, .12);
    transition: transform .1s ease, background .15s ease, opacity .15s ease;
    -webkit-tap-highlight-color: transparent;
}

.rb-btn:hover:not(:disabled) {
    transform: translateY(-1px);
    background: var(--rb-accent-light);
}

.rb-btn:disabled {
    opacity: .45;
    cursor: default;
}

.rb-btn svg {
    width: 16px;
    height: 16px;
}

.rb-btn-primary {
    background: var(--rb-accent);
    color: #fff;
    box-shadow: 0 3px 0 var(--rb-accent-dark);
}

.rb-btn-primary:hover:not(:disabled) {
    background: var(--rb-accent);
}

.rb-btn-big {
    font-size: 16px;
    padding: 12px 24px;
}

.rb-btn-icon {
    padding: 9px 12px;
}

.rb-btn-on {
    background: var(--rb-accent-light);
}

.rb-btn-run {
    background: var(--rb-accent);
    color: #fff;
    box-shadow: 0 3px 0 var(--rb-accent-dark);
    min-width: 96px;
    font-size: 15px;
}

.rb-btn-run:hover:not(:disabled) {
    background: var(--rb-accent);
}

.rb-btn-pause {
    background: #F59E0B;
    box-shadow: 0 3px 0 #b45309;
}

.rb-btn-pause:hover:not(:disabled) {
    background: #F59E0B;
}

.rb-chip-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    border: 1px solid var(--rb-glass-border);
    background: var(--rb-glass-bg);
    color: var(--rb-accent-dark);
    border-radius: 999px;
    font-weight: 800;
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
    padding: 8px 12px;
    white-space: nowrap;
}

.rb-chip-btn svg {
    width: 14px;
    height: 14px;
}

.rb-chip-accent {
    background: var(--rb-accent);
    border-color: var(--rb-accent-dark);
    color: #fff;
}

.rb-round-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: #fff;
    color: var(--rb-accent-dark);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 0 rgba(0, 0, 0, .12);
}

.rb-link-btn {
    border: none;
    background: none;
    color: #fff;
    opacity: .85;
    font-size: 12px;
    font-weight: 700;
    text-decoration: underline;
    cursor: pointer;
}

/* ---- top bar ---- */

.rb-topbar {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.rb-topbar-title {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
    font-size: 19px;
    font-weight: 800;
    color: #fff;
    text-shadow: 0 1px 3px rgba(0, 0, 0, .25);
    text-align: center;
    min-width: 0;
}

.rb-mnum {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 28px;
    padding: 0 6px;
    border-radius: 8px;
    background: #fff;
    color: var(--rb-accent-dark);
    font-size: 15px;
    text-shadow: none;
}

.rb-best {
    display: inline-flex;
    gap: 1px;
}

.rb-star {
    display: inline-flex;
    color: rgba(255, 255, 255, .55);
}

.rb-star svg {
    width: 1em;
    height: 1em;
}

.rb-star-on {
    color: #FACC15;
    filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .25));
}

.rb-best .rb-star {
    font-size: 15px;
}

/* ---- mission map ---- */

.rb-hero {
    display: flex;
    align-items: center;
    gap: 16px;
    background: var(--rb-glass-bg);
    backdrop-filter: blur(14px) saturate(160%);
    -webkit-backdrop-filter: blur(14px) saturate(160%);
    border: 1px solid var(--rb-glass-border);
    border-radius: var(--kw-radius, 12px);
    padding: 12px 18px 12px 12px;
    margin-bottom: 14px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .1);
}

.rb-hero-canvas {
    width: 140px;
    height: 140px;
    flex: 0 0 auto;
    image-rendering: pixelated;
    cursor: pointer;
}

.rb-hero-body {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
}

.rb-hero-title {
    font-size: 22px;
    font-weight: 900;
    color: var(--rb-text);
}

.rb-hero-sub {
    font-size: 14px;
    font-weight: 600;
    color: #475569;
}

.rb-hero-stars {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-weight: 800;
    color: var(--rb-text);
}

.rb-missions {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 10px;
}

.rb-mcard {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    text-align: left;
    border: 1px solid var(--rb-glass-border);
    border-radius: var(--kw-radius, 12px);
    background: var(--rb-glass-bg);
    padding: 12px;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, .1);
    transition: transform .15s ease, box-shadow .15s ease;
}

.rb-mcard:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 16px rgba(0, 0, 0, .14);
}

.rb-mcard-num {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    flex: 0 0 auto;
    border-radius: 10px;
    background: var(--rb-accent);
    color: #fff;
    font-size: 18px;
    font-weight: 900;
    box-shadow: 0 3px 0 var(--rb-accent-dark);
}

.rb-mcard-body {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
    flex: 1 1 auto;
}

.rb-mcard-title {
    font-size: 15px;
    font-weight: 800;
    color: var(--rb-text);
}

.rb-mcard-concept {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    font-weight: 700;
    color: #64748b;
}

.rb-mcard-stars {
    display: inline-flex;
    font-size: 15px;
}

.rb-mcard-stars .rb-star {
    color: #cbd5e1;
}

.rb-mcard-stars .rb-star-on {
    color: #F59E0B;
}

.rb-mcard-new {
    position: absolute;
    top: -8px;
    right: 10px;
    background: #8B5CF6;
    color: #fff;
    font-size: 11px;
    font-weight: 800;
    border-radius: 999px;
    padding: 2px 8px;
}

.rb-mcard-next {
    border: 2px solid var(--rb-accent);
    animation: rb-glow-kf 1.6s ease-in-out infinite;
}

.rb-mcard-locked {
    opacity: .6;
    cursor: default;
}

.rb-mcard-locked .rb-mcard-num {
    background: #94a3b8;
    box-shadow: 0 3px 0 #64748b;
}

.rb-mcard-locked:hover {
    transform: none;
}

.rb-map-foot {
    text-align: center;
    margin-top: 14px;
}

/* ---- workshop ---- */

.rb-ws-hello {
    text-align: center;
    font-size: 15px;
    font-weight: 700;
    color: #fff;
    text-shadow: 0 1px 3px rgba(0, 0, 0, .25);
    margin-bottom: 10px;
}

.rb-ws {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr);
    gap: 14px;
    background: var(--rb-glass-bg);
    backdrop-filter: blur(14px) saturate(160%);
    -webkit-backdrop-filter: blur(14px) saturate(160%);
    border: 1px solid var(--rb-glass-border);
    border-radius: var(--kw-radius, 12px);
    padding: 14px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .1);
    margin-bottom: 14px;
}

.rb-ws-preview {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    border-radius: 10px;
    background: linear-gradient(#bfe6ff, #eaf7ff);
    padding: 10px;
}

.rb-ws-canvas {
    width: 100%;
    max-width: 280px;
    aspect-ratio: 1 / 1;
    image-rendering: pixelated;
    cursor: pointer;
}

.rb-ws-rotate {
    display: flex;
    gap: 10px;
}

.rb-ws-abilities {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 5px;
}

.rb-ws-ab-title {
    width: 100%;
    text-align: center;
    font-size: 12px;
    font-weight: 800;
    color: #334155;
}

.rb-ab {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    font-weight: 800;
    color: #94a3b8;
    background: rgba(255, 255, 255, .7);
    border-radius: 999px;
    padding: 3px 9px;
}

.rb-ab-on {
    color: #fff;
    background: var(--rb-accent);
}

.rb-ws-parts {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 0;
}

.rb-ws-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.rb-ws-tab {
    border: none;
    background: #fff;
    color: #475569;
    border-radius: 999px;
    padding: 7px 12px;
    font-size: 13px;
    font-weight: 800;
    cursor: pointer;
}

.rb-ws-tab-on {
    background: var(--rb-accent);
    color: #fff;
}

.rb-ws-options {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
    gap: 8px;
}

.rb-part {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    border: 3px solid transparent;
    border-radius: 12px;
    background: #fff;
    padding: 6px 4px 8px;
    cursor: pointer;
    box-shadow: 0 2px 0 rgba(0, 0, 0, .1);
    transition: transform .1s ease;
}

.rb-part:hover {
    transform: translateY(-2px);
}

.rb-part-on {
    border-color: var(--rb-accent);
    background: var(--rb-accent-light);
}

.rb-part-canvas {
    width: 64px;
    height: 64px;
    image-rendering: pixelated;
}

.rb-part-name {
    font-size: 12px;
    font-weight: 800;
    color: var(--rb-text);
    text-align: center;
}

.rb-part-gives {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 11px;
    font-weight: 800;
    color: #fff;
    background: var(--rb-tool);
    border-radius: 999px;
    padding: 1px 7px;
}

.rb-part-locked {
    cursor: help;
}

.rb-part-locked .rb-part-canvas {
    filter: grayscale(1) brightness(.6);
    opacity: .5;
}

.rb-part-lock {
    position: absolute;
    top: 6px;
    right: 6px;
    color: #64748b;
}

.rb-ws-desc {
    min-height: 20px;
    font-size: 13px;
    font-weight: 700;
    color: #334155;
}

.rb-ws-needs {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    font-size: 13px;
}

.rb-ws-needs[hidden] {
    display: none;
}

.rb-ws-needs-title {
    font-weight: 800;
    color: #334155;
}

.rb-ws-actions {
    justify-content: center;
}

/* ---- mission screen ---- */

.rb-brief {
    text-align: center;
    font-size: 15px;
    font-weight: 800;
    color: #fff;
    text-shadow: 0 1px 3px rgba(0, 0, 0, .3);
    margin-bottom: 6px;
}

.rb-tip {
    font-weight: 600;
    opacity: .92;
}

.rb-goals {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
    margin-bottom: 10px;
}

.rb-goal {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: var(--rb-glass-bg);
    border: 1px solid var(--rb-glass-border);
    color: var(--rb-text);
    border-radius: 999px;
    padding: 4px 11px;
    font-size: 12px;
    font-weight: 700;
}

.rb-goal svg {
    width: 12px;
    height: 12px;
    color: #cbd5e1;
}

.rb-goal-met {
    background: var(--rb-accent);
    border-color: var(--rb-accent-dark);
    color: #fff;
}

.rb-goal-met svg {
    color: #FACC15;
}

.rb-main {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
}

@media (min-width: 900px) {
    .rb-main {
        grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr);
        align-items: start;
    }
}

.rb-stage {
    position: relative;
    border-radius: var(--kw-radius, 12px);
    overflow: hidden;
    background: linear-gradient(#8fd3ff 0%, #c9ecff 70%, #e8f7ff 100%);
    box-shadow: 0 3px 10px rgba(0, 0, 0, .18);
}

.rb-canvas {
    display: block;
    width: 100%;
    height: 300px;
    image-rendering: pixelated;
}

.rb-toast {
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    width: max-content;
    max-width: calc(100% - 24px);
    background: rgba(20, 20, 20, .8);
    color: #fff;
    font-size: 14px;
    font-weight: 700;
    line-height: 1.35;
    text-align: center;
    padding: 8px 14px;
    border-radius: 10px;
    pointer-events: none;
    z-index: 2;
}

.rb-toast[hidden] {
    display: none;
}

.rb-toast-in {
    animation: rb-toast-kf .25s ease;
}

.rb-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
    background: rgba(15, 23, 42, .35);
    z-index: 3;
    overflow-y: auto;
    animation: rb-fade-kf .2s ease;
}

.rb-overlay[hidden] {
    display: none;
}

.rb-result,
.rb-intro {
    width: 100%;
    max-width: 440px;
    max-height: 100%;
    overflow-y: auto;
    background: #fff;
    border-radius: 16px;
    padding: 16px 18px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, .25);
    animation: rb-pop-kf .3s ease;
}

.rb-result-title,
.rb-intro-title {
    font-size: 22px;
    font-weight: 900;
    color: var(--rb-text);
    margin-bottom: 6px;
}

.rb-result-stars {
    display: flex;
    justify-content: center;
    gap: 4px;
    font-size: 38px;
    margin-bottom: 8px;
}

.rb-result-stars .rb-star {
    color: #e2e8f0;
}

.rb-result-stars .rb-star-on {
    color: #F59E0B;
    animation: rb-pop-kf .4s ease both;
}

.rb-result-stars .rb-star-on:nth-child(2) { animation-delay: .15s; }
.rb-result-stars .rb-star-on:nth-child(3) { animation-delay: .3s; }

.rb-result-list {
    list-style: none;
    margin: 0 auto 8px;
    padding: 0;
    display: inline-flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    font-size: 14px;
    font-weight: 700;
}

.rb-result-list li {
    display: flex;
    align-items: center;
    gap: 6px;
}

.rb-ok { color: #047857; }
.rb-miss { color: #94a3b8; }

.rb-result-score {
    font-size: 18px;
    font-weight: 900;
    color: var(--rb-accent-dark);
    margin-bottom: 6px;
}

.rb-result-tip {
    font-size: 13px;
    font-weight: 700;
    color: #92400e;
    background: #fef3c7;
    border-radius: 10px;
    padding: 7px 10px;
    margin-bottom: 8px;
}

.rb-result-final {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: 15px;
    font-weight: 900;
    color: var(--rb-text);
    margin-bottom: 8px;
}

.rb-result-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin-top: 6px;
}

.rb-result .rb-btn,
.rb-intro .rb-btn {
    background: #f1f5f9;
}

.rb-result .rb-btn-primary,
.rb-intro .rb-btn-primary {
    background: var(--rb-accent);
}

.rb-share {
    justify-content: center;
    margin-top: 10px;
}

.rb-intro {
    text-align: left;
}

.rb-intro-title {
    text-align: center;
}

.rb-intro-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px solid #f1f5f9;
}

.rb-intro-item:last-of-type {
    border-bottom: none;
}

.rb-intro-block {
    flex: 0 0 auto;
    width: 48px;
    height: 48px;
    justify-content: center;
    padding: 0;
    cursor: default;
}

.rb-intro-block .rb-glyph {
    width: 26px;
    height: 26px;
}

.rb-intro-part {
    width: 56px;
    height: 56px;
    flex: 0 0 auto;
    image-rendering: pixelated;
}

.rb-intro-emoji {
    font-size: 34px;
    width: 48px;
    text-align: center;
    flex: 0 0 auto;
}

.rb-intro-name {
    font-size: 15px;
    font-weight: 900;
    color: var(--rb-text);
}

.rb-intro-text {
    font-size: 13px;
    font-weight: 600;
    color: #475569;
    line-height: 1.4;
}

.rb-needs {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
    padding: 6px 10px;
    border-radius: 12px;
    background: #fff7ed;
    border: 1px solid #fed7aa;
    font-size: 13px;
}

.rb-needs[hidden] {
    display: none;
}

.rb-needs-ok {
    background: var(--rb-glass-bg);
    border-color: var(--rb-glass-border);
}

.rb-needs-title {
    font-weight: 800;
    color: #334155;
}

.rb-need {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-weight: 800;
    color: #b91c1c;
    background: #fee2e2;
    border-radius: 999px;
    padding: 2px 9px;
}

.rb-need svg {
    width: 13px;
    height: 13px;
}

.rb-need-ok {
    color: #047857;
    background: #d1fae5;
}

.rb-controls {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin-top: 10px;
}

/* ---- code panels ---- */

.rb-col-code {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 0;
}

.rb-panel {
    background: var(--rb-glass-bg);
    backdrop-filter: blur(14px) saturate(160%);
    -webkit-backdrop-filter: blur(14px) saturate(160%);
    border: 1px solid var(--rb-glass-border);
    border-radius: var(--kw-radius, 12px);
    padding: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .1);
}

.rb-panel-head {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.rb-panel-title {
    font-size: 15px;
    font-weight: 900;
    color: var(--rb-text);
}

.rb-panel-sub {
    font-size: 12px;
    font-weight: 700;
    color: #64748b;
}

.rb-count {
    font-size: 12px;
    font-weight: 800;
    color: var(--rb-accent-dark);
    background: var(--rb-accent-light);
    border-radius: 999px;
    padding: 2px 8px;
}

.rb-count-over {
    color: #92400e;
    background: #fef3c7;
}

.rb-panel-tools {
    margin-left: auto;
    display: flex;
    gap: 6px;
}

.rb-tool-btn {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    border: none;
    background: #fff;
    color: #475569;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 0 rgba(0, 0, 0, .1);
}

.rb-tool-btn svg {
    width: 15px;
    height: 15px;
}

.rb-palette {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.rb-pal {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: none;
    border-radius: 10px;
    padding: 8px 12px 8px 10px;
    min-height: 42px;
    font-size: 14px;
    font-weight: 800;
    color: #fff;
    cursor: pointer;
    text-shadow: 0 1px 0 rgba(0, 0, 0, .2);
    transition: transform .1s ease, filter .15s ease;
    -webkit-tap-highlight-color: transparent;
}

.rb-pal:hover {
    transform: translateY(-2px);
    filter: brightness(1.06);
}

.rb-pal:active {
    transform: translateY(1px);
}

.rb-pal .rb-glyph {
    width: 20px;
    height: 20px;
}

.rb-pal-locked {
    filter: grayscale(.85);
    opacity: .6;
}

.rb-pal-lock {
    position: absolute;
    top: -6px;
    right: -6px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #334155;
    color: #fff;
    font-size: 11px;
}

.rb-g-move { background: var(--rb-move); box-shadow: 0 3px 0 var(--rb-move-dark); }
.rb-g-tool { background: var(--rb-tool); box-shadow: 0 3px 0 var(--rb-tool-dark); }
.rb-g-loop { background: var(--rb-loop); box-shadow: 0 3px 0 var(--rb-loop-dark); }
.rb-g-sense { background: var(--rb-sense); box-shadow: 0 3px 0 var(--rb-sense-dark); }

.rb-program {
    position: relative;
    min-height: 120px;
    max-height: 360px;
    overflow-y: auto;
    border-radius: 10px;
    background: rgba(255, 255, 255, .75);
    padding: 8px;
    cursor: text;
    -webkit-overflow-scrolling: touch;
}

@media (min-width: 900px) {
    .rb-program {
        max-height: 420px;
    }
}

.rb-program-busy {
    cursor: default;
}

/* Blocks are dragged to reorder them: no text selection or iOS long-press menu. */
.rb-program .rb-block,
.rb-program .rb-c-head {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

.rb-program-dragging,
.rb-program-dragging * {
    cursor: grabbing !important;
}

.rb-program-dragging .rb-caret {
    display: none;
}

.rb-dragging {
    opacity: .3;
}

#game-root .rb-ghost {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1000;
    margin: 0;
    pointer-events: none;
    opacity: .92;
    box-shadow: 0 10px 22px rgba(0, 0, 0, .28);
    rotate: -2deg;
}

#game-root .rb-ghost .rb-del,
#game-root .rb-ghost .rb-badge {
    display: none !important;
}

.rb-drop {
    height: 8px;
    border-radius: 4px;
    background: var(--rb-accent);
    box-shadow: 0 0 0 3px rgba(16, 185, 129, .3);
}

.rb-list {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.rb-list-root {
    min-height: 100px;
}

.rb-empty {
    font-size: 13px;
    font-weight: 700;
    color: #94a3b8;
    text-align: center;
    padding: 14px 6px;
}

.rb-block,
.rb-c-head {
    position: relative;
    display: flex;
    align-items: center;
    gap: 7px;
    min-height: 38px;
    padding: 6px 36px 6px 10px;
    border-radius: 9px;
    color: #fff;
    font-size: 14px;
    font-weight: 800;
    text-shadow: 0 1px 0 rgba(0, 0, 0, .2);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.rb-block .rb-glyph,
.rb-c-head .rb-glyph {
    width: 19px;
    height: 19px;
}

.rb-c {
    border-radius: 10px;
    padding: 0 0 0 0;
    box-shadow: none;
}

.rb-c.rb-g-loop { background: var(--rb-loop); }
.rb-c.rb-g-sense { background: var(--rb-sense); }

.rb-c-body {
    margin-left: 16px;
    padding: 5px 6px 5px 6px;
    border-radius: 8px 0 0 8px;
    background: rgba(255, 255, 255, .88);
    min-height: 30px;
}

.rb-c-mid {
    padding: 4px 12px;
    color: #fff;
    font-size: 13px;
    font-weight: 900;
    cursor: pointer;
    text-shadow: 0 1px 0 rgba(0, 0, 0, .2);
}

.rb-c-foot {
    height: 14px;
    cursor: pointer;
    border-radius: 0 0 10px 10px;
}

.rb-slot-empty {
    font-size: 12px;
    font-weight: 700;
    color: #94a3b8;
    border: 2px dashed #cbd5e1;
    border-radius: 8px;
    padding: 5px 8px;
    text-align: center;
    cursor: pointer;
}

.rb-caret {
    height: 5px;
    border-radius: 3px;
    background: var(--rb-accent);
    box-shadow: 0 0 0 2px rgba(16, 185, 129, .25);
    animation: rb-blink-kf 1s ease-in-out infinite;
}

.rb-del {
    position: absolute;
    top: 50%;
    right: 5px;
    transform: translateY(-50%);
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: none;
    background: rgba(0, 0, 0, .25);
    color: #fff;
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.rb-del svg {
    width: 12px;
    height: 12px;
}

.rb-block.rb-selected > .rb-del,
.rb-c.rb-selected > .rb-c-head > .rb-del {
    display: inline-flex;
}

.rb-block.rb-selected,
.rb-c.rb-selected > .rb-c-head {
    outline: 3px solid #0f172a;
    outline-offset: 1px;
}

.rb-stepper {
    display: inline-flex;
    align-items: center;
    background: rgba(0, 0, 0, .18);
    border-radius: 999px;
    padding: 2px;
}

.rb-step-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: none;
    background: #fff;
    color: var(--rb-loop-dark);
    font-size: 18px;
    font-weight: 900;
    line-height: 1;
    cursor: pointer;
    padding: 0;
}

.rb-num {
    min-width: 26px;
    text-align: center;
    font-size: 16px;
}

.rb-times {
    font-weight: 700;
    opacity: .9;
}

.rb-cond {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    border: none;
    background: #fff;
    color: var(--rb-sense-dark);
    border-radius: 999px;
    padding: 4px 9px 4px 4px;
    font-size: 13px;
    font-weight: 800;
    cursor: pointer;
    text-shadow: none;
}

.rb-cond svg {
    width: 11px;
    height: 11px;
}

.rb-cond-img {
    width: 20px;
    height: 20px;
    border-radius: 5px;
    image-rendering: pixelated;
}

.rb-badge {
    display: none;
    margin-left: auto;
    font-size: 12px;
    font-weight: 900;
    background: #fff;
    color: #0f172a;
    border-radius: 999px;
    padding: 1px 8px;
    text-shadow: none;
}

.rb-badge-on {
    display: inline-block;
}

/* Run-time states. */

.rb-block.rb-running,
.rb-c.rb-running > .rb-c-head {
    box-shadow: 0 0 0 3px #fff, 0 0 0 6px #FACC15;
    transform: scale(1.02);
}

.rb-c.rb-check-yes > .rb-c-head {
    box-shadow: 0 0 0 3px #fff, 0 0 0 6px #22c55e;
}

.rb-c.rb-check-no > .rb-c-head {
    box-shadow: 0 0 0 3px #fff, 0 0 0 6px #ef4444;
}

.rb-block.rb-error,
.rb-c.rb-error > .rb-c-head {
    background: #EF4444;
    box-shadow: 0 0 0 3px #fff, 0 0 0 6px #b91c1c;
    animation: rb-shake-kf .4s ease;
}

.rb-block.rb-next,
.rb-c.rb-next > .rb-c-head {
    box-shadow: 0 0 0 3px #fff, 0 0 0 6px rgba(250, 204, 21, .6);
}

.rb-pop {
    animation: rb-pop-kf .25s ease;
}

.rb-glow {
    animation: rb-hint-kf .8s ease-in-out 3;
}

.rb-pulse {
    animation: rb-hint-kf .7s ease-in-out 2;
}

.rb-shake {
    animation: rb-shake-kf .4s ease;
}

/* ---- phone ---- */

@media (max-width: 560px) {
    .rb-hide-xs {
        display: none;
    }

    .rb-topbar-title {
        font-size: 16px;
    }

    .rb-ws {
        grid-template-columns: minmax(0, 1fr);
    }

    .rb-hero-canvas {
        width: 104px;
        height: 104px;
    }

    .rb-hero-title {
        font-size: 18px;
    }

    .rb-levels {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .rb-pal {
        padding: 7px 10px 7px 8px;
        font-size: 13px;
    }

    .rb-btn {
        padding: 8px 12px;
        font-size: 13px;
    }

    .rb-controls {
        gap: 6px;
    }
}

/* ---- keyframes ---- */

@keyframes rb-pulse-kf {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.12); }
}

@keyframes rb-toast-kf {
    from { opacity: 0; transform: translate(-50%, -6px); }
    to { opacity: 1; transform: translate(-50%, 0); }
}

@keyframes rb-fade-kf {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes rb-pop-kf {
    0% { transform: scale(.7); opacity: 0; }
    70% { transform: scale(1.06); opacity: 1; }
    100% { transform: scale(1); }
}

@keyframes rb-blink-kf {
    0%, 100% { opacity: 1; }
    50% { opacity: .35; }
}

@keyframes rb-shake-kf {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-5px); }
    40% { transform: translateX(5px); }
    60% { transform: translateX(-3px); }
    80% { transform: translateX(3px); }
}

@keyframes rb-hint-kf {
    0%, 100% { box-shadow: 0 0 0 0 rgba(250, 204, 21, 0); }
    50% { box-shadow: 0 0 0 6px rgba(250, 204, 21, .95); transform: translateY(-2px); }
}

@keyframes rb-glow-kf {
    0%, 100% { box-shadow: 0 2px 6px rgba(0, 0, 0, .1); }
    50% { box-shadow: 0 0 0 4px rgba(16, 185, 129, .35); }
}
