/* ============================================
   Look & Find Game - Main Stylesheet
   ============================================ */

html, body {
    width: 100%;
    height: 100dvh;
    height: 100vh;
    margin: 0;
    padding: 0;
    overflow: hidden;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    -webkit-text-size-adjust: 100%;
    position: fixed;
    touch-action: manipulation;
    /* iOS specific */
    -webkit-touch-callout: none;
    -webkit-user-select: none;
}

:root {
    --sprite-cell-size: 204.8px;
    --primary-color: #FF9999;
    --secondary-color: #FF7F7F;
    --sidebar-bg: #FFE4D6;
    --scene-bg: #D4F1F4;
    --scene-dot: #B8E0E8;
    --success-color: #8FD081;
    --dark-success: #6BA850;
    --safe-top: env(safe-area-inset-top, 0);
    --safe-bottom: env(safe-area-inset-bottom, 0);
    --safe-left: env(safe-area-inset-left, 0);
    --safe-right: env(safe-area-inset-right, 0);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Comic Sans MS', 'Arial Rounded MT Bold', sans-serif;
    background-color: #f4f4f4;
    height: 100%;
    width: 100%;
    overflow: hidden;
}

/* ============================================
   Game Container Layout
   ============================================ */

#game-container {
    display: flex;
    width: 100%;
    height: 100dvh;
    background-color: white;
    overflow: hidden;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
}

#sidebar {
    width: clamp(70px, 12vw, 200px);
    background-color: var(--sidebar-bg);
    padding: 8px 4px;
    padding-left: calc(8px + var(--safe-left));
    padding-top: calc(8px + var(--safe-top));
    padding-bottom: calc(8px + var(--safe-bottom));
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    border-right: 3px solid var(--primary-color);
}

h1 {
    color: var(--secondary-color);
    margin-top: 0;
    font-size: 0.9em;
    margin-bottom: 4px;
    display: none;
}

p {
    font-size: 0.8em;
    color: #333;
    line-height: 1.2;
    margin-bottom: 6px;
    display: none;
}

/* ============================================
   Items List & Cards
   ============================================ */

.items-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
    overflow-y: auto;
    padding-right: 2px;
}

.item-card {
    background-color: white;
    border-radius: 6px;
    padding: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    transition: transform 0.2s ease;
    position: relative;
    flex: 0 0 auto;
}

.item-card:hover {
    transform: scale(1.05);
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

.item-preview {
    width: 100%;
    max-height: 120px;
    background-color: #E1F5FE;
    border: 2px solid var(--primary-color);
    border-radius: 4px;
    margin-bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.item-preview img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.item-name {
    font-weight: bold;
    color: #333;
    font-size: 0.6em;
    display: none;
    margin-top: 2px;
}

.item-card.found {
    background-color: var(--success-color);
}

.item-card.found .item-name {
    color: white;
}

.item-card.found::after {
    content: '✓';
    position: absolute;
    top: -5px;
    right: -5px;
    background-color: var(--dark-success);
    color: white;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9em;
    font-weight: bold;
}

/* ============================================
   Scene Area
   ============================================ */

#scene-area {
    position: relative;
    flex-grow: 1;
    background-color: var(--scene-bg);
    background-image: radial-gradient(var(--scene-dot) 20%, transparent 20%);
    background-size: 30px 30px;
    overflow: hidden;
}

/* ============================================
   Sprite Objects
   ============================================ */

.sprite-object {
    position: absolute;
    max-width: 120px;
    max-height: 120px;
    width: auto;
    height: auto;
    cursor: pointer;
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    filter: drop-shadow(2px 4px 6px rgba(0,0,0,0.2));
    image-rendering: high-quality;
    object-fit: contain;
}

.sprite-object:hover {
    transform: scale(1.1);
    z-index: 100;
}

.sprite-object.found {
    animation: popDisappear 0.4s ease-out forwards;
    pointer-events: none;
}

/* ============================================
   Animations
   ============================================ */

@keyframes popDisappear {
    0% {
        transform: scale(1.1);
    }
    50% {
        transform: scale(1.4) rotate(10deg);
        opacity: 1;
    }
    100% {
        transform: scale(0) rotate(-10deg);
        opacity: 0;
    }
}

.confetti {
    position: absolute;
    width: 10px;
    height: 10px;
    background-color: #FFD700;
    animation: confettiFall 2.5s ease-out forwards;
}

@keyframes confettiFall {
    0% {
        opacity: 1;
        transform: translate(0, 0) rotate(0deg);
    }
    100% {
        opacity: 0;
        transform: translate(var(--tx), var(--ty)) rotate(360deg);
    }
}

.celebrate-text {
    position: absolute;
    font-size: 3em;
    font-weight: bold;
    animation: celebratePopup 2.5s ease-out forwards;
    pointer-events: none;
}

@keyframes celebratePopup {
    0% {
        opacity: 1;
        transform: scale(0) rotate(0deg);
    }
    50% {
        opacity: 1;
        transform: scale(1.2) rotate(10deg);
    }
    80% {
        opacity: 1;
        transform: scale(0.8) rotate(-5deg) translateY(-150px);
    }
    100% {
        opacity: 0;
        transform: scale(0.5) rotate(-10deg) translateY(-300px);
    }
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(255, 215, 0, 0.7);
    }
    50% {
        box-shadow: 0 0 0 30px rgba(255, 215, 0, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(255, 215, 0, 0);
    }
}

@keyframes fireworksExplosion {
    0% {
        opacity: 1;
        transform: translate(0, 0) rotate(0deg) scale(1);
    }
    50% {
        opacity: 1;
    }
    100% {
        opacity: 0;
        transform: translate(var(--tx), var(--ty)) rotate(var(--rotation)) scale(0);
    }
}

/* ============================================
   Buttons & Controls
   ============================================ */

#refresh-btn {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    padding: 20px 50px;
    font-size: 2em;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(0,0,0,0.3);
    font-weight: bold;
    z-index: 10000;
    animation: popIn 0.5s ease-out;
    transition: background-color 0.3s;
}

#refresh-btn:hover {
    background-color: #E53935;
    transform: translate(-50%, -50%) scale(1.05);
}

#refresh-btn:active {
    transform: translate(-50%, -50%) scale(0.95);
}

#fullscreen-btn {
    position: fixed;
    top: 12px;
    right: 72px;
    padding: 10px 16px;
    font-size: 1.2em;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    font-weight: bold;
    z-index: 1000;
    transition: all 0.3s ease;
    min-width: 50px;
    display: none;
}

#fullscreen-btn:hover {
    background-color: #FF7F7F;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    transform: scale(1.05);
}

#fullscreen-btn:active {
    transform: scale(0.95);
}

#reload-btn {
    position: fixed;
    top: 12px;
    right: 12px;
    padding: 10px 16px;
    font-size: 1.2em;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    font-weight: bold;
    z-index: 1000;
    transition: all 0.3s ease;
    min-width: 50px;
}

#reload-btn:hover {
    background-color: #FF7F7F;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    transform: scale(1.05);
}

#reload-btn:active {
    transform: scale(0.95);
}

@keyframes popIn {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0);
    }
    100% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

/* ============================================
   Overlay
   ============================================ */

.overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: none;
    z-index: 9999;
}

.overlay.show {
    display: block;
}

/* ============================================
   Loader
   ============================================ */

.loader {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 9999;
}

.loader::after {
    content: "";
    display: block;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 4px solid var(--primary-color);
    border-color: var(--primary-color) transparent var(--primary-color) transparent;
    animation: spin 1.2s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

/* ============================================
   Responsive Design - Tablet (768px)
   ============================================ */

@media (max-width: 768px) {
    #game-container {
        flex-direction: column;
    }

    #sidebar {
        width: 100%;
        height: auto;
        max-height: 35vh;
        border-right: none;
        border-bottom: 4px solid var(--primary-color);
        padding: 12px;
        padding-left: calc(12px + var(--safe-left));
        padding-right: calc(12px + var(--safe-right));
        overflow-x: auto;
        overflow-y: hidden;
        min-width: auto;
        max-width: none;
    }

    h1 {
        font-size: 1.3em;
        margin-bottom: 8px;
        display: block;
    }

    p {
        font-size: 0.95em;
        margin-bottom: 10px;
        display: block;
    }

    .items-list {
        flex-direction: row;
        flex-wrap: nowrap;
        gap: 10px;
        overflow-x: auto;
        overflow-y: hidden;
        padding: 5px 0;
        padding-right: 8px;
    }

    .item-card {
        flex: 0 0 auto;
        min-width: 100px;
        padding: 6px;
        border-radius: 6px;
    }

    .item-preview {
        width: 80px;
        height: 80px;
        border: 2px solid var(--primary-color);
    }

    .item-name {
        font-size: 0.75em;
        display: block;
        margin-top: 3px;
    }

    #fullscreen-btn {
        padding: 8px 14px;
        font-size: 1em;
        min-width: 45px;
    }

    #reload-btn {
        padding: 8px 12px;
        font-size: 0.9em;
        right: 62px;
    }
}

/* ============================================
   Responsive Design - Mobile (600px)
   ============================================ */

@media (max-width: 600px) {
    #sidebar {
        max-height: 40vh;
        padding: 12px;
        padding-left: calc(12px + var(--safe-left));
        padding-right: calc(12px + var(--safe-right));
    }

    h1 {
        font-size: 1.1em;
        display: block;
    }

    p {
        font-size: 0.9em;
        display: block;
    }

    .items-list {
        gap: 10px;
    }

    .item-card {
        min-width: 90px;
        padding: 6px;
    }

    .item-preview {
        width: 75px;
        height: 75px;
    }

    .item-name {
        font-size: 0.75em;
        display: block;
    }

    #fullscreen-btn {
        padding: 8px 12px;
        font-size: 0.9em;
    }

    #reload-btn {
        padding: 8px 10px;
        font-size: 0.85em;
        right: 55px;
    }
}

/* ============================================
   Responsive Design - Mobile (480px)
   ============================================ */

@media (max-width: 480px) {
    html, body {
        position: fixed;
        width: 100vw;
        height: 100vh;
        height: 100dvh;
        overflow: hidden;
    }

    #game-container {
        height: 100dvh;
    }

    #sidebar {
        max-height: 45vh;
        padding: 10px;
        padding-bottom: calc(10px + var(--safe-bottom));
        padding-left: calc(10px + var(--safe-left));
        padding-right: calc(10px + var(--safe-right));
    }

    h1 {
        font-size: 1em;
        margin-bottom: 5px;
    }

    p {
        font-size: 0.85em;
        margin-bottom: 8px;
    }

    .items-list {
        gap: 8px;
    }

    .item-card {
        min-width: 85px;
        padding: 5px;
    }

    .item-preview {
        width: 70px;
        height: 70px;
        border: 2px solid var(--primary-color);
    }

    .item-name {
        font-size: 0.7em;
    }

    .sprite-object {
        max-width: 80px;
        max-height: 80px;
    }

    #fullscreen-btn {
        display: none !important;
    }

    #reload-btn {
        padding: 8px 8px;
        font-size: 0.8em;
        top: 12px;
        right: 12px;
    }
}
