/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
    min-height: 100vh;
    color: #333;
    overflow: hidden;
    transition: all 0.3s ease;
}

/* Theme Variables */
:root {
    /* devblob theme (default) */
    --bg-primary: #ff6b35;
    --bg-secondary: #1a1a1a;
    --accent-primary: #ff6b35;
    --accent-secondary: #ff8c42;
    --text-primary: #1a1a1a;
    --text-secondary: #2d2d2d;
    --text-light: #666;
    --card-bg-primary: #fff5f0;
    --card-bg-secondary: #ffe8d9;
    --card-bg-alt: #f0f0f0;
    --card-bg-alt2: #e8e8e8;
    --card-bg-special: #fff8f0;
    --card-bg-special2: #ffeddb;
    --header-bg: rgba(26, 26, 26, 0.9);
    --header-text: white;
    --cardfile-bg-primary: #2d2d2d;
    --cardfile-bg-secondary: #1a1a1a;
    --cardfile-border: #ff6b35;
    --cardfile-text: white;
    --timer-bg-primary: #1a1a1a;
    --timer-bg-secondary: #2d2d2d;
    --canvas-gradient1: rgba(255, 107, 53, 0.1);
    --canvas-gradient2: rgba(26, 26, 26, 0.1);
}

[data-theme="matrix"] {
    --bg-primary: #00ff41;
    --bg-secondary: #000000;
    --accent-primary: #00ff41;
    --accent-secondary: #39ff14;
    --text-primary: #00ff41;
    --text-secondary: #1a1a1a;
    --text-light: #39ff14;
    --card-bg-primary: #0a0f0a;
    --card-bg-secondary: #0f1f0f;
    --card-bg-alt: #001100;
    --card-bg-alt2: #002200;
    --card-bg-special: #0a1f0a;
    --card-bg-special2: #0f2f0f;
    --header-bg: rgba(0, 0, 0, 0.9);
    --header-text: #00ff41;
    --cardfile-bg-primary: #002200;
    --cardfile-bg-secondary: #001100;
    --cardfile-border: #00ff41;
    --cardfile-text: #00ff41;
    --timer-bg-primary: #001100;
    --timer-bg-secondary: #002200;
    --canvas-gradient1: rgba(0, 255, 65, 0.1);
    --canvas-gradient2: rgba(0, 0, 0, 0.3);
}

[data-theme="easter"] {
    --bg-primary: #ffb6c1;
    --bg-secondary: #e6e6fa;
    --accent-primary: #ff69b4;
    --accent-secondary: #da70d6;
    --text-primary: #4b0082;
    --text-secondary: #663399;
    --text-light: #9370db;
    --card-bg-primary: #fff0f5;
    --card-bg-secondary: #ffe4e1;
    --card-bg-alt: #f0e68c;
    --card-bg-alt2: #dda0dd;
    --card-bg-special: #e0ffff;
    --card-bg-special2: #f0fff0;
    --header-bg: rgba(75, 0, 130, 0.9);
    --header-text: #ffb6c1;
    --cardfile-bg-primary: #9370db;
    --cardfile-bg-secondary: #8a2be2;
    --cardfile-border: #ff69b4;
    --cardfile-text: white;
    --timer-bg-primary: #8a2be2;
    --timer-bg-secondary: #9370db;
    --canvas-gradient1: rgba(255, 182, 193, 0.2);
    --canvas-gradient2: rgba(230, 230, 250, 0.2);
}

[data-theme="ocean"] {
    --bg-primary: #006994;
    --bg-secondary: #0a2f4a;
    --accent-primary: #4a90c2;
    --accent-secondary: #5ba3d4;
    --text-primary: #0a2f4a;
    --text-secondary: #2c5f7a;
    --text-light: #7ab8d3;
    --card-bg-primary: #e8f4f8;
    --card-bg-secondary: #d4edda;
    --card-bg-alt: #cce7f0;
    --card-bg-alt2: #b8dce8;
    --card-bg-special: #e0f7fa;
    --card-bg-special2: #b2ebf2;
    --header-bg: rgba(10, 47, 74, 0.9);
    --header-text: #4a90c2;
    --cardfile-bg-primary: #2c5f7a;
    --cardfile-bg-secondary: #1e4a5f;
    --cardfile-border: #4a90c2;
    --cardfile-text: white;
    --timer-bg-primary: #1e4a5f;
    --timer-bg-secondary: #2c5f7a;
    --canvas-gradient1: rgba(74, 144, 194, 0.15);
    --canvas-gradient2: rgba(10, 47, 74, 0.15);
}

[data-theme="sunset"] {
    --bg-primary: #ff6b35;
    --bg-secondary: #2d1b69;
    --accent-primary: #f7931e;
    --accent-secondary: #ffb347;
    --text-primary: #2d1b69;
    --text-secondary: #5d4e75;
    --text-light: #8e7a9b;
    --card-bg-primary: #fff2e6;
    --card-bg-secondary: #ffe5cc;
    --card-bg-alt: #ffeaa7;
    --card-bg-alt2: #fdcb6e;
    --card-bg-special: #ffe8d6;
    --card-bg-special2: #ffccb3;
    --header-bg: rgba(45, 27, 105, 0.9);
    --header-text: #f7931e;
    --cardfile-bg-primary: #5d4e75;
    --cardfile-bg-secondary: #4a3c63;
    --cardfile-border: #f7931e;
    --cardfile-text: white;
    --timer-bg-primary: #4a3c63;
    --timer-bg-secondary: #5d4e75;
    --canvas-gradient1: rgba(247, 147, 30, 0.15);
    --canvas-gradient2: rgba(45, 27, 105, 0.15);
}

[data-theme="forest"] {
    --bg-primary: #228b22;
    --bg-secondary: #1a3b1a;
    --accent-primary: #32cd32;
    --accent-secondary: #90ee90;
    --text-primary: #1a3b1a;
    --text-secondary: #2d5d2d;
    --text-light: #6b8e6b;
    --card-bg-primary: #f0fff0;
    --card-bg-secondary: #e6ffe6;
    --card-bg-alt: #dcedc8;
    --card-bg-alt2: #c8e6c8;
    --card-bg-special: #f1f8e9;
    --card-bg-special2: #e8f5e8;
    --header-bg: rgba(26, 59, 26, 0.9);
    --header-text: #32cd32;
    --cardfile-bg-primary: #2d5d2d;
    --cardfile-bg-secondary: #1a4a1a;
    --cardfile-border: #32cd32;
    --cardfile-text: white;
    --timer-bg-primary: #1a4a1a;
    --timer-bg-secondary: #2d5d2d;
    --canvas-gradient1: rgba(50, 205, 50, 0.15);
    --canvas-gradient2: rgba(26, 59, 26, 0.15);
}

[data-theme="midnight"] {
    --bg-primary: #6a4c93;
    --bg-secondary: #0f0f23;
    --accent-primary: #9d4edd;
    --accent-secondary: #c77dff;
    --text-primary: #c77dff;
    --text-secondary: #2a2a3e;
    --text-light: #6a6a8a;
    --card-bg-primary: #1a1a2e;
    --card-bg-secondary: #16213e;
    --card-bg-alt: #0f3460;
    --card-bg-alt2: #533483;
    --card-bg-special: #1e1e3f;
    --card-bg-special2: #2a2a5a;
    --header-bg: rgba(15, 15, 35, 0.9);
    --header-text: #c77dff;
    --cardfile-bg-primary: #2a2a3e;
    --cardfile-bg-secondary: #1a1a2e;
    --cardfile-border: #9d4edd;
    --cardfile-text: #c77dff;
    --timer-bg-primary: #1a1a2e;
    --timer-bg-secondary: #2a2a3e;
    --canvas-gradient1: rgba(157, 78, 221, 0.15);
    --canvas-gradient2: rgba(15, 15, 35, 0.2);
}

/* Layout Components */
.container {
    position: relative;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
}

.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    background: var(--header-bg);
    backdrop-filter: blur(10px);
    padding: 15px 20px;
    color: var(--header-text);
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 20px rgba(0, 0, 0, 0.3);
}

.header h1 {
    font-size: 1.5rem;
    color: var(--accent-primary);
}

.header-controls {
    display: flex;
    gap: 15px;
    align-items: center;
}

.canvas {
    position: absolute;
    top: 70px;
    left: 0;
    right: 0;
    bottom: 0;
    overflow: auto;
    background:
        radial-gradient(circle at 25% 25%, var(--canvas-gradient1) 0%, transparent 50%),
        radial-gradient(circle at 75% 75%, var(--canvas-gradient2) 0%, transparent 50%);
}

/* Auth Modal */
.auth-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.auth-content {
    background: white;
    padding: 40px;
    border-radius: 15px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    max-width: 400px;
    width: 90%;
    text-align: center;
}

/* Form Elements */
input[type="text"],
input[type="email"],
input[type="password"],
textarea {
    width: 100%;
    padding: 12px;
    border: 2px solid #e1e8ed;
    border-radius: 8px;
    font-size: 16px;
    transition: border-color 0.3s ease;
    font-family: inherit;
    margin-bottom: 10px;
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
textarea:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(var(--accent-primary), 0.1);
}

/* Buttons */
.btn {
    background: linear-gradient(45deg, var(--accent-primary), var(--accent-secondary));
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 600;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(var(--accent-primary), 0.3);
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(var(--accent-primary), 0.4);
    background: linear-gradient(45deg, var(--accent-secondary), var(--accent-primary));
}

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

.btn-secondary {
    background: linear-gradient(45deg, var(--cardfile-bg-primary), var(--cardfile-bg-secondary));
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.btn-secondary:hover {
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

.btn-danger {
    background: linear-gradient(45deg, var(--cardfile-bg-secondary), var(--cardfile-bg-primary));
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.btn-danger:hover {
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

.btn-small {
    padding: 6px 12px;
    font-size: 14px;
    min-width: 60px;
}

/* Theme Selector */
.theme-selector {
    background: var(--header-bg);
    color: var(--header-text);
    border: 1px solid var(--accent-primary);
    border-radius: 6px;
    padding: 6px 12px;
    font-size: 14px;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.3s ease;
}

.theme-selector:hover {
    border-color: var(--accent-secondary);
    box-shadow: 0 0 8px rgba(var(--accent-primary), 0.3);
}

.theme-selector option {
    background: var(--bg-secondary);
    color: var(--header-text);
}

/* Note Cards */
.note-card {
    position: absolute;
    width: 250px;
    min-height: 200px;
    background: linear-gradient(135deg, var(--card-bg-primary) 0%, var(--card-bg-secondary) 100%);
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    border-left: 4px solid var(--accent-primary);
    transition: box-shadow 0.3s ease, transform 0.3s ease;
    overflow: hidden;
    user-select: none;
    min-width: 200px;
    min-height: 150px;
    max-width: 500px;
    max-height: 600px;
    display: flex;
    flex-direction: column;
    z-index: 1;
}

.note-card:hover {
    box-shadow: 0 8px 25px rgba(var(--accent-primary), 0.2);
    transform: scale(1.02);
}

.note-card.dragging {
    z-index: 1000;
    transform: rotate(5deg) scale(1.05);
    box-shadow: 0 15px 30px rgba(0, 0, 0, 0.3);
}

.note-card.editing {
    z-index: 500;
    box-shadow: 0 10px 30px rgba(var(--accent-primary), 0.3);
}

.note-card:nth-child(even) {
    background: linear-gradient(135deg, var(--card-bg-alt) 0%, var(--card-bg-alt2) 100%);
    border-left: 4px solid var(--cardfile-bg-primary);
}

.note-card:nth-child(3n) {
    background: linear-gradient(135deg, var(--card-bg-special) 0%, var(--card-bg-special2) 100%);
    border-left: 4px solid var(--accent-secondary);
}

.note-header {
    padding: 15px 15px 0 15px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    margin-bottom: 10px;
    position: relative;
    flex-shrink: 0;
    cursor: move;
}

.note-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary, #ffffff);
    border: none;
    background: transparent;
    width: 100%;
    resize: none;
    outline: none;
    min-height: 30px;
    font-family: inherit;
    overflow-y: hidden;
}

.note-title::placeholder {
    color: var(--text-light, #bbbbbb);
    font-weight: 400;
}

.note-content {
    padding: 0 15px 15px 15px;
    color: var(--text-primary, #ffffff);
    line-height: 1.6;
    border: none;
    background: transparent;
    width: 100%;
    resize: none;
    outline: none;
    font-family: inherit;
    font-size: 14px;
    flex: 1;
    height: calc(100% - 80px);
}

.note-content::placeholder {
    color: var(--text-light, #bbbbbb);
}

.note-actions {
    position: absolute;
    top: 10px;
    right: 10px;
    display: flex;
    gap: 5px;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.note-card:hover .note-actions {
    opacity: 1;
}

.note-meta {
    position: absolute;
    bottom: 5px;
    left: 15px;
    right: 15px;
    font-size: 0.7rem;
    color: #666;
    display: flex;
    justify-content: space-between;
}

/* Cardfiles */
.cardfile {
    position: absolute;
    width: 200px;
    min-width: 180px;
    max-width: 400px;
    min-height: 300px;
    max-height: 600px;
    background: linear-gradient(135deg, var(--cardfile-bg-primary) 0%, var(--cardfile-bg-secondary) 100%);
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    border: 2px solid var(--cardfile-border);
    transition: box-shadow 0.3s ease, transform 0.3s ease;
    overflow: hidden;
    user-select: none;
    color: var(--cardfile-text);
    z-index: 1;
    display: flex;
    flex-direction: column;
}

.cardfile:hover {
    box-shadow: 0 8px 25px rgba(var(--cardfile-border), 0.3);
    transform: scale(1.02);
}

.cardfile.dragging {
    z-index: 1000;
    transform: rotate(5deg) scale(1.05);
    box-shadow: 0 15px 30px rgba(0, 0, 0, 0.3);
}

.cardfile.drop-target {
    border-color: var(--accent-secondary);
    box-shadow: 0 0 20px rgba(var(--cardfile-border), 0.5);
    animation: pulse 1s infinite;
}

.cardfile-header {
    padding: 15px;
    border-bottom: 1px solid rgba(255, 107, 53, 0.3);
    background: rgba(255, 107, 53, 0.1);
    font-weight: bold;
    color: var(--cardfile-border);
    position: relative;
    cursor: move;
    flex-shrink: 0;
}

.cardfile-title {
    background: transparent;
    border: none;
    color: var(--cardfile-border);
    font-weight: bold;
    font-size: 14px;
    width: 100%;
    text-align: center;
    outline: none;
    font-family: inherit;
}

.cardfile-title::placeholder {
    color: rgba(255, 107, 53, 0.7);
}

.cardfile-list {
    padding: 10px;
    flex: 1;
    overflow-y: auto;
    min-height: 0; /* Important for flex child scrolling */
}

.cardfile-item {
    padding: 8px 10px;
    margin: 2px 0;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.3s ease, transform 0.2s ease;
    font-size: 0.9rem;
    border-left: 3px solid var(--cardfile-border);
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 32px; /* Ensure consistent height */
}

.cardfile-item:hover {
    background: rgba(255, 107, 53, 0.2);
}

.cardfile-item.dragging-item {
    transform: rotate(2deg) scale(1.05);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    z-index: 1000;
    opacity: 0.8;
}

.cardfile-item.drop-indicator {
    border-top: 3px solid var(--accent-secondary);
    background: rgba(255, 107, 53, 0.3);
}

.cardfile-item-drag-handle {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.5);
    cursor: grab;
    padding: 2px 4px;
    opacity: 0;
    transition: opacity 0.3s ease;
    flex-shrink: 0;
    user-select: none;
    line-height: 1;
    width: 16px;
    text-align: center;
}

.cardfile-item:hover .cardfile-item-drag-handle {
    opacity: 1;
}

.cardfile-item-drag-handle:active {
    cursor: grabbing;
}

.cardfile-item-content {
    flex: 1;
    min-width: 0; /* Allow text to truncate */
    cursor: pointer;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Timer Cards */
.timer-card {
    position: absolute;
    width: 250px;
    height: 300px;
    background: linear-gradient(135deg, var(--timer-bg-primary) 0%, var(--timer-bg-secondary) 100%);
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    border: 2px solid var(--cardfile-border);
    transition: box-shadow 0.3s ease, transform 0.3s ease;
    overflow: hidden;
    user-select: none;
    color: var(--cardfile-text);
    z-index: 1;
}

.timer-card:hover {
    box-shadow: 0 8px 25px rgba(var(--cardfile-border), 0.3);
    transform: scale(1.02);
}

.timer-card.dragging {
    z-index: 1000;
    transform: rotate(5deg) scale(1.05);
    box-shadow: 0 15px 30px rgba(0, 0, 0, 0.3);
}

.timer-display {
    text-align: center;
    padding: 20px;
    font-size: 2rem;
    font-weight: bold;
    color: var(--cardfile-border);
    background: rgba(255, 107, 53, 0.1);
    position: relative;
    cursor: move;
}

.timer-title {
    background: transparent;
    border: none;
    color: var(--cardfile-border);
    font-weight: bold;
    font-size: 14px;
    width: 100%;
    text-align: center;
    outline: none;
    font-family: inherit;
    margin-bottom: 10px;
}

.timer-title::placeholder {
    color: rgba(255, 107, 53, 0.7);
}

.timer-controls {
    padding: 20px;
    text-align: center;
}

.timer-history {
    padding: 10px;
    max-height: 120px;
    overflow-y: auto;
    font-size: 0.8rem;
}

.timer-entry {
    padding: 4px 8px;
    margin: 2px 0;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    border-left: 2px solid var(--cardfile-border);
}

/* Drag Handles */
.drag-handle {
    position: absolute;
    top: 5px;
    left: 5px;
    width: 20px;
    height: 20px;
    background: rgba(255, 107, 53, 0.3);
    border-radius: 4px;
    cursor: move;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: var(--accent-primary);
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 10;
    user-select: none;
}

.note-card:hover .drag-handle,
.cardfile:hover .drag-handle,
.timer-card:hover .drag-handle {
    opacity: 1;
}

/* Resize Handles */
.resize-handle {
    position: absolute;
    background: rgba(255, 107, 53, 0.5);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.resize-handle.right {
    top: 0;
    right: 0;
    width: 4px;
    height: 100%;
    cursor: ew-resize;
}

.resize-handle.bottom {
    bottom: 0;
    left: 0;
    width: 100%;
    height: 4px;
    cursor: ns-resize;
}

.resize-handle.corner {
    bottom: 0;
    right: 0;
    width: 12px;
    height: 12px;
    cursor: nw-resize;
}

.note-card:hover .resize-handle,
.cardfile:hover .resize-handle {
    opacity: 1;
}

/* Cardfile-specific resize handles */
.cardfile .resize-handle {
    background: var(--cardfile-border);
    opacity: 0;
}

.cardfile:hover .resize-handle {
    opacity: 0.7;
}

/* Notifications */
.error {
    position: fixed;
    top: 90px;
    right: 20px;
    color: var(--text-primary);
    background: #fff0f0;
    padding: 15px;
    border-radius: 8px;
    border-left: 4px solid var(--accent-primary);
    z-index: 1500;
    max-width: 300px;
}

.success {
    position: fixed;
    top: 90px;
    right: 20px;
    color: var(--text-primary);
    background: #f0fff0;
    padding: 15px;
    border-radius: 8px;
    border-left: 4px solid var(--accent-secondary);
    z-index: 1500;
    max-width: 300px;
}

.loading {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--accent-primary);
    font-size: 1.1rem;
    z-index: 1500;
}

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

.user-info {
    color: var(--accent-primary);
    font-weight: 500;
}

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

/* Responsive Styles */
@media (max-width: 768px) {
    .header {
        flex-direction: column;
        gap: 10px;
        padding: 10px;
    }

    .canvas {
        top: 90px;
    }

    .note-card {
        width: 200px;
        min-height: 150px;
    }

    .auth-content {
        padding: 20px;
    }
}