#game-root {
    --te-accent: #10B981;
    --te-accent-dark: #0c8d64;
    --te-accent-light: #e3f9ef;
    --te-accent-border: #a7f3d0;
    --te-glass-bg: rgba(255, 255, 255, .72);
    --te-glass-border: rgba(255, 255, 255, .5);
    --te-text: var(--kw-text, #2D2A32);
}

#game-root .kwi-muted { color: #cbd5e1; }

.te-wrap {
    max-width: 920px;
    margin: 0 auto;
}

.te-wrap-narrow {
    max-width: 560px;
}

.te-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: 12px;
}

.te-row-between {
    justify-content: space-between;
}

.te-spacer {
    flex: 1 1 auto;
}

/* ---- loading / error ---- */

.te-status {
    text-align: center;
    padding: 48px 16px;
}

.te-status-icon {
    font-size: 44px;
    margin-bottom: 10px;
    color: #fff;
}

.te-pulse {
    animation: te-pulse 1.2s ease-in-out infinite;
}

.te-status-text {
    font-size: 15px;
    font-weight: 700;
    color: #fff;
    text-shadow: 0 1px 3px rgba(0, 0, 0, .2);
}

.te-status-error {
    display: inline-block;
    background: #EF4444;
    padding: 6px 16px;
    border-radius: 999px;
    text-shadow: none;
}

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

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

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

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

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

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

.te-level-card {
    display: flex;
    flex-direction: column;
    border: 1px solid var(--te-glass-border);
    border-radius: var(--kw-radius, 12px);
    background: var(--te-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;
}

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

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

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

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

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

/* ---- pills and small buttons ---- */

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

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

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

.te-pill-icon svg {
    width: 12px;
    height: 12px;
}

.te-chip-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    border: 1px solid var(--te-glass-border);
    background: var(--te-glass-bg);
    color: var(--te-accent-dark);
    border-radius: 999px;
    font-weight: 800;
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
    padding: 7px 12px 7px 10px;
    transition: transform .1s ease, background .15s ease;
}

.te-chip-btn svg {
    width: 12px;
    height: 12px;
}

.te-chip-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, .9);
    transform: translateY(-1px);
}

.te-chip-btn:disabled {
    opacity: .5;
    cursor: default;
}

/* ---- setup ---- */

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

.te-panel-title {
    font-size: 16px;
    font-weight: 900;
    color: var(--te-accent-dark);
    margin-bottom: 10px;
}

.te-topic-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.te-topic {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 16px;
    border: 2px solid var(--te-accent-border);
    border-radius: 999px;
    background: #fff;
    color: var(--te-text);
    font-size: 15px;
    font-weight: 800;
    cursor: pointer;
    transition: transform .1s ease, background .12s ease;
}

.te-topic:hover {
    transform: translateY(-1px);
}

.te-topic.te-selected {
    background: var(--te-accent);
    border-color: var(--te-accent-dark);
    color: #fff;
}

.te-topic-emoji {
    font-size: 16px;
    line-height: 1;
}

.te-how {
    text-align: center;
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    text-shadow: 0 1px 3px rgba(0, 0, 0, .25);
    margin: 4px 8px 14px;
}

.te-btn-primary,
.te-btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: none;
    padding: 12px 20px;
    border-radius: 999px;
    font-weight: 800;
    font-size: 14px;
    cursor: pointer;
    transition: transform .1s ease;
}

.te-btn-primary svg,
.te-btn-secondary svg {
    width: 14px;
    height: 14px;
}

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

.te-btn-primary:hover {
    transform: translateY(-1px);
}

.te-btn-secondary {
    background: var(--te-accent-light);
    color: var(--te-accent-dark);
}

.te-btn-secondary:hover {
    background: var(--te-accent-border);
}

.te-btn-big {
    display: flex;
    width: 100%;
    max-width: 320px;
    margin: 0 auto;
    padding: 16px 24px;
    font-size: 19px;
    box-shadow: 0 4px 0 var(--te-accent-dark);
}

.te-btn-big svg {
    width: 18px;
    height: 18px;
}

/* ---- race ---- */

.te-toolbar {
    margin-bottom: 8px;
}

.te-stage {
    position: relative;
    border-radius: var(--kw-radius, 12px);
    overflow: hidden;
    box-shadow: 0 4px 16px rgba(0, 0, 0, .18);
    background: #d6eeff;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

.te-canvas {
    display: block;
    width: 100%;
    height: 300px;
}

.te-paused {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    width: 100%;
    border: none;
    background: rgba(15, 23, 42, .45);
    color: #fff;
    cursor: pointer;
    font: inherit;
}

.te-paused[hidden] {
    display: none;
}

.te-paused-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--te-accent);
    box-shadow: 0 4px 0 var(--te-accent-dark);
}

.te-paused-icon svg {
    width: 30px;
    height: 30px;
}

.te-paused-title {
    font-size: 24px;
    font-weight: 900;
}

.te-paused-sub {
    font-size: 14px;
    font-weight: 700;
    opacity: .9;
}

/* ---- results ---- */

.te-done-card {
    text-align: center;
    background: var(--te-glass-bg);
    backdrop-filter: blur(14px) saturate(160%);
    -webkit-backdrop-filter: blur(14px) saturate(160%);
    border: 1px solid var(--te-glass-border);
    border-radius: var(--kw-radius, 12px);
    padding: 20px 18px 22px;
    box-shadow: 0 3px 12px rgba(0, 0, 0, .12);
    animation: te-pop-in .3s ease;
}

.te-done-hero {
    position: relative;
    display: inline-block;
}

.te-medal {
    position: absolute;
    top: 0;
    right: -14px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    color: #fff;
    box-shadow: 0 3px 0 rgba(0, 0, 0, .15);
}

.te-medal svg {
    width: 24px;
    height: 24px;
}

.te-done-title {
    font-size: 22px;
    font-weight: 900;
    color: var(--te-accent-dark);
    margin: 6px 0 4px;
}

.te-done-stars {
    color: #f59e0b;
    font-size: 24px;
    letter-spacing: 3px;
}

.te-star svg {
    width: 24px;
    height: 24px;
}

.te-done-score {
    font-size: 16px;
    font-weight: 700;
    color: #4b5563;
    margin: 4px 0 10px;
}

.te-done-score b {
    color: var(--te-text);
    font-size: 20px;
}

.te-done-stats {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
    margin-bottom: 12px;
}

.te-done-stats[hidden] {
    display: none;
}

.te-stat {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 5px 10px;
    border-radius: 999px;
    background: var(--te-accent-light);
    color: var(--te-accent-dark);
    font-size: 13px;
    font-weight: 800;
}

.te-stat svg {
    width: 13px;
    height: 13px;
}

.te-stat-fire {
    background: #fff7ed;
    color: #ea580c;
}

.te-done-share {
    justify-content: center;
    margin-top: 14px;
}

.te-done-actions {
    justify-content: center;
    margin-top: 16px;
}

/* ---- setup: bunnies ---- */

.te-bunny-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.te-bunny-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 6px 4px 10px;
    border: 3px solid transparent;
    border-radius: var(--kw-radius, 12px);
    background: #fff;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, .08);
    transition: transform .12s ease, border-color .12s ease, box-shadow .12s ease;
}

.te-bunny-card:hover {
    transform: translateY(-3px);
}

.te-bunny-card.te-selected {
    border-color: var(--te-bunny);
    background: color-mix(in srgb, var(--te-bunny) 16%, #fff);
    box-shadow: 0 6px 14px rgba(0, 0, 0, .14);
}

.te-bunny-canvas {
    display: block;
    width: 100%;
    max-width: 112px;
    aspect-ratio: 140 / 150;
    height: auto;
}

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

.te-pill-bunny {
    background: color-mix(in srgb, var(--te-bunny) 25%, #fff);
    color: #1f2937;
    box-shadow: inset 0 0 0 2px var(--te-bunny);
}

/* ---- run: HUD over the 3D scene ---- */

.te-hud {
    position: absolute;
    top: 10px;
    left: 10px;
    right: 10px;
    display: flex;
    align-items: center;
    gap: 8px;
    pointer-events: none;
}

.te-hud-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 11px;
    border-radius: 999px;
    background: rgba(255, 255, 255, .85);
    color: #3b2a14;
    font-size: 15px;
    font-weight: 900;
    line-height: 1.1;
    box-shadow: 0 2px 6px rgba(0, 0, 0, .15);
}

.te-hud-pill svg {
    width: 14px;
    height: 14px;
    color: var(--te-accent-dark);
}

.te-hud-emoji {
    font-size: 16px;
    line-height: 1;
}

.te-bump {
    animation: te-bump .25s ease;
}

.te-hud-danger {
    gap: 2px;
    padding: 4px 8px;
}

.te-monkey {
    font-size: 17px;
    line-height: 1;
    filter: grayscale(1);
    opacity: .3;
    transition: opacity .2s ease, filter .2s ease, transform .2s ease;
}

.te-monkey-on {
    filter: none;
    opacity: 1;
    transform: scale(1.12);
}

.te-hud-alarm {
    background: #fee2e2;
    box-shadow: 0 0 0 2px #ef4444, 0 2px 6px rgba(0, 0, 0, .15);
    animation: te-alarm .8s ease-in-out infinite;
}

.te-turn {
    position: absolute;
    left: 50%;
    top: 46%;
    transform: translateX(-50%);
    padding: 8px 20px;
    border-radius: 999px;
    background: #ffd6e7;
    color: #be185d;
    font-size: 26px;
    font-weight: 900;
    box-shadow: 0 4px 0 #f472b6;
    pointer-events: none;
    white-space: nowrap;
    animation: te-turn-pulse .5s ease-in-out infinite alternate;
}

.te-turn[hidden] {
    display: none;
}

.te-pops {
    position: absolute;
    left: 0;
    right: 0;
    top: 38%;
    display: flex;
    flex-direction: column;
    align-items: center;
    pointer-events: none;
}

.te-pop {
    font-size: 34px;
    font-weight: 900;
    color: #10B981;
    -webkit-text-stroke: 1px rgba(0, 0, 0, .2);
    text-shadow: 0 2px 0 #fff, 0 0 12px rgba(255, 255, 255, .9);
    animation: te-pop-up 1.2s ease forwards;
    white-space: nowrap;
}

.te-pop-bad { color: #fb7185; }
.te-pop-warn { color: #f97316; font-size: 26px; }
.te-pop-super { color: #f59e0b; font-size: 40px; }

.te-count {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 96px;
    font-weight: 900;
    color: #f472b6;
    text-shadow: 0 4px 0 #fff, 0 0 18px rgba(255, 255, 255, .8);
    pointer-events: none;
}

.te-count-pop {
    animation: te-count .9s ease forwards;
}

.te-count-go {
    color: #10B981;
}

.te-help {
    position: absolute;
    left: 50%;
    bottom: 12px;
    transform: translateX(-50%);
    max-width: calc(100% - 24px);
    padding: 6px 14px;
    border-radius: 999px;
    background: rgba(15, 23, 42, .62);
    color: #fff;
    font-size: 13px;
    font-weight: 800;
    text-align: center;
    pointer-events: none;
    transition: opacity .5s ease;
}

.te-help-hide {
    opacity: 0;
}

.te-flash {
    position: absolute;
    inset: 0;
    pointer-events: none;
    opacity: 0;
}

.te-flash-hit {
    background: radial-gradient(ellipse at center, transparent 45%, rgba(239, 68, 68, .55));
    animation: te-flash .45s ease;
}

.te-flash-good {
    background: radial-gradient(ellipse at center, transparent 50%, rgba(16, 185, 129, .4));
    animation: te-flash .5s ease;
}

.te-flash-exit {
    background: #fffbea;
    animation: te-flash-exit 2.4s ease forwards;
}

/* touch pad under the scene */

.te-pad {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

.te-pad-btn {
    flex: 1 1 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-height: 50px;
    border: none;
    border-radius: var(--kw-radius, 12px);
    background: rgba(255, 255, 255, .85);
    color: var(--te-accent-dark);
    font-size: 14px;
    font-weight: 900;
    box-shadow: 0 3px 0 rgba(0, 0, 0, .15);
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
}

.te-pad-btn svg {
    width: 22px;
    height: 22px;
}

.te-pad-btn:active {
    transform: translateY(2px);
    box-shadow: 0 1px 0 rgba(0, 0, 0, .15);
}

/* results extras */

.te-done-bunny {
    display: block;
    width: 150px;
    height: auto;
    aspect-ratio: 160 / 170;
}

.te-medal {
    background: #f59e0b;
}

.te-medal-caught {
    background: #fde68a;
    font-size: 26px;
}

.te-stat-coin {
    background: #fffbeb;
    color: #b45309;
}

.te-practice {
    max-width: 380px;
    margin: 4px auto 0;
    padding: 10px 14px;
    border-radius: 12px;
    background: #fff;
    text-align: left;
}

.te-practice[hidden] {
    display: none;
}

.te-practice-title {
    font-size: 14px;
    font-weight: 900;
    color: #dc2626;
    margin-bottom: 4px;
}

.te-practice ul {
    margin: 0;
    padding-left: 20px;
}

.te-practice li {
    font-size: 16px;
    font-weight: 800;
    color: var(--te-text);
    line-height: 1.5;
}

.te-retry {
    margin-top: 14px;
}

/* ---- phones ---- */

@media (max-width: 560px) {
    .te-pill-topic,
    .te-pill-bunny {
        display: none;
    }

    .te-help {
        font-size: 12px;
        padding: 5px 10px;
        bottom: 8px;
    }

    .te-bunny-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 6px;
    }

    .te-bunny-name {
        font-size: 13px;
    }

    .te-hud-pill {
        font-size: 13px;
        padding: 4px 9px;
    }

    .te-monkey {
        font-size: 14px;
    }

    .te-turn {
        font-size: 21px;
    }

    .te-pop {
        font-size: 28px;
    }

    .te-count {
        font-size: 72px;
    }
}

@keyframes te-pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.15); opacity: .7; }
}

@keyframes te-card-in {
    from { opacity: .4; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes te-pop-in {
    0% { transform: scale(.85); }
    100% { transform: scale(1); }
}

@keyframes te-shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-6px); }
    40% { transform: translateX(6px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(4px); }
}

@keyframes te-bump {
    0% { transform: scale(1); }
    50% { transform: scale(1.18); }
    100% { transform: scale(1); }
}

@keyframes te-alarm {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.06); }
}

@keyframes te-turn-pulse {
    from { transform: translateX(-50%) scale(1); }
    to { transform: translateX(-50%) scale(1.1); }
}

@keyframes te-pop-up {
    0% { opacity: 0; transform: translateY(10px) scale(.7); }
    15% { opacity: 1; transform: translateY(0) scale(1.1); }
    25% { transform: scale(1); }
    75% { opacity: 1; }
    100% { opacity: 0; transform: translateY(-30px); }
}

@keyframes te-count {
    0% { opacity: 0; transform: scale(1.6); }
    20% { opacity: 1; transform: scale(1); }
    80% { opacity: 1; }
    100% { opacity: 0; transform: scale(.9); }
}

@keyframes te-flash {
    0% { opacity: 1; }
    100% { opacity: 0; }
}

@keyframes te-flash-exit {
    0% { opacity: 0; }
    35% { opacity: .2; }
    100% { opacity: 1; }
}
