body {
    font-family: 'Arial', sans-serif;
    background: linear-gradient(135deg, #121212, #1a1a2a, #121212);
    background-size: 400% 400%;
    animation: gradientBG 15s ease infinite;
    color: #e0e0e0;
    display: flex;
    /* justify-content: center; */
    /* align-items: flex-start; */ /* Align top */
    min-height: 100vh;
    margin: 0;
    padding: 20px; /* Add padding around */
    box-sizing: border-box;
    overflow-y: auto; /* Allow scrolling if content overflows */
    transition: background 0.5s ease;
}

@keyframes gradientBG {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.main-container {
    display: flex;
    gap: 30px;
    width: 100%;
    max-width: 1600px; /* Increased max-width for chat */
    margin: 0 auto; /* Center the container */
    align-items: flex-start; /* Align items to the top */
}

.phonk-maker {
    background: linear-gradient(145deg, #2a2a3a, #1f1f2f);
    padding: 30px;
    border-radius: 10px;
    border: 1px solid rgba(255,255,255,0.05);
    box-shadow: 
        0 15px 35px rgba(0,0,0,0.2), 
        0 5px 15px rgba(0,0,0,0.1);
    text-align: center;
    /* width: 65%; */ /* Adjust width */
    flex: 3; /* Adjusted flex ratio */
    min-width: 600px; /* Minimum width */
    transition: all 0.3s ease;
}

.phonk-maker:hover {
    transform: translateY(-5px);
    box-shadow: 
        0 20px 40px rgba(0,0,0,0.3), 
        0 7px 20px rgba(0,0,0,0.15);
}

.published-beats {
    background-color: #2a2a2a;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.4);
    /* width: 30%; */ /* Adjust width */
    flex: 1.5; /* Adjusted flex ratio */
    min-width: 300px;
    max-height: 80vh; /* Limit height */
    overflow-y: auto; /* Scroll if needed */
}

.published-beats h2 {
    color: #4caf50; /* Green heading */
    text-align: center;
    margin-top: 0;
    margin-bottom: 20px;
    text-shadow: 0 0 5px #03a9f4;
}

#beats-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.category-heading {
    color: #aaa;
    font-size: 1.1em;
    text-align: left;
    margin-top: 15px;
    margin-bottom: 8px;
    border-bottom: 1px solid #555;
    padding-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.category-new {
    color: #03a9f4; /* Light Blue */
    border-bottom-color: #03a9f4;
}
.category-older {
    color: #aaa;
}

.beat-item {
    background: linear-gradient(145deg, #333, #2a2a2a);
    padding: 10px 15px;
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    cursor: default; /* Indicate it's not clickable itself */
    transition: all 0.3s ease;
}

.beat-item:hover {
    transform: translateX(5px);
    box-shadow: 
        0 5px 15px rgba(0,0,0,0.2), 
        inset 0 0 10px rgba(255,255,255,0.05);
}

.beat-info {
    flex-grow: 1;
    text-align: left;
}

.beat-name {
    font-weight: bold;
    color: #e0e0e0;
    margin-bottom: 3px;
    word-break: break-word; /* Prevent long names breaking layout */
}

.beat-creator {
    font-size: 0.85em;
    color: #aaa;
}
.beat-creator img {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    vertical-align: middle;
    margin-right: 4px;
}

.load-beat-button {
    background-color: #4caf50;
    color: white;
    border: none;
    padding: 5px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9em;
    transition: background-color 0.2s ease;
    flex-shrink: 0; /* Prevent button shrinking */
}

.load-beat-button:hover {
    background-color: #66bb6a;
}

h1 {
    color: #ff4081; /* Neon pink */
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 30px;
    text-shadow: 0 0 5px #ff4081, 0 0 10px #ff4081;
}

.controls {
    margin-bottom: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
}

.controls button {
    background: linear-gradient(145deg, #ff4081, #ff2d6a);
    border: none;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.3s ease;
    color: #1a1a1a;
    padding: 0;
    box-shadow: 
        0 4px 6px rgba(0,0,0,0.1), 
        inset 0 2px 4px rgba(255,255,255,0.2);
    transform: perspective(200px) rotateX(-2deg);
}

.controls button:hover {
    transform: perspective(200px) rotateX(0) scale(1.05);
    box-shadow: 
        0 6px 8px rgba(0,0,0,0.15), 
        inset 0 2px 6px rgba(255,255,255,0.3);
}

.controls button svg {
    width: 24px;
    height: 24px;
}

#download-button {
     background-color: #4caf50; /* Green */
}
#download-button:hover {
     background-color: #81c784;
}
#download-button:disabled {
    background-color: #555;
    cursor: not-allowed;
    opacity: 0.6;
}

label {
    font-size: 1.1em;
}

input[type="range"] {
    cursor: pointer;
    width: 150px;
}

#tempo-value {
    font-weight: bold;
    min-width: 35px; /* Slightly wider for 3 digits */
    display: inline-block;
}

.templates-section {
    margin-bottom: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
}

.templates-section label {
    font-size: 1em; /* Slightly smaller label */
}

#template-select {
    padding: 5px 8px;
    background-color: #444;
    color: #e0e0e0;
    border: 1px solid #555;
    border-radius: 4px;
    cursor: pointer;
}

#clear-button {
    padding: 5px 10px;
    background-color: #f44336; /* Red */
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9em;
    transition: background-color 0.2s ease;
}
#clear-button:hover {
    background-color: #e57373;
}

.custom-instrument-section {
    margin-bottom: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap; /* Allow wrapping on smaller screens */
    padding: 10px;
    background-color: #333; /* Slightly different background */
    border-radius: 5px;
}

.custom-instrument-section label {
    font-size: 1em;
    color: #bbb;
}

.custom-instrument-section input[type="file"] {
    color: #e0e0e0;
    font-size: 0.9em;
    max-width: 150px; /* Limit width */
}

.custom-instrument-section input[type="file"]::file-selector-button {
    padding: 4px 8px;
    background-color: #555;
    color: #e0e0e0;
    border: 1px solid #666;
    border-radius: 3px;
    cursor: pointer;
    transition: background-color 0.2s ease;
    margin-right: 5px;
}

.custom-instrument-section input[type="file"]::file-selector-button:hover {
    background-color: #666;
}

.custom-instrument-section input[type="text"] {
    padding: 5px 8px;
    background-color: #444;
    color: #e0e0e0;
    border: 1px solid #555;
    border-radius: 4px;
    font-size: 0.9em;
    width: 120px; /* Fixed width for name */
}

#add-instrument-button {
    padding: 5px 10px;
    background-color: #8bc34a; /* Light Green */
    color: #1a1a1a; /* Dark text */
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9em;
    transition: background-color 0.2s ease;
}
#add-instrument-button:hover {
    background-color: #9ccc65;
}
#add-instrument-button:disabled {
    background-color: #555;
    color: #888;
    cursor: not-allowed;
    opacity: 0.6;
}

.sequencer {
    margin-bottom: 20px;
    position: relative;
}

.track {
    display: flex;
    align-items: center;
    margin-bottom: 8px; /* Slightly less margin */
    background-color: #333;
    padding: 4px; /* Slightly less padding */
    border-radius: 5px;
    position: relative; /* Needed for positioning remove button */
}

.instrument-label {
    width: 80px;
    text-align: right;
    padding-right: 10px;
    font-weight: bold;
    font-size: 0.85em; /* Smaller labels */
    color: #aaa;
    flex-shrink: 0;
    overflow: hidden; /* Hide long names */
    text-overflow: ellipsis; /* Add ... for long names */
    white-space: nowrap; /* Prevent wrapping */
}

.remove-instrument-button {
    position: absolute;
    left: 5px; /* Position near the left edge of the track */
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: #888;
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    padding: 0 5px;
    line-height: 1;
    display: none; /* Initially hidden */
    opacity: 0.7;
    transition: color 0.2s, opacity 0.2s;
}

.track:hover .remove-instrument-button {
    display: block; /* Show on track hover */
}

.remove-instrument-button:hover {
    color: #f44336; /* Red on hover */
    opacity: 1;
}

.steps {
    display: flex;
    flex-grow: 1;
    justify-content: space-between;
}

.step {
    background: linear-gradient(145deg, #444, #333);
    /* Adjust width based on container, ensure 16 fit */
    flex-basis: calc(100% / 16 - 4px); /* Account for margin */
    aspect-ratio: 1 / 1; /* Make them square */
    /* Removed fixed width/height */
    min-width: 25px; /* Minimum size */
    border: 1px solid rgba(255,255,255,0.05);
    cursor: pointer;
    transition: all 0.2s ease;
    margin: 2px;
    border-radius: 3px;
    flex-shrink: 0;
}

.step.active {
    background: linear-gradient(145deg, #ff4081, #ff2d6a);
    box-shadow: 
        0 0 10px rgba(255,64,129,0.5), 
        inset 0 0 5px rgba(255,255,255,0.2);
    transform: scale(1.05);
}

.step.playing {
    transform: scale(1.1);
    border-color: #fff;
    z-index: 1; /* Ensure playing indicator is on top */
    position: relative;
}

.step:nth-child(4n) {
    margin-right: 6px; /* Slightly larger margin every 4 steps */
}
.step:nth-child(4n + 1) {
     background-color: #4a4a4a; /* Slightly lighter bg for downbeats */
}
.step.active:nth-child(4n + 1) {
     background-color: #ff79b0; /* Lighter active for downbeats */
}

.indicator-container {
    width: calc(100% - 90px); /* Match steps width (label + padding) */
    margin-left: 90px; /* Align with steps */
    height: 5px;
    position: relative;
    background-color: #444;
    border-radius: 2.5px;
    overflow: hidden;
}

.indicator-bar {
    position: absolute;
    top: 0;
    left: 0;
    width: calc(100% / 16); /* Width of one step */
    height: 100%;
    background-color: #fff;
    border-radius: 2.5px;
    transition: left 0.05s linear;
    visibility: hidden;
}

.indicator-bar.visible {
    visibility: visible;
}

.publish-section {
    margin-top: 30px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
}

#beat-name {
    padding: 8px 12px;
    background-color: #444;
    color: #e0e0e0;
    border: 1px solid #555;
    border-radius: 4px;
    flex-grow: 1;
    max-width: 300px; /* Limit width */
}

#publish-button {
    padding: 8px 15px;
    background-color: #03a9f4; /* Light Blue */
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1em;
    transition: background-color 0.2s ease;
}
#publish-button:hover {
    background-color: #29b6f6;
}
#publish-button:disabled {
    background-color: #555;
    cursor: not-allowed;
    opacity: 0.6;
}

.chat-container {
    background-color: #2a2a2a;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.4);
    flex: 1.5; /* Adjusted flex ratio */
    min-width: 300px;
    max-height: 80vh; /* Same height limit as beats */
    display: flex;
    flex-direction: column; /* Stack elements vertically */
}

.chat-container h2 {
    color: #03a9f4; /* Light Blue heading */
    text-align: center;
    margin-top: 0;
    margin-bottom: 15px;
    text-shadow: 0 0 5px #03a9f4;
}

#chat-messages {
    flex-grow: 1; /* Take available space */
    background-color: #333;
    border-radius: 5px;
    padding: 10px;
    margin-bottom: 10px;
    overflow-y: auto; /* Enable scrolling for messages */
    min-height: 200px; /* Ensure a minimum height */
    display: flex;
    flex-direction: column-reverse; /* Newest messages at the bottom */
}

.chat-message {
    margin-bottom: 8px;
    padding: 5px 8px;
    border-radius: 4px;
    word-wrap: break-word; /* Wrap long messages */
    max-width: 95%; /* Prevent messages from taking full width */
}

.chat-message .meta {
    font-size: 0.8em;
    color: #aaa;
    margin-bottom: 3px;
    display: flex;
    align-items: center;
}

.chat-message .meta img {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    margin-right: 5px;
    vertical-align: middle;
}

.chat-message .username {
    font-weight: bold;
    margin-right: 5px;
}

.chat-message .timestamp {
    font-size: 0.9em;
}

.chat-message .text {
    color: #e0e0e0;
}

.chat-message-system {
    font-style: italic;
    color: #aaa;
    text-align: center;
    margin: 8px 0;
    font-size: 0.9em;
}

.chat-input-area {
    background: linear-gradient(145deg, #2a2a3a, #1f1f2f);
    border-radius: 10px;
    padding: 5px;
    box-shadow: 
        0 4px 6px rgba(0,0,0,0.1), 
        inset 0 2px 4px rgba(255,255,255,0.05);
    display: flex;
    gap: 5px;
}

#chat-input {
    flex-grow: 1; /* Take remaining width */
    padding: 8px 10px;
    background-color: #444;
    color: #e0e0e0;
    border: 1px solid #555;
    border-radius: 4px;
}

#chat-send {
    background: linear-gradient(145deg, #03a9f4, #0288d1);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9em;
    transition: all 0.3s ease;
    box-shadow: 
        0 4px 6px rgba(0,0,0,0.1), 
        inset 0 2px 4px rgba(255,255,255,0.2);
}

#chat-send:hover {
    transform: scale(1.05);
    box-shadow: 
        0 6px 8px rgba(0,0,0,0.15), 
        inset 0 2px 6px rgba(255,255,255,0.3);
}
#chat-send:disabled {
    background-color: #555;
    cursor: not-allowed;
    opacity: 0.6;
}

/* Styles for Blocked Beats Section */
.blocked-beats {
    background-color: #2a2a2a;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.4);
    flex: 1.5; /* Same flex as published beats */
    min-width: 300px;
    max-height: 80vh; /* Limit height */
    overflow-y: auto; /* Scroll if needed */
}

.blocked-beats h2 {
    color: #f44336; /* Red heading */
    text-align: center;
    margin-top: 0;
    margin-bottom: 20px;
    text-shadow: 0 0 5px #f44336;
}

#blocked-beats-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.blocked-beat-item {
    background-color: #333;
    padding: 10px 15px;
    border-radius: 5px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    cursor: default;
    opacity: 0.8; /* Slightly faded */
}

.blocked-beat-item .beat-info {
    flex-grow: 1;
    text-align: left;
    font-size: 0.9em; /* Slightly smaller text */
}

/* Styles for Flagged Beats Section */
.flagged-beats {
    background-color: #2a2a2a;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.4);
    flex: 1.5; /* Same flex as other sidebars */
    min-width: 300px;
    max-height: 80vh; /* Limit height */
    overflow-y: auto; /* Scroll if needed */
}

.flagged-beats h2 {
    color: #ff9800; /* Orange heading */
    text-align: center;
    margin-top: 0;
    margin-bottom: 20px;
    text-shadow: 0 0 5px #ff9800;
}

#flagged-beats-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.flagged-beat-item {
    background-color: #333;
    padding: 10px 15px;
    border-radius: 5px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    cursor: default;
    opacity: 0.9; /* Slightly less faded than blocked */
}

.flagged-beat-item .beat-info {
    flex-grow: 1;
    text-align: left;
    font-size: 0.9em;
}

/* Styles for Community Instruments Section */
.community-instruments {
    background-color: #2a2a2a;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.4);
    flex: 1.5; /* Same flex as published beats */
    min-width: 300px;
    max-height: 80vh; /* Limit height */
    overflow-y: auto; /* Scroll if needed */
}

.community-instruments h2 {
    color: #8bc34a; /* Light Green heading */
    text-align: center;
    margin-top: 0;
    margin-bottom: 20px;
    text-shadow: 0 0 5px #8bc34a;
}

#community-instruments-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.instrument-item {
    background-color: #333;
    padding: 10px 15px;
    border-radius: 5px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    cursor: default;
}

.instrument-item .instrument-info {
    flex-grow: 1;
    text-align: left;
}

.instrument-item .instrument-name {
    font-weight: bold;
    color: #e0e0e0;
    margin-bottom: 3px;
    word-break: break-word;
}

.instrument-item .instrument-creator {
    font-size: 0.85em;
    color: #aaa;
}
.instrument-item .instrument-creator img {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    vertical-align: middle;
    margin-right: 4px;
}

.instrument-item .load-instrument-button {
    background-color: #8bc34a; /* Light Green */
    color: #1a1a1a;
    border: none;
    padding: 5px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9em;
    transition: background-color 0.2s ease;
    flex-shrink: 0;
}

.instrument-item .load-instrument-button:hover {
    background-color: #9ccc65;
}
.instrument-item .load-instrument-button:disabled {
    background-color: #555;
    color: #888;
    cursor: not-allowed;
    opacity: 0.6;
}

/* Sticky Note Styles */
.sticky-note {
    position: fixed;
    bottom: 20px;
    left: 20px;
    background-color: #fffacd; /* Light yellow */
    color: #333; /* Dark text */
    padding: 15px 20px;
    padding-top: 30px; /* Make space for close button */
    border-radius: 5px;
    box-shadow: 5px 5px 10px rgba(0, 0, 0, 0.3);
    z-index: 1000; /* Ensure it's on top */
    max-width: 250px;
    font-family: 'Comic Sans MS', cursive, sans-serif; /* Optional: sticky note font */
    font-size: 0.9em;
    line-height: 1.4;
    transform: rotate(-2deg); /* Slight rotation */
    transition: transform 0.2s ease-in-out, opacity 0.3s ease, visibility 0.3s ease;
    opacity: 1;
    visibility: visible;
}

.close-sticky-note {
    position: absolute;
    top: 5px;
    right: 5px;
    background: rgba(0, 0, 0, 0.1);
    border: none;
    border-radius: 50%;
    color: #555;
    cursor: pointer;
    font-size: 16px;
    font-weight: bold;
    line-height: 18px; /* Center the 'x' */
    width: 20px;
    height: 20px;
    text-align: center;
    padding: 0;
    transition: background-color 0.2s, color 0.2s;
}

.close-sticky-note:hover {
    background: rgba(0, 0, 0, 0.2);
    color: #000;
}

.sticky-note:hover {
    transform: rotate(0deg) scale(1.02); /* Straighten on hover */
}

.sticky-note p {
    margin: 0 0 10px 0;
}
.sticky-note p:last-child {
    margin-bottom: 0;
}

.sticky-note a {
    color: #0066cc;
    text-decoration: underline;
    font-weight: bold;
}

.sticky-note a:hover {
    color: #004c99;
}

/* Popup Styles */
.popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.popup-overlay.active {
    opacity: 1;
    visibility: visible;
}

.popup-container {
    background: linear-gradient(145deg, #2a2a3a, #1f1f2f);
    padding: 25px;
    border-radius: 10px;
    box-shadow: 
        0 15px 35px rgba(0,0,0,0.4),
        0 5px 15px rgba(0,0,0,0.2);
    max-width: 90%;
    width: 400px;
    transform: scale(0.7);
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.popup-overlay.active .popup-container {
    transform: scale(1);
    opacity: 1;
}

.popup-content {
    color: #e0e0e0;
    text-align: center;
}

.popup-content p {
    margin: 0 0 20px 0;
    font-size: 1.1em;
    line-height: 1.4;
}

#popup-close {
    background: linear-gradient(145deg, #ff4081, #ff2d6a);
    color: white;
    border: none;
    padding: 10px 25px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1em;
    transition: all 0.3s ease;
    box-shadow: 
        0 4px 6px rgba(0,0,0,0.1),
        inset 0 2px 4px rgba(255,255,255,0.2);
}

#popup-close:hover {
    transform: translateY(-2px);
    box-shadow: 
        0 6px 8px rgba(0,0,0,0.15),
        inset 0 2px 6px rgba(255,255,255,0.3);
}

/* Hide default alerts */
.alert {
    display: none !important;
}

@media (max-width: 1400px) { /* Adjusted breakpoint for 3 columns */
    .main-container {
        flex-direction: column;
        align-items: center;
        max-width: 95%; /* Use more width when stacked */
    }
    .phonk-maker, .published-beats, .chat-container, .blocked-beats, .community-instruments, .flagged-beats {
        width: 95%;
        max-width: 800px; /* Limit width on smaller screens when stacked */
        flex: none; /* Reset flex sizing */
        margin-bottom: 20px; /* Add margin between stacked items */
    }
    .published-beats, .chat-container, .blocked-beats, .community-instruments, .flagged-beats {
        max-height: 50vh; /* Adjust height when stacked */
    }
}

@media (max-width: 768px) {
    .phonk-maker {
        padding: 20px;
    }
    .controls {
        flex-wrap: wrap; /* Wrap controls if needed */
        gap: 10px;
    }
    input[type="range"] {
        width: 100px;
    }
    .instrument-label {
        width: 60px;
        font-size: 0.8em;
    }
    .indicator-container {
        width: calc(100% - 70px);
        margin-left: 70px;
    }
    .step {
        min-width: 20px;
    }
    .publish-section {
        flex-direction: column;
        gap: 15px;
    }
    #beat-name {
        width: 80%;
        max-width: none;
    }
}

/* Adjust sticky note position on smaller screens */
@media (max-width: 768px) {
    .sticky-note {
        bottom: 10px;
        left: 10px;
        max-width: 200px;
        padding: 10px 15px;
        font-size: 0.8em;
    }
}