/* --- Base Styling --- */
body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #1a1a1a; 
    color: #333;
    margin: 0;
    padding: 20px;
    display: flex;
    justify-content: center;
}

#game-container {
    background-color: #fff;
    width: 100%;
    max-width: 1300px;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.8);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* --- Status Bar & Tension Meter --- */
#status-bar {
    background-color: #3e2723;
    padding: 15px 25px;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 3px solid #d84315;
}

.status-left { display: flex; align-items: center; gap: 15px; }
.status-left h2 { margin: 0; font-size: 1rem; text-transform: uppercase; letter-spacing: 1px;}

.tension-bar-container {
    width: 200px; height: 12px;
    background-color: #111; border-radius: 6px; overflow: hidden;
}

#tension-fill {
    height: 100%; 
    /* Removed the static background gradient here */
    transition: width 0.5s ease-in-out, background-color 0.5s ease-in-out;
}

.status-right { display: flex; align-items: center; gap: 20px; }
.status-right p { margin: 0; font-style: italic; opacity: 0.9; font-size: 1.1rem; }

#settings-btn {
    background-color: #5d4037;
    padding: 8px 15px;
    font-size: 0.9rem;
}
#settings-btn:hover { background-color: #4e342e; }

/* --- Main Display (Room + Inspector) --- */
#main-display {
    display: flex;
    height: 550px;
}

#room-view {
    flex-grow: 1; 
    display: flex;
    justify-content: space-around;
    align-items: flex-end; 
    padding: 0 10px;
    background-color: #8c92ac; 
    background-image: url('assets/Backgrounds/Meeting_Room.png'); 
    background-size: cover;
    background-position: center bottom;
    position: relative;
    transition: width 0.3s ease;
    overflow: hidden; 
}

/* --- Characters & Previews --- */
.character-slot {
    position: relative; display: flex; flex-direction: column;
    justify-content: flex-end; align-items: center;
    height: 100%; width: 25%; 
    cursor: pointer; z-index: 10;
}

.character-slot img {
    height: 115%; 
    width: auto; 
    max-width: none; 
    margin-bottom: -65%; /* YOUR PERFECTED CROP SETTING */
    object-fit: contain;
    object-position: bottom center; 
    filter: drop-shadow(0 5px 15px rgba(0,0,0,0.4));
    display: block; 
    transition: transform 0.2s ease, filter 0.2s ease;
    transform-origin: bottom center; 
}

.character-slot:hover { z-index: 15; }
.character-slot:hover img {
    transform: scale(1.03); 
    filter: drop-shadow(0 10px 25px rgba(0,0,0,0.6));
}

.preview-bubble {
    position: absolute;
    top: 5px; 
    width: 150px; padding: 10px 15px;
    border-radius: 12px; font-size: 0.9rem; line-height: 1.3;
    z-index: 20; pointer-events: none;
    box-shadow: 0 4px 10px rgba(0,0,0,0.4);
    display: -webkit-box; -webkit-line-clamp: 3;
    -webkit-box-orient: vertical; overflow: hidden;
}

.speech-bubble { background-color: #ffffff; color: #222; border: 2px solid #bdc3c7; font-weight: bold; }
.thought-bubble { background-color: #f1f5f8; color: #555; border: 2px dashed #95a5a6; font-style: italic; }

/* --- Side Inspector Panel --- */
#inspector-panel {
    width: 320px; background-color: #fcf9f2; 
    border-left: 2px solid #ccc; padding: 25px;
    box-sizing: border-box; overflow-y: auto;
    position: relative; z-index: 30;
}

.close-inspector {
    position: absolute; top: 10px; right: 15px;
    background: none; border: none; font-size: 1.5rem;
    color: #888; cursor: pointer;
}

#inspector-name { margin-top: 0; color: #3e2723; border-bottom: 2px solid #d84315; padding-bottom: 5px; }
.inspector-section { margin-top: 20px; }
.inspector-section h3 { margin: 0 0 5px 0; color: #d84315; font-size: 0.9rem; text-transform: uppercase;}
.spoken-text { font-weight: bold; font-size: 1.05rem; color: #222;}
.thought-text { font-style: italic; color: #555; }
.action-text { color: #444; }

/* --- Settings Modal --- */
.settings-content {
    width: 400px;
    position: relative;
    color: #333;
}

.settings-content h2 { margin-top: 0; border-bottom: 2px solid #eee; padding-bottom: 10px; }

.setting-row {
    display: flex; justify-content: space-between; align-items: center;
    margin: 20px 0; font-size: 1.1rem;
}

.setting-row select {
    padding: 5px 10px; font-size: 1rem; border-radius: 5px;
}

.save-btn { width: 100%; margin-top: 20px; background-color: #7f8c8d; }
.save-btn:hover { background-color: #636e72; }

/* --- Input Area --- */
#input-area {
    padding: 20px; display: flex; gap: 15px;
    background-color: #efebe4; border-top: 1px solid #ccc;
}

#player-input {
    flex-grow: 1; height: 60px; padding: 12px;
    border-radius: 8px; border: 1px solid #bbb;
    resize: none; font-family: inherit; font-size: 1.1rem;
}

button {
    padding: 0 30px; background-color: #d84315; 
    color: white; border: none; border-radius: 8px;
    font-weight: bold; cursor: pointer; font-size: 1.1rem;
    transition: background-color 0.2s;
}

button:hover { background-color: #bf360c; }

/* --- Utilities --- */
.hidden { display: none !important; }
.overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background-color: rgba(0,0,0,0.85); display: flex; justify-content: center; align-items: center;
    z-index: 1000;
}
.overlay-content { background: #fff; padding: 40px; border-radius: 12px; text-align: left; }

#history-panel {
    position: fixed;
    top: 0;
    left: -380px; 
    width: 350px;
    height: 100%;
    background-color: #fdfbf7;
    box-shadow: 5px 0 25px rgba(0,0,0,0.5);
    transition: left 0.3s ease-in-out; 
    z-index: 2000;
    box-sizing: border-box;
    /* NEW: Flexbox setup to separate the sticky header and the scrolling list */
    display: flex;
    flex-direction: column;
}

/* When this class is added via JS, it slides onto the screen */
#history-panel.open {
    left: 0;
}

#history-panel h2 {
    color: #3e2723;
    border-bottom: 2px solid #d84315;
    padding-bottom: 10px;
    margin-top: 0;
}

#history-btn {
    background-color: #f39c12; /* Distinct color so it stands out */
    padding: 8px 15px;
    font-size: 0.9rem;
}
#history-btn:hover { background-color: #e67e22; }

.history-header {
    position: relative; /* Allows the absolute 'close' button to stick to this header */
    padding: 25px 25px 15px 25px;
    background-color: #fdfbf7;
    flex-shrink: 0; /* Prevents the header from collapsing */
    box-shadow: 0 4px 10px rgba(0,0,0,0.05); /* Adds a nice subtle shadow over the scrolling text */
    z-index: 10;
}

#history-list {
    padding: 10px 25px 25px 25px;
    overflow-y: auto; /* Moves the scrollbar to ONLY this list */
    flex-grow: 1; /* Tells the list to take up the rest of the height */
}

/* Cleaner styling for the export button with a hover effect */
.export-btn {
    width: 100%; 
    padding: 10px; 
    background-color: #3498db; 
    color: white; 
    border: none; 
    border-radius: 5px; 
    cursor: pointer; 
    font-weight: bold;
    transition: background-color 0.2s;
}

.export-btn:hover {
    background-color: #2980b9;
}

/* Individual History Card */
.history-item {
    background: #fff;
    padding: 15px;
    margin-bottom: 15px;
    border-radius: 8px;
    border-left: 5px solid #d84315;
    box-shadow: 0 3px 8px rgba(0,0,0,0.1);
}

.history-turn-number {
    font-size: 0.8rem;
    color: #95a5a6;
    text-transform: uppercase;
    margin-bottom: 5px;
    font-weight: bold;
}

.history-player-text {
    font-weight: bold;
    color: #2c3e50;
    margin-bottom: 8px;
    font-size: 1rem;
}

.history-summary-text {
    font-size: 0.9rem;
    color: #7f8c8d;
    font-style: italic;
    background: #f1f5f8;
    padding: 8px;
    border-radius: 4px;
}

.rewind-btn {
    width: 100%;
    background: #bdc3c7;
    color: #333;
    padding: 8px;
    font-size: 0.9rem;
    margin-top: 10px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: background 0.2s;
}

.rewind-btn:hover { background: #e74c3c; color: white; }

/* Add this to the end of style.css */
#save-data-box {
    border: 1px solid #ccc;
    background-color: #f9f9f9;
    color: #333;
}

#save-data-box:focus {
    outline: none;
    border-color: #d84315;
}

/* Mic Button Recording State */
#mic-btn.recording {
    background-color: #e74c3c !important; /* Red */
    animation: mic-pulse 1.5s infinite;
}

@keyframes mic-pulse {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.4); }
    70% { transform: scale(1.1); box-shadow: 0 0 0 10px rgba(231, 76, 60, 0); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(231, 76, 60, 0); }
}

/* =========================================
   📱 MOBILE RESPONSIVENESS STYLES (FINAL FIX)
   ========================================= */

/* Universal Mobile Fixes (Both Portrait & Landscape) */
@media (max-width: 768px), (max-height: 600px) {
    body { 
        padding: 0; 
        background-color: #000; 
        margin: 0; 
        overflow: hidden; 
    }

    #game-container {
        height: 100dvh; 
        border-radius: 0;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        box-sizing: border-box;
    }

    #status-bar, #input-area {
        flex-shrink: 0; 
    }

    #main-display {
        flex: 1;
        height: auto;
        min-height: 0;
        display: flex;
    }

    #room-view {
        flex: 1; 
        min-height: 0; 
        display: flex;
        padding: 10px;
        box-sizing: border-box;
    }
    
    .character-slot { box-sizing: border-box; }

    /* FIXED: Inspector panel is now a floating overlay on mobile */
    #inspector-panel {
        position: fixed;
        top: 0;
        right: 0;
        height: 100%;
        width: 300px;
        max-width: 85vw; /* Prevents it from being too wide on small phones */
        z-index: 3000;
        box-shadow: -5px 0 25px rgba(0,0,0,0.6);
    }
}

/* 1. PORTRAIT MODE (Phones held vertically) */
@media (max-width: 768px) and (orientation: portrait) {
    #status-bar {
        flex-direction: column;
        padding: 10px;
        gap: 10px;
        text-align: center;
    }
    .status-left { flex-direction: column; gap: 5px; }

    #room-view {
        flex-wrap: wrap;
        align-content: stretch; 
        justify-content: space-between; 
        overflow: hidden; 
        gap: 10px 0; 
    }

    .character-slot {
        width: 48%; 
        height: 48%; 
        display: flex;
        flex-direction: column;
        margin: 0; 
        justify-content: flex-end;
    }

    .character-slot img {
        height: 100%; 
        width: 100%; 
        object-fit: cover; 
        object-position: top center; 
        margin-bottom: 0; 
        
        -webkit-mask-image: linear-gradient(to bottom, rgba(0,0,0,1) 60%, rgba(0,0,0,0) 100%);
        mask-image: linear-gradient(to bottom, rgba(0,0,0,1) 60%, rgba(0,0,0,0) 100%);
    }

    .character-slot .preview-bubble {
        position: relative !important;
        bottom: auto !important; left: auto !important; top: auto !important; transform: none !important;
        width: 95% !important;
        margin: 0 auto 5px auto !important;
        font-size: 0.85rem;
        padding: 8px !important;
        z-index: 10;
    }
}

/* 2. LANDSCAPE MODE (Phones held horizontally) */
@media (max-height: 600px) and (orientation: landscape) {
    #status-bar { 
        padding: 5px; 
        flex-direction: row; 
        justify-content: space-between; 
    }
    .status-left h2 { font-size: 0.8rem; }
    .status-left { gap: 10px; }
    
    /* FIXED: Prevents turn summary text from overlapping the UI */
    .status-right p {
        font-size: 0.8rem;
        max-width: 35vw;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        margin-right: 10px;
    }

    #input-area { padding: 5px 10px; }
    #player-input { height: 40px; } 

    #room-view {
        flex-wrap: nowrap !important; 
        overflow: hidden; 
        justify-content: space-around; 
        align-items: flex-end; 
        padding: 0; 
    }

    .character-slot {
        flex: 1; 
        height: 100%;
        position: relative; 
        display: flex;
        flex-direction: column;
        justify-content: flex-end; /* Anchors everything to the bottom */
        align-items: center; 
    }

    /* FIXED: Characters shrunk slightly to leave room for bubbles */
    .character-slot img {
        height: 150%; /* Leaves the top 25% of the screen totally empty */
        width: 100%;
        max-width: none; 
        margin-bottom: -65%; 
        object-fit: contain;
        object-position: bottom center;
        transform: none;
    }
    
    .character-slot:hover img { transform: none; }
    
    /* FIXED: Bubbles pin to the empty space at the very top */
    .character-slot .preview-bubble {
        position: absolute !important;
        top: 2px !important; 
        left: 50% !important;
        transform: translateX(-50%) !important; 
        width: 95% !important; 
        font-size: 0.7rem; 
        line-height: 1.1;
        padding: 4px !important;
        margin: 0 !important;
        z-index: 20; 
        box-sizing: border-box;
    }
}

/* =========================================
   SUPERVISOR OFFICE STYLES
   ========================================= */

#supervisor-btn {
    background-color: #8e44ad;
    padding: 8px 15px;
    font-size: 0.9rem;
}
#supervisor-btn:hover { background-color: #732d91; }

#supervisor-office {
    flex-grow: 1;
    display: flex;
    background-color: #d1d8e0;
    /* NEW: Watanabe's Background Asset */
    background-image: url('assets/Backgrounds/Watanabe_Office.png'); 
    background-size: cover;
    background-position: center bottom;
    position: relative;
    overflow: hidden;
}

.leave-btn {
    position: absolute;
    top: 15px;
    left: 15px;
    background-color: #2c3e50;
    padding: 10px 20px;
    z-index: 50;
}
.leave-btn:hover { background-color: #1a252f; }

#supervisor-visuals {
    flex: 1;
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: flex-end; /* Anchors him to the bottom */
    align-items: center;
    overflow: hidden; /* Hides the negative crop overflow */
}

#supervisor-visuals img {
    height: 115%; /* Matches the other characters */
    width: auto;
    max-width: none;
    margin-bottom: -65%; /* YOUR PERFECTED CROP SETTING */
    object-fit: contain;
    object-position: bottom center;
    filter: drop-shadow(0 10px 20px rgba(0,0,0,0.6));
    display: block;
    transition: all 0.3s ease;
    transform-origin: bottom center;
}

#supervisor-chat-panel {
    width: 400px;
    background: rgba(255, 255, 255, 0.95);
    border-left: 3px solid #8e44ad;
    display: flex;
    flex-direction: column;
}

#supervisor-chat-history {
    flex-grow: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.sup-msg {
    padding: 12px;
    border-radius: 8px;
    max-width: 85%;
    line-height: 1.4;
    font-size: 0.95rem;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.sup-msg.user {
    background: #e1d5e7;
    align-self: flex-end;
    border-bottom-right-radius: 0;
    color: #333;
}

.sup-msg.sensei {
    background: #fcf9f2;
    border: 1px solid #ccc;
    align-self: flex-start;
    border-bottom-left-radius: 0;
    color: #222;
}

#supervisor-input-area {
    padding: 20px;
    display: flex;
    gap: 15px;
    background-color: #f4ecf7;
    border-top: 2px solid #8e44ad;
}

#supervisor-input {
    flex-grow: 1;
    height: 60px;
    padding: 12px;
    border-radius: 8px;
    border: 1px solid #bbb;
    resize: none;
    font-family: inherit;
    font-size: 1.1rem;
}

/* Mobile Responsiveness for Office */
@media (max-width: 768px) {
    #supervisor-office { flex-direction: column; }
    #supervisor-visuals { display: none; } /* Hide sprite on small phones to save space for chat */
    #supervisor-chat-panel { width: 100%; height: 100%; border-left: none; }
}