/* ================================
   RESET & BASE STYLES
   ================================ */
@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&family=Pixelify+Sans:wght@400;600&display=swap');

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

:root {
    /* Color Palette - Pixel Art Themed */
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-dark: #0f0e17;
    --accent-primary: #ff6b6b;
    --accent-secondary: #4ecdc4;
    --accent-gold: #ffd700;
    --text-primary: #effffa;
    --text-secondary: #c5c6c7;
    --border-color: #45a29e;

    /* Pixel Art Font */
    --font-pixel: 'Press Start 2P', cursive;
    --font-readable: 'Pixelify Sans', sans-serif;
}

body {
    font-family: var(--font-readable);
    background: linear-gradient(135deg, var(--bg-dark) 0%, var(--bg-primary) 100%);
    color: var(--text-primary);
    overflow-x: hidden;
    min-height: 100vh;
}

/* ================================
   SCREENS SYSTEM
   ================================ */
.screen {
    display: none;
    height: 100vh;
    width: 100%;
    overflow: hidden;
}

.screen.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ================================
   LANGUAGE SELECTION
   ================================ */
#language-selection {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.language-container {
    text-align: center;
    padding: 2rem;
}

.language-container h1 {
    font-family: var(--font-pixel);
    font-size: clamp(1rem, 3vw, 1.5rem);
    margin-bottom: 3rem;
    color: var(--text-primary);
    text-shadow: 3px 3px 0 rgba(0, 0, 0, 0.3);
}

.language-buttons {
    display: flex;
    gap: 2rem;
    flex-wrap: wrap;
    justify-content: center;
}

.lang-btn {
    background: var(--bg-secondary);
    border: 4px solid var(--border-color);
    padding: 2rem 3rem;
    cursor: pointer;
    font-family: var(--font-readable);
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    transition: all 0.3s ease;
    border-radius: 10px;
    box-shadow: 0 8px 0 var(--bg-dark);
}

.lang-btn:hover {
    transform: translateY(-5px);
    box-shadow: 0 13px 0 var(--bg-dark);
    border-color: var(--accent-gold);
}

.lang-btn:active {
    transform: translateY(4px);
    box-shadow: 0 4px 0 var(--bg-dark);
}

.lang-btn .flag {
    font-size: 4rem;
}

/* ================================
   MODAL
   ================================ */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--bg-secondary);
    border: 5px solid var(--accent-secondary);
    border-radius: 15px;
    padding: 2rem;
    max-width: 600px;
    width: 90%;
    box-shadow: 0 0 50px rgba(78, 205, 196, 0.5);
    animation: modalSlideIn 0.5s ease;
}

@keyframes modalSlideIn {
    from {
        transform: translateY(-100px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.timer {
    font-family: var(--font-pixel);
    font-size: clamp(1rem, 4vw, 1.5rem);
    color: var(--accent-gold);
    background: var(--bg-dark);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    border: 3px solid var(--accent-gold);
}

.game-timer {
    position: absolute;
    top: 20px;
    left: 20px;
    z-index: 200;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
    background: rgba(15, 14, 23, 0.9);
    /* High contrast */
}

.timer.expired {
    color: var(--accent-primary);
    border-color: var(--accent-primary);
    animation: pulse 1s infinite;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.6;
    }
}

.close-btn {
    background: var(--accent-primary);
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 1.5rem;
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: bold;
}

.close-btn:hover {
    transform: rotate(90deg);
    background: #ff5252;
}

.modal-body {
    text-align: center;
}

.modal-body h2 {
    font-family: var(--font-pixel);
    font-size: clamp(0.9rem, 3vw, 1.3rem);
    margin-bottom: 1.5rem;
    color: var(--accent-secondary);
}

.modal-body p {
    font-size: 1.1rem;
    line-height: 1.6;
    margin-bottom: 2rem;
    color: var(--text-secondary);
}

.start-btn {
    background: var(--accent-gold);
    border: 4px solid #ffa500;
    padding: 1rem 3rem;
    font-family: var(--font-readable);
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--bg-dark);
    cursor: pointer;
    border-radius: 10px;
    transition: all 0.3s ease;
    box-shadow: 0 6px 0 #cc8800;
}

.start-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 9px 0 #cc8800;
}

.start-btn:active {
    transform: translateY(3px);
    box-shadow: 0 3px 0 #cc8800;
}

/* ================================
   GAME CONTAINER
   ================================ */
#game-container {
    position: relative;
    width: 100%;
    height: 100%;
    padding: 1rem;
}

.room-view {
    position: relative;
    max-width: 1200px;
    max-height: 100%;
    width: auto;
    margin: 0 auto;
    background: var(--bg-dark);
    border: 5px solid var(--border-color);
    border-radius: 10px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ================================
   MAIN ROOM
   ================================ */
.room {
    display: none;
    width: 100%;
    width: 100%;
    /* height: 100% removed for auto height */
    position: relative;
}

.room.active {
    display: block;
}

.room-background {
    position: relative;
    display: inline-block;
    max-width: 100%;
    max-height: 100%;
}

/* Background Image Element */
.bg-layer {
    max-width: 100%;
    max-height: calc(100vh - 2rem - 10px);
    /* viewport - padding - border */
    width: auto;
    height: auto;
    display: block;
}

/* Legacy drawing elements hidden */
.floor,
.door-frame,
.door-panel,
.door-lock,
.shelf,
.books,
.table-top,
.table-legs,
.safe-body,
.safe-panel,
.safe-handle {
    display: none !important;
}

.floor {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 20%;
    background: linear-gradient(to bottom, #5a4a3a 0%, #3a2a1a 100%);
    border-top: 3px solid #8b7355;
}

/* Door (Center) */
.hotspot.door {
    position: absolute;
    width: 22%;
    height: 48%;
    top: 22%;
    left: 50%;
    cursor: pointer;
    z-index: 10;
}

.door-graphic {
    width: 100%;
    height: 100%;
    position: relative;
    display: none !important;
    /* Hidden as per user request (zones only) */
}

.door-frame {
    width: 100%;
    height: 100%;
    background: #654321;
    border: 4px solid #8b5a2b;
    border-radius: 8px 8px 0 0;
    position: relative;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
}

.door-panel {
    position: absolute;
    top: 10%;
    left: 10%;
    right: 10%;
    bottom: 40%;
    background: #8b5a2b;
    border: 3px solid #a0522d;
    border-radius: 5px;
}

.door-lock {
    position: absolute;
    top: 50%;
    left: 65%;
    transform: translate(-50%, -50%);
    font-size: 2rem;
    animation: lockGlow 2s ease infinite;
}

@keyframes lockGlow {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.7;
    }
}

.door-graphic.unlocked .door-lock {
    content: "🔓";
}

.door-graphic.opening {
    animation: doorOpen 1s ease forwards;
}

@keyframes doorOpen {
    to {
        transform: perspective(500px) rotateY(-90deg);
        opacity: 0;
    }
}

/* Bookshelf (Right) */
.hotspot.bookshelf {
    position: absolute;
    width: 9%;
    height: 11%;
    top: 46%;
    right: 12%;
    cursor: pointer;
    transition: transform 0.2s;
}

.hotspot.bookshelf:hover {
    transform: scale(1.05);
}

.bookshelf-graphic {
    width: 100%;
    height: 100%;
    display: none !important;
    /* Hidden as per user request */
    position: relative;
}

.shelf {
    position: absolute;
    top: 50%;
    left: 10%;
    right: 10%;
    height: 8%;
    background: #4e342e;
    border: 2px solid #3e2723;
}

.books {
    display: flex;
    gap: 8%;
    position: absolute;
    top: 20%;
    left: 10%;
    right: 10%;
    height: 30%;
}

.book {
    flex: 1;
    border: 2px solid rgba(0, 0, 0, 0.3);
    border-radius: 2px;
}

.book.red {
    background: #e74c3c;
}

.book.blue {
    background: #3498db;
}

.book.green {
    background: #2ecc71;
}

.book.yellow {
    background: #f39c12;
}

.book.glow {
    box-shadow: 0 0 20px rgba(52, 152, 219, 0.8);
    animation: bookPulse 1.5s ease infinite;
}

@keyframes bookPulse {

    0%,
    100% {
        box-shadow: 0 0 20px rgba(52, 152, 219, 0.8);
    }

    50% {
        box-shadow: 0 0 30px rgba(52, 152, 219, 1);
    }
}

/* Safe on Table (Left) */
.hotspot.safe {
    position: absolute;
    width: 9%;
    height: 13%;
    bottom: 35%;
    left: 11%;
    cursor: pointer;
    transition: transform 0.2s;
}

.hotspot.safe:hover {
    transform: scale(1.05);
}

.table-graphic {
    position: absolute;
    bottom: 0;
    width: 100%;
    height: 50%;
    /* Table logic is now in the safe.svg or implicitly handled, 
       but if safe.svg acts as safe only, we might miss the table.
       My created safe.svg was 600x420 safe only.
       Let's use safe.svg as the safe object. */
}

.table-top {
    position: absolute;
    top: 0;
    width: 100%;
    height: 15%;
    background: #8b7355;
    border: 3px solid #6d5a43;
    border-radius: 5px;
}

.table-legs {
    position: absolute;
    top: 15%;
    left: 20%;
    width: 10%;
    height: 85%;
    background: #6d5a43;
    border: 2px solid #5a4a3a;
}

.table-legs::after {
    content: '';
    position: absolute;
    left: 400%;
    width: 100%;
    height: 100%;
    background: #6d5a43;
    border: 2px solid #5a4a3a;
}

.safe-graphic {
    position: absolute;
    top: 0;
    left: 15%;
    width: 70%;
    height: 100%;
    /* Height increased to fill space */
    display: none !important;
    /* Hidden as per user request */
}

.safe-body {
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #7f8c8d 0%, #95a5a6 50%, #7f8c8d 100%);
    border: 4px solid #5a6266;
    border-radius: 8px;
    position: relative;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.4);
}

.safe-panel {
    position: absolute;
    top: 20%;
    left: 20%;
    right: 20%;
    bottom: 30%;
    background: #34495e;
    border: 3px solid #2c3e50;
    border-radius: 5px;
}

.safe-handle {
    position: absolute;
    top: 65%;
    left: 50%;
    transform: translateX(-50%);
    font-size: 1.5rem;
}

/* ================================
   CLOSE-UP VIEWS
   ================================ */
.closeup {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 100;
}

.closeup.active {
    display: block;
}

.closeup-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    cursor: pointer;
}

.closeup-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 80%;
    max-width: 600px;
    height: 70%;
    background: var(--bg-secondary);
    border: 5px solid var(--accent-secondary);
    border-radius: 15px;
    padding: 2rem;
    animation: zoomIn 0.3s ease;
}

@keyframes zoomIn {
    from {
        transform: translate(-50%, -50%) scale(0.5);
        opacity: 0;
    }

    to {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
}

/* Book Open */
/* Book Open */
.book-open {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: transparent;
    background-image: url('assets/book.png');
    background-size: 100% 100%;
    border-radius: 10px;
    overflow: hidden;
    position: relative;
    padding: 5%;
}

.book-content-area {
    width: 80%;
    height: 65%;
    display: block;
    overflow-y: hidden;

    /* 2-Column Layout */
    column-count: 2;
    column-gap: 3rem;
    column-fill: auto;

    padding: 0.5rem;
}

.riddle-text {
    font-family: var(--font-readable);
    font-size: clamp(1.3rem, 2.2vw, 1.4rem);
    color: #3E2723;
    line-height: 1.5;
    font-weight: 600;
    text-shadow: none;
    margin: 0;
    /* Ensure text breaks properly */
    word-wrap: break-word;
}

/* Legacy book elements removed */
.book-page,
.page-decoration {
    display: none;
}



/* Safe Panel Close-up */
.safe-panel-closeup {
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #7f8c8d 0%, #95a5a6 100%);
    border-radius: 10px;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
}

.safe-input-container {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    width: 100%;
    align-items: center;
}

.digital-input {
    background: #1a1a1a;
    color: #00ff00;
    font-family: 'Courier New', monospace;
    font-size: 2rem;
    padding: 1rem;
    border: 4px solid #2c3e50;
    border-radius: 8px;
    width: 90%;
    max-width: 400px;
    text-align: center;
    letter-spacing: 0.2rem;
    box-shadow: inset 0 0 20px rgba(0, 255, 0, 0.2);
    /* Remove default input styles */
    outline: none;
    text-transform: uppercase;
}

.digital-input:focus {
    border-color: #00ff00;
    box-shadow: 0 0 10px rgba(0, 255, 0, 0.5), inset 0 0 20px rgba(0, 255, 0, 0.2);
}

.safe-submit-btn {
    background: var(--accent-gold);
    color: var(--bg-dark);
    font-family: var(--font-readable);
    font-size: 1.5rem;
    font-weight: 600;
    padding: 1rem 3rem;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    text-transform: uppercase;
    box-shadow: 0 5px 15px rgba(255, 215, 0, 0.3);
}

.safe-submit-btn:hover {
    transform: scale(1.05);
    background: #ffecb3;
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.6);
}

.safe-message {
    font-family: var(--font-readable);
    font-size: 1rem;
    color: var(--accent-primary);
    min-height: 1.5rem;
    text-align: center;
}

/* Safe Interior */
.safe-interior {
    width: 100%;
    height: 100%;
    background: url('assets/safe_interior_empty.png') no-repeat center center;
    background-size: contain;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.key-item {
    text-align: center;
    cursor: pointer;
    transition: transform 0.3s;
}

.key-item:hover {
    transform: scale(1.1);
}

.key-graphic {
    width: 128px;
    height: 100px;
    margin-left: auto;
    margin-right: auto;
    /*background-color: rgba(255, 215, 0, 0.2);*/
    /* Fallback */
    background-image: url('assets/key.png');
    background-repeat: no-repeat;
    background-position: center center;
    background-size: contain;
    font-size: 0;
    /* Hide emoji */
    animation: keyFloat 2s ease-in-out infinite;
}

@keyframes keyFloat {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-10px);
    }
}

#pickup-text {
    font-family: var(--font-pixel);
    font-size: 0.8rem;
    color: var(--accent-gold);
    margin-top: 1rem;
}

/* ================================
   INVENTORY
   ================================ */
.inventory {
    position: absolute;
    bottom: 1rem;
    right: 1rem;
    background: var(--bg-secondary);
    border: 4px solid var(--border-color);
    border-radius: 10px;
    padding: 1rem;
    min-width: 150px;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
}

.inventory-title {
    font-family: var(--font-pixel);
    font-size: 0.7rem;
    color: var(--accent-secondary);
    margin-bottom: 0.5rem;
    text-align: center;
}

.inventory-slots {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    min-height: 60px;
}

.inventory-item {
    width: 60px;
    height: 60px;
    background: var(--bg-dark);
    border: 3px solid var(--border-color);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0;
    /* Hide emoji text */
    cursor: pointer;
    transition: all 0.3s;
    position: relative;
    background-image: none;
    /* Default none until item added */
    background-repeat: no-repeat;
    background-position: center;
    background-size: 80%;
}

.inventory-item[data-item="key"] {
    background-image: url('assets/key.png');
}

.inventory-item:hover {
    transform: scale(1.1);
    border-color: var(--accent-gold);
}

.inventory-item.selected {
    border-color: var(--accent-gold);
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.6);
}

.inventory-item.selected::after {
    content: '✓';
    position: absolute;
    top: -10px;
    right: -10px;
    background: var(--accent-gold);
    color: var(--bg-dark);
    width: 25px;
    height: 25px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    font-weight: bold;
}

/* ================================
   TIMER MESSAGE
   ================================ */
.timer-message {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 200;
}

.timer-message.hidden {
    display: none;
}

.message-box {
    background: var(--bg-secondary);
    border: 5px solid var(--accent-primary);
    border-radius: 15px;
    padding: 2rem;
    text-align: center;
    box-shadow: 0 0 50px rgba(255, 107, 107, 0.5);
    animation: modalSlideIn 0.5s ease;
}

.message-box p {
    font-family: var(--font-pixel);
    font-size: clamp(0.8rem, 2vw, 1rem);
    color: var(--accent-primary);
    margin-bottom: 1.5rem;
}

.close-message-btn {
    background: var(--accent-gold);
    border: 3px solid #ffa500;
    padding: 0.8rem 2rem;
    font-family: var(--font-readable);
    font-size: 1rem;
    font-weight: 600;
    color: var(--bg-dark);
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.3s;
}

.close-message-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 0 #cc8800;
}

/* ================================
   HOME PAGE
   ================================ */
#home-page {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    animation: fadeIn 1s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.home-container {
    max-width: 800px;
    padding: 2rem;
    text-align: center;
}

.home-container h1 {
    font-family: var(--font-pixel);
    font-size: clamp(1.2rem, 4vw, 2rem);
    margin-bottom: 1.5rem;
    color: var(--text-primary);
    text-shadow: 3px 3px 0 rgba(0, 0, 0, 0.3);
}

.home-container p {
    font-size: 1.2rem;
    line-height: 1.8;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.home-content {
    background: rgba(255, 255, 255, 0.1);
    border: 3px solid rgba(255, 255, 255, 0.2);
    border-radius: 15px;
    padding: 2rem;
    margin-top: 2rem;
    backdrop-filter: blur(10px);
}

/* ================================
   RESPONSIVE DESIGN
   ================================ */
@media (max-width: 768px) {
    .language-container h1 {
        font-size: 0.8rem;
    }

    .lang-btn {
        padding: 1.5rem 2rem;
    }

    .lang-btn .flag {
        font-size: 3rem;
    }

    .modal-content {
        padding: 1.5rem;
    }

    .timer {
        font-size: 0.9rem;
        padding: 0.4rem 0.8rem;
    }

    .modal-body h2 {
        font-size: 0.8rem;
    }

    .keypad {
        gap: 0.5rem;
    }

    .key-btn {
        padding: 0.8rem;
        font-size: 1.2rem;
    }

    .inventory {
        bottom: 0.5rem;
        right: 0.5rem;
        padding: 0.5rem;
        min-width: 100px;
    }

    .inventory-title {
        font-size: 0.5rem;
    }

    .inventory-item {
        width: 45px;
        height: 45px;
        font-size: 1.5rem;
    }

    .riddle-text {
        font-size: 0.9rem;
    }
}

@media (max-width: 480px) {
    .language-buttons {
        flex-direction: column;
        gap: 1rem;
    }

    .closeup-content {
        width: 95%;
        padding: 1rem;
    }

    .book-page {
        padding: 1rem;
    }
}