/* ── Sliding Puzzle Theme ── */
:root {
    --sp-accent: #0891B2;
    --sp-accent-light: #22D3EE;
    --sp-accent-dark: #0E7490;
    --sp-bg: #0F1923;
    --sp-surface: #1A2736;
    --sp-surface-light: #243447;
    --sp-text: #E2E8F0;
    --sp-text-dim: #94A3B8;
    --sp-tile: #1E3A5F;
    --sp-tile-hover: #264A73;
    --sp-tile-correct: rgba(8, 145, 178, 0.25);
    --sp-empty: #0D1520;
    --sp-success: #22C55E;
    --sp-gold: #EAB308;
}

/* ── Layout ── */
.sp-layout {
    display: flex;
    justify-content: center;
    gap: 20px;
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    min-height: calc(100vh - 80px);
}

.ad-slot { width: 160px; flex-shrink: 0; }
.ad-slot--left, .ad-slot--right { display: flex; align-items: flex-start; }
.ad-placeholder--vertical {
    width: 160px; height: 600px;
    background: var(--sp-surface);
    border: 1px dashed var(--sp-text-dim);
    display: flex; align-items: center; justify-content: center;
    color: var(--sp-text-dim); font-size: 12px; border-radius: 8px;
}

#slidingpuzzle-app {
    flex: 1;
    max-width: 700px;
    min-width: 320px;
}

/* ── Screens ── */
.screen { display: none; }
.screen.active { display: block; animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* ── Header ── */
.sp-header {
    text-align: center;
    padding: 40px 0 30px;
}
.sp-logo { margin-bottom: 16px; }
.sp-logo-tiles {
    display: inline-grid;
    grid-template-columns: repeat(2, 32px);
    gap: 3px;
}
.sp-logo-tiles span {
    width: 32px; height: 32px;
    display: flex; align-items: center; justify-content: center;
    background: var(--sp-accent);
    color: #fff;
    font-family: 'Syne', sans-serif;
    font-weight: 800;
    font-size: 0.9rem;
    border-radius: 4px;
}
.sp-logo-tiles span.empty {
    background: var(--sp-empty);
}
.sp-header h1 {
    font-family: 'Syne', sans-serif;
    font-size: 2.6rem;
    font-weight: 800;
    color: var(--sp-accent);
    letter-spacing: 3px;
    margin: 0;
    text-shadow: 0 0 30px rgba(8, 145, 178, 0.3);
}
.subtitle {
    color: var(--sp-text-dim);
    font-size: 1rem;
    margin-top: 8px;
}

/* ── Cards ── */
.card {
    background: var(--sp-surface);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 16px;
    border: 1px solid var(--sp-surface-light);
}
.card__title {
    font-family: 'Syne', sans-serif;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--sp-accent);
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 12px;
}

/* ── Difficulty Grid ── */
.difficulty-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}
.diff-btn {
    background: var(--sp-bg);
    border: 2px solid var(--sp-surface-light);
    border-radius: 10px;
    padding: 14px 8px;
    cursor: pointer;
    text-align: center;
    transition: all 0.2s;
    color: var(--sp-text);
}
.diff-btn:hover { border-color: var(--sp-accent); background: var(--sp-surface-light); }
.diff-btn.selected { border-color: var(--sp-accent); background: rgba(8, 145, 178, 0.15); }
.diff-icon { display: block; font-size: 1.4rem; font-weight: 800; margin-bottom: 4px; color: var(--sp-accent); font-family: 'JetBrains Mono', monospace; }
.diff-btn span:nth-child(2) { display: block; font-weight: 600; font-size: 0.9rem; }
.diff-desc { display: block; font-size: 0.75rem; color: var(--sp-text-dim); margin-top: 2px; }

/* ── Mode Select ── */
.mode-select {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}
.mode-btn {
    background: var(--sp-bg);
    border: 2px solid var(--sp-surface-light);
    border-radius: 10px;
    padding: 14px;
    cursor: pointer;
    color: var(--sp-text);
    font-weight: 600;
    text-align: center;
    transition: all 0.2s;
}
.mode-btn:hover { border-color: var(--sp-accent); }
.mode-btn.selected { border-color: var(--sp-accent); background: rgba(8, 145, 178, 0.1); }
.mode-icon { display: block; font-size: 1.5rem; margin-bottom: 4px; }

/* ── Buttons ── */
.menu-actions { text-align: center; margin-top: 24px; }
.btn {
    font-family: 'Syne', sans-serif;
    font-weight: 700;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    letter-spacing: 1px;
}
.btn--primary {
    background: var(--sp-accent);
    color: #fff;
    padding: 14px 40px;
    font-size: 1.1rem;
}
.btn--primary:hover { background: var(--sp-accent-light); transform: translateY(-2px); box-shadow: 0 4px 20px rgba(8, 145, 178, 0.4); }
.btn--lg { font-size: 1.1rem; }
.btn--sm { padding: 8px 16px; font-size: 0.8rem; }
.btn--outline {
    background: transparent;
    color: var(--sp-accent);
    border: 2px solid var(--sp-accent);
    padding: 8px 20px;
}
.btn--outline:hover { background: rgba(8, 145, 178, 0.1); }
.btn--ghost {
    background: transparent;
    color: var(--sp-text-dim);
    padding: 10px 20px;
}
.btn--ghost:hover { color: var(--sp-accent); }

/* ── HUD ── */
#game-hud {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--sp-surface);
    border-radius: 12px;
    padding: 12px 20px;
    margin-bottom: 16px;
    border: 1px solid var(--sp-surface-light);
}
.hud__cell { text-align: left; }
.hud__cell--center { text-align: center; }
.hud__cell--right { text-align: right; }
.hud__label { display: block; font-size: 0.7rem; color: var(--sp-text-dim); text-transform: uppercase; letter-spacing: 1px; }
.hud__value { font-family: 'JetBrains Mono', monospace; font-size: 1.4rem; font-weight: 700; color: var(--sp-text); }
.hud__timer { color: var(--sp-accent); }

/* ── Board ── */
.sp-board-area {
    display: flex;
    justify-content: center;
    margin-bottom: 12px;
}

.sp-board {
    display: grid;
    gap: 4px;
    background: var(--sp-bg);
    border: 3px solid var(--sp-surface-light);
    border-radius: 12px;
    padding: 8px;
    box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.3);
    position: relative;
}

.sp-tile {
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    cursor: pointer;
    font-family: 'Syne', sans-serif;
    font-weight: 800;
    user-select: none;
    transition: transform 0.15s cubic-bezier(0.25, 0.46, 0.45, 0.94),
                background 0.3s, box-shadow 0.3s;
    position: relative;
    overflow: hidden;
}

.sp-tile--number {
    background: var(--sp-tile);
    color: var(--sp-text);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}
.sp-tile--number:hover {
    background: var(--sp-tile-hover);
    transform: scale(1.03);
}
.sp-tile--number.correct {
    background: var(--sp-tile-correct);
    border: 1px solid rgba(8, 145, 178, 0.4);
}
.sp-tile--number.sliding {
    z-index: 10;
    transition: transform 0.15s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.sp-tile--empty {
    background: var(--sp-empty);
    cursor: default;
    box-shadow: inset 0 4px 12px rgba(0, 0, 0, 0.5);
    border-radius: 8px;
}

.sp-tile--image {
    background-size: cover;
    background-position: center;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}
.sp-tile--image:hover { transform: scale(1.02); }
.sp-tile--image .tile-num {
    position: absolute;
    top: 3px; left: 5px;
    font-size: 0.6rem;
    color: rgba(255,255,255,0.7);
    text-shadow: 0 1px 2px rgba(0,0,0,0.8);
}

/* ── Goal hint ── */
.sp-goal-hint { text-align: center; margin-bottom: 12px; }
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.7); display: flex; align-items: center; justify-content: center; z-index: 100; }
.overlay.hidden { display: none; }
.overlay__box {
    background: var(--sp-surface);
    border-radius: 16px;
    padding: 24px;
    text-align: center;
    border: 1px solid var(--sp-surface-light);
}
.overlay__box h3 {
    color: var(--sp-accent);
    font-family: 'Syne', sans-serif;
    margin: 0 0 16px;
}
.sp-board--mini {
    width: 200px;
    height: 200px;
    margin: 0 auto 16px;
    pointer-events: none;
}
.sp-board--mini .sp-tile { font-size: 0.7rem !important; }

/* ── Actions ── */
.sp-actions {
    display: flex;
    justify-content: center;
    gap: 12px;
}

/* Win celebration */
@keyframes celebrate {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); box-shadow: 0 0 20px rgba(34, 197, 94, 0.5); }
    100% { transform: scale(1); }
}
.sp-board.solved {
    animation: celebrate 0.6s ease;
    border-color: var(--sp-success);
}
.sp-board.solved .sp-tile--number {
    background: rgba(34, 197, 94, 0.2);
    border: 1px solid rgba(34, 197, 94, 0.3);
}

/* ── Result Card ── */
.result-card, .lb-card {
    background: var(--sp-surface);
    border-radius: 16px;
    padding: 40px 30px;
    text-align: center;
    border: 1px solid var(--sp-surface-light);
    max-width: 420px;
    margin: 60px auto;
}
.result-card h2, .lb-card h2 {
    font-family: 'Syne', sans-serif;
    font-size: 1.8rem;
    color: var(--sp-accent);
    margin: 0 0 20px;
    letter-spacing: 3px;
}
.result-score {
    font-family: 'JetBrains Mono', monospace;
    font-size: 3rem;
    font-weight: 700;
    color: var(--sp-text);
    margin-bottom: 8px;
}
.result-detail {
    color: var(--sp-text-dim);
    font-size: 0.9rem;
    margin-bottom: 20px;
}
#nickname {
    width: 100%;
    max-width: 280px;
    padding: 10px 16px;
    background: var(--sp-bg);
    border: 2px solid var(--sp-surface-light);
    border-radius: 8px;
    color: var(--sp-text);
    font-size: 1rem;
    text-align: center;
    outline: none;
    margin-bottom: 16px;
}
#nickname:focus { border-color: var(--sp-accent); }
.result-actions { display: flex; justify-content: center; gap: 12px; margin-bottom: 12px; }

/* ── Leaderboard ── */
#leaderboard-list {
    list-style: none;
    padding: 0;
    margin: 20px 0;
}
#leaderboard-list li {
    display: flex;
    justify-content: space-between;
    padding: 10px 16px;
    border-bottom: 1px solid var(--sp-surface-light);
    color: var(--sp-text);
    font-family: 'JetBrains Mono', monospace;
}
#leaderboard-list li:first-child { color: var(--sp-accent); font-weight: 700; }

/* ── Responsive ── */
@media (max-width: 900px) {
    .ad-slot--left, .ad-slot--right { display: none; }
    .sp-layout { padding: 10px; }
}
@media (max-width: 500px) {
    .sp-header h1 { font-size: 1.8rem; }
    .difficulty-grid { gap: 6px; }
    .diff-btn { padding: 10px 4px; }
    #game-hud { padding: 8px 12px; }
    .hud__value { font-size: 1.1rem; }
    .sp-board { padding: 4px; gap: 3px; }
}
