/* ==========================================
   1. GLOBAL SYSTEM & VARIABLES
   ========================================== */
:host { 
    pointer-events: none; 
    width: 100%; 
    height: 100%; 
    position: absolute; 
    top: 0; 
    left: 0; 
}

:root {
    --neon-amber: #ffb000;
    --dark-bg: rgba(12, 14, 17, 0.95);
    --panel-bg: rgba(26, 30, 36, 0.95);
    --border-color: #333;
    --text-color: #e0e0e0;
    --terminal-green: #00ff66;
}

/* ==========================================
   2. LEFT-ANCHORED MAP TERMINAL UI
   ========================================== */
.map-interface-container {
    position: fixed;
    left: 0;           /* Anchored to the Left Edge */
    top: 20px;         /* Positioned near the top */
    z-index: 9999;
    display: flex;
    align-items: center;
    width: auto;
    /* Mechanical Slide Animation */
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* When collapsed, slide to the left by exactly the width of the panel (250px) */
.map-interface-container.collapsed {
    transform: translateX(-250px);
}

.map-control-overlay {
    position: relative; 
    background: var(--panel-bg);
    border: 2px solid var(--neon-amber);
    border-left: none; /* Flush against the left screen edge */
    width: 250px;
    padding: 15px;
    border-radius: 0 4px 4px 0; /* Rounded on the right side only */
    box-shadow: 4px 4px 15px rgba(0,0,0,0.5);
    pointer-events: auto; /* Catch clicks */
    box-sizing: border-box;
}

/* The Handle (Attached to the right side of the panel) */
.map-control-overlay::after {
    content: "▶"; 
    position: absolute;
    right: -28px; /* Sticks out past the right edge */
    top: 50%;
    transform: translateY(-50%);
    background: var(--neon-amber);
    color: #000;
    padding: 15px 5px;
    cursor: pointer;
    border-radius: 0 5px 5px 0;
    font-weight: bold;
    box-shadow: 4px 0px 10px rgba(0,0,0,0.5);
}

/* Change arrow direction when the panel is OPEN (not collapsed) */
.map-interface-container:not(.collapsed) .map-control-overlay::after {
    content: "◀";
}

/* Terminal Buttons & Selects */
.terminal-back-btn {
    background: #050505;
    color: var(--neon-amber);
    border: 1px solid #444;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.8rem;
    font-weight: bold;
    padding: 10px 15px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-transform: uppercase;
    height: 38px;
    box-sizing: border-box;
    width: 100%;
    margin-bottom: 10px;
}

.terminal-back-btn:hover {
    background: #111;
    border-color: var(--neon-amber);
    box-shadow: inset 3px 0 0 var(--neon-amber);
}

.switcher-box {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.switcher-box label {
    font-size: 0.65rem;
    color: #888;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.map-control-overlay select {
    background: #050505; 
    color: var(--terminal-green); 
    border: 1px solid #444; 
    font-family: inherit; 
    padding: 5px 10px; 
    font-weight: bold;
    font-size: 0.85rem;
    height: 28px;
    border-radius: 2px;
    box-sizing: border-box;
    width: 100%;
}

.map-control-overlay select:focus {
    outline: none;
    border-color: var(--neon-amber);
}

/* ==========================================
   3. CHARACTER SIDEBAR & CREATOR
   ========================================== */
#creator-form {
    transition: opacity 0.3s ease, filter 0.3s ease;
}

#creator-form.inactive {
    opacity: 0.3;
    pointer-events: none;
    filter: grayscale(100%);
}

#character-sidebar {
    pointer-events: auto;
    position: absolute;
    top: 0;
    right: 0;
    width: 450px;
    height: 100%;
    background-color: var(--dark-bg);
    color: var(--text-color);
    font-family: 'Courier New', Courier, monospace;
    margin: 0;
    padding: 20px;
    box-sizing: border-box;
    overflow-y: auto;
    border-left: 2px solid var(--neon-amber);
    box-shadow: -5px 0 25px rgba(0,0,0,0.8);
    transform: translateX(100%); 
    transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

#character-sidebar.is-open { transform: translateX(0); }

header { text-align: center; border-bottom: 2px solid var(--neon-amber); padding-bottom: 10px; margin-bottom: 20px; }
h1 { color: var(--neon-amber); margin: 0; text-transform: uppercase; letter-spacing: 2px; font-size: 1.2rem; }

.panel { background-color: var(--panel-bg); border: 1px solid var(--border-color); padding: 15px; border-radius: 4px; margin-bottom: 15px; }
.panel-title { color: var(--neon-amber); font-weight: bold; text-transform: uppercase; border-bottom: 1px solid var(--border-color); padding-bottom: 5px; margin-top: 0; margin-bottom: 15px; font-size: 0.9rem; }
.control-group { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; margin-bottom: 15px; }
label { display: block; margin-bottom: 5px; font-weight: bold; color: #aaa; text-transform: uppercase; font-size: 0.75rem; }

select, input, textarea { width: 100%; padding: 8px; background-color: #050505; color: var(--text-color); border: 1px solid var(--border-color); font-family: inherit; border-radius: 4px; box-sizing: border-box; font-size: 0.8rem; }
select:focus, input:focus, textarea:focus { outline: none; border-color: var(--neon-amber); background-color: #111; }

.terminal-log { background-color: #050505; border: 1px solid #222; border-left: 3px solid var(--terminal-green); padding: 10px; font-size: 0.8rem; line-height: 1.4; min-height: 100px; color: var(--terminal-green); white-space: pre-wrap; overflow-y: auto; }

/* ==========================================
   4. SCROLLBARS & TABS
   ========================================== */
.wrapper.char-creator { max-height: 100vh; overflow-y: auto; pointer-events: auto; padding-bottom: 40px; box-sizing: border-box; }
.wrapper.char-creator::-webkit-scrollbar { width: 8px; }
.wrapper.char-creator::-webkit-scrollbar-track { background: #0a0a0a; border-left: 1px solid #222; }
.wrapper.char-creator::-webkit-scrollbar-thumb { background: #333; border-radius: 4px; }
.wrapper.char-creator::-webkit-scrollbar-thumb:hover { background: var(--neon-amber); }

.tab-nav { display: flex; gap: 15px; margin-bottom: 20px; border-bottom: 2px solid #222; padding-bottom: 0; }
.tab-btn { background: transparent; color: #666; border: none; border-bottom: 3px solid transparent; padding: 10px 20px; font-family: 'Courier New', Courier, monospace; font-weight: bold; font-size: 1rem; cursor: pointer; text-transform: uppercase; transition: all 0.2s ease; }
.tab-btn:hover { color: #aaa; }
.tab-btn.active { color: var(--neon-amber); border-bottom: 3px solid var(--neon-amber); background: linear-gradient(0deg, rgba(255, 176, 0, 0.1) 0%, transparent 100%); }
.tab-content { animation: fadeIn 0.3s ease; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

/* ==========================================
   5. MENU & MASTER CONSOLE OVERRIDES
   ========================================== */
.console-wrapper { background-color: var(--dark-bg); color: var(--text-color); font-family: 'Courier New', Courier, monospace; width: 100%; height: 100%; display: flex; flex-direction: column; box-sizing: border-box; padding: 20px; }
.console-header { border-bottom: 2px solid var(--neon-amber); padding-bottom: 10px; margin-bottom: 20px; display: flex; justify-content: space-between; align-items: center; }
.console-body { display: flex; gap: 20px; flex: 1; min-height: 0; }
.registry-sidebar { flex: 0 0 300px; background: var(--panel-bg); border: 1px solid var(--border-color); padding: 15px; display: flex; flex-direction: column; border-radius: 4px; }
.registry-list { flex: 1; border: 1px solid #222; background: #050505; margin-top: 10px; padding: 10px; overflow-y: auto; font-size: 0.85rem; }
.ingestion-matrix { flex: 1; background: var(--panel-bg); border: 1px solid var(--border-color); padding: 20px; border-radius: 4px; overflow-y: auto; }

button { width: 100%; padding: 12px; background-color: #222; color: var(--neon-amber); border: 1px solid var(--neon-amber); font-family: inherit; font-weight: bold; cursor: pointer; }
button:hover { background-color: var(--neon-amber); color: #000; }

.menu-wrapper { background-color: var(--dark-bg); color: var(--text-color); font-family: 'Courier New', Courier, monospace; width: 400px; margin: 50px auto; padding: 30px; border: 1px solid var(--border-color); border-top: 3px solid var(--neon-amber); box-shadow: 0 0 30px rgba(0,0,0,0.8); display: flex; flex-direction: column; gap: 20px; }
.nav-btn { width: 100%; padding: 15px; margin-bottom: 15px; background-color: #050505; color: var(--text-color); border: 1px solid #333; font-family: inherit; font-size: 1rem; font-weight: bold; text-align: left; cursor: pointer; transition: all 0.2s ease; display: flex; align-items: center; }
.btn-num { color: var(--neon-amber); margin-right: 15px; font-size: 1.2rem; }
.nav-btn:hover:not(.locked) { background-color: #111; border-color: var(--neon-amber); box-shadow: inset 5px 0 0 var(--neon-amber); }
.nav-btn.locked { opacity: 0.4; cursor: not-allowed; filter: grayscale(100%); border-color: #ff4c4c; flex-direction: column; align-items: flex-start; }
.lock-status { font-size: 0.7rem; color: #ff4c4c; margin-top: 5px; }
.nav-btn.gm-unlocked { border-color: var(--terminal-green); }
.nav-btn.gm-unlocked .btn-num, .nav-btn.gm-unlocked .lock-status { color: var(--terminal-green); }

/* Char Creator Specific Buttons */
.stat-upgrade-box { background: #111; border: 1px solid #333; padding: 10px; border-radius: 4px; text-align: center; }
.stat-controls { display: flex; gap: 5px; margin-top: 5px; }
.stat-controls input { width: 60%; text-align: center; font-size: 1.2rem; font-weight: bold; color: var(--neon-amber); background: #000; }
.btn-upgrade-stat { width: 40%; background: #222; color: var(--terminal-green); border: 1px solid var(--terminal-green); font-size: 1.2rem; padding: 0; line-height: 1; }
.btn-upgrade-stat:hover { background: var(--terminal-green); color: #000; }

/* ==========================================
   6. DRAGGABLE COMMS LINK (CHAT)
   ========================================== */
.chat-container {
    position: absolute;
    top: 50px;
    right: 50px; /* Default starting position */
    width: 350px;
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-top: 3px solid var(--neon-amber);
    border-radius: 4px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.8);
    display: flex;
    flex-direction: column;
    z-index: 9998; /* Just under the main terminal */
    
    /* The Dimmable Effect */
    opacity: 0.5;
    transition: opacity 0.3s ease;
    pointer-events: auto;
}

/* Lights up to full opacity when hovering or focused */
.chat-container:hover, .chat-container:focus-within {
    opacity: 1.0;
}

.chat-header {
    background: #050505;
    padding: 8px 10px;
    cursor: grab; /* Shows the grab hand for moving */
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #222;
    font-size: 0.8rem;
}

.chat-header:active {
    cursor: grabbing;
}

.chat-channel-select {
    background: transparent;
    color: var(--text-color);
    border: none;
    font-family: inherit;
    font-size: 0.7rem;
    font-weight: bold;
    cursor: pointer;
}

.chat-messages {
    height: 250px;
    overflow-y: auto;
    padding: 10px;
    font-size: 0.8rem;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Custom Scrollbar for Chat */
.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-track { background: #0a0a0a; }
.chat-messages::-webkit-scrollbar-thumb { background: #333; border-radius: 3px; }

.chat-input {
    background: #050505;
    color: var(--terminal-green);
    border: none;
    border-top: 1px solid #333;
    padding: 10px;
    font-family: inherit;
    font-size: 0.85rem;
    outline: none;
}
.chat-input:focus {
    background: #111;
}

/* Chat Message Styling */
.chat-msg-row {
    display: flex;
    gap: 10px;
    align-items: flex-start;
}
.chat-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 1px solid var(--neon-amber);
    object-fit: cover;
}
.chat-content { flex: 1; }
.chat-username { font-weight: bold; color: var(--neon-amber); font-size: 0.75rem; margin-bottom: 2px; }
.chat-text { color: var(--text-color); line-height: 1.3; }

/* ==========================================
   7. SEAMLESS TRANSITION BLACKOUT (CLICK BARRIER)
   ========================================== */
.matrix-blackout {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: #000000;
    opacity: 0;
    display: none; /* Hidden by default when not in use */
    pointer-events: none; 
    z-index: 100000; 
    transition: opacity 0.3s ease-in-out;
}

/* While engaged, it is completely visible and swallows ALL inputs */
.matrix-blackout.engaged {
    display: block !important;
    opacity: 1 !important;
    pointer-events: auto !important; /* Total input block block */
}

.char-quick-card:hover {
    background: #1a1a1a !important;
    border-color: var(--neon-amber) !important;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(255, 176, 0, 0.2);
}

.vtt-token-preview-anchor {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    border: 3px dashed var(--neon-amber);
    background: transparent; /* Allows Construct 3 sprites to overlay from below */
    display: inline-block;
    vertical-align: middle;
    margin-right: 15px;
}

/* ==========================================
   8. TACTICAL MOBILE RESPONSIVENESS (PHONES/TABLETS)
   ========================================== */
@media (max-width: 768px) {
    /* 1. Eliminate Browser Auto-Zoom & Fix Touch Targets */
    select, input, textarea, button {
        min-height: 44px !important; 
        font-size: 16px !important; 
        padding: 10px !important;
    }

    /* 2. Stack the Account Hub Menus Vertically */
    .console-body {
        flex-direction: column;
        overflow-y: auto;
    }
    
    .registry-sidebar {
        flex: 0 0 auto;
        width: 100%;
        border-right: none;
        border-bottom: 2px solid var(--neon-amber);
        margin-bottom: 20px;
    }

    /* 3. Character Creator Sidebar (Full Screen Mode) */
    #character-sidebar {
        width: 100vw; 
        border-left: none;
        padding: 10px;
    }
    
    /* Stack side-by-side elements on the character sheet */
    .control-group {
        grid-template-columns: 1fr; 
        gap: 10px;
    }
    
    #tab-identity {
        grid-template-columns: 1fr !important;
    }
    
    /* Allow tabs to wrap if there are too many for one row */
    .tab-nav {
        flex-wrap: wrap; 
    }
    
    .tab-btn {
        flex: 1 1 40%; 
        font-size: 0.85rem;
        padding: 10px 5px;
    }

    /* 4. Map Terminal UI (Slide Out Override) */
    .map-control-overlay {
        width: 85vw; /* Leaves a tiny sliver of map visible on the right */
        max-width: 320px;
    }
    
    .map-interface-container.collapsed {
        /* Syncs the slide animation perfectly to the new mobile width */
        transform: translateX(-85vw); 
    }

    /* 5. Comms Link (Chat Drawer) */
    .chat-container {
        top: auto;
        bottom: 0;
        right: 0;
        width: 100%;
        border-radius: 10px 10px 0 0; 
        border-right: none;
        border-bottom: none;
        box-shadow: 0 -5px 20px rgba(0,0,0,0.8);
    }
}