/* Basic reset and body styles */
body, html {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: sans-serif;
    background-color: #2c2c2c;
    color: #f0f0f0;
    overflow: hidden; /* Prevent body scrollbars */
}

.hidden {
    display: none !important;
}

/* Main application container */
#app-container {
    display: flex;
    flex-direction: row;
    height: 100vh;
}

/* Container for all sidebars */
#sidebar-container {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0; /* Make it full height */
    z-index: 10;

    display: flex;
    flex-direction: row;
    flex-shrink: 0;
    background-color: #1e1e1e;
    border-right: 1px solid #444;
}
/* Panel is a flex container for buttons and content */
.sidebar-panel {
    display: flex;
    flex-direction: column; /* Arrange buttons and content vertically */
    width: 100px;
    box-sizing: border-box;
    border-right: 1px solid #333;
    padding: 0; /* Padding is now handled by sub-elements */
}

/* Custom Scroll Buttons */
.scroll-button {
    flex-shrink: 0; /* Prevent buttons from shrinking */
    height: 25px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 20px;
    color: #aaa;
    background-color: #2a2a2a;
    cursor: pointer;
    user-select: none; /* Prevent text selection on click */
    transition: background-color 0.2s;
}
.scroll-button:hover {
    background-color: #3f3f3f;
}
.scroll-button.disabled {
    opacity: 0.3;
    cursor: not-allowed;
    background-color: #2a2a2a; /* Reset hover effect */
}

/* Wrapper to hide scrollbar */
.sidebar-content-wrapper {
    flex-grow: 1; /* This takes up all available space between buttons */
    overflow: hidden; /* This hides the native scrollbar */
    position: relative;
}

/* The actual scrollable area */
.sidebar-content {
    height: 100%;
    overflow-y: scroll; /* Enable scrolling (mouse wheel, touch) */
    padding: 10px;
    box-sizing: border-box;
    /* This hides the scrollbar in modern browsers */
    scrollbar-width: none;  /* Firefox */
}
/* This hides the scrollbar in Webkit browsers (Chrome, Safari) */
.sidebar-content::-webkit-scrollbar {
    display: none;
}


/* Wrapper for item and its overlays */
.sidebar-item-wrapper {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    margin-bottom: 10px;
}
/* The last item in a panel should have no bottom margin for better spacing */
.sidebar-item-wrapper:last-child {
    margin-bottom: 0;
}

.sidebar-item {
    width: 100%;
    height: 100%;
    background-color: #3a3a3a;
    border: 2px solid #555;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.1s ease, border-color 0.1s ease;
    object-fit: cover;
    display: block;
    box-sizing: border-box; /* Important for border animations */
}

.sidebar-item:hover {
    transform: scale(1.05);
    border-color: #00aaff; /* Hover is still blue */
}

/* 1. Selected State */
.sidebar-item.selected {
    border-color: #c58af9; /* Light purple */
}
.sidebar-item.selected:hover {
    border-color: #d4a7fa; /* Brighter purple on hover */
}

/* 2. Locked State */
.sidebar-item.locked {
    filter: grayscale(1) brightness(0.5);
    cursor: not-allowed;
}
.sidebar-item.locked:hover {
    transform: none; /* Disable hover effect */
    border-color: #555; /* Reset border color on hover */
}
.lock-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: white;
    text-shadow: 0 0 5px black, 0 0 5px black;
    pointer-events: none; /* Allows clicks to go through if needed */
}
.lock-overlay img {
    width: 60%;
    height: 60%;
}
.lock-overlay span {
    font-size: 1.5em;
    font-weight: bold;
}

/* 3. Status States */
@keyframes pulse-yellow {
    0% { box-shadow: 0 0 0 0 rgba(255, 255, 0, 0.7); }
    70% { box-shadow: 0 0 0 10px rgba(255, 255, 0, 0); }
    100% { box-shadow: 0 0 0 0 rgba(255, 255, 0, 0); }
}
@keyframes pulse-blue {
    0% { box-shadow: 0 0 0 0 rgba(0, 191, 255, 0.7); }
    70% { box-shadow: 0 0 0 10px rgba(0, 191, 255, 0); }
    100% { box-shadow: 0 0 0 0 rgba(0, 191, 255, 0); }
}

.sidebar-item.unseen {
    border: 2px solid white;
}
.sidebar-item.new {
    animation: pulse-yellow 2s infinite;
    border-color: yellow;
}
.sidebar-item.updated {
    animation: pulse-blue 2s infinite;
    border-color: #00bfff;
}


/* Main content iframe takes up the rest of the space */
iframe[name="content-frame"] {
    /* Add a permanent margin to create space for the first, non-overlay sidebar panel */
    margin-left: 100px; 
    /* Explicitly set the width to fill the remaining space */
    width: calc(100% - 100px);

    flex-grow: 1;
    height: 100%;
    border: none;
    background-color: #333;
}

/* --- Core Item Styles --- */

.core-items-container {
    flex-shrink: 0;
    padding: 10px;
    border-top: 1px solid #333;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    background-color: #2a2a2a;
}

.sidebar-item-wrapper.core-item {
    width: 100%;
    margin-bottom: 0;
}

/* --- Core Modal Styles (REVISED FOR DYNAMIC SCALING) --- */

#core-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    
    opacity: 1;
    pointer-events: all;
    transition: opacity 0.4s ease-out;
}

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

#core-modal-container {
    position: relative;
    /* width and height are now set by JavaScript */
    
    /* 
      Use the --modal-scale variable provided by JS. 
      Default to 1 if the variable isn't set yet.
    */
    transform: scale(var(--modal-scale, 1));
    
    /* Transition the transform property for smooth scaling and movement */
    transition: transform 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
}

#core-modal-overlay.hidden #core-modal-container {
    /* 
      When hidden, slide down AND use the current scale.
      This ensures the animation is smooth even after a resize.
    */
    transform: translateY(110vh) scale(var(--modal-scale, 1));
}

#core-modal-overlay iframe {
    /* The iframe should now fill its container, which is being scaled */
    width: 100%;
    height: 100%;
    border: 2px solid #555;
    border-radius: 10px;
    background-color: #333;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    display: block; 
    box-sizing: border-box; /* Include border in the size */
}

#core-modal-close {
    position: absolute;
    /* Scale the button's position relative to the container's scale */
    top: calc(10px / var(--modal-scale, 1));
    right: calc(10px / var(--modal-scale, 1));
    width: calc(30px / var(--modal-scale, 1));
    height: calc(30px / var(--modal-scale, 1));
    font-size: calc(24px / var(--modal-scale, 1));
    
    background-color: white;
    color: #333;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    line-height: 1;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
    z-index: 1001;
    
    /* Animate the button's properties as the scale changes */
    transition: top 0.4s, right 0.4s, width 0.4s, height 0.4s, font-size 0.4s;
}

/* ADD THESE NEW STYLES TO YOUR EXISTING style.css */

/* --- Completed Game Star Overlay --- */
.completed-star-overlay {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 25%; /* Relative to the wrapper size */
    height: 25%;
    pointer-events: none; /* Let clicks pass through */
    z-index: 5;
}
.completed-star-overlay svg {
    width: 100%;
    height: 100%;
    color: #FFD700; /* Gold color for the star */
    filter: drop-shadow(0px 0px 2px rgba(0, 0, 0, 0.8));
}


/* --- Total Star Count Display --- */
#star-counter-display {
    position: fixed;
    bottom: 15px;
    right: 15px;
    background-color: rgba(30, 30, 30, 0.9);
    color: #f0f0f0;
    padding: 8px 15px;
    border-radius: 20px;
    border: 1px solid #555;
    display: flex;
    align-items: center;
    font-size: 1.2em;
    font-weight: bold;
    z-index: 1000;
    box-shadow: 0 4px 10px rgba(0,0,0,0.4);
    user-select: none;
}

#star-counter-display svg {
    width: 24px;
    height: 24px;
    margin-right: 8px;
    color: #FFD700; /* Gold */
}

/* --- Integrated Chat Widget --- */
#chat-widget {
    position: fixed;
    /* Position and size will be set by JS, with these as fallbacks */
    bottom: 15px;
    left: 15px;
    width: 350px;
    height: 450px; /* Default expanded height */
    min-width: 250px;
    min-height: 200px;
    max-width: 90vw;
    max-height: 80vh;
    background-color: rgba(30, 30, 30, 0.95);
    border: 1px solid #555;
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    z-index: 999;
    box-shadow: 0 4px 10px rgba(0,0,0,0.4);
    transition: opacity 0.3s ease;
    opacity: 0.4;
    overflow: hidden; /* Important for border-radius */
}

#chat-widget:hover {
    opacity: 1;
}

#chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #007acc;
    color: white;
    cursor: move;
    flex-shrink: 0;
    height: 35px;
    padding-left: 5px;
    user-select: none;
}

#chat-toggle-btn {
    background: none;
    border: none;
    color: white;
    font-size: 1.2em;
    padding: 0 10px;
    cursor: pointer;
    height: 100%;
}

#chat-widget.collapsed {
    height: 35px; 
    min-height: 35px; 
    opacity: 0.6;
}

#chat-widget.collapsed:hover {
    opacity: 1;
}

#chat-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#chat-tabs {
    display: flex;
    gap: 2px;
    height: 100%;
}

.chat-tab {
    padding: 0 15px;
    background-color: #005a99;
    border: none;
    color: #ccc;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    border-radius: 4px 4px 0 0;
}
.chat-tab.active {
    background-color: rgba(30, 30, 30, 0.95);
    color: white;
    font-weight: bold;
}
.close-tab-btn {
    background: none;
    border: none;
    color: #ccc;
    cursor: pointer;
    font-size: 1.2em;
    padding: 0;
}
.close-tab-btn:hover {
    color: white;
}

#chat-log-panels {
    flex-grow: 1;
    position: relative;
}

.chat-log-panel {
    position: absolute;
    width: 100%;
    height: 100%;
    overflow-y: auto;
    padding: 10px;
    font-size: 0.9em;
    box-sizing: border-box;
    display: none;
}
.chat-log-panel.active {
    display: block;
}

#chat-resize-handle {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 15px;
    height: 15px;
    cursor: se-resize;
    border-bottom: 2px solid #fff;
    border-right: 2px solid #fff;
    opacity: 0.5;
}

@keyframes pulse-yellow-chat {
    0% { box-shadow: 0 0 0 0 rgba(255, 255, 0, 0.7); }
    70% { box-shadow: 0 0 0 10px rgba(255, 255, 0, 0); }
    100% { box-shadow: 0 0 0 0 rgba(255, 255, 0, 0); }
}

#chat-widget.new-message.collapsed {
    animation: pulse-yellow-chat 2s;
    animation-iteration-count: 2;
}

.chat-message { margin-bottom: 8px; word-wrap: break-word; }
.chat-message .sender { font-weight: bold; color: #00aaff; margin-right: 5px; }
#chat-form { display: flex; border-top: 1px solid #555; padding: 8px; gap: 8px; flex-shrink: 0; }
#chat-input { flex-grow: 1; background-color: #1a1a1d; border: 1px solid #45a29e; color: #c5c6c7; padding: 8px; border-radius: 4px; }
#chat-form button { background-color: #45a29e; border: none; color: #0b0c10; font-weight: bold; border-radius: 4px; padding: 0 12px; cursor: pointer; }

/* --- Chat Form Enhancements --- */
#chat-form {
    position: relative; /* Needed for the character counter positioning */
}

.char-counter {
    position: absolute;
    top: -22px; /* Position it above the input box */
    right: 10px;
    font-size: 0.8em;
    color: #aaa;
    background-color: #2a2a2a;
    padding: 2px 6px;
    border-radius: 4px;
}

.char-counter.limit-exceeded {
    color: #e74c3c; /* Red */
    font-weight: bold;
}

/* --- Clickable Lobby Links in Chat --- */
.lobby-link {
    background-color: #005a99;
    color: #e0e0e0;
    padding: 3px 8px;
    border-radius: 4px;
    cursor: pointer;
    text-decoration: none;
    transition: background-color 0.2s;
}

.lobby-link:hover {
    background-color: #007acc;
    color: #fff;
}

.lobby-link[data-joinable="false"] {
    background-color: #444;
    cursor: not-allowed;
    text-decoration: line-through;
}

.lobby-link-invalid {
    color: #888;
    font-style: italic;
}

/* --- Generic Toast Notification --- */
@keyframes toast-in-out {
    0% { transform: translateY(-100%); opacity: 0; }
    15% { transform: translateY(10%); opacity: 1; }
    85% { transform: translateY(10%); opacity: 1; }
    100% { transform: translateY(-100%); opacity: 0; }
}

#toast-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 2000;
    display: flex;
    justify-content: center;
    pointer-events: none;
}

.toast-message {
    margin-top: 20px;
    padding: 12px 25px;
    border-radius: 8px;
    color: #fff;
    font-weight: bold;
    box-shadow: 0 5px 15px rgba(0,0,0,0.4);
    animation: toast-in-out 4s ease-in-out forwards;
}

.toast-message.error {
    background-color: #e74c3c; /* Red */
}