:root {
    --bg: #0f172a;
    --text: #f8fafc;
    --primary: #3b82f6;
    --primary-glow: rgba(59, 130, 246, 0.5);
    --tile-bg: rgba(255, 255, 255, 0.05);
    --tile-border: rgba(255, 255, 255, 0.1);
    --correct-bg: #10b981;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* Usuwamy globalne wymuszenia body/html aby nie niszczyć głównego CSS */
.konektor-app {
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - 60px);
    max-width: 800px;
    margin: 0 auto;
    padding: 20px 20px 0 20px;
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg);
    color: var(--text);
    overflow-x: hidden;
    overscroll-behavior-y: contain;
}

.game-area {
    display: flex;
    flex-direction: column;
    flex: 1;
    position: sticky;
    top: 60px;
    /* Offset dla fixed-header na Wyrazoholicy.pl */
    height: calc(100dvh - 60px);
    height: calc(100vh - 60px);
    /* Fallback */
    background-color: var(--bg);
    z-index: 50;
    margin-left: -20px;
    margin-right: -20px;
    padding: 10px 20px 20px 20px;
    scroll-margin-top: 60px;
}

.scroll-hint {
    display: block;
    text-align: center;
    font-size: 0.8rem;
    color: var(--primary);
    opacity: 0.7;
    margin-bottom: 5px;
    cursor: pointer;
    padding: 5px;
    transition: opacity 0.2s;
}

.scroll-hint:active {
    opacity: 0.4;
}

header {
    text-align: center;
    margin-bottom: 20px;
}

header h1 {
    font-size: 3rem;
    font-weight: 800;
    text-transform: uppercase;
    background: linear-gradient(135deg, #60a5fa, #3b82f6);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 5px;
}

header p {
    opacity: 0.8;
    font-size: 0.95rem;
    margin-bottom: 15px;
}

.score {
    font-size: 1.2rem;
    font-weight: 600;
    background: rgba(0, 0, 0, 0.2);
    padding: 5px 15px;
    border-radius: 20px;
    display: inline-block;
}

.settings {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 20px;
    margin-bottom: 20px;
    background: rgba(0, 0, 0, 0.2);
    padding: 10px 20px;
    border-radius: 20px;
}

.settings label {
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 0.95rem;
    opacity: 0.9;
}

.settings input[type=range] {
    margin-top: 5px;
    width: 140px;
    accent-color: var(--primary);
}

.board {
    flex: 1;
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
    align-items: flex-start;
    justify-content: center;
    gap: 12px;
    padding: 20px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 20px;
    border: 1px solid var(--tile-border);
    overflow-y: auto;
    position: relative;
    touch-action: auto;
    -webkit-overflow-scrolling: touch;
    min-height: 200px;
}

.tile {
    background: var(--tile-bg);
    border: 1px solid var(--tile-border);
    backdrop-filter: blur(10px);
    border-radius: 12px;
    padding: 14px 20px;
    font-size: 1.25rem;
    font-weight: 600;
    cursor: grab;
    user-select: none;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s, background 0.2s, box-shadow 0.2s;
    touch-action: none;
    z-index: 10;
}

.tile:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2);
}

.tile:active {
    cursor: grabbing;
}

/* Kiedy użytkownik podnosi, oryginał robi się bledszy jako "miejsce docelowe" */
.tile.dragging {
    opacity: 0.3;
    pointer-events: none;
}

/* Klon, który porusza się za palcem */
.ghost-tile {
    position: fixed;
    pointer-events: none;
    /* musi być none aby elementFromPoint sprawdził co jest "pod spodem" */
    z-index: 9999;
    background: rgba(59, 130, 246, 0.2);
    border: 1px solid var(--primary);
    box-shadow: 0 0 20px var(--primary-glow);
    border-radius: 12px;
    padding: 14px 20px;
    font-size: 1.25rem;
    font-weight: 600;
    color: white;
    transform: translate(-50%, -50%);
    /* środek w punkcie klikniecia */
    font-family: 'Outfit', sans-serif;
    backdrop-filter: blur(15px);
}

.tile.merged {
    background: var(--correct-bg);
    color: #fff;
    cursor: default;
    border-color: #059669;
    box-shadow: 0 0 15px rgba(16, 185, 129, 0.4);
}

/* Animacje złączenia */
@keyframes pop {
    0% {
        transform: scale(0.8);
        opacity: 0;
    }

    50% {
        transform: scale(1.15);
        box-shadow: 0 0 30px rgba(16, 185, 129, 0.8);
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.tile.merged-animate {
    animation: pop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.hidden {
    display: none !important;
}

#win-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100dvh;
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(8px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

#win-screen h2 {
    font-size: 3.5rem;
    color: var(--correct-bg);
    margin-bottom: 10px;
    text-shadow: 0 0 20px rgba(16, 185, 129, 0.5);
}

#win-screen p {
    font-size: 1.2rem;
    opacity: 0.8;
    margin-bottom: 25px;
}

#restart-btn {
    padding: 15px 35px;
    border: none;
    border-radius: 30px;
    background: var(--primary);
    color: white;
    font-size: 1.3rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, background 0.2s, box-shadow 0.2s;
    box-shadow: 0 0 15px var(--primary-glow);
}

#restart-btn:hover,
.btn-primary:hover {
    background: #2563eb;
    transform: scale(1.05);
    box-shadow: 0 0 25px var(--primary-glow);
}

.actions {
    text-align: center;
    margin-top: 15px;
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
}

.btn-secondary {
    padding: 10px 25px;
    border: 1px solid var(--tile-border);
    border-radius: 20px;
    background: var(--tile-bg);
    color: var(--text);
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
}

#solution-list {
    max-height: 60vh;
    overflow-y: auto;
    margin-bottom: 20px;
    width: 95%;
    max-width: 500px;
    text-align: center;
    background: rgba(0, 0, 0, 0.3);
    padding: 15px;
    border-radius: 12px;
}

.solution-item {
    padding: 10px 5px;
    border-bottom: 1px solid var(--tile-border);
    font-size: 1.1rem;
    line-height: 1.3;
}

.solution-item:last-child {
    border-bottom: none;
}

/* Responsive adjustments */
@media(max-width: 600px) {
    header h1 {
        font-size: 2.2rem;
    }

    .tile {
        padding: 10px 15px;
        font-size: 1.1rem;
    }

    .ghost-tile {
        padding: 10px 15px;
        font-size: 1.1rem;
    }

    .actions .btn-secondary {
        padding: 10px 10px;
        font-size: 0.95rem;
        flex: 1;
        border-radius: 12px;
    }
}

/* Wersja desktopowa - zdejmujemy sticky bo miesci sie na ekranie */
@media(min-width: 769px) {
    .konektor-app {
        padding: 20px;
    }

    .game-area {
        position: static;
        height: auto;
        margin-left: 0;
        margin-right: 0;
        padding: 0;
        background-color: transparent;
    }

    .scroll-hint {
        display: none;
    }
}