/* Base styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Merriweather', serif;
    background-color: #f5f5f5;
    color: #333;
    line-height: 1.6;
    padding: 0;
    margin: 0;
    overflow-x: hidden;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
}

/* Navigation */
.main-nav {
    background-color: #CBB0FF;
    padding: 1rem 2rem;
    display: flex;
    justify-content: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.nav-link {
    color: white;
    text-decoration: none;
    padding: 0.5rem 1rem;
    margin: 0 0.5rem;
    border-radius: 4px;
    transition: background-color 0.3s;
    font-family: 'Merriweather', serif;
    font-size: 0.9rem;
    font-weight: 700;
}

.nav-link:hover,
.nav-link.active {
    background-color: #b495f0;
}

.user-info {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 1rem;
}

#username-display {
    color: white;
    font-weight: bold;
}

#logout-btn {
    padding: 0.5rem 1rem;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 1px solid white;
    border-radius: 5px;
    cursor: pointer;
    font-family: 'Merriweather', serif;
}

#logout-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Page Header */
.page-header {
    text-align: center;
    margin: 3rem 0 2rem;
    padding-bottom: 2rem;
    border-bottom: 1px solid #eee;
}

.page-header h1 {
    font-size: 2.8rem;
    color: #CBB0FF;
    margin-bottom: 0.5rem;
    font-family: 'Merriweather', serif;
    font-weight: 700;
}

.page-header p {
    font-size: 1.3rem;
    color: #777;
    margin-top: 1.5rem;
}

/* Tabs for Public/My Boards */
.boards-tabs {
    display: flex;
    margin-bottom: 2rem;
    border-bottom: 2px solid #ddd;
}

.tab-btn {
    padding: 1rem 2rem;
    background: none;
    border: none;
    cursor: pointer;
    font-family: 'Merriweather', serif;
    font-size: 1.1rem;
    font-weight: 700;
    color: #777;
    position: relative;
    transition: color 0.3s;
}

.tab-btn:hover {
    color: #CBB0FF;
}

.tab-btn.active {
    color: #CBB0FF;
}

.tab-btn.active::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 100%;
    height: 3px;
    background-color: #CBB0FF;
}

/* Login Prompt */
.login-prompt {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 50vh;
}

.prompt-content {
    background: white;
    padding: 2rem;
    border-radius: 15px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    text-align: center;
    max-width: 400px;
}

.prompt-content h2 {
    color: #CBB0FF;
    margin-bottom: 1rem;
}

/* Boards Grid */
.boards-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.primary-btn {
    padding: 0.8rem 1.5rem;
    background: #CBB0FF;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-family: 'Merriweather', serif;
    font-size: 1rem;
    font-weight: 700;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.primary-btn:hover {
    background: #b495f0;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.primary-btn:active {
    transform: translateY(0);
}

.boards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 2rem;
}

.board-card {
    background: white;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
    cursor: pointer;
}

.board-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

.board-thumbnail {
    height: 180px;
    background: linear-gradient(135deg, #CBB0FF 0%, #a890e0 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    font-size: 1.3rem;
    font-weight: 700;
}

.board-info {
    padding: 1.5rem;
}

.board-title {
    font-weight: bold;
    margin-bottom: 0.5rem;
    color: #555;
    font-size: 1.2rem;
}

.board-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #888;
    font-size: 0.9rem;
}

.board-author {
    font-style: italic;
}

/* Board Editor */
.editor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    flex-wrap: wrap;
    gap: 1rem;
    padding: 1.5rem;
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.editor-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.visibility-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.visibility-toggle label {
    font-weight: bold;
    color: #555;
}

.visibility-toggle select {
    padding: 0.5rem;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-family: 'Merriweather', serif;
    background: white;
    cursor: pointer;
}

#share-section {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

#share-link {
    padding: 0.5rem;
    border: 1px solid #ddd;
    border-radius: 5px;
    width: 250px;
    font-family: 'Merriweather', serif;
    background: #f9f9f9;
}

/* Enhanced Toolbar */
.enhanced-toolbar {
    background: white;
    padding: 1.2rem;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    margin-bottom: 1.5rem;
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
    align-items: center;
}

.toolbar-section {
    display: flex;
    align-items: center;
    gap: 0.8rem;
}

.toolbar-label {
    font-weight: bold;
    color: #555;
    min-width: 60px;
}

.toolbar-select,
.toolbar-input {
    padding: 0.5rem;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-family: 'Merriweather', serif;
    background: white;
}

.toolbar-input[type="number"] {
    width: 70px;
}

.color-picker {
    width: 40px;
    height: 40px;
    padding: 0;
    border: 2px solid #ddd;
    border-radius: 5px;
    cursor: pointer;
    background: white;
}

.color-picker::-webkit-color-swatch-wrapper {
    padding: 0;
}

.color-picker::-webkit-color-swatch {
    border: none;
    border-radius: 3px;
}

/* Editor Tools */
.editor-tools {
    background: white;
    padding: 1.5rem;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    margin-bottom: 2rem;
    display: flex;
    flex-wrap: wrap;
    gap: 2rem;
}

.tools-section {
    flex: 1;
    min-width: 250px;
}

.tools-section h3 {
    margin-bottom: 1rem;
    color: #555;
    font-size: 1.1rem;
}

.tool-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 0.8rem;
}

.tool-btn {
    padding: 0.8rem 1.2rem;
    background: #f0f0f0;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.3s ease;
    font-family: 'Merriweather', serif;
    font-weight: 500;
}

.tool-btn:hover {
    background: #e0e0f0;
    transform: translateY(-2px);
}

.tool-btn.active {
    background: #CBB0FF;
    color: white;
}

/* Board Canvas */
.board-canvas-container {
    background: white;
    padding: 2rem;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    margin-bottom: 3rem;
    min-height: 600px;
    position: relative;
}

.board-canvas {
    position: relative;
    width: 100%;
    height: 600px;
    background: #f9f9f9;
    border: 2px dashed #ddd;
    overflow: hidden;
    touch-action: none;
    user-select: none;
}

/* Draggable Elements */
.draggable {
    position: absolute !important;
    cursor: move;
    user-select: none;
    resize: none;
    overflow: hidden;
    min-width: 80px;
    min-height: 40px;
    border: 2px solid transparent;
    transition: border-color 0.2s ease, transform 0.2s ease;
    touch-action: none;
}

.draggable.selected {
    border-color: #CBB0FF !important;
    box-shadow: 0 0 0 2px rgba(203, 176, 255, 0.3);
    z-index: 1000 !important;
}

.draggable:hover {
    border-color: rgba(203, 176, 255, 0.5);
}

.draggable img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    pointer-events: none;
}

.draggable-text {
    padding: 0.8rem;
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid #ddd;
    border-radius: 8px;
    font-family: 'Merriweather', serif;
    outline: none;
    overflow: auto;
    resize: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.draggable-text:focus {
    border-color: #CBB0FF;
    box-shadow: 0 0 0 2px rgba(203, 176, 255, 0.3);
}

.draggable-sticker {
    font-size: 3rem;
    display: flex;
    justify-content: center;
    align-items: center;
    background: transparent;
    border: none !important;
    user-select: none;
}

.draggable-music {
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 0;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    position: relative;
}

.draggable-music::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 40px;
    background: rgba(203, 176, 255, 0.1);
    z-index: 1;
    cursor: move;
    border-radius: 8px 8px 0 0;
}

.draggable-music iframe {
    width: 100%;
    height: 100%;
    border: none;
    pointer-events: none;
}

.draggable-music .music-drag-handle {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 40px;
    z-index: 2;
    cursor: move;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #CBB0FF;
    font-size: 1.2rem;
    opacity: 0;
    transition: opacity 0.2s;
    background: rgba(255, 255, 255, 0.9);
}

.draggable-music:hover .music-drag-handle,
.draggable-music.selected .music-drag-handle {
    opacity: 1;
}

.music-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, #f5f0ff 0%, #e8e0ff 100%);
    color: #666;
    padding: 1rem;
    text-align: center;
}

.music-placeholder i {
    font-size: 2.5rem;
    margin-bottom: 0.8rem;
    color: #CBB0FF;
    animation: pulse 2s infinite;
}

.draggable-shape {
    background: #CBB0FF;
    border: 2px solid #b495f0;
    border-radius: 8px;
}

.draggable-shape.circle {
    border-radius: 50%;
}

.draggable-controls {
    position: absolute;
    top: -35px;
    right: 0;
    background: white;
    padding: 0.5rem;
    border-radius: 6px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
    display: flex;
    gap: 0.5rem;
    z-index: 1001;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.draggable:hover .draggable-controls,
.draggable.selected .draggable-controls {
    opacity: 1;
}

.draggable-controls button {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    width: 28px;
    height: 28px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
}

.draggable-controls button:hover {
    background: #f0f0f0;
}

.draggable-controls .delete-element {
    color: #ff4444;
    background: rgba(255, 68, 68, 0.1);
    width: 32px;
    height: 32px;
}

.draggable-controls .delete-element:hover {
    background: rgba(255, 68, 68, 0.2);
    transform: scale(1.1);
}

/* Resize handle */
.resize-handle {
    position: absolute;
    width: 20px;
    height: 20px;
    background: #CBB0FF;
    border: 2px solid white;
    border-radius: 50%;
    bottom: -10px;
    right: -10px;
    cursor: nwse-resize;
    z-index: 1001;
    opacity: 0;
    transition: opacity 0.2s ease, transform 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.draggable:hover .resize-handle,
.draggable.selected .resize-handle {
    opacity: 1;
}

.resize-handle:hover {
    transform: scale(1.2);
}

/* Delete confirmation */
.delete-confirmation {
    position: absolute;
    top: -45px;
    right: 0;
    background: white;
    padding: 0.8rem;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    z-index: 1002;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    min-width: 180px;
}

.delete-confirmation p {
    margin: 0;
    font-size: 0.9rem;
    color: #333;
}

.delete-confirmation-buttons {
    display: flex;
    gap: 0.5rem;
}

.delete-confirm-btn,
.delete-cancel-btn {
    padding: 0.4rem 0.8rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
    flex: 1;
}

.delete-confirm-btn {
    background: #ff4444;
    color: white;
}

.delete-confirm-btn:hover {
    background: #cc0000;
}

.delete-cancel-btn {
    background: #f0f0f0;
    color: #666;
}

.delete-cancel-btn:hover {
    background: #e0e0e0;
}

/* Debug Panel */
.debug-panel {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: rgba(255, 255, 255, 0.95);
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    border: 2px solid #CBB0FF;
    max-width: 300px;
    max-height: 400px;
    overflow-y: auto;
    z-index: 9999;
    font-family: 'Courier New', monospace;
}

.debug-panel h3 {
    margin-bottom: 10px;
    color: #CBB0FF;
    font-family: 'Merriweather', serif;
}

#debug-info {
    font-size: 11px;
    color: #333;
    line-height: 1.4;
    background: #f9f9f9;
    padding: 10px;
    border-radius: 4px;
    margin-bottom: 10px;
    max-height: 300px;
    overflow-y: auto;
}

#debug-info div {
    margin-bottom: 5px;
    padding-bottom: 5px;
    border-bottom: 1px solid #eee;
}

#debug-info small {
    color: #888;
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(2px);
}

.modal-content {
    background-color: #2c2c2c;
    margin: 10% auto;
    padding: 2.5rem;
    border-radius: 15px;
    width: 90%;
    max-width: 450px;
    position: relative;
    box-shadow: 0 5px 25px rgba(0, 0, 0, 0.5);
    font-family: 'Merriweather', serif;
    color: white;
    text-align: center;
    animation: modalFadeIn 0.3s ease;
}

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

.close-modal {
    position: absolute;
    top: 1rem;
    right: 1.5rem;
    font-size: 1.8rem;
    cursor: pointer;
    color: #aaa;
    transition: color 0.2s;
}

.close-modal:hover {
    color: white;
}

.modal-content h2 {
    color: #CBB0FF;
    margin-bottom: 1.5rem;
    font-size: 1.8rem;
}

.modal-footer {
    margin-top: 1.5rem;
    text-align: center;
    color: #aaa;
    font-size: 0.9rem;
}

/* Form Styles */
.form-group {
    margin-bottom: 1.5rem;
    text-align: left;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: bold;
    color: #ddd;
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 0.9rem;
    border: 1px solid #444;
    border-radius: 8px;
    font-family: 'Merriweather', serif;
    background: #3a3a3a;
    color: white;
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: #CBB0FF;
}

.form-group textarea {
    min-height: 80px;
    resize: vertical;
}

.submit-btn {
    width: 100%;
    padding: 1rem;
    background: #CBB0FF;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-family: 'Merriweather', serif;
    font-weight: bold;
    font-size: 1rem;
    transition: all 0.3s ease;
}

.submit-btn:hover {
    background: #b495f0;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.submit-btn:active {
    transform: translateY(0);
}

/* Loading spinner */
.loading-spinner {
    grid-column: 1 / -1;
    text-align: center;
    padding: 3rem;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(203, 176, 255, 0.2);
    border-top: 4px solid #CBB0FF;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

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

/* Empty states */
.empty-boards {
    grid-column: 1 / -1;
    text-align: center;
    padding: 3rem 2rem;
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    margin: 1rem 0;
}

.empty-boards p {
    font-size: 1.1rem;
    color: #666;
    margin-bottom: 1.5rem;
}

/* Error messages */
.error-message {
    grid-column: 1 / -1;
    text-align: center;
    padding: 2rem;
    background: #fff5f5;
    border: 1px solid #fed7d7;
    border-radius: 12px;
    color: #c53030;
    margin: 1rem 0;
}

/* Board visibility badges */
.board-visibility {
    display: inline-block;
    padding: 0.3rem 0.8rem;
    border-radius: 15px;
    font-size: 0.8rem;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.board-visibility.public {
    background: #d4edda;
    color: #155724;
}

.board-visibility.private {
    background: #f8d7da;
    color: #721c24;
}

/* Text editor states */
#bold-btn.active,
#italic-btn.active,
#underline-btn.active,
#align-left-btn.active,
#align-center-btn.active,
#align-right-btn.active {
    background: #CBB0FF !important;
    color: white !important;
}

/* Save button states */
#save-board-btn.saving {
    background: #95a5a6;
    cursor: not-allowed;
}

#save-board-btn.saved {
    background: #27ae60;
    animation: pulse 0.5s ease;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

/* Drag overlay */
.drag-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(203, 176, 255, 0.1);
    backdrop-filter: blur(2px);
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2rem;
    color: #CBB0FF;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
}

.drag-overlay.active {
    opacity: 1;
}

/* Utility Classes */
.hidden {
    display: none !important;
}

/* Responsive Design */
@media (max-width: 1024px) {
    .container {
        padding: 1.5rem;
    }
    
    .board-canvas-container {
        min-height: 500px;
        padding: 1.5rem;
    }
    
    .board-canvas {
        height: 500px;
    }
    
    .debug-panel {
        max-width: 250px;
    }
}

@media (max-width: 768px) {
    .container {
        padding: 1rem;
    }
    
    .editor-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }
    
    .editor-actions {
        width: 100%;
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }
    
    #share-section {
        width: 100%;
    }
    
    #share-link {
        width: 100%;
    }
    
    .enhanced-toolbar {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }
    
    .toolbar-section {
        width: 100%;
        justify-content: space-between;
    }
    
    .tools-section {
        min-width: 100%;
    }
    
    .user-info {
        display: none;
    }
    
    .main-nav {
        flex-wrap: wrap;
        justify-content: center;
        padding: 1rem;
    }
    
    .nav-link {
        margin: 0.2rem;
        font-size: 0.8rem;
        padding: 0.4rem 0.8rem;
    }
    
    .board-canvas-container {
        min-height: 400px;
        padding: 1rem;
    }
    
    .board-canvas {
        height: 400px;
    }
    
    .boards-tabs {
        flex-direction: column;
    }
    
    .tab-btn {
        width: 100%;
        text-align: center;
        padding: 0.8rem 1rem;
    }
    
    .debug-panel {
        max-width: 200px;
        font-size: 10px;
    }
}

@media (max-width: 480px) {
    .page-header h1 {
        font-size: 2rem;
    }
    
    .page-header p {
        font-size: 1.1rem;
    }
    
    .board-canvas-container {
        min-height: 300px;
        padding: 0.5rem;
    }
    
    .board-canvas {
        height: 300px;
    }
    
    .tool-btn {
        padding: 0.6rem 1rem;
        font-size: 0.9rem;
    }
    
    .draggable-controls {
        top: -40px;
        right: 50%;
        transform: translateX(50%);
    }
    
    .debug-panel {
        display: none !important; /* Hide debug panel on very small screens */
    }
}