/* Sort It! Game Styles */
:root {
    --card-bg: #ffffff;
    --card-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    /* Default fallback colors */
    --left-color: #ff6b6b;
    --right-color: #4ecdc4;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    touch-action: none;
}

body {
    font-family: 'Fredoka', sans-serif;
    /* Split background exactly down the middle */
    background: linear-gradient(90deg, var(--left-color) 50%, var(--right-color) 50%);
    min-height: 100vh;
    width: 100vw;
    overflow: hidden;
    position: fixed;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.5s ease;
}

/* Background Images */
.bg-half {
    position: absolute;
    top: 0;
    width: 50vw;
    height: 100vh;
    background-size: cover;
    background-position: center;
    z-index: -1;
    opacity: 0;
    transition: opacity 0.5s ease;
}

/* Add a dark gradient overlay so the text/cards pop */
.bg-half::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0.1), rgba(0, 0, 0, 0.3));
}

.bg-half.left {
    left: 0;
}

.bg-half.right {
    right: 0;
}

/* Back Button */
.back-btn {
    position: fixed;
    top: calc(20px + env(safe-area-inset-top));
    left: calc(20px + env(safe-area-inset-left));
    width: 70px;
    height: 70px;
    background: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    text-decoration: none;
    transition: transform 0.1s;
}

.back-btn:active {
    transform: translateY(6px);
    box-shadow: 0 0 0 #ccc, 0 4px 10px rgba(0, 0, 0, 0.2);
}

/* Category Labels */
.category-label {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    padding: 20px 30px;
    border-radius: 25px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    z-index: 10;
    /* Soft white bubble to stand out against the colored sides */
    background: rgba(255, 255, 255, 0.85);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(5px);
    border: 4px solid rgba(255, 255, 255, 0.72);
    font: inherit;
    cursor: pointer;
    min-width: 150px;
}

.category-label:focus-visible,
.control-btn:focus-visible,
.back-btn:focus-visible,
.start-btn:focus-visible {
    outline: 5px solid #1d4ed8;
    outline-offset: 4px;
}

.category-label:active:not(:disabled) {
    transform: translateY(-50%) scale(0.95);
}

.category-label:disabled {
    cursor: default;
}

.category-label.left {
    left: 20px;
    color: var(--left-color);
}

.category-label.right {
    right: 20px;
    color: var(--right-color);
}

.cat-emoji {
    font-size: 3rem;
}

.cat-text {
    font-size: 1.2rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: #1e293b;
}

/* Swipe Indicators (fade in on drag) */
.swipe-indicator {
    position: fixed;
    top: 50%;
    transform: translateY(-50%) scale(0.5);
    font-size: 8rem;
    opacity: 0;
    transition: opacity 0.2s, transform 0.2s;
    z-index: 50;
    pointer-events: none;
}

.swipe-indicator.left {
    left: 15%;
}

.swipe-indicator.right {
    right: 15%;
}

.swipe-indicator.active {
    opacity: 1;
    transform: translateY(-50%) scale(1);
}

/* Card Container */
.card-container {
    position: relative;
    width: 320px;
    height: 400px;
    perspective: 1000px;
}

/* The Card */
.card {
    width: 100%;
    height: 100%;
    background: var(--card-bg);
    border-radius: 30px;
    box-shadow: var(--card-shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: grab;
    position: absolute;
    transform-origin: center bottom;
    transition: none;
    overflow: hidden;
}

.card.animating {
    transition: transform 0.3s ease-out;
}

.card.wrong {
    animation: wobble 0.5s ease-in-out;
}

.card img {
    max-width: 85%;
    max-height: 85%;
    object-fit: contain;
    pointer-events: none;
}

/* Familiar controls */
.control-btn {
    position: fixed;
    top: calc(20px + env(safe-area-inset-top));
    background: white;
    border: 0;
    width: 62px;
    height: 62px;
    border-radius: 50%;
    font-size: 2rem;
    box-shadow: 0 6px 0 #ddd, 0 10px 20px rgba(0, 0, 0, 0.1);
    z-index: 100;
    cursor: pointer;
}

.replay-btn {
    left: calc(104px + env(safe-area-inset-left));
}

.sound-btn {
    right: calc(20px + env(safe-area-inset-right));
}

.control-btn:active {
    transform: translateY(4px);
    box-shadow: 0 2px 0 #ddd;
}

.feedback {
    position: fixed;
    bottom: calc(24px + env(safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%);
    z-index: 120;
    min-height: 1.5em;
    padding: 10px 20px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.92);
    color: #334155;
    font-size: 1.2rem;
    font-weight: 700;
    pointer-events: none;
}

.feedback:empty {
    display: none;
}

/* Confetti */
#confetti-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 200;
    overflow: hidden;
}

.confetti {
    position: absolute;
    width: 15px;
    height: 15px;
    border-radius: 3px;
    animation: confetti-fall 1.5s ease-out forwards;
}

@keyframes confetti-fall {
    0% {
        transform: translateY(0) rotate(0deg);
        opacity: 1;
    }

    100% {
        transform: translateY(100vh) rotate(720deg);
        opacity: 0;
    }
}

@keyframes wobble {

    0%,
    100% {
        transform: translateX(0) rotate(0deg);
    }

    20% {
        transform: translateX(-20px) rotate(-5deg);
    }

    40% {
        transform: translateX(20px) rotate(5deg);
    }

    60% {
        transform: translateX(-15px) rotate(-3deg);
    }

    80% {
        transform: translateX(15px) rotate(3deg);
    }
}

/* Responsive adjustments */
@media (max-width: 600px) {
    .category-label {
        padding: 15px 20px;
    }

    .cat-emoji {
        font-size: 2rem;
    }

    .cat-text {
        font-size: 0.9rem;
    }

    .card-container {
        width: 280px;
        height: 350px;
    }
}

@media (min-width: 1024px) {
    .card-container {
        width: 400px;
        height: 500px;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════════
   START SCREEN OVERLAY
   ═══════════════════════════════════════════════════════════════════════════════ */

.start-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.start-content {
    background: white;
    padding: 3rem;
    border-radius: 20px;
    text-align: center;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
    transform: scale(1);
    animation: popIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn {
    0% {
        transform: scale(0.5);
        opacity: 0;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.start-content h1 {
    font-size: 4rem;
    margin-bottom: 1rem;
    color: #333;
}

.start-content p {
    font-size: 2rem;
    margin-bottom: 2rem;
    color: #666;
}

.start-btn {
    font-size: 2.5rem;
    padding: 1.5rem 4rem;
    background: #4ade80;
    color: white;
    border: none;
    border-radius: 50px;
    font-family: inherit;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 8px 15px rgba(74, 222, 128, 0.4);
    transition: transform 0.2s, background 0.2s;
}

.start-btn:active {
    transform: scale(0.95);
    background: #22c55e;
}

.finish-screen {
    position: fixed;
    inset: 0;
    z-index: 900;
    display: grid;
    place-items: center;
    background: rgba(15, 23, 42, 0.48);
}

.finish-screen[hidden] {
    display: none;
}

.finish-content {
    display: grid;
    gap: 1.5rem;
    justify-items: center;
    padding: 2.5rem 3rem;
    border-radius: 28px;
    background: white;
    color: #334155;
    font-size: 2.4rem;
    font-weight: 700;
    text-align: center;
}

/* iPad landscape: keep swipe targets large without crowding category homes. */
@media (min-width: 768px) and (max-width: 1366px) and (orientation: landscape) {
    .back-btn { top: calc(16px + env(safe-area-inset-top)); left: calc(16px + env(safe-area-inset-left)); width: 62px; height: 62px; font-size: 2.15rem; }
    .control-btn { top: calc(16px + env(safe-area-inset-top)); width: 56px; height: 56px; font-size: 1.8rem; }
    .replay-btn { left: calc(90px + env(safe-area-inset-left)); }
    .sound-btn { right: calc(16px + env(safe-area-inset-right)); }
    .category-label { padding: 14px 18px; border-radius: 20px; }
    .category-label.left { left: calc(16px + env(safe-area-inset-left)); }
    .category-label.right { right: calc(16px + env(safe-area-inset-right)); }
    .cat-emoji { font-size: 2.55rem; }
    .cat-text { font-size: 1rem; letter-spacing: 1px; }
    .card-container { width: min(35vw, 380px); height: min(55vw, 470px); }
    .start-content { padding: 2.4rem 3.4rem; }
}

@media (orientation: portrait) {
    .category-label { top: 43%; min-width: 140px; padding: 15px 13px; }
    .category-label.left { left: calc(14px + env(safe-area-inset-left)); }
    .category-label.right { right: calc(14px + env(safe-area-inset-right)); }
    .cat-emoji { font-size: 2.35rem; }
    .cat-text { font-size: 0.85rem; letter-spacing: 1px; }
    .card-container { width: min(39vw, 320px); height: min(49vw, 400px); }
    .feedback { bottom: calc(18px + env(safe-area-inset-bottom)); font-size: 1rem; }
}
