body {
    margin: 0;
    padding: 0;
    background: #1a1a1a;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    overflow: hidden;
}
canvas {
    display: block;
}
/* UI System Styles */
.ui-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none; /* Disables clicks on the container itself */
    z-index: 1000;
    display: flex;
    flex-direction: column;
    padding: 20px;
    box-sizing: border-box;
    gap: 15px; /* Adds space between UI sections */
}
.ui-container > * {
    pointer-events: auto; /* Re-enables clicks for direct children of the container */
}
/* New Top Bar Container */
.ui-top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    pointer-events: auto; /* Enable clicks on items inside */
}
/* New Left Column for stacked panels */
.ui-left-column {
    display: flex;
    flex-direction: column;
    gap: 15px;
    align-items: flex-start;
}
.panel {
    background: rgba(10, 15, 20, 0.75);
    color: #e0e0e0;
    border-radius: 20px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.37);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    opacity: 0;
    transition: opacity 0.4s ease, transform 0.4s ease;
    pointer-events: none;
    border: 1px solid rgba(255, 255, 255, 0.18);
    position: relative; /* All panels are relative now */
}
.panel.visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}
.panel-header {
    font-size: 12px;
    color: #8899aa;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 10px;
}
.action-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}
.action-button {
    background-color: rgba(255, 255, 255, 0.1);
    color: #e0e0e0;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    padding: 10px;
    cursor: pointer;
    font-size: 14px;
    transition: background-color 0.2s ease, border-color 0.2s ease;
    font-family: inherit;
}
.action-button:hover {
    background-color: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.4);
}
.action-button.active {
    background-color: #00AFFF;
    color: #ffffff;
    border-color: #00AFFF;
    font-weight: bold;
}
.object-selection {
    background: rgba(0,0,0,0.2);
    padding: 12px;
    border-radius: 8px;
    text-align: center;
    font-weight: 500;
}
.texture-selection {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
    gap: 8px;
    padding: 8px;
    background: rgba(0,0,0,0.15);
    border-radius: 8px;
    min-height: 40px; /* Ensure it has a size even when empty */
    align-content: flex-start;
}
.texture-selection .action-button {
    width: 40px;
    height: 40px;
    padding: 0;
    overflow: hidden;
    background-size: cover;
    background-position: center;
}
.texture-selection .no-textures-message {
    grid-column: 1 / -1; /* Span all columns */
    color: #8899aa;
    font-size: 12px;
    text-align: center;
    align-self: center;
    padding: 10px 0;
}
#character-panel {
    padding: 20px;
    border: 2px solid #4a9eff;
    min-width: 300px;
    box-shadow: 0 0 15px rgba(74, 158, 255, 0.5), inset 0 0 5px rgba(74, 158, 255, 0.3);
    transform: translateY(-20px);
}
.character-panel-header {
    display: flex;
    align-items: center;
    margin-bottom: 15px;
}
.character-panel-indicator {
    width: 12px;
    height: 12px;
    background: #ff4444;
    border-radius: 50%;
    margin-right: 10px;
}
.character-panel-title {
    color: #ff8c42;
    font-weight: bold;
}
.character-panel-body {
    font-size: 14px;
    line-height: 1.6;
}
.character-panel-body span {
    color: #ffffff;
    background: rgba(74, 158, 255, 0.2);
    padding: 2px 8px;
    border-radius: 5px;
    border: 1px solid rgba(74, 158, 255, 0.5);
    font-family: 'Courier New', Courier, monospace;
}
#interaction-panel {
    position: absolute;
    bottom: 20px; /* Position relative to viewport bottom */
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: linear-gradient(135deg, rgba(0,0,0,0.9), rgba(30,30,30,0.95));
    padding: 25px 35px;
    border-radius: 20px;
    border: 2px solid #66ff66;
    max-width: 500px;
    text-align: center;
    box-shadow: 0 6px 25px rgba(102,255,102,0.4);
}
.interaction-title {
    color: #66ff66;
    font-weight: bold;
    margin-bottom: 10px;
}
#interaction-text {
    font-size: 16px;
    line-height: 1.5;
}
.interaction-tip {
    margin-top: 15px;
    padding: 8px 16px;
    background: rgba(102,255,102,0.2);
    border-radius: 15px;
    font-size: 14px;
}
.interaction-tip span {
    color: #66ff66;
}
#control-hints {
    background: rgba(0, 0, 0, 0.7);
    padding: 12px;
    border-radius: 12px;
    border: 1px solid #ffc400;
    font-size: 24px;
    box-shadow: 0 0 15px rgba(255, 196, 0, 0.6);
    opacity: 1;
    cursor: pointer;
    color: #ffc400;
}
/* Chat Interaction Prompt */
#chat-interaction-prompt {
    position: absolute; /* Positioned relative to the game-viewport */
    bottom: 10%;
    left: 50%;
    transform: translateX(-50%) translateY(20px); /* Initial state for transition */
    background: rgba(10, 15, 20, 0.85);
    color: #e0e5f0;
    padding: 12px 25px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease-out, transform 0.3s ease-out;
    z-index: 1000;
    font-size: 16px;
    white-space: nowrap; /* Prevent text from wrapping */
}
#chat-interaction-prompt.chat-available {
    border-width: 2px;
    border-color: rgba(255, 80, 80, 1);
    animation: pulse-red 2s infinite;
}
#chat-interaction-prompt.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
#chat-interaction-prompt kbd {
    display: inline-block;
    padding: 3px 8px;
    font-size: 14px;
    font-weight: bold;
    line-height: 1;
    color: #2c3e50;
    background: #ecf0f1;
    border: 1px solid #bdc3c7;
    border-radius: 4px;
    box-shadow: 0 2px 0 #bdc3c7;
    margin: 0 4px;
}
/* Exit Chat Button */
#exit-chat-button {
    position: absolute; /* Changed from fixed to absolute */
    bottom: 20px;
    left: 20px;
    background: rgba(220, 50, 50, 0.75);
    color: #ffffff;
    padding: 10px 20px;
    border-radius: 10px;
    border: 1px solid rgba(255, 100, 100, 0.4);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    font-size: 15px;
    font-weight: bold;
    cursor: pointer;
    z-index: 1002;
    transition: background-color 0.2s ease;
}
#exit-chat-button:hover {
    background: rgba(240, 70, 70, 0.9);
    border-color: rgba(255, 120, 120, 0.6);
}
/* Autopilot Toggle Button */
#toggle-autopilot-button {
    position: absolute;
    bottom: 20px;
    right: 20px;
    background: rgba(220, 50, 50, 0.75); /* Red for 'Stop' */
    color: #ffffff;
    padding: 10px 20px;
    border-radius: 10px;
    border: 1px solid rgba(100, 180, 255, 0.4);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    font-size: 15px;
    font-weight: bold;
    cursor: pointer;
    z-index: 1002;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: opacity 0.3s ease-out, transform 0.3s ease-out, background-color 0.2s ease;
}
#toggle-autopilot-button.visible {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}
#toggle-autopilot-button:hover {
    background: rgba(240, 70, 70, 0.9);
    border-color: rgba(255, 120, 120, 0.6);
}
#toggle-autopilot-button.start-mode {
    background: rgba(40, 180, 120, 0.75); /* Green for 'Start' */
}
#toggle-autopilot-button.start-mode:hover {
    background: rgba(60, 200, 140, 0.9);
}
@keyframes pulse-red {
    0% {
        box-shadow: 0 5px 20px rgba(220, 50, 50, 0.4);
        border-color: rgba(220, 50, 50, 0.75);
    }
    50% {
        box-shadow: 0 8px 30px rgba(255, 80, 80, 0.6);
        border-color: rgba(255, 80, 80, 1);
    }
    100% {
        box-shadow: 0 5px 20px rgba(220, 50, 50, 0.4);
        border-color: rgba(220, 50, 50, 0.75);
    }
}
/* Live Viewer Count */
#live-viewer-count {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding: 8px 20px;
    border-radius: 25px;
    border: 2px solid rgba(255, 255, 255, 0.9);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    pointer-events: none;
    margin-bottom: 15px;
}
.live-circle {
    background: #ff4444;
    color: white;
    font-weight: bold;
    font-size: 12px;
    padding: 4px 8px;
    border-radius: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
    animation: live-pulse 2s infinite;
}
#viewer-count-display {
    color: white;
    font-weight: bold;
    font-size: 16px;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
}
@keyframes live-pulse {
    0% { opacity: 1; }
    50% { opacity: 0.7; }
    100% { opacity: 1; }
}
/* Responsive Design - Smaller Desktop/Laptop Breakpoints */
/* 1280px and below - Small desktops/laptops */
@media (max-width: 1280px) {
    .ui-container {
        padding: 15px;
        gap: 12px;
    }
    
    /* Chat interaction prompt adjustments */
    #chat-interaction-prompt {
        font-size: 14px;
        padding: 10px 20px;
        max-width: 400px;
    }
    
    #chat-interaction-prompt kbd {
        padding: 2px 6px;
        font-size: 12px;
    }
    
    /* UI widgets stack positioning */
    .ui-widgets-stack {
        top: 15px;
        right: 15px;
        gap: 10px;
    }
    
    /* Live viewer count adjustments */
    #live-viewer-count {
        padding: 6px 16px;
        gap: 10px;
        margin-bottom: 12px;
    }
    
    #viewer-count-display {
        font-size: 14px;
    }
    
    .live-circle {
        font-size: 11px;
        padding: 3px 7px;
    }
    
    /* Button adjustments */
    #exit-chat-button,
    #toggle-autopilot-button {
        padding: 8px 16px;
        font-size: 14px;
        bottom: 15px;
    }
    
    #exit-chat-button {
        left: 15px;
    }
    
    #toggle-autopilot-button {
        right: 15px;
    }
}
/* 1024px and below - Compact laptops/tablets in landscape */
@media (max-width: 1024px) {
    .ui-container {
        padding: 12px;
        gap: 10px;
    }
    
    /* Chat interaction prompt - more compact */
    #chat-interaction-prompt {
        font-size: 13px;
        padding: 8px 16px;
        max-width: 350px;
    }
    
    /* Suspicion bar positioning */
    .suspicion-bar-container {
        padding: 12px 20px;
        min-width: 240px;
        top: 3%;
    }
    
    .suspicion-bar-label {
        font-size: 14px;
        letter-spacing: 1.5px;
    }
    
    /* UI widgets stack - smaller gaps and positioning */
    .ui-widgets-stack {
        top: 12px;
        right: 12px;
        gap: 8px;
    }
    
    /* Live viewer count - more compact */
    #live-viewer-count {
        padding: 5px 14px;
        gap: 8px;
        margin-bottom: 10px;
    }
    
    #viewer-count-display {
        font-size: 13px;
    }
    
    .live-circle {
        font-size: 10px;
        padding: 3px 6px;
    }
    
    /* Interaction panel adjustments */
    #interaction-panel {
        padding: 20px 28px;
        max-width: 400px;
        bottom: 15px;
    }
    
    .interaction-title {
        font-size: 14px;
    }
    
    #interaction-text {
        font-size: 15px;
    }
    
    .interaction-tip {
        font-size: 13px;
        padding: 6px 14px;
    }
    
    /* Control hints adjustments */
    #control-hints {
        padding: 10px;
        font-size: 20px;
        border-radius: 10px;
    }
    
    /* Panel adjustments */
    .panel {
        border-radius: 16px;
    }
    
    #character-panel {
        padding: 16px;
        min-width: 260px;
    }
    
    .character-panel-body {
        font-size: 13px;
    }
}
/* 900px and below - Small tablets/large phones in landscape */
@media (max-width: 900px) {
    .ui-container {
        padding: 10px;
    }
    
    /* Chat interaction prompt - even more compact */
    #chat-interaction-prompt {
        font-size: 12px;
        padding: 6px 12px;
        max-width: 300px;
        white-space: normal; /* Allow wrapping on smaller screens */
    }
    
    /* UI widgets stack */
    .ui-widgets-stack {
        top: 10px;
        right: 10px;
    }
    
    /* Buttons - smaller */
    #exit-chat-button,
    #toggle-autopilot-button {
        padding: 6px 12px;
        font-size: 13px;
        bottom: 10px;
    }
    
    #exit-chat-button {
        left: 10px;
    }
    
    #toggle-autopilot-button {
        right: 10px;
    }
}