/* =============================================
   슬라이딩 퍼즐 스타일
   ============================================= */

html { background: #000; }

.sp-body {
    overflow: hidden;
    height: 100dvh;
    max-width: 480px;
    margin: 0 auto;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: #f0f0f0;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

.sp-game {
    width: 100%;
    height: 100dvh;
    max-width: 480px;
    display: flex;
    flex-direction: column;
    position: relative;
    transition: background-color 0.15s;
}

/* Top Bar */
.sp-top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    z-index: 10;
    flex-shrink: 0;
}
.sp-back {
    color: rgba(255, 255, 255, 0.7);
    text-decoration: none;
    font-size: 14px;
    padding: 6px 12px;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.2);
}
.sp-back:hover { color: #fff; }
.sp-info-badge {
    font-size: 13px;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.8);
    padding: 4px 12px;
    border-radius: 20px;
    background: rgba(0, 0, 0, 0.2);
}

/* Content */
.sp-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 16px 24px;
    overflow-y: auto;
}

/* ===== States ===== */

/* Intro */
.state-intro { background: #0f0f23; }
.state-intro .sp-content {
    justify-content: flex-start;
    padding-top: 40px;
}

.sp-intro-emoji { font-size: 72px; margin-bottom: 16px; }
.sp-intro-title {
    font-size: 28px;
    font-weight: 800;
    color: #fff;
    margin-bottom: 8px;
}
.sp-intro-desc {
    font-size: 15px;
    color: rgba(255, 255, 255, 0.6);
    line-height: 1.6;
    margin-bottom: 20px;
    text-align: center;
}
.sp-intro-desc strong { color: #ffd700; }

.sp-best {
    background: rgba(255, 255, 255, 0.06);
    border-radius: 10px;
    padding: 10px 18px;
    margin-bottom: 12px;
    font-size: 14px;
    color: rgba(255, 255, 255, 0.7);
}

.sp-size-select {
    display: flex;
    gap: 10px;
    margin-bottom: 24px;
}
.sp-size-btn {
    padding: 12px 20px;
    background: rgba(255, 255, 255, 0.06);
    border: 2px solid rgba(255, 255, 255, 0.12);
    border-radius: 12px;
    color: #fff;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s;
}
.sp-size-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.25);
}
.sp-size-btn:active { transform: scale(0.95); }
.sp-size-btn.sp-size-active {
    background: rgba(59, 130, 246, 0.25);
    border-color: #3B82F6;
    color: #93C5FD;
}

.sp-btn-start {
    display: inline-block;
    padding: 16px 48px;
    background: #3B82F6;
    color: #fff;
    border: none;
    border-radius: 14px;
    font-size: 18px;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.1s;
}
.sp-btn-start:active { transform: scale(0.95); }

/* Playing */
.state-playing { background: #0f0f23; }
.state-playing .sp-content {
    justify-content: flex-start;
    padding-top: 16px;
}

.sp-status-bar {
    display: flex;
    justify-content: space-between;
    width: 100%;
    max-width: 360px;
    margin-bottom: 12px;
    font-size: 14px;
    color: rgba(255, 255, 255, 0.6);
}
.sp-status-bar strong {
    color: #fff;
    font-weight: 700;
}

/* Board */
.sp-board {
    display: grid;
    gap: 4px;
    padding: 8px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    margin-bottom: 16px;
    touch-action: none;
}

.sp-tile {
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    font-weight: 800;
    cursor: pointer;
    transition: transform 0.12s ease, background 0.12s;
    position: relative;
}
.sp-tile:active { transform: scale(0.93); }
.sp-tile-filled {
    background: rgba(59, 130, 246, 0.2);
    border: 1px solid rgba(59, 130, 246, 0.3);
    color: #93C5FD;
}
.sp-tile-filled:hover {
    background: rgba(59, 130, 246, 0.3);
}
.sp-tile-correct {
    background: rgba(16, 185, 129, 0.2);
    border-color: rgba(16, 185, 129, 0.3);
    color: #6EE7B7;
}
.sp-tile-empty {
    background: rgba(255, 255, 255, 0.02);
    border: 1px dashed rgba(255, 255, 255, 0.08);
    cursor: default;
}

/* Board sizes */
.sp-board-3 {
    grid-template-columns: repeat(3, 1fr);
    width: min(calc(100vw - 64px), 300px);
    height: min(calc(100vw - 64px), 300px);
}
.sp-board-3 .sp-tile { font-size: 28px; }

.sp-board-4 {
    grid-template-columns: repeat(4, 1fr);
    width: min(calc(100vw - 48px), 340px);
    height: min(calc(100vw - 48px), 340px);
}
.sp-board-4 .sp-tile { font-size: 22px; }

.sp-board-5 {
    grid-template-columns: repeat(5, 1fr);
    width: min(calc(100vw - 48px), 360px);
    height: min(calc(100vw - 48px), 360px);
}
.sp-board-5 .sp-tile { font-size: 17px; }

.sp-board-3 .sp-tile,
.sp-board-4 .sp-tile,
.sp-board-5 .sp-tile {
    aspect-ratio: 1;
}

/* Controls */
.sp-controls {
    display: flex;
    gap: 10px;
    margin-bottom: 12px;
}
.sp-ctrl-btn {
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 10px;
    color: rgba(255, 255, 255, 0.7);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}
.sp-ctrl-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
}
.sp-ctrl-btn:active { transform: scale(0.95); }

/* Win animation */
@keyframes spWin {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}
.sp-board-win {
    animation: spWin 0.5s ease;
}
.sp-board-win .sp-tile-filled {
    background: rgba(16, 185, 129, 0.3);
    border-color: rgba(16, 185, 129, 0.5);
    color: #6EE7B7;
}

/* Result */
.state-result { background: #0f0f23; }
.state-result .sp-content {
    justify-content: flex-start;
    padding-top: 32px;
}

.sp-result-badge {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    border: 3px solid;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin-bottom: 12px;
}
.sp-result-emoji { font-size: 40px; }
.sp-result-grade {
    font-size: 28px;
    font-weight: 900;
    margin-top: 2px;
}
.sp-result-label {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 4px;
}
.sp-result-size-info {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.5);
    margin-bottom: 16px;
}

.sp-result-stats {
    display: flex;
    gap: 32px;
    margin-bottom: 16px;
}
.sp-stat {
    text-align: center;
}
.sp-stat-val {
    display: block;
    font-size: 28px;
    font-weight: 800;
    color: #fff;
}
.sp-stat-label {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.5);
}

.sp-new-record {
    background: rgba(255, 215, 0, 0.15);
    border: 1px solid rgba(255, 215, 0, 0.3);
    color: #ffd700;
    padding: 8px 20px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 12px;
}

/* Buttons */
.sp-result-btns {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
    flex-wrap: wrap;
    justify-content: center;
}
.sp-btn-share, .sp-btn-retry {
    border: none;
    border-radius: 14px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.1s;
}
.sp-btn-share:active, .sp-btn-retry:active { transform: scale(0.95); }

.sp-btn-share {
    padding: 16px 32px;
    background: #FEE500;
    color: #191919;
    font-size: 17px;
    box-shadow: 0 4px 16px rgba(254, 229, 0, 0.3);
    flex: 1;
    min-width: 160px;
    border-radius: 12px;
}
.sp-btn-retry {
    padding: 16px 24px;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

/* Ranking */
.sp-ranking-section {
    width: 100%;
    max-width: 360px;
    padding-bottom: 40px;
}
.sp-ranking-title {
    font-size: 16px;
    font-weight: 700;
    color: #fff;
    margin-bottom: 12px;
    text-align: center;
}
.sp-rankings-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.sp-rank-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.04);
    border-radius: 8px;
    font-size: 13px;
}
.sp-rank-pos {
    width: 28px;
    text-align: center;
    font-weight: 700;
}
.sp-rank-name {
    flex: 1;
    color: #fff;
    font-weight: 600;
}
.sp-rank-grade {
    font-size: 12px;
    font-weight: 600;
}
.sp-rank-score {
    color: rgba(255, 255, 255, 0.5);
    font-size: 12px;
    min-width: 60px;
    text-align: right;
}
.sp-no-ranking {
    text-align: center;
    color: rgba(255, 255, 255, 0.3);
    font-size: 13px;
    padding: 16px;
}

/* Toast */
.sp-toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.85);
    color: #fff;
    padding: 12px 24px;
    border-radius: 10px;
    font-size: 14px;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
    white-space: nowrap;
}
.sp-toast-show {
    opacity: 1;
    pointer-events: auto;
}
