#game-root {
    --sp-accent: #10B981;
    --sp-accent-dark: #0e9c6f;
    --sp-accent-light: #e3f9ef;
    --sp-accent-border: #a7f3d0;
    border-radius: var(--kw-radius, 16px);
}

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

.sp-wrap {
    max-width: 460px;
    margin: 0 auto;
}

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

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

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

.sp-loading-text {
    font-size: 15px;
    color: #666;
}

.sp-error-text {
    font-size: 15px;
    font-weight: 700;
    color: #EF4444;
}

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

.sp-header-icon {
    display: flex;
    line-height: 1;
}

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

.sp-header-title {
    font-weight: 800;
    color: var(--sp-accent);
}

.sp-setup-panel {
    background: #fff;
    border-radius: var(--kw-radius, 16px);
    padding: 16px;
    margin-bottom: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .06);
}

.sp-setup-label {
    font-size: 14px;
    font-weight: 800;
    color: var(--sp-accent-dark);
    text-align: left;
    margin-bottom: 12px;
}

.sp-mode-row {
    justify-content: flex-start;
    margin-bottom: 0;
}

.sp-mode-btn {
    position: relative;
    border: 2px solid var(--sp-accent-border);
    background: #fff;
    color: var(--sp-accent-dark);
    border-radius: 999px;
    padding: 8px 18px;
    font-weight: 700;
    font-size: 13px;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, .06);
    transition: transform .1s ease, background .15s ease, border-color .15s ease, color .15s ease, box-shadow .15s ease;
}

.sp-mode-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, .1);
}

/* Compound selector (see .sp-level-card.sp-level-card-selected below for
   why) so the selected ring still wins while hovering. */
.sp-mode-btn.sp-mode-btn-active {
    border-color: var(--sp-accent);
    background: var(--sp-accent-light);
    color: var(--sp-accent-dark);
}

.sp-mode-btn-active::after {
    content: '✓';
    position: absolute;
    top: -6px;
    right: -6px;
    width: 18px;
    height: 18px;
    background: var(--sp-accent);
    color: #fff;
    border-radius: 50%;
    font-size: 11px;
    font-weight: 800;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
}

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

.sp-level-card {
    position: relative;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    border: 2px solid var(--sp-accent-border);
    border-radius: var(--kw-radius, 16px);
    background: #fff;
    padding: 0;
    cursor: pointer;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .08);
    transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease, background .15s ease;
}

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

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

/* Compound selector (matches .sp-level-card:hover's specificity, and is
   declared after it) so the selected ring still wins while hovering -
   .sp-level-card-selected alone would lose to :hover's box-shadow, since
   a single class has lower specificity than class+pseudo-class. Mirrors
   .sp-mode-btn.sp-mode-btn-active above so Level and Theme share one
   selected look: accent border + tinted background + inset ring + a
   small ✓ badge (same treatment mind-tic-tac-toe's setup screen uses). */
.sp-level-card.sp-level-card-selected {
    border-color: var(--sp-accent);
    background: var(--sp-accent-light);
}

.sp-level-card-selected .sp-level-name {
    color: var(--sp-accent-dark);
}

.sp-level-card-selected::after {
    content: '✓';
    position: absolute;
    top: 8px;
    right: 8px;
    width: 20px;
    height: 20px;
    background: var(--sp-accent);
    color: #fff;
    border-radius: 50%;
    font-size: 12px;
    font-weight: 800;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
}

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

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

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

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

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

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

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

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

.sp-change-level-btn {
    border: none;
    background: none;
    color: var(--sp-accent-dark);
    font-weight: 700;
    font-size: 12px;
    cursor: pointer;
    padding: 4px;
}

.sp-change-level-btn:hover {
    color: var(--sp-accent);
}

.sp-stat-row {
    justify-content: center;
    margin-bottom: 14px;
}

.sp-stat {
    background: var(--sp-accent-light);
    color: var(--sp-accent-dark);
    border-radius: 999px;
    padding: 6px 14px;
    font-weight: 700;
    font-size: 14px;
}

.sp-theme-row {
    justify-content: center;
    align-items: center;
    margin-bottom: 14px;
}

.sp-theme-thumb {
    display: inline-block;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background-color: #f4f9f7;
    background-size: cover;
    background-position: center;
    box-shadow: 0 2px 6px rgba(0, 0, 0, .18);
    flex-shrink: 0;
    cursor: pointer;
    transition: transform .15s ease, box-shadow .15s ease;
}

.sp-theme-thumb:hover {
    transform: scale(1.12);
    box-shadow: 0 4px 10px rgba(0, 0, 0, .3);
}

.sp-theme-name {
    font-weight: 700;
    font-size: 13px;
    color: var(--sp-accent-dark);
}

/* Tapping/clicking .sp-theme-thumb opens this full-screen preview (see
   showThemePreview in game.js) - position:fixed so it covers the whole
   viewport whether or not the game is in native browser fullscreen. */
.sp-theme-preview-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .78);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 24px;
    box-sizing: border-box;
    z-index: 9999;
    cursor: pointer;
    animation: sp-fade-in .15s ease;
}

.sp-theme-preview-img {
    max-width: 90%;
    max-height: 80%;
    box-shadow: 0 12px 30px rgba(0, 0, 0, .45);
    background: #fff;
}

.sp-theme-preview-caption {
    color: #fff;
    font-weight: 800;
    font-size: 16px;
    text-shadow: 0 1px 3px rgba(0, 0, 0, .5);
}

.sp-board-wrap {
    position: relative;
    margin: 0 auto;
    background: #fff;
    border-radius: var(--kw-radius, 16px);
    padding: 8px;
    box-shadow: 0 3px 12px rgba(0, 0, 0, .07);
    animation: sp-fade-in .25s ease;
}

.sp-board {
    position: relative;
    width: 100%;
    background: linear-gradient(180deg, #f4f9f7, #eef8f3);
    overflow: hidden;
}

.sp-board-numbers {
    border-radius: 12px;
}

.sp-board-picture {
    border-radius: 0;
}

.sp-tile {
    position: absolute;
    box-sizing: border-box;
    transition: left .18s ease, top .18s ease;
}

.sp-tile-inner {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    user-select: none;
    transition: filter .15s ease;
}

.sp-tile-inner:hover {
    filter: brightness(1.06);
}

.sp-tile-inner.sp-bump {
    animation: sp-shake .2s ease;
}

.sp-tile-inner.sp-hint-active {
    animation: sp-hint-glow 1s ease-in-out infinite;
}

.sp-tile-inner-numbers {
    inset: 3px;
    border-radius: 10px;
    font-size: var(--sp-tile-font, 24px);
    font-weight: 800;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, .3);
    box-shadow: 0 2px 4px rgba(0, 0, 0, .18), inset 0 -3px 0 rgba(0, 0, 0, .12), inset 0 2px 0 rgba(255, 255, 255, .25);
}

.sp-tile-inner-picture {
    inset: 1px;
    background-color: #e5e7eb;
    background-repeat: no-repeat;
}

.sp-tile-badge {
    position: absolute;
    top: 4px;
    left: 4px;
    min-width: 18px;
    height: 18px;
    padding: 0 4px;
    border-radius: 999px;
    background: rgba(255, 255, 255, .9);
    color: #1F2937;
    font-size: 11px;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
    text-shadow: none;
}

.sp-toast {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, .75);
    color: #fff;
    font-weight: 800;
    font-size: 16px;
    padding: 14px 22px;
    border-radius: 14px;
    animation: sp-toast-pop .3s ease;
    pointer-events: none;
    white-space: nowrap;
    z-index: 3;
}

.sp-actions-row {
    justify-content: center;
    margin-top: 18px;
    margin-bottom: 0;
}

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

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

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

.sp-done-card {
    text-align: center;
    background: #fff;
    border-radius: var(--kw-radius, 16px);
    padding: 32px 20px;
    box-shadow: 0 3px 12px rgba(0, 0, 0, .07);
    animation: sp-pop .3s ease;
}

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

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

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

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

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

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

.sp-star-filled {
    color: #FBBF24;
}

.sp-star-empty {
    color: #D1D5DB;
}

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

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

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

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

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

.sp-btn-primary:disabled {
    opacity: .45;
    cursor: default;
    box-shadow: none;
    pointer-events: none;
}

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

.sp-start-btn {
    display: block;
    width: 100%;
    box-sizing: border-box;
    text-align: center;
    font-size: 16px;
    padding: 14px 22px;
}

.sp-start-hint {
    text-align: center;
    font-size: 12px;
    color: #888;
    min-height: 16px;
    margin-top: 8px;
}

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

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

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

@keyframes sp-toast-pop {
    0% { transform: translate(-50%, -50%) scale(.85); opacity: 0; }
    100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

@keyframes sp-shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    50% { transform: translateX(4px); }
    75% { transform: translateX(-3px); }
}

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

@keyframes sp-hint-glow {
    0%, 100% { filter: brightness(1); }
    50% { filter: brightness(1.4); }
}

@media (max-width: 380px) {
    .sp-levels {
        grid-template-columns: 1fr;
    }
}
