@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:ital,wght@0,300;0,400;0,600;1,300;1,400&display=swap');

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #ffffff;
    font-family: 'Cormorant Garamond', 'Georgia', serif;
    color: #111;
    cursor: default;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
    /* Prevent pull-to-refresh and overscroll on mobile */
    overscroll-behavior: none;
    touch-action: none;
}

#game-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    /* iOS safe area: use dvh if supported, fallback to 100vh */
    height: 100vh;
    height: 100dvh;
}

#game-canvas {
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

/* ── UI Overlays ── */

.ui-text {
    position: absolute;
    pointer-events: none;
    transition: opacity 0.6s ease;
    opacity: 0;
}

.ui-text.visible {
    opacity: 1;
}

#room-name {
    top: 40px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 1.6rem;
    font-weight: 300;
    letter-spacing: 0.25em;
    text-transform: uppercase;
    color: #222;
    white-space: nowrap;
}

#description {
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 600px;
    text-align: center;
    font-size: 1.15rem;
    font-style: italic;
    color: #333;
    line-height: 1.6;
}

#hint {
    bottom: 130px;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 500px;
    text-align: center;
    font-size: 0.95rem;
    color: #666;
    font-style: italic;
}

/* ── Inventory Bar ── */

#inventory-bar {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid #ccc;
    border-radius: 4px;
    opacity: 0;
    transition: opacity 0.4s ease;
    pointer-events: none;
}

#inventory-bar.visible {
    opacity: 1;
    pointer-events: auto;
}

.inventory-item {
    width: 48px;
    height: 48px;
    border: 1px solid #999;
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.7rem;
    text-align: center;
    padding: 2px;
    transition: border-color 0.2s;
    background: #fff;
}

.inventory-item:hover {
    border-color: #333;
}

.inventory-item.selected {
    border-color: #000;
    border-width: 2px;
    box-shadow: 0 0 4px rgba(0, 0, 0, 0.2);
}

#item-tooltip {
    position: absolute;
    display: none;
    background: #fff;
    border: 1px solid #999;
    padding: 6px 12px;
    font-size: 0.85rem;
    max-width: 200px;
    pointer-events: none;
    z-index: 100;
}

/* ── Modals ── */

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.85);
    z-index: 200;
    opacity: 1;
    transition: opacity 0.4s ease;
}

.modal.hidden {
    opacity: 0;
    pointer-events: none;
}

#text-modal-content {
    max-width: 500px;
    width: 90%;
    padding: 40px;
    border: 1px solid #aaa;
    background: #fefefe;
    position: relative;
    line-height: 1.8;
    font-size: 1.1rem;
}

#text-modal-content::before {
    content: '';
    position: absolute;
    top: 8px;
    left: 8px;
    right: 8px;
    bottom: 8px;
    border: 1px dashed #ccc;
    pointer-events: none;
}

#text-modal-body {
    margin-bottom: 24px;
    white-space: pre-wrap;
}

.modal-close {
    display: inline-block;
    padding: 6px 20px;
    border: 1px solid #999;
    background: #fff;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.9rem;
    letter-spacing: 0.1em;
    transition: background 0.2s;
}

.modal-close:hover {
    background: #f0f0f0;
}

#photo-modal-image {
    max-width: 80vw;
    max-height: 70vh;
    border: 3px solid #333;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

/* ── Loading Screen ── */

#loading {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #fff;
    z-index: 999;
    transition: opacity 1s ease;
}

#loading.hidden {
    opacity: 0;
    pointer-events: none;
}

#loading h1 {
    font-size: 2.5rem;
    font-weight: 300;
    letter-spacing: 0.4em;
    margin-bottom: 20px;
    color: #222;
}

#loading p {
    font-size: 1rem;
    color: #888;
    font-style: italic;
}

/* ── Back Button ── */

#back-btn {
    position: absolute;
    top: 40px;
    left: 30px;
    width: 36px;
    height: 36px;
    border: 1px solid #bbb;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.7);
    color: #555;
    font-size: 1.1rem;
    font-family: inherit;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.4s ease, border-color 0.2s;
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

#back-btn.visible {
    opacity: 1;
    pointer-events: auto;
}

#back-btn:hover {
    border-color: #666;
    color: #222;
    background: rgba(255, 255, 255, 0.9);
}

/* ── Cursors ── */

body.cursor-pointer {
    cursor: pointer;
}

body.cursor-grab {
    cursor: grab;
}

body.cursor-zoom-in {
    cursor: zoom-in;
}

/* ── Mobile / Small Screens ── */

@media (max-width: 768px) {
    #room-name {
        top: 24px;
        font-size: 1.1rem;
        letter-spacing: 0.15em;
    }

    #description {
        bottom: 50px;
        font-size: 0.95rem;
        line-height: 1.5;
    }

    #hint {
        bottom: 100px;
        font-size: 0.85rem;
    }

    #back-btn {
        top: 20px;
        left: 16px;
        width: 32px;
        height: 32px;
        font-size: 0.95rem;
    }

    #loading h1 {
        font-size: 1.8rem;
        letter-spacing: 0.3em;
    }

    #loading p {
        font-size: 0.9rem;
    }

    #text-modal-content {
        padding: 24px;
        font-size: 1rem;
    }

    .inventory-item {
        width: 40px;
        height: 40px;
    }

    #photo-modal-image {
        max-width: 92vw;
        max-height: 65vh;
    }
}

@media (max-width: 480px) {
    #room-name {
        top: 16px;
        font-size: 0.95rem;
    }

    #description {
        bottom: 36px;
        font-size: 0.85rem;
    }

    #back-btn {
        top: 14px;
        left: 12px;
        width: 28px;
        height: 28px;
        font-size: 0.85rem;
    }
}

/* ── iOS safe areas ── */

@supports (padding: env(safe-area-inset-top)) {
    #back-btn {
        top: calc(40px + env(safe-area-inset-top));
        left: calc(30px + env(safe-area-inset-left));
    }

    #room-name {
        top: calc(40px + env(safe-area-inset-top));
    }

    #description {
        bottom: calc(80px + env(safe-area-inset-bottom));
    }

    @media (max-width: 768px) {
        #back-btn {
            top: calc(20px + env(safe-area-inset-top));
            left: calc(16px + env(safe-area-inset-left));
        }

        #room-name {
            top: calc(24px + env(safe-area-inset-top));
        }

        #description {
            bottom: calc(50px + env(safe-area-inset-bottom));
        }
    }
}
