body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: #f4f7f9;
    color: #333;
    text-align: center;
    margin: 0;
    overflow: hidden; /* Prevent scrollbars from dragging */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

h1 {
    font-weight: 600;
    color: #4a5568;
    margin-bottom: 10px;
}

#admin-panel {
    display: flex;
    flex-wrap: wrap; /* Allow wrapping for multiple sections */
    justify-content: center;
    align-items: center;
    gap: 10px; /* Gap between sections */
    padding: 10px 20px;
    background-color: #e2eaf0;
    border-bottom: 1px solid #cbd5e0;
    box-shadow: 0 2px 4px rgba(0,0,0,0.03);
    position: relative; /* Needed for z-index to work */
    z-index: 110; /* Ensure admin panel is above draggable elements */
}

.admin-section {
    display: flex;
    gap: 10px;
    align-items: center;
    padding: 5px 10px;
    border-radius: 8px;
    background-color: #f8fbfd; /* Slightly different background for sections */
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.05);
}

#admin-panel input[type="text"] {
    padding: 8px 12px;
    border: 1px solid #cbd5e0;
    border-radius: 6px;
    font-size: 1rem;
    width: 180px; /* Slightly reduced width for better fit */
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

#admin-panel input[type="text"]:focus {
    border-color: #63b3ed;
    box-shadow: 0 0 0 3px rgba(66, 153, 225, 0.5);
}

#admin-panel button {
    padding: 8px 15px;
    background-color: #4299e1;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
}

#admin-panel button:hover {
    background-color: #3182ce;
}

#admin-panel button:active {
    transform: translateY(1px);
}

.message {
    font-size: 0.9rem;
    margin-left: 10px;
    min-width: 250px;
    text-align: left;
    font-weight: 500;
}

.message.success {
    color: green;
}

.message.error {
    color: red;
}

.message.warning {
    color: orange;
}

.message.info {
    color: blue;
}

#game-wrapper {
    display: flex;
    height: calc(100vh - 200px); /* Adjust for h1 and admin panel to fit on screen */
}

#game-container {
    flex-grow: 1;
    position: relative;
    border: 1px solid #e2e8f0;
    background-color: #ffffff;
    margin: 20px;
    border-radius: 10px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}

#elements-sidebar {
    width: 200px;
    flex-shrink: 0;
    background-color: #fdfdfd;
    border-right: 1px solid #e2e8f0;
    padding: 20px 10px;
    box-sizing: border-box;
    overflow-y: auto;
    position: relative; /* Needed for z-index to work */
    z-index: 110; /* Ensure sidebar is above draggable elements */
}

#elements-sidebar h2 {
    margin-top: 0;
    font-size: 1.2rem;
    color: #718096;
}

#sidebar-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

.element {
    width: 80px;
    height: 80px;
    border: 2px solid #cbd5e0;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    cursor: grab;
    user-select: none;
    position: absolute; /* Required for Draggable */
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    transition: box-shadow 0.2s, transform 0.2s;
    z-index: 10; /* Default z-index for elements */
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    position: relative; /* For the overlay */
    overflow: hidden; /* Hide overflow of image if any */
}

.element:active {
    cursor: grabbing;
    box-shadow: 0 8px 16px rgba(0,0,0,0.15);
    transform: scale(1.05);
    z-index: 100; /* Higher z-index when being dragged */
}

.thinking-element {
    background-color: #fce4ec; /* Light pink for thinking */
    border-color: #f8bbd0;
    cursor: not-allowed;
    pointer-events: none; /* Prevent interaction while thinking */
    z-index: 101; /* Ensure it appears above other elements */
    background-image: none !important; /* No image for thinking state */
}

.element-sidebar-item {
    width: 90px; /* Make sidebar items square */
    height: 90px; /* Make sidebar items square */
    border: 2px solid transparent;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    user-select: none;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    transition: transform 0.2s, box-shadow 0.2s;
    background-color: #fff;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    position: relative; /* For the overlay */
    overflow: hidden; /* Hide overflow of image if any */
}

.element-sidebar-item:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.element-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background-color: rgba(255, 255, 255, 0.4); /* Semi-transparent overlay */
    border-radius: inherit; /* Inherit border-radius from parent */
    text-shadow: 1px 1px 2px rgba(0,0,0,0.2);
    box-sizing: border-box; /* Include padding in width/height */
    padding: 5px; /* Added padding to prevent text/emoji from touching edges */
}

.element-emoji {
    font-size: 36px;
    line-height: 1;
}

.element-name {
    font-size: 14px;
    margin-top: 8px;
    font-weight: 500;
    color: #333; /* Darker color for contrast */
}

/* New styles for the family tree modal */
.family-tree-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.family-tree-modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.family-tree-modal-content {
    background-color: #ffffff;
    border-radius: 12px;
    padding: 30px;
    width: 90%;
    max-width: 900px; /* Increased max-width for better tree display */
    max-height: 90%;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    position: relative;
    display: flex;
    flex-direction: column;
    transform: translateY(20px);
    transition: transform 0.3s ease;
}

.family-tree-modal-overlay.active .family-tree-modal-content {
    transform: translateY(0);
}

.close-button {
    position: absolute;
    top: 15px;
    right: 20px;
    background: none;
    border: none;
    font-size: 2rem;
    cursor: pointer;
    color: #666;
    transition: color 0.2s;
}

.close-button:hover {
    color: #333;
}

.family-tree-modal-content h2 {
    margin-top: 0;
    margin-bottom: 20px;
    color: #4a5568;
    font-size: 1.8rem;
    border-bottom: 1px solid #e2eaf0;
    padding-bottom: 15px;
}

#tree-display {
    overflow-y: auto;
    flex-grow: 1;
    padding-right: 10px; /* For scrollbar */
    display: flex; /* Changed to flex for depth levels */
    flex-direction: column;
    gap: 25px; /* Space between depth levels */
}

.tree-depth-level {
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 15px;
    background-color: #fafbfd;
    box-shadow: 0 2px 8px rgba(0,0,0,0.02);
}

.tree-depth-level h3 {
    margin-top: 0;
    margin-bottom: 15px;
    color: #5a677b;
    font-size: 1.3rem;
    border-bottom: 1px dashed #e2e8f0;
    padding-bottom: 10px;
}

.level-elements-container {
    display: flex;
    flex-wrap: wrap; /* Allow elements to wrap within a level */
    gap: 20px; /* Space between nodes */
    justify-content: center; /* Center nodes horizontally */
}

.tree-node {
    display: flex;
    flex-direction: column;
    align-items: center; /* Center content in the node */
    justify-content: center; /* Center content vertically */
    width: 120px; /* Make tree nodes square */
    height: 120px; /* Make tree nodes square */
    padding: 0; /* No padding, overlay handles it */
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background-color: #f7fafc;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    transition: background-color 0.2s, transform 0.2s;
    cursor: pointer; /* Indicate clickable for fun fact */
    position: relative; /* For absolute positioning of fun fact/recipe */
    text-align: center; /* Center text */
    flex-shrink: 0; /* Prevent nodes from shrinking */
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    overflow: hidden;
}

.tree-node:hover {
    background-color: #edf2f7;
    transform: translateY(-2px); /* Slight lift on hover */
}

/* Adjustments for tree-node specific text/emoji sizes within overlay */
.tree-node .element-overlay .element-emoji {
    font-size: 32px; /* Adjust emoji size */
    margin-right: 0; /* Remove margin as it's stacked */
    line-height: 1;
}

.tree-node .element-overlay .element-name {
    font-size: 1rem; /* Adjust font size */
    font-weight: 600;
    color: #2d3748;
    margin-top: 5px; /* Space between emoji and name */
}

.tree-node.undiscovered {
    background-color: #fce4ec; /* Light pink */
    border-color: #f8bbd0;
    color: #d81b60;
    background-image: none !important; /* Ensure no image for undiscovered */
}

.tree-node.undiscovered .element-overlay {
    background-color: rgba(255, 255, 255, 0.9); /* More opaque for undiscovered */
}

.tree-node.undiscovered .element-overlay .element-name {
    color: #d81b60;
}

/* Styles for the new recipe diagram within tree-node */
.recipe-diagram {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    height: 100%;
    background-color: rgba(255, 255, 255, 0.95);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 10px;
    box-sizing: border-box;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    z-index: 5;
}

.tree-node:hover .recipe-diagram {
    opacity: 1;
    visibility: visible;
}

.recipe-diagram .ingredients-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    margin-bottom: 5px; /* Space before the vertical line */
}

.recipe-diagram .ingredient-bubble {
    display: flex;
    align-items: center;
    background-color: #e6fffa;
    border: 1px solid #81e6d9;
    border-radius: 20px;
    padding: 4px 8px;
    font-size: 0.8rem;
    font-weight: 500;
    color: #2c7a7b;
    white-space: nowrap; /* Prevent wrapping */
}

.recipe-diagram .ingredient-bubble .element-emoji {
    font-size: 16px; /* Smaller emoji for recipe ingredients */
    margin-right: 4px;
}

.recipe-diagram .ingredient-bubble.undiscovered-ingredient {
    background-color: #fff0f6;
    border-color: #fbb6ce;
    color: #d81b60;
}

.recipe-diagram .combination-line {
    width: 2px;
    height: 15px; /* Length of the vertical line */
    background-color: #a0aec0;
    margin-bottom: 5px;
    position: relative;
}

.recipe-diagram .combination-line::before {
    content: '';
    position: absolute;
    width: 100%;
    height: 2px;
    background-color: #a0aec0;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    /* This horizontal line connects the two ingredients visually to the vertical line */
    /* Adjust width to span roughly between ingredient bubbles + gap */
    width: calc(100% + 20px); /* Extend beyond the central line to meet ingredients */
}

.recipe-diagram .result-bubble {
    display: flex;
    align-items: center;
    background-color: #c4f1f9;
    border: 1px solid #81e6d9;
    border-radius: 20px;
    padding: 4px 8px;
    font-size: 0.9rem;
    font-weight: 600;
    color: #00796b;
    white-space: nowrap;
}

.recipe-diagram .result-bubble .element-emoji {
    font-size: 18px;
    margin-right: 4px;
}

/* New styles for fun fact display */
.fun-fact-display {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    height: 100%;
    background-color: rgba(255, 255, 255, 0.95);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 10px;
    box-sizing: border-box;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    z-index: 10;
    font-size: 0.9rem;
    color: #4a5568;
    text-align: center;
    overflow: auto; /* Enable scrolling for long facts */
}

.fun-fact-display.active {
    opacity: 1;
    visibility: visible;
}

.fun-fact-display .loading-spinner {
    border: 4px solid #f3f3f3;
    border-top: 4px solid #4299e1;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    animation: spin 1s linear infinite;
    margin-bottom: 10px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.fun-fact-display p {
    margin: 0;
    padding: 0 5px;
}