#game-root {
    --tw-accent: #10B981;
    --tw-accent-dark: #0c8d64;
    --tw-accent-light: #e3f9ef;
    --tw-accent-border: #a7f3d0;
    --tw-glass-bg: rgba(255, 255, 255, .62);
    --tw-glass-border: rgba(255, 255, 255, .45);
    /* Palette chrome modeled on Minecraft's gray inventory UI. */
    --tw-slot-bg: #8b8b8b;
    --tw-slot-light: #ffffff;
    --tw-slot-dark: #373737;
    --tw-panel: #c6c6c6;
}

/*
 * 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(--tw-accent); }
#game-root .kwi-success { color: #10B981; }
#game-root .kwi-danger { color: #EF4444; }
#game-root .kwi-trophy { color: #F59E0B; }
#game-root .kwi-stars { color: #8B5CF6; }
#game-root .kwi-thumbsup { color: #10B981; }
#game-root .kwi-lightning { color: #3B82F6; }
#game-root .kwi-smile { color: #F472B6; }
#game-root .kwi-muted { color: #cbd5e1; }

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

.tw-wrap {
    max-width: 860px;
    margin: 0 auto;
}

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

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

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

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

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

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

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

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

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

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

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

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

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

.tw-level-card:active {
    transform: translateY(-1px);
}

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

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

.tw-level-name {
    font-size: 17px;
    font-weight: 800;
    color: var(--kw-text, #2D2A32);
    text-align: center;
}

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

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

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

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

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

.tw-change-level-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    border: 1px solid var(--tw-glass-border);
    background: var(--tw-glass-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: var(--tw-accent-dark);
    border-radius: 999px;
    font-weight: 700;
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
    padding: 6px 12px 6px 10px;
    transition: transform .1s ease, background .15s ease;
}

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

.tw-change-level-btn:hover {
    background: rgba(255, 255, 255, .8);
    transform: translateY(-1px);
}

/* ---- quest card & village chips ---- */

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

.tw-quest-pic {
    width: 46px;
    height: 46px;
    flex: 0 0 auto;
}

.tw-quest-emoji {
    font-size: 34px;
    line-height: 1;
    flex: 0 0 auto;
}

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

.tw-quest-title {
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--tw-accent-dark);
}

.tw-quest-text {
    font-size: 15px;
    font-weight: 800;
    line-height: 1.25;
    color: var(--kw-text, #2D2A32);
}

.tw-quest-bar {
    display: block;
    height: 8px;
    border-radius: 999px;
    background: rgba(0, 0, 0, .1);
    overflow: hidden;
}

.tw-quest-fill {
    display: block;
    height: 100%;
    border-radius: 999px;
    background: var(--tw-accent);
    transition: width .3s ease;
}

.tw-quest-count {
    flex: 0 0 auto;
    font-size: 15px;
    font-weight: 900;
    color: var(--tw-accent-dark);
    font-variant-numeric: tabular-nums;
}

.tw-quest-unlock {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 10px;
    font-weight: 800;
    text-transform: uppercase;
    color: #777;
    border-left: 1px dashed rgba(0, 0, 0, .15);
    padding-left: 10px;
}

.tw-quest-unlock img {
    width: 36px;
    height: 36px;
    filter: grayscale(.6);
    opacity: .85;
}

.tw-quest-done {
    background: var(--tw-accent);
    border-color: var(--tw-accent-dark);
}

.tw-quest-done .tw-quest-title,
.tw-quest-done .tw-quest-text {
    color: #fff;
}

.tw-chips {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
    margin-bottom: 8px;
}

.tw-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--tw-glass-bg);
    border: 1px solid var(--tw-glass-border);
    color: var(--kw-text, #2D2A32);
    border-radius: 999px;
    padding: 3px 10px;
    font-size: 12px;
    font-weight: 700;
}

/* ---- island stage ---- */

.tw-stage {
    position: relative;
    border-radius: var(--kw-radius, 12px);
    overflow: hidden;
    box-shadow: 0 3px 10px rgba(0, 0, 0, .2);
    background: #2f86d0;
}

.tw-canvas {
    display: block;
    width: 100%;
    cursor: pointer;
    /* Drags paint pieces (or pan with the Move tool), so the page must not
       scroll or zoom under the finger. */
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}

.tw-view-btns {
    position: absolute;
    top: 8px;
    right: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.tw-view-btn {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 10px;
    background: rgba(0, 0, 0, .3);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background .15s ease;
}

.tw-view-btn:hover:not(:disabled) {
    background: rgba(0, 0, 0, .45);
}

.tw-view-btn:disabled {
    opacity: .35;
    cursor: default;
}

.tw-view-btn svg {
    width: 17px;
    height: 17px;
}

.tw-toast {
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    max-width: calc(100% - 110px);
    background: rgba(20, 20, 20, .78);
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    line-height: 1.35;
    text-align: center;
    padding: 7px 14px;
    border-radius: 10px;
    pointer-events: none;
}

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

.tw-toast-show {
    animation: tw-toast-in .25s ease;
}

/* ---- palette ---- */

.tw-palette {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(54px, 1fr));
    gap: 4px;
    margin-top: 10px;
    padding: 5px;
    background: var(--tw-panel);
    border: 3px solid;
    border-color: var(--tw-slot-light) var(--tw-slot-dark) var(--tw-slot-dark) var(--tw-slot-light);
    border-radius: 6px;
}

.tw-slot {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    min-height: 64px;
    padding: 3px 2px;
    background: var(--tw-slot-bg);
    border: 3px solid;
    border-color: var(--tw-slot-dark) var(--tw-slot-light) var(--tw-slot-light) var(--tw-slot-dark);
    border-radius: 2px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.tw-slot-pic {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
}

.tw-slot-pic img {
    width: 40px;
    height: 40px;
}

.tw-slot-emoji {
    font-size: 26px;
    line-height: 1;
}

.tw-slot-label {
    font-size: 10px;
    font-weight: 800;
    color: #fff;
    text-shadow: 1px 1px 0 #3f3f3f;
    white-space: nowrap;
}

.tw-slot-selected {
    border-color: #fff;
    box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--tw-accent);
    background: #a3a3a3;
    z-index: 1;
}

.tw-slot-lock,
.tw-slot-new {
    display: none;
    position: absolute;
    pointer-events: none;
}

.tw-slot-locked {
    cursor: help;
}

.tw-slot-locked .tw-slot-pic,
.tw-slot-locked .tw-slot-label {
    filter: grayscale(1) brightness(.55);
    opacity: .6;
}

.tw-slot-locked .tw-slot-lock {
    display: block;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -60%);
    font-size: 20px;
}

.tw-slot-fresh .tw-slot-new {
    display: block;
    top: -6px;
    right: -6px;
    background: #F59E0B;
    color: #fff;
    font-size: 9px;
    font-weight: 900;
    padding: 1px 5px;
    border-radius: 999px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
}

.tw-slot-fresh {
    animation: tw-wiggle 1s ease-in-out 3;
}

/* ---- controls ---- */

.tw-control-row {
    justify-content: center;
    margin-top: 12px;
    margin-bottom: 0;
}

.tw-btn {
    border: none;
    background: var(--tw-accent-light);
    color: var(--tw-accent-dark);
    border-radius: 999px;
    padding: 9px 16px;
    font-weight: 800;
    font-size: 13px;
    cursor: pointer;
    transition: transform .1s ease, background .15s ease;
}

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

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

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

.tw-btn-finish:hover:not(:disabled) {
    background: var(--tw-accent);
}

.tw-tip {
    min-height: 20px;
    margin-top: 10px;
    font-size: 13px;
    font-weight: 700;
    line-height: 1.35;
    text-align: center;
    color: #fff;
    text-shadow: 0 1px 3px rgba(0, 0, 0, .25);
}

/* ---- result screen ---- */

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

.tw-done-emoji {
    font-size: 56px;
    margin-bottom: 8px;
}

.tw-done-title {
    font-size: 20px;
    font-weight: 800;
    color: var(--tw-accent-dark);
    margin-bottom: 12px;
}

.tw-done-shot-wrap {
    margin: 0 auto 12px;
}

.tw-done-shot {
    display: block;
    max-width: 100%;
    margin: 0 auto;
    border-radius: 8px;
    border: 3px solid #fff;
    box-shadow: 0 3px 10px rgba(0, 0, 0, .2);
    image-rendering: pixelated;
}

.tw-done-score {
    font-size: 16px;
    font-weight: 600;
    color: #555;
    margin-bottom: 10px;
}

.tw-done-meta {
    display: flex;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}

.tw-done-meta-item {
    background: var(--tw-accent-light);
    color: var(--tw-accent-dark);
    border-radius: 999px;
    padding: 4px 12px;
    font-size: 12px;
    font-weight: 700;
}

.tw-done-stars {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 4px;
    font-size: 24px;
}

.tw-done-share {
    justify-content: center;
    margin-top: 16px;
}

.tw-done-actions {
    justify-content: center;
    margin-top: 20px;
}

.tw-btn-primary,
.tw-btn-secondary {
    border: none;
    padding: 12px 22px;
    border-radius: 999px;
    font-weight: 800;
    font-size: 14px;
    cursor: pointer;
    transition: transform .1s ease;
}

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

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

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

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

@keyframes tw-fade-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

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

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

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

@keyframes tw-wiggle {
    0%, 100% { transform: rotate(0); }
    25% { transform: rotate(-6deg) scale(1.06); }
    75% { transform: rotate(6deg) scale(1.06); }
}

@media (max-width: 576px) {
    .tw-toast {
        max-width: calc(100% - 64px);
        font-size: 12px;
    }

    .tw-view-btns {
        top: 6px;
        right: 6px;
        gap: 4px;
    }

    .tw-view-btn {
        width: 32px;
        height: 32px;
    }

    .tw-quest {
        padding: 8px 10px;
        gap: 8px;
    }

    .tw-quest-pic {
        width: 38px;
        height: 38px;
    }

    .tw-quest-text {
        font-size: 13px;
    }

    .tw-quest-unlock {
        display: none;
    }

    .tw-palette {
        grid-template-columns: repeat(auto-fill, minmax(52px, 1fr));
    }
}
