@import url('https://fonts.googleapis.com/css2?family=Luckiest+Guy&family=Poppins:wght@400;500;700&display=swap');

:root {
    --primary-color: #007bff; /* Bright Blue */
    --secondary-color: #e9ecef; /* Light Gray for elements */
    --accent-color: #28a745; /* Bright Green */
    --bg-color: #ffffff; /* White */
    --text-color: #212529; /* Dark Gray text */
    --container-bg: #f8f9fa; /* Off-white container */
    --border-color: #dee2e6; /* Light Gray border */
    --element-bg: #ffffff;
    --primary-border: #0069d9; /* Darker Blue */

    /* Theme One vars */
    --one-primary: #0077ff; /* Blue */
    --one-secondary: #000000; /* Black */
    --one-accent: #ffffff; /* White */
    --one-bg: #000000; /* Black */
    --one-text: #ffffff; /* White */
    --one-container-bg: #1a1a1a;
    --one-border: #0077ff;
    --one-element-bg: #111111;
}

body {
    font-family: 'Poppins', Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    margin: 0;
    padding: 20px;
    background-image: url('/background.png');
    background-size: cover;
    background-position: center;
    box-sizing: border-box;
    position: relative; /* Needed for absolute positioning of children */
    overflow-x: hidden; /* Prevent horizontal scroll from decorations */
    transition: background-color 0.5s ease;
}

body.theme-one-active {
    --primary-color: var(--one-primary);
    --secondary-color: var(--one-secondary);
    --accent-color: var(--one-accent);
    --bg-color: var(--one-bg);
    --text-color: var(--one-text);
    --container-bg: var(--one-container-bg);
    --border-color: var(--one-border);
    --element-bg: var(--one-element-bg);
    --primary-border: var(--one-accent);
    background-image: none;
}

#app {
    background-color: rgba(255, 255, 255, 0.9); /* Semi-transparent white */
    padding: 20px;
    border-radius: 25px;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
    width: 100%;
    max-width: 800px;
    border: 3px solid var(--border-color);
    z-index: 10;
    position: relative;
    transition: background-color 0.5s ease, border-color 0.5s ease;
}

.logo-container {
    text-align: center;
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 3px dashed var(--border-color);
}

#logo-text {
    font-family: 'Luckiest Guy', cursive;
    font-size: 4rem;
    color: var(--primary-color);
    text-shadow: 
        0 0 4px rgba(255, 255, 255, 0.8),
        0 0 8px rgba(255, 255, 255, 0.8),
        0 0 12px var(--primary-color),
        0 0 16px var(--primary-color);
    margin: 0;
}

#logo {
    display: none; /* Hide old logo img, replaced by h1 */
}

h1, h2, h3 {
    font-family: 'Luckiest Guy', cursive;
    letter-spacing: 1px;
}

h2 {
    color: var(--primary-color);
}

h3 {
    color: var(--text-color);
}

.main-container {
    display: flex;
    flex-wrap: nowrap;
    gap: 30px;
}

#character-display {
    flex: 1;
    min-width: 300px;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #f0f2f5;
    border-radius: 10px;
    border: 3px dashed var(--border-color);
    position: relative; /* Needed for positioning draggable parts */
    overflow: hidden; /* Hide parts dragged outside */
}

#character-svg {
    overflow: visible;
}

#character-svg .animated-group {
    animation: idle-bob 4s ease-in-out infinite;
    transform-origin: center bottom;
}

@keyframes idle-bob {
  0%, 100% {
    transform: translateY(0) scale(1, 1);
  }
  50% {
    transform: translateY(-4px) scale(0.98, 1.02);
  }
}

#controls {
    flex: 1;
    min-width: 300px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* --- New Tab Styles --- */
.controls-tabs {
    display: flex;
    gap: 5px;
    border-bottom: 3px solid var(--border-color);
}

.tab-btn {
    padding: 10px 15px;
    cursor: pointer;
    border: 2px solid transparent;
    border-bottom: none;
    background-color: transparent;
    border-radius: 8px 8px 0 0;
    font-family: 'Luckiest Guy', cursive;
    font-size: 18px;
    color: var(--text-color);
    position: relative;
    top: 3px;
    transition: all 0.2s ease;
}

.tab-btn:hover {
    background-color: var(--secondary-color);
}

.tab-btn.active {
    background-color: var(--container-bg);
    border-color: var(--border-color);
    color: var(--primary-color);
}

.controls-panels {
    padding: 0;
}

.tab-panel {
    display: none;
    flex-direction: column;
    gap: 15px;
    animation: fadeIn 0.3s ease-in-out;
}

.tab-panel.active {
    display: flex;
}

.control-group {
    background: var(--element-bg);
    padding: 15px;
    border-radius: 12px;
    border: 2px solid var(--border-color);
    box-shadow: 0 4px 0px rgba(0,0,0,0.05);
    transition: all 0.2s ease;
}

.control-group:focus-within {
    border-color: var(--primary-color);
    box-shadow: 0 4px 0 var(--primary-color);
}

.control-group h3 {
    margin-top: 0;
    margin-bottom: 12px;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 8px;
    font-size: 1.4rem;
}

.control-group label {
    font-weight: bold;
    margin-right: 10px;
    margin-bottom: 0;
    display: inline-block;
}

.control-group #character-name-input {
    width: 100%;
    padding: 10px;
    border-radius: 8px;
    border: 2px solid var(--border-color);
    background-color: #fff;
    color: var(--text-color);
    font-family: inherit;
    font-size: 1em;
    box-sizing: border-box;
    margin-top: 5px;
}
.control-group #character-name-input:focus {
    outline: none;
    border-color: var(--primary-color);
}

input[type="color"] {
    width: 100%;
    height: 40px;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    padding: 2px 4px;
    cursor: pointer;
    border-radius: 8px;
    background: none;
}

.button-group {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

.button-group button {
    flex-grow: 1;
}

.shape-btn, .selector button, .action-buttons button, .texture-btn {
    padding: 10px 15px;
    border: 2px solid #ccc;
    background-color: #f0f0f0;
    color: #333;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s ease-out;
    font-size: 14px;
    font-family: 'Poppins', sans-serif;
    font-weight: 500;
    box-shadow: 0 3px 0 #bbb;
}

.shape-btn:hover, .selector button:hover, .action-buttons button:hover, .texture-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 0 #bbb;
    background-color: #e9e9e9;
}

.shape-btn:active, .selector button:active, .action-buttons button:active, .texture-btn:active {
    transform: translateY(1px);
    box-shadow: 0 1px 0 #bbb;
}

.shape-btn:disabled {
    background-color: #e9ecef;
    border-color: #ced4da;
    color: #6c757d;
    cursor: not-allowed;
    box-shadow: 0 3px 0 #adb5bd;
    transform: none;
}
.shape-btn:disabled:hover {
    background-color: #e9ecef;
    transform: none;
    box-shadow: 0 3px 0 #adb5bd;
}

#shape-btn.active, .power-btn.active, .texture-btn.active, .shape-btn.active {
    background-color: var(--primary-color);
    color: white;
    border-color: var(--primary-border);
    box-shadow: 0 3px 0 #0056b3;
}

.selector {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}
.selector > div {
    display: flex;
    align-items: center;
    gap: 10px;
}
.selector span {
    min-width: 80px;
    text-align: center;
    font-weight: 700;
    color: var(--primary-color);
}
.selector button {
    padding: 5px 10px;
}

/* Styles for Draggable Part Controls */
.draggable-part-control {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-color);
}

.draggable-part-control:last-child {
    border-bottom: none;
}

.draggable-part-control .part-name {
    font-weight: 500;
    color: var(--text-color);
}

.draggable-part-control .part-actions button {
    padding: 5px 10px;
    margin-left: 5px;
    border: 1px solid #ccc;
    background-color: #f0f0f0;
    color: #333;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
}

.draggable-part-control .part-actions button:hover {
    background-color: var(--primary-color);
    color: #111;
}

/* Styles for parts being dragged on the SVG */
.draggable-part {
    cursor: grab;
    transition: transform 0.1s ease-out;
}
.draggable-part:active {
    cursor: grabbing;
}

.toggle-container {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 28px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 50%;
}

.slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: var(--primary-color);
}

input:checked + .slider:before {
    transform: translateX(22px);
    background-color: white;
}

#gradient-controls, #gradient-angle-control {
    margin-top: 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

#gradient-controls.hidden, #gradient-angle-control.hidden {
    display: none;
}

.button-group-small button {
    padding: 5px 10px;
    font-size: 12px;
    border: 2px solid #ccc;
    background-color: #f0f0f0;
    color: #333;
    border-radius: 8px;
    cursor: pointer;
    font-family: 'Poppins', sans-serif;
    font-weight: 500;
    box-shadow: 0 2px 0 #bbb;
}

.button-group-small button:hover {
    background-color: #e9e9e9;
}

.button-group-small button.active {
    background-color: var(--primary-color);
    color: white;
    border-color: var(--primary-border);
    box-shadow: 0 2px 0 #0056b3;
}

#outline-controls {
    margin-top: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
#outline-controls.hidden {
    display: none;
}

.slider-container {
    display: flex;
    align-items: center;
    gap: 10px;
}

.width-slider {
    flex-grow: 1;
    margin: 0;
}

/* Add a class for highlighting tutorial elements */
.tutorial-highlight {
    position: relative;
    z-index: 1001;
    box-shadow: 0 0 0 4px var(--primary-color), 0 0 20px 10px rgba(0, 123, 255, 0.5);
    border-radius: 10px;
    transition: box-shadow 0.3s ease-in-out;
    background: var(--element-bg); /* Add bg to make elements inside stand out */
}

#outline-controls label {
    margin-bottom: -5px; /* Reduce space below label */
    color: var(--text-color);
    border: none;
    min-width: unset;
}
.action-buttons button:disabled {
    background-color: #adb5bd;
    border-color: #6c757d;
    box-shadow: 0 3px 0 #6c757d;
    cursor: not-allowed;
}

#randomize-btn {
    background-color: #6c757d;
    border-color: #5a6268;
    box-shadow: 0 3px 0 #545b62;
}

#randomize-btn:hover {
     background-color: #5a6268;
     box-shadow: 0 5px 0 #545b62;
}

#tutorial-btn {
    background-color: #6c757d; /* Dodger Blue */
    border-color: #5a6268;
    box-shadow: 0 3px 0 #545b62;
}

#tutorial-btn:hover {
    background-color: #5a6268;
}

#generate-bio-btn {
    background-color: #6c757d; /* Teal */
    border-color: #5a6268;
    box-shadow: 0 3px 0 #545b62;
}

#generate-bio-btn:hover {
    background-color: #5a6268;
}

#download-btn {
    background-color: #6c757d;
    border-color: #5a6268;
    box-shadow: 0 3px 0 #545b62;
}

#download-btn:hover {
    background-color: #5a6268;
}

#post-gallery-btn {
    background-color: #6c757d; /* Light Blue */
    border-color: #5a6268;
    box-shadow: 0 3px 0 #545b62;
}

#post-gallery-btn:hover {
    background-color: #5a6268;
}

#mute-btn {
    background-color: #6c757d; /* Gray */
    border-color: #5a6268;
    box-shadow: 0 3px 0 #545b62;
    color: white;
}
#mute-btn:hover {
    background-color: #5a6268;
}
#mute-btn.muted {
    background-color: #dc3545; /* Red */
    border-color: #c82333;
    box-shadow: 0 3px 0 #bd2130;
}
#mute-btn.muted:hover {
    background-color: #c82333;
}

#bio-display {
    margin-top: 20px;
    background: var(--element-bg);
    padding: 20px;
    border-radius: 12px;
    border: 2px solid var(--border-color);
    animation: fadeIn 0.5s ease-in-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

#bio-display.hidden {
    display: none;
}

#bio-display h2 {
    margin-top: 0;
    margin-bottom: 10px;
    color: var(--primary-color);
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 5px;
}

#bio-content h4 {
    margin-top: 0;
    margin-bottom: 8px;
    font-size: 1.2em;
    color: var(--primary-color);
}

#bio-content p {
    white-space: pre-wrap; /* To respect newlines from AI */
    line-height: 1.5;
    margin: 0 0 10px 0;
}

#bio-content .loading, #bio-content .error {
    text-align: center;
    font-style: italic;
    color: #6c757d;
    padding: 20px;
}

#bio-content .error {
    color: #dc3545;
    font-weight: bold;
}

#voice-controls {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 2px dashed var(--border-color);
    text-align: center;
}

#voice-controls.hidden {
    display: none;
}

#generate-voice-btn {
    background-color: #ff7043; /* Deep Orange */
    border-color: #f4511e;
    box-shadow: 0 3px 0 #e64a19;
    color: white;
    font-weight: 500;
    padding: 10px 15px;
    font-size: 1em;
    cursor: pointer;
    border-radius: 8px;
    margin-bottom: 10px;
    transition: all 0.15s ease-out;
}

#generate-voice-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 0 #e64a19;
    background-color: #f4511e;
}

#generate-voice-btn:disabled {
    background-color: #adb5bd;
    border-color: #6c757d;
    box-shadow: 0 3px 0 #6c757d;
    cursor: not-allowed;
    transform: none;
}

#catchphrase-display {
    font-style: italic;
    font-weight: bold;
    color: var(--primary-color);
    margin: 10px 0;
    min-height: 24px; /* Prevent layout shift */
}

#character-voice-audio {
    width: 100%;
    margin-top: 10px;
}

#character-voice-audio:not([src]) {
    display: none;
}

#fun-facts-container {
    margin-top: 20px;
    background: var(--element-bg);
    padding: 20px;
    border-radius: 12px;
    border: 2px solid var(--border-color);
    animation: fadeIn 0.5s ease-in-out;
    text-align: center;
}

#fun-facts-container h2 {
    margin-top: 0;
    margin-bottom: 15px;
    color: var(--accent-color);
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 10px;
}

#fun-fact-content p {
    font-style: italic;
    line-height: 1.6;
    margin: 0;
    min-height: 40px; /* Prevent layout shift */
    font-family: 'Poppins',sans-serif;
    margin-top: 15px;
    background-color: var(--secondary-color);
    border-radius: 8px;
    padding: 10px;
    color: var(--text-color);
}

#new-fact-btn {
    padding: 10px 20px;
    border: 2px solid #ccc;
    font-weight: bold;
    border-radius: 8px;
    cursor: pointer;
    transition: all .15s ease-out;
    font-size: 16px;
    font-family: 'Poppins',sans-serif;
    margin-top: 15px;
    background-color: var(--accent-color);
    border-color: #218838;
    box-shadow: 0 3px 0 #1e7e34;
    color: white;
}

#new-fact-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 0 #1e7e34;
    background-color: #218838;
}

#new-fact-btn:active {
    transform: translateY(1px);
    box-shadow: 0 1px 0 #1e7e34;
}

#scenario-creator {
    margin-top: 20px;
    background: var(--element-bg);
    padding: 20px;
    border-radius: 12px;
    border: 2px solid var(--border-color);
    animation: fadeIn 0.5s ease-in-out;
}
#scenario-creator.hidden {
    display: none;
}

#scenario-creator h2 {
    margin-top: 0;
    margin-bottom: 10px;
    color: var(--accent-color);
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 8px;
}

#scenario-creator p {
    margin-top: 0;
    margin-bottom: 15px;
}

#scenario-creator textarea {
    width: 100%;
    min-height: 80px;
    padding: 10px;
    border-radius: 8px;
    border: 2px solid var(--border-color);
    background-color: #fff;
    color: var(--text-color);
    font-family: inherit;
    font-size: 1em;
    box-sizing: border-box;
    margin-bottom: 15px;
    resize: vertical;
}

#generate-scenario-btn {
    background-color: var(--accent-color); /* Pink */
    font-weight: bold;
    width: auto;
    border-color: #218838;
    box-shadow: 0 3px 0 #1e7e34;
    color: white;
}
#generate-scenario-btn:hover {
    background-color: #218838;
}

#scenario-display.hidden {
    display: none;
}

#scenario-content {
    margin-top: 20px;
}

#scenario-content .loading, #scenario-content .error {
    text-align: center;
    font-style: italic;
    color: #6c757d;
    padding: 20px;
}
#scenario-content .error {
    color: #dc3545;
    font-weight: bold;
}

#scenario-image {
    width: 100%;
    max-width: 400px;
    height: auto;
    border-radius: 8px;
    border: 3px solid #ccc;
    margin: 0 auto 15px auto;
    display: block;
    background-color: #e9ecef;
}

#scenario-text {
    background: #e9ecef;
    padding: 15px;
    border-radius: 8px;
    white-space: pre-wrap;
    line-height: 1.6;
    border: 2px solid var(--border-color);
}

.limb-style-btn {
    padding: 5px 10px;
    font-size: 12px;
    border: 2px solid #ccc;
    background-color: #f0f0f0;
    color: #333;
    border-radius: 8px;
    cursor: pointer;
    font-family: 'Poppins', sans-serif;
    font-weight: 500;
    box-shadow: 0 2px 0 #bbb;
}
.limb-style-btn:hover {
    background-color: #e9e9e9;
}
.limb-style-btn.active {
    background-color: var(--primary-color);
    color: white;
    border-color: var(--primary-border);
    box-shadow: 0 2px 0 #0056b3;
}

/* --- Multiplayer Section --- */
#multiplayer-container {
    margin-top: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}
#multiplayer-container.hidden {
    display: none;
}

#gallery-container, #item-drawer-container {
    background: var(--element-bg);
    padding: 20px;
    border-radius: 12px;
    border: 2px solid var(--border-color);
    animation: fadeIn 0.5s ease-in-out;
}

#gallery-container h2, #item-drawer-container h2 {
    margin-top: 0;
    margin-bottom: 10px;
    color: var(--primary-color);
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 8px;
}

#gallery-controls {
    margin-bottom: 15px;
    display: flex;
    justify-content: flex-end;
}

#sort-gallery-btn {
    padding: 8px 15px;
    border: 2px solid #ccc;
    background-color: #f0f0f0;
    color: #333;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    box-shadow: 0 2px 0 #bbb;
    transition: all 0.1s ease;
}

#sort-gallery-btn:hover {
    background-color: var(--primary-color);
    color: white;
    border-color: var(--primary-border);
    transform: translateY(-1px);
    box-shadow: 0 3px 0 #0056b3;
}

#gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 15px;
}

.gallery-card {
    border: 2px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    background: #fff;
    color: var(--text-color);
}
.gallery-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 6px 15px rgba(0,0,0,0.1);
}

.gallery-card img {
    width: 100%;
    height: 150px;
    object-fit: contain;
    background-color: #f0f2f5;
    display: block;
}

.gallery-card-info {
    padding: 10px;
    position: relative;
}

.gallery-card-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 8px;
}

.vote-btn, .add-ragdoll-btn {
    padding: 4px 8px;
    font-size: 12px;
    background-color: #6c757d;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.vote-btn:hover, .add-ragdoll-btn:hover {
    background-color: var(--accent-color);
}

.vote-btn:disabled {
    background-color: #adb5bd;
    cursor: not-allowed;
}
.add-ragdoll-btn {
    background-color: #17a2b8; /* Info Blue */
}
.add-ragdoll-btn:hover {
    background-color: #138496;
}
.add-ragdoll-btn:disabled {
     background-color: #adb5bd;
    cursor: not-allowed;
}

.vote-count {
    font-size: 14px;
    font-weight: bold;
    color: var(--primary-color);
}

.gallery-card-info h4 {
    margin: 0 0 5px 0;
    font-size: 1em;
    font-family: 'Poppins', sans-serif;
    font-weight: 700;
    color: var(--text-color);
}
.gallery-card-info p {
    margin: 0;
    font-size: 0.8em;
    color: #6c757d;
}

#item-drawer-canvas {
    border: 2px dashed var(--border-color);
    border-radius: 8px;
    background-color: #f4f0fd;
    cursor: crosshair;
    width: 100%;
    height: auto;
    aspect-ratio: 1/1;
}

#drawer-controls {
    display: flex;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
    margin-bottom: 15px;
}

#drawer-controls button {
    padding: 8px 12px;
    border: 2px solid #ccc;
    background-color: #f0f0f0;
    color: #333;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    box-shadow: 0 2px 0 #bbb;
    transition: all 0.1s ease;
}
#drawer-controls button:hover {
    transform: translateY(-1px);
    box-shadow: 0 3px 0 #bbb;
    background-color: #e9e9e9;
}
#drawer-controls button:active, #drawer-controls button.active {
    transform: translateY(1px);
    box-shadow: 0 1px 0 #0056b3;
    background-color: var(--primary-color);
    color: white;
    border-color: var(--primary-border);
}

#drawer-save-btn {
    margin-left: auto;
    background-color: var(--accent-color);
    border-color: #218838;
    box-shadow: 0 3px 0 #1e7e34;
    color: white;
}
#drawer-save-btn:hover {
    background-color: #218838;
}
#drawer-save-btn:disabled {
    background-color: #adb5bd;
    border-color: #6c757d;
    box-shadow: 0 3px 0 #6c757d;
    cursor: not-allowed;
}

#ragdoll-container {
    margin-top: 20px;
    background: var(--element-bg);
    padding: 20px;
    border-radius: 12px;
    border: 2px solid var(--border-color);
    animation: fadeIn 0.5s ease-in-out;
}

#ragdoll-container h2 {
    margin-top: 0;
    margin-bottom: 10px;
    color: var(--accent-color);
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 8px;
}

#ragdoll-container p {
    margin-top: 0;
    margin-bottom: 15px;
}

#ragdoll-canvas-container {
    width: 100%;
    height: 400px;
    background-color: #f0f2f5;
    border-radius: 8px;
    border: 3px dashed var(--border-color);
    position: relative;
    overflow: hidden;
}

#ragdoll-canvas-container canvas {
    display: block;
    background-color: transparent;
}

/* --- Ask Character Section --- */
#ask-character-container {
    margin-top: 20px;
    background: var(--element-bg);
    padding: 20px;
    border-radius: 12px;
    border: 2px solid var(--border-color);
    animation: fadeIn 0.5s ease-in-out;
}
#ask-character-container.hidden {
    display: none;
}
#ask-character-container h2 {
    margin-top: 0;
    margin-bottom: 10px;
    color: #ff7043; /* Deep Orange */
}
#ask-input-area {
    display: flex;
    gap: 10px;
    margin-top: 15px;
}
#ask-character-input {
    flex-grow: 1;
    padding: 10px;
    border-radius: 8px;
    border: 2px solid var(--border-color);
    background-color: #fff;
    color: var(--text-color);
    font-family: inherit;
    font-size: 1em;
}
#ask-character-btn {
    padding: 10px 15px;
    border: 2px solid #ccc;
    background-color: #ff7043;
    border-color: #f4511e;
    box-shadow: 0 3px 0 #e64a19;
    color: white;
    font-weight: bold;
    border-radius: 8px;
    cursor: pointer;
    transition: all .15s ease-out;
}
#ask-character-btn:hover {
     background-color: #f4511e;
}
#ask-character-btn:disabled {
    background-color: #adb5bd;
    border-color: #6c757d;
    box-shadow: 0 3px 0 #6c757d;
    cursor: not-allowed;
}
#ask-response-area {
    margin-top: 15px;
    padding: 15px;
    background-color: var(--secondary-color);
    border-radius: 8px;
    border-left: 5px solid #ff7043;
    font-style: italic;
    white-space: pre-wrap;
    line-height: 1.5;
}
#ask-response-area.hidden {
    display: none;
}

/* --- Challenge Section --- */
#challenge-container {
    margin-top: 20px;
    background: var(--element-bg);
    padding: 20px;
    border-radius: 12px;
    border: 2px solid var(--border-color);
    animation: fadeIn 0.5s ease-in-out;
}

#challenge-container h2 {
    margin-top: 0;
    margin-bottom: 10px;
    color: #ff7043; /* Deep Orange */
    border-bottom: 2px solid #ff8a65;
    padding-bottom: 8px;
}

#challenge-container p {
    margin-top: 0;
    margin-bottom: 15px;
    color: var(--text-color);
    font-weight: bold;
}

#start-challenge-btn {
    background-color: #dc3545; /* Red */
    border-color: #c82333;
    box-shadow: 0 3px 0 #bd2130;
    color: white;
    font-weight: bold;
}
#start-challenge-btn:hover {
    background-color: #c82333;
}

#challenge-game-area {
    width: 100%;
    height: 300px;
    background-color: #f0f2f5;
    border-radius: 8px;
    border: 3px dashed var(--primary-color);
    position: relative;
    overflow: hidden;
    margin-bottom: 15px;
}
#challenge-game-area.hidden {
    display: none;
}

#challenge-hud {
    position: absolute;
    top: 10px;
    left: 10px;
    right: 10px;
    display: flex;
    justify-content: space-between;
    font-family: 'Luckiest Guy', cursive;
    font-size: 24px;
    color: var(--primary-color);
    text-shadow: 1px 1px 2px rgba(0,0,0,0.2);
    z-index: 100;
    pointer-events: none;
}

.challenge-char {
    position: absolute;
    cursor: pointer;
    width: 80px;
    height: 80px;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    transition: transform 0.1s ease;
    will-change: transform, opacity;
}
.challenge-char:active {
    transform: scale(0.9);
}

@keyframes pop-up {
    0% { transform: scale(0); opacity: 0; }
    50% { transform: scale(1.1); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}
@keyframes disappear {
    from { transform: scale(1); opacity: 1; }
    to { transform: scale(0); opacity: 0; }
}

@keyframes hop {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-30px); }
}

@keyframes peek-from-side {
    0% { transform: translateX(-100%); }
    20% { transform: translateX(0); }
    80% { transform: translateX(0); }
    100% { transform: translateX(-100%); }
}

.anim-pop {
    animation: pop-up 0.3s ease-out forwards;
}
.anim-hop {
    animation: hop 1s ease-in-out infinite, pop-up 0.2s forwards;
}
.anim-peek {
    animation: peek-from-side 2s ease-in-out forwards;
}
.is-hit {
    animation: disappear 0.2s ease-in forwards !important;
    pointer-events: none;
}

/* --- Chat Widget --- */
#chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 320px;
    max-width: 90vw;
    background-color: var(--container-bg);
    border: 3px solid var(--primary-color);
    border-radius: 15px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
    z-index: 999;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: all 0.3s ease;
}
#chat-widget.hidden {
    display: none;
}
#chat-widget.collapsed {
    height: 48px;
}
#chat-header {
    background-color: var(--primary-color);
    color: white;
    padding: 10px 15px;
    font-family: 'Luckiest Guy', cursive;
    font-size: 1.2em;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
}
#chat-toggle-btn {
    background: none;
    border: 2px solid white;
    color: white;
    font-weight: bold;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    cursor: pointer;
    line-height: 20px;
    text-align: center;
}
#chat-body {
    display: flex;
    flex-direction: column;
    height: 300px;
}
#chat-messages {
    flex-grow: 1;
    overflow-y: auto;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.chat-message {
    display: flex;
    gap: 8px;
    align-items: flex-start;
}
.chat-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
}
.chat-message-content {
    display: flex;
    flex-direction: column;
}
.chat-username {
    font-weight: bold;
    font-size: 0.9em;
    color: var(--primary-color);
}
.chat-text {
    background: var(--element-bg);
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 0.95em;
    word-break: break-word;
}
#chat-input-container {
    display: flex;
    padding: 10px;
    border-top: 2px solid var(--border-color);
}
#chat-input {
    flex-grow: 1;
    border: 2px solid var(--border-color);
    padding: 8px;
    border-radius: 8px 0 0 8px;
    outline: none;
}
#chat-input:focus {
    border-color: var(--primary-color);
}
#chat-send-btn {
    padding: 8px 15px;
    border: none;
    background-color: var(--primary-color);
    color: white;
    font-weight: bold;
    border-radius: 0 8px 8px 0;
    cursor: pointer;
}

/* --- Decoration Styles --- */
#decorations {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 5;
}

#decorations > * {
    position: absolute;
    animation: decor-float 6s ease-in-out infinite alternate;
}

#decor-tlc {
    width: 120px;
    bottom: 2vh;
    right: 2vw;
    animation-duration: 8s;
}

#decor-sign-container {
    bottom: 2vh;
    left: 2vw;
    width: 150px;
    animation-duration: 9s;
    animation-delay: -2s;
    cursor: pointer;
}

#decor-sign-container img {
    width: 100%;
}

#decor-sign-text {
    font-family: 'Luckiest Guy', cursive;
    color: #4a2511;
    font-size: 28px;
    position: absolute;
    top: 25%;
    left: 50%;
    transform: translateX(-50%) rotate(-5deg);
    text-shadow: 1px 1px 0 rgba(255, 255, 255, 0.7);
    white-space: nowrap;
}

#decor-char1 {
    width: 90px;
    top: 15vh;
    left: 1vw;
    transform: rotate(15deg);
    animation-duration: 7s;
    animation-delay: -1s;
}

#decor-char2 {
    width: 100px;
    top: 35vh;
    right: 1vw;
    transform: rotate(-10deg);
    animation-delay: -3s;
}

@keyframes decor-float {
    from {
        transform: translateY(0px);
    }
    to {
        transform: translateY(-20px);
    }
}

#decor-one {
    position: fixed;
    width: 70px;
    opacity: 0;
    cursor: pointer;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 100;
}

#limb-color-control.hidden {
    display: none;
}

#limb-color-control {
    margin-top: 10px;
}

#limb-color-control label {
    margin-right: 10px;
    font-weight: bold;
}

#limb-color-control input[type="color"] {
    width: calc(100% - 110px); /* Adjust width to fit label */
    display: inline-block;
    vertical-align: middle;
}

/* --- Tutorial Styles --- */
#tutorial-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.75);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 1;
    transition: opacity 0.3s ease;
}

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

#tutorial-modal {
    background: var(--container-bg);
    padding: 20px;
    border-radius: 20px;
    border: 3px solid var(--primary-color);
    box-shadow: 0 5px 25px rgba(0,0,0,0.1);
    max-width: 450px;
    width: 90%;
    text-align: center;
}

#blocky-guide {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 20px;
    min-height: 120px; /* Prevent collapsing */
    position: relative; /* Required for absolute positioning of Two */
    overflow-x: clip; /* Prevent Two from causing horizontal scroll */
}

#blocky-guide img {
    width: 100px;
    height: auto;
    animation: blocky-bob 3s ease-in-out infinite;
    flex-shrink: 0;
}

@keyframes blocky-bob {
  0%, 100% {
    transform: translateY(0) rotate(-2deg);
  }
  50% {
    transform: translateY(-8px) rotate(2deg);
  }
}

#speech-bubble {
    flex-grow: 1;
    background: var(--element-bg);
    padding: 15px;
    border-radius: 12px;
    border: 2px solid var(--border-color);
    position: relative;
    text-align: left;
    z-index: 5; /* Ensure it's above Two */
}

#speech-bubble::before {
    content: '';
    position: absolute;
    left: -10px;
    top: 30px;
    width: 0;
    height: 0;
    border-top: 10px solid transparent;
    border-bottom: 10px solid transparent;
    border-right: 10px solid var(--border-color);
}

#two-speech-bubble {
    position: absolute;
    bottom: 110%; /* Appear above the main bubble */
    right: -20px;
    width: 140px;
    background: #495057;
    padding: 10px;
    border-radius: 12px;
    border: 2px solid #6c757d;
    text-align: center;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.3s ease, transform 0.3s ease;
    z-index: 10;
}

#two-speech-bubble.visible {
    opacity: 1;
    transform: translateY(0);
}

#two-speech-bubble::before {
    content: '';
    position: absolute;
    right: 30px;
    bottom: -10px;
    width: 0;
    height: 0;
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
    border-top: 10px solid #6c757d;
}

#two-speech-bubble p {
    margin: 0;
    font-size: 14px;
    color: #fff;
    font-weight: 500;
}

#speech-bubble p {
    margin: 0;
    line-height: 1.4;
    font-size: 15px;
}

#tutorial-nav {
    display: flex;
    justify-content: space-between;
    gap: 10px;
}

#tutorial-nav button {
    padding: 10px 15px;
    border: 2px solid #ccc;
    background-color: #f0f0f0;
    color: #333;
    border-radius: 8px;
    cursor: pointer;
    font-family: 'Poppins', sans-serif;
    font-weight: 500;
    box-shadow: 0 3px 0 #bbb;
    transition: all 0.1s ease;
}

#tutorial-nav button:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 0 #bbb;
    background-color: #e9e9e9;
}

#tutorial-nav button:active {
    transform: translateY(1px);
    box-shadow: 0 1px 0 #bbb;
}

#tutorial-two {
    position: absolute;
    right: -40px; /* Start mostly hidden */
    bottom: -15px;
    width: 80px;
    transform: rotate(-15deg);
    opacity: 0;
    transition: all 0.5s cubic-bezier(0.25, 1, 0.5, 1);
    z-index: 1; /* Behind Blocky */
    animation: two-bob 4s ease-in-out infinite alternate;
}

@keyframes two-bob {
    from {
        transform: translateY(0) rotate(-15deg);
    }
    to {
        transform: translateY(-5px) rotate(-10deg);
    }
}

#tutorial-two.visible {
    right: -25px; /* Slide into view */
    opacity: 1;
    transform: rotate(10deg);
}

#tutorial-close {
    background-color: #dc3545;
    border-color: #c82333;
    box-shadow: 0 3px 0 #bd2130;
    color: white;
}

#tutorial-next {
    background-color: var(--primary-color);
    border-color: var(--primary-border);
    box-shadow: 0 3px 0 #0056b3;
    color: white;
}

/* Jumpscare styles */
#jumpscare-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: black;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}
#jumpscare-overlay.hidden {
    display: none;
}
#jumpscare-overlay img {
    max-width: 90%;
    max-height: 90%;
    object-fit: contain;
    animation: shake 0.5s cubic-bezier(.36,.07,.19,.97) both;
}

@keyframes shake {
  10%, 90% { transform: translate3d(-1px, 0, 0); }
  20%, 80% { transform: translate3d(2px, 0, 0); }
}

@keyframes glitch-anim {
    0% { transform: translate(0); }
    10% { transform: translate(-2px, 2px); }
    20% { transform: translate(2px, -2px); }
    30% { transform: translate(-2px, -2px); }
    40% { transform: translate(2px, 2px); }
    50% { transform: translate(0); }
    60% { transform: translate(2px, -2px) scaleX(1.05); }
    70% { transform: translate(-2px, 2px) scaleY(0.95); }
    80% { transform: translate(0, 0) scale(1,1); }
    100% { transform: translate(0); }
}