@import url('../styles.css');

.mobile-score {
    display: none;
    position: absolute;
    top: 5px;
    right: 5px;
    z-index: 1002;
    background: rgba(36,36,36,0.85);
    color: var(--text-muted);
    font-size: 0.8rem;
    padding: 0.7rem 1.2rem;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    font-weight: bold;
}
.responsive-layout {
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: flex-start;
    gap: 2.5rem;
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem 1rem;
    box-sizing: border-box;
}
.game-side {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    gap: 1rem;
}
.info-side {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-start;
    min-width: 280px;
    max-width: 400px;
    background: rgba(36,36,36,0.85);
    border-radius: 18px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.25);
    padding: 2rem;
}
.info-side h1 {
    font-size: 2.2rem;
    margin-bottom: 1rem;
    background: var(--grad-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.info-side p { font-size: 1.1rem; margin-bottom: 1.5rem; color: var(--text-muted); }
.buttons-panel { display: flex; gap: 1rem; margin-top: 1.5rem; flex-wrap: wrap; }
@media (max-width: 900px) {
    .responsive-layout { flex-direction: column; align-items: center; gap: 1.5rem; padding: 1rem 0.5rem; }
    .info-side { max-width: 100vw; width: 100%; margin-top: 0; align-items: center; text-align: center; }
    .info-side h1 { font-size: 1.7rem; }
    .game-side { width: 100%; justify-content: center; }
}
body { background: var(--grad-bg); color: #fff; min-height: 100vh; margin: 0; }

/* ===================== SIZE SELECTOR ===================== */
.size-selector {
    display: flex;
    gap: 8px;
    justify-content: center;
}
.size-btn {
    padding: 0.4rem 1rem;
    border: 2px solid #555;
    background: #2a2a2a;
    color: #aaa;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: bold;
    cursor: pointer;
    transition: border-color 0.2s, color 0.2s, background 0.2s;
    touch-action: manipulation;
}
.size-btn.active {
    border-color: #8fd3f4;
    color: #8fd3f4;
    background: rgba(143,211,244,0.12);
}
.size-btn:hover { border-color: #8fd3f4; color: #8fd3f4; }

/* ===================== PUZZLE BOARD ===================== */
.puzzle-board {
    display: grid;
    gap: 6px;
    background: rgba(255,255,255,0.08);
    border-radius: 14px;
    padding: 10px;
    width: 360px;
    height: 360px;
    box-sizing: border-box;
    position: relative;
}
/* Grid column/row counts are set dynamically via inline style */

/* ===================== TILES ===================== */
.puzzle-tile {
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    font-weight: 900;
    color: #fff;
    cursor: pointer;
    touch-action: manipulation;
    user-select: none;
    position: relative;
    /* CSS transition for smooth sliding */
    transition: transform 0.12s ease-out, box-shadow 0.15s;
    box-shadow: 0 3px 10px rgba(0,0,0,0.35), inset 0 1px 0 rgba(255,255,255,0.15);
    text-shadow: 0 1px 3px rgba(0,0,0,0.4);
}

/* Color ranges by tile value */
.puzzle-tile[data-val="1"],
.puzzle-tile[data-val="2"],
.puzzle-tile[data-val="3"],
.puzzle-tile[data-val="4"],
.puzzle-tile[data-val="5"] {
    background: linear-gradient(135deg, #1565c0 0%, #42a5f5 100%);
}
.puzzle-tile[data-val="6"],
.puzzle-tile[data-val="7"],
.puzzle-tile[data-val="8"],
.puzzle-tile[data-val="9"],
.puzzle-tile[data-val="10"] {
    background: linear-gradient(135deg, #1b5e20 0%, #66bb6a 100%);
}
.puzzle-tile[data-val="11"],
.puzzle-tile[data-val="12"],
.puzzle-tile[data-val="13"],
.puzzle-tile[data-val="14"],
.puzzle-tile[data-val="15"] {
    background: linear-gradient(135deg, #bf360c 0%, #ff8a65 100%);
}
.puzzle-tile[data-val="16"],
.puzzle-tile[data-val="17"],
.puzzle-tile[data-val="18"],
.puzzle-tile[data-val="19"],
.puzzle-tile[data-val="20"],
.puzzle-tile[data-val="21"],
.puzzle-tile[data-val="22"],
.puzzle-tile[data-val="23"],
.puzzle-tile[data-val="24"] {
    background: linear-gradient(135deg, #6a1b9a 0%, #ce93d8 100%);
}

.puzzle-tile.movable {
    box-shadow: 0 3px 10px rgba(0,0,0,0.35), 0 0 0 2px rgba(143,211,244,0.5), inset 0 1px 0 rgba(255,255,255,0.15);
}
.puzzle-tile.movable:hover {
    transform: scale(1.06);
    box-shadow: 0 6px 18px rgba(0,0,0,0.4), 0 0 0 3px rgba(143,211,244,0.7), inset 0 1px 0 rgba(255,255,255,0.2);
}
.puzzle-tile:active { transform: scale(0.95); }

.puzzle-tile.empty {
    background: rgba(255,255,255,0.04);
    box-shadow: inset 0 2px 8px rgba(0,0,0,0.35);
    cursor: default;
    border: 2px dashed rgba(255,255,255,0.1);
}
.puzzle-tile.empty:hover { transform: none; box-shadow: inset 0 2px 8px rgba(0,0,0,0.35); }
.puzzle-tile.empty:active { transform: none; }

/* Hint highlight */
@keyframes hintPulse {
    0%,100% { box-shadow: 0 3px 10px rgba(0,0,0,0.35), 0 0 0 3px rgba(255,215,0,0.8); }
    50%      { box-shadow: 0 3px 10px rgba(0,0,0,0.35), 0 0 16px 6px rgba(255,215,0,0.9); }
}
.puzzle-tile.hint {
    animation: hintPulse 0.6s ease-in-out 3;
}

/* ===================== WIN ANIMATION ===================== */
@keyframes tileWave {
    0%,100% { transform: scale(1) rotate(0deg); }
    30%     { transform: scale(1.18) rotate(-4deg); }
    60%     { transform: scale(1.1) rotate(3deg); }
}
.puzzle-tile.wave {
    animation: tileWave 0.5s ease-in-out forwards;
}

/* Solved overlay */
@keyframes solvedFadeIn {
    0%   { opacity: 0; transform: scale(0.7); }
    60%  { transform: scale(1.05); }
    100% { opacity: 1; transform: scale(1); }
}
.solved-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(24,24,24,0.7);
    border-radius: 14px;
    z-index: 10;
    animation: solvedFadeIn 0.4s cubic-bezier(0.34,1.56,0.64,1) forwards;
}
.solved-text {
    font-size: 2.2rem;
    font-weight: 900;
    background: var(--grad-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-align: center;
    line-height: 1.3;
}

/* ===================== MOVES COUNTER BOUNCE ===================== */
@keyframes movesBounce {
    0%,100% { transform: scale(1); }
    50%      { transform: scale(1.4); color: #8fd3f4; }
}
#moves.bounce {
    display: inline-block;
    animation: movesBounce 0.25s ease-out forwards;
}

/* ===================== RECORDS PANEL ===================== */
.records-panel {
    margin-top: 1rem;
    width: 100%;
}
.records-panel h3 {
    font-size: 0.85rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin: 0 0 0.5rem 0;
}
.record-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    color: #aaa;
    padding: 3px 0;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}
.record-row .rec-label { color: #888; }
.record-row .rec-val { color: #8fd3f4; font-weight: bold; }

/* ===================== HINT BUTTON ===================== */
#hintBtn {
    background: rgba(255,215,0,0.15);
    color: #ffd700;
    border: 2px solid rgba(255,215,0,0.4);
    border-radius: 8px;
    padding: 0.65rem 1.3rem;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.2s, transform 0.15s;
    touch-action: manipulation;
}
#hintBtn:hover { background: rgba(255,215,0,0.25); transform: scale(1.04); }
#hintBtn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

/* ===================== SCORE PANEL ===================== */
.score-panel {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    font-size: 1rem;
    color: var(--text-muted);
    width: 100%;
}

/* ===================== BUTTONS ===================== */
#startBtn, #restartBtn {
    background: var(--grad-primary); color: #222; border: none; border-radius: 8px;
    padding: 0.9rem 2rem; font-size: 1.1rem; font-weight: bold; cursor: pointer;
    margin: 0 0.5rem; box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    transition: background 0.2s, transform 0.2s;
}
#startBtn:hover, #restartBtn:hover { opacity: 0.9; transform: scale(1.05); }
#playAgainBtn {
    background: #8fd3f4; color: #222; border: none; border-radius: 8px;
    padding: 1rem 2.2rem; font-size: 1.2rem; font-weight: bold; cursor: pointer;
    transition: background 0.2s; margin-top: 1rem;
}
#playAgainBtn:hover { background: #5ec2e6; }
.popup {
    position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(24,24,24,0.95); display: flex; align-items: center;
    justify-content: center; z-index: 1000;
}
.popup-content {
    background: #242424; padding: 2.5rem 3rem; border-radius: 20px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.4); text-align: center;
    min-width: 280px; max-width: 90vw;
}
.popup-content h2 { margin-top: 0; color: #8fd3f4; font-size: 2rem; }
.popup-content p { font-size: 1.5rem; margin: 1.5rem 0; }

@media (max-width: 420px) {
    .puzzle-board { width: calc(100vw - 32px); height: calc(100vw - 32px); }
    .puzzle-tile { font-size: 1.5rem; }
    .size-btn { padding: 0.3rem 0.7rem; font-size: 0.8rem; }
}
