/* Root Variables for Theming */
:root {
    --primary-color: #4A90E2;
    --secondary-color: #50E3C2;
    --background-color: #2E2E2E;
    --sidebar-background: #3C3C3C;
    --node-background: #3C3C3C;
    --text-color: #FFFFFF;
    --muted-text-color: #A1A1A3;
    --border-radius: 8px;
    --transition-speed: 0.3s;
    --shadow-color: rgba(0, 0, 0, 0.5);
    --font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* Global Styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: var(--font-family);
}

body {
    background-color: var(--background-color);
    color: var(--text-color);
    height: 100vh;
    overflow: hidden;
}

#container {
    display: flex;
    height: 100vh;
    padding-left: 300px;
    /* Adjusted for wider sidebar */
}

#sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: 320px;
    /* Sidebar width */
    height: 100%;
    background-color: var(--sidebar-background);
    color: var(--text-color);
    overflow-y: auto;
    z-index: 1000;
}

#sidebar-header {
    padding: 20px;
    text-align: center;
    border-bottom: 1px solid var(--muted-text-color);
}

#sidebar-header h2 {
    font-size: 24px;
    font-weight: 600;
}

#sidebar-logo {
    width: 40px; /* Adjust size as needed */
    height: auto;
    display: block;
    margin: 0 auto 10px auto; /* Center and add space below the logo */
  }

#characterList {
    padding: 20px;
}

.character-item {
    display: flex;
    /* Added for flex layout */
    flex-direction: column;
    /* Stack child elements vertically */
    background-color: var(--node-background);
    border-radius: var(--border-radius);
    padding: 10px;
    margin-bottom: 20px;
    box-shadow: 0 4px 6px var(--shadow-color);
    transition: background-color var(--transition-speed) ease;
    cursor: grab;
}

.character-item:active {
    cursor: grabbing;
}

.character-item:hover {
    background-color: var(--secondary-color);
}

.character-header {
    display: flex;
    align-items: center;
    margin-bottom: 10px;
}

.character-name {
    flex-grow: 1;
    background: none;
    border: none;
    border-bottom: 1px solid var(--muted-text-color);
    color: var(--text-color);
    font-size: 18px;
    padding: 5px;
    outline: none;
    transition: border-color var(--transition-speed) ease;
    width: 80%;
}

.character-name:focus {
    border-color: var(--primary-color);
}

.delete-character {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-color);
    position: static;
    margin-left: 0px;
    padding: 5px;
}

.delete-character svg {
    width: 20px;
    height: 20px;
    fill: var(--text-color);
}

/* Updated Color Icon Wrapper Styles */
.color-icon-wrapper {
    position: relative;
    /* Ensure the color input is positioned relative to this wrapper */
}

/* Updated Color Icon Styles */
.color-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    /* Center the icon */
    color: var(--text-color);
    position: relative;
    align-self: flex-start;
    padding: 5px;
    /* Adjust padding for better click area */
    background: #555555;
    width: 100%;
    border: 1px solid var(--muted-text-color);
    border-radius: var(--border-radius);
    cursor: pointer;
}

.color-icon svg {
    width: 24px;
    height: 24px;
    fill: var(--text-color);
}

.color-icon-wrapper input[type="color"] {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    /* Cover the entire button */
    height: 100%;
    /* Cover the entire button */
    opacity: 0;
    /* Make it invisible */
    cursor: pointer;
    z-index: 2;
    /* Ensure it sits above other elements */
}

.character-item textarea {
    width: 100%;
    height: 80px;
    background-color: var(--sidebar-background);
    border: 1px solid var(--muted-text-color);
    border-radius: var(--border-radius);
    padding: 10px;
    color: var(--text-color);
    resize: none;
    outline: none;
    margin-bottom: 10px;
    transition: border-color var(--transition-speed) ease;
}

.character-item textarea:focus {
    border-color: var(--primary-color);
}

#addCharacterButton,
#exportButton,
#importButton {
    width: calc(100% - 40px);
    margin: 0 20px 20px 20px;
    padding: 15px;
    background-color: #555555;
    /* Dark grey color */
    color: var(--text-color);
    border: none;
    border-radius: var(--border-radius);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color var(--transition-speed) ease;
}

#addCharacterButton:hover,
#exportButton:hover,
#importButton:hover {
    background-color: #666666;
}

#storyMapWrapper {
    flex-grow: 1;
    overflow: auto;
    position: relative;
}

#storyMap {
    position: relative;
    width: 100%;
    /* Changed from 2000px to 100% */
    height: 100%;
    /* Changed from 2000px to 100% */
}

#connectorCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    /* Changed from 2000px to 100% */
    height: 100%;
    /* Changed from 2000px to 100% */
    pointer-events: none;
}

.node {
    position: absolute;
    background-color: var(--node-background);
    border-radius: var(--border-radius);
    box-shadow: 4px 4px 6px var(--shadow-color);
    padding: 10px;
    min-width: 250px;
    /* Adjusted width */
    max-width: 500px;
    /* Optional: limit the maximum width */
    min-height: 150px;
    max-height: 600px;
    width: 250px;
    height: 200px;
    display: flex;
    flex-direction: column;
    color: var(--text-color);
    transition: background-color var(--transition-speed) ease, transform var(--transition-speed) ease;
    cursor: grab;
}

.node:active {
    cursor: grabbing;
}


.node .header {
    display: flex;
    align-items: center;
    margin-bottom: 8px;
}

.node .character-select {
    width: 100%;
    /* Ensure it fits within the node */
    background-color: var(--sidebar-background);
    border: 1px solid var(--muted-text-color);
    border-radius: var(--border-radius);
    color: var(--text-color);
    padding: 5px;
    font-size: 16px;
    outline: none;
    cursor: pointer;
    transition: border-color var(--transition-speed) ease;
}

.node .character-select:focus {
    border-color: var(--primary-color);
}

.node .character-select option {
    background-color: var(--sidebar-background);
    color: var(--text-color);
}

.node textarea {
    width: 100%;
    /* Ensure it fits within the node */
    flex-grow: 1;
    background-color: var(--sidebar-background);
    border: 1px solid var(--muted-text-color);
    border-radius: var(--border-radius);
    color: var(--text-color);
    padding: 10px;
    font-size: 14px;
    resize: none;
    outline: none;

    transition: border-color var(--transition-speed) ease;
}

.node textarea:focus {
    border-color: var(--primary-color);
}

/* Type Icon Styles */
.type-icon {
    cursor: pointer;
    width: 24px;
    height: 24px;
    margin-left: 8px;
    /* Space between character select and icon */
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Position the type icon within the header */
.header {
    display: flex;
    align-items: center;
    position: relative;
    /* For absolute positioning of typeSelect */
}

/* Style for the type selection dropdown */
.type-select {
    width: 120px;
    padding: 4px;
    font-size: 14px;
}


/* Dialogue Node Styles 
.node.dialogue {
    border: 2px solid #4caf50;
  }
  
  .node.action {
    border: 2px solid #2196f3;
  }
  
  .node.choice {
    border: 2px solid #ff9800;
  }*/


.delete-node {
    background: #555555;
    width: 100%;
    border: 1px solid var(--muted-text-color);
    border-radius: var(--border-radius);
    cursor: pointer;
    color: var(--text-color);
    align-self: flex-start;
    /* Align to the left */
    margin-top: auto;
    /* Push to the bottom */
    padding: 5px;
    /* Adjust padding if necessary */
}

.delete-node svg {
    width: 24px;
    height: 24px;
    fill: var(--text-color);
}

.node .resize-handle {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 15px;
    height: 15px;
    cursor: se-resize;
}

.node .resize-handle::after {
    content: '';
    position: absolute;
    width: 15px;
    height: 15px;
    background-image: linear-gradient(135deg, transparent 50%, var(--muted-text-color) 50%);
    background-size: 100% 100%;
    background-repeat: no-repeat;
}

/* Context Menu Styles */
.context-menu {
    position: fixed;
    /* Changed from absolute to fixed */
    width: 150px;
    background-color: var(--node-background);
    border: 1px solid var(--muted-text-color);
    border-radius: var(--border-radius);
    box-shadow: 0 4px 6px var(--shadow-color);
    display: none;
    /* Hidden by default */
    z-index: 10000;
    /* Ensure it appears above other elements */

    /* Temporary styles for debugging */
    /* background-color: red; */
}

.context-menu ul {
    list-style: none;
    padding: 5px 0;
    margin: 0;
}

.context-menu li {
    padding: 10px 20px;
    cursor: pointer;
    color: var(--text-color);
    transition: background-color var(--transition-speed) ease;
}

.context-menu li:hover {
    background-color: var(--secondary-color);
}


/* Custom Dropdown Styles */
.custom-dropdown {
    position: absolute;
    background-color: var(--node-background);
    border: 1px solid var(--muted-text-color);
    border-radius: var(--border-radius);
    box-shadow: 0 4px 6px var(--shadow-color);
    display: none;
    /* Hidden by default */
    z-index: 10000;
    /* Ensure it appears above other elements */
    width: 150px;
    /* Adjust as needed */
}

.custom-dropdown ul {
    list-style: none;
    padding: 5px 0;
    margin: 0;
}

.custom-dropdown li {
    padding: 10px 20px;
    cursor: pointer;
    color: var(--text-color);
    transition: background-color var(--transition-speed) ease;
}

.custom-dropdown li:hover {
    background-color: var(--secondary-color);
}


/* Highlight selectable nodes */
.node.selectable {
    outline: 2px dashed var(--primary-color);
}

/* Connector Line Styles */
.connector-line {
    cursor: pointer;
    transition: stroke var(--transition-speed) ease;
}

.connector-line:hover {
    stroke: var(--primary-color);
}

/* Connector Lines */
line {
    stroke: var(--muted-text-color);
    stroke-width: 2;
}

/* Drag-over Effects */
.node.drag-over {
    outline: 2px dashed var(--primary-color);
}

#storyMap.drag-over {
    border: 2px dashed var(--primary-color);
}

#canvasMessage {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--muted-text-color);
    text-align: center;
    font-size: 18px;
    line-height: 1.5;
}


/* Simulation Modal Styles */
/* Simulation Modal Styles */
.simulation-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.8); /* Semi-transparent backdrop */
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 20000; /* Higher than context menu */
}

.simulation-content {
    background-color: var(--node-background);
    color: var(--text-color);
    padding: 20px;
    border-radius: var(--border-radius);
    width: 60%;
    max-width: 600px;
    box-shadow: 0 4px 6px var(--shadow-color);
    display: flex;
    flex-direction: column;
    align-items: center;
}

.simulation-dialogue {
    font-size: 18px;
    margin-bottom: 20px;
    text-align: center;
}

.simulation-choices {
    display: flex;
    flex-direction: column;
    width: 100%;
    gap: 10px;
}

.simulation-choices button {
    padding: 10px;
    background-color: var(--primary-color);
    border: none;
    border-radius: var(--border-radius);
    color: var(--text-color);
    font-size: 16px;
    cursor: pointer;
    transition: background-color var(--transition-speed) ease;
}

.simulation-choices button:hover {
    background-color: var(--secondary-color);
}

.simulation-navigation {
    margin-top: 10px;
    width: 100%;
    display: flex;
    justify-content: flex-start; /* Align Back button to the left */
}

.simulation-back {
    padding: 10px 20px;
    width: 100%;
    background-color: #555555;
    border: none;
    border-radius: var(--border-radius);
    color: var(--text-color);
    font-size: 16px;
    cursor: pointer;
    transition: background-color var(--transition-speed) ease;
}

.simulation-back:hover {
    background-color: #666666;
}

/* Style for the "Next" button */
.simulation-choices button.next-button {
    background-color: var(--primary-color);
    /* You can choose a different color or style */
}

.simulation-choices button.next-button:hover {
    background-color: var(--secondary-color);
}

.simulation-close {
    margin-top: 20px;
    padding: 10px 20px;
    background-color: #555555;
    border: none;
    border-radius: var(--border-radius);
    color: var(--text-color);
    font-size: 16px;
    cursor: pointer;
    transition: background-color var(--transition-speed) ease;
}

.simulation-close:hover {
    background-color: #666666;
}

.node.active-simulation {
    border: 3px solid var(--primary-color);
    box-shadow: 0 0 10px var(--primary-color);
    transform: scale(1.05);
}

.simulation-character {
    font-size: 20px;
    font-weight: bold;
    margin-bottom: 10px;
    text-align: center;
}

/* Italicize action dialogues */
.simulation-dialogue em {
    font-style: italic;
    color: #f1c40f; /* Optional: Change color for actions */
  }
  
  /* Error Message Styling */
  .simulation-dialogue .error-message {
    color: #e74c3c;
    font-weight: bold;
  }
  

/* Scrollbar Styles */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-thumb {
    background-color: var(--muted-text-color);
    border-radius: 4px;
}

::-webkit-scrollbar-track {
    background-color: var(--sidebar-background);
}

/* Responsive Design */
@media (max-width: 768px) {
    #sidebar {
        width: 200px;
    }

    #container {
        padding-left: 200px;
    }

    .character-name {
        font-size: 16px;
    }

    .delete-character svg,
    .color-icon svg {
        width: 18px;
        height: 18px;
    }
}