@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700&display=swap');

:root {
    /* Color Palette - Light Mode */
    --bg-app: #f8fafc;
    --bg-panel: rgba(255, 255, 255, 0.75);
    --border-panel: rgba(226, 232, 240, 0.8);
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --accent: #6366f1;
    --accent-hover: #4f46e5;
    --accent-light: rgba(99, 102, 241, 0.1);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 10px 30px -10px rgba(0, 0, 0, 0.08), 0 1px 3px rgba(0, 0, 0, 0.03);
    --shadow-lg: 0 20px 40px -15px rgba(0, 0, 0, 0.12), 0 1px 5px rgba(0, 0, 0, 0.04);
    --grid-line: rgba(203, 213, 225, 0.4);
    --grid-dot: rgba(203, 213, 225, 0.6);
    --tooltip-bg: #0f172a;
    --tooltip-text: #ffffff;
    
    /* Preset Colors for Brush */
    --color-black: #0f172a;
    --color-gray: #64748b;
    --color-red: #ef4444;
    --color-orange: #f97316;
    --color-green: #10b981;
    --color-blue: #3b82f6;
    --color-purple: #8b5cf6;
    --color-pink: #ec4899;
}

[data-theme="dark"] {
    /* Color Palette - Dark Mode */
    --bg-app: #090d16;
    --bg-panel: rgba(15, 23, 42, 0.75);
    --border-panel: rgba(51, 65, 85, 0.5);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --accent: #818cf8;
    --accent-hover: #6366f1;
    --accent-light: rgba(129, 140, 248, 0.15);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 10px 30px -10px rgba(0, 0, 0, 0.4), 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 20px 40px -15px rgba(0, 0, 0, 0.5), 0 1px 5px rgba(0, 0, 0, 0.2);
    --grid-line: rgba(51, 65, 85, 0.35);
    --grid-dot: rgba(71, 85, 105, 0.5);
    --tooltip-bg: #f8fafc;
    --tooltip-text: #0f172a;

    --color-black: #f8fafc;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-drag: none;
}

body {
    font-family: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-app);
    color: var(--text-primary);
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    position: relative;
    transition: background-color 0.3s ease;
}

/* Canvas container */
#canvas-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    touch-action: none;
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
    cursor: crosshair;
}

canvas.grabbing {
    cursor: grabbing !important;
}

canvas.grab {
    cursor: grab !important;
}

/* Floating Glassmorphic Panels */
.glass-panel {
    background: var(--bg-panel);
    backdrop-filter: blur(16px) saturate(180%);
    -webkit-backdrop-filter: blur(16px) saturate(180%);
    border: 1px solid var(--border-panel);
    border-radius: 16px;
    box-shadow: var(--shadow-md);
    z-index: 10;
    transition: background 0.3s, border-color 0.3s, box-shadow 0.3s, transform 0.2s;
}

.glass-panel:hover {
    box-shadow: var(--shadow-lg);
}

/* Control Buttons & Icons */
.btn-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border-radius: 12px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    position: relative;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-icon:hover {
    color: var(--text-primary);
    background: var(--accent-light);
    transform: translateY(-1px);
}

.btn-icon:active {
    transform: translateY(1px) scale(0.95);
}

.btn-icon.active {
    color: var(--accent);
    background: var(--accent-light);
    border: 1px solid rgba(99, 102, 241, 0.2);
}

.btn-icon svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    fill: none;
}

/* Top bar navigation */
.top-bar-left {
    position: absolute;
    top: 20px;
    left: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
}

.top-bar-right {
    position: absolute;
    top: 20px;
    right: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
}

.divider {
    width: 1px;
    height: 24px;
    background-color: var(--border-panel);
    margin: 0 4px;
}

.brand {
    font-weight: 700;
    font-size: 16px;
    color: var(--accent);
    margin-right: 8px;
    letter-spacing: -0.5px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.brand-dot {
    width: 8px;
    height: 8px;
    background-color: var(--accent);
    border-radius: 50%;
    display: inline-block;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(99, 102, 241, 0.7); }
    70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(99, 102, 241, 0); }
    100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(99, 102, 241, 0); }
}

/* Bottom Main Toolbar */
.main-toolbar {
    position: absolute;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 12px;
    align-items: center;
    min-width: 520px;
}

.toolbar-row {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    justify-content: space-between;
}

.tool-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Color Presets */
.color-group {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 4px;
}

.color-swatch {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    cursor: pointer;
    position: relative;
    border: 2px solid transparent;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.1);
}

.color-swatch:hover {
    transform: scale(1.2);
}

.color-swatch.active {
    transform: scale(1.15);
    border-color: var(--text-primary);
    box-shadow: 0 0 0 2px var(--bg-app), var(--shadow-sm);
}

/* Custom Color Picker Button */
.color-picker-wrapper {
    position: relative;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    cursor: pointer;
    overflow: hidden;
    border: 2px solid transparent;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.1);
    transition: all 0.2s ease;
    background: conic-gradient(red, yellow, lime, aqua, blue, magenta, red);
}

.color-picker-wrapper:hover {
    transform: scale(1.2);
}

.color-picker-wrapper.active {
    transform: scale(1.15);
    border-color: var(--text-primary);
    box-shadow: 0 0 0 2px var(--bg-app), var(--shadow-sm);
}

.color-picker-wrapper input[type="color"] {
    position: absolute;
    top: -5px;
    left: -5px;
    width: 34px;
    height: 34px;
    border: none;
    background: none;
    cursor: pointer;
    opacity: 0;
}

/* Size Slider Styles */
.slider-group {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-grow: 1;
    margin-left: 12px;
}

.size-preview-container {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    background: var(--accent-light);
    color: var(--accent);
}

.size-preview-dot {
    background-color: var(--accent);
    border-radius: 50%;
    transition: width 0.1s ease, height 0.1s ease;
}

.size-slider-wrapper {
    position: relative;
    flex-grow: 1;
    display: flex;
    align-items: center;
}

.size-slider {
    -webkit-appearance: none;
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: var(--border-panel);
    outline: none;
    cursor: pointer;
    transition: background 0.3s;
}

.size-slider::-webkit-canvas-slider-runnable-track {
    background: var(--border-panel);
}

.size-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent);
    border: 3px solid var(--bg-panel);
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: transform 0.1s ease, background-color 0.3s;
}

.size-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    background: var(--accent-hover);
}

.size-slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent);
    border: 3px solid var(--bg-panel);
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: transform 0.1s ease;
}

.size-slider::-moz-range-thumb:hover {
    transform: scale(1.2);
}

/* Bottom Left Zoom Indicator */
.zoom-controls {
    position: absolute;
    bottom: 30px;
    left: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
}

.zoom-text {
    font-size: 13px;
    font-weight: 600;
    min-width: 46px;
    text-align: center;
    color: var(--text-secondary);
}

/* Tooltips */
[data-tooltip] {
    position: relative;
}

[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 10px);
    left: 50%;
    transform: translateX(-50%) translateY(4px);
    background: var(--tooltip-bg);
    color: var(--tooltip-text);
    padding: 5px 9px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 500;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    box-shadow: var(--shadow-sm);
    transition: opacity 0.15s cubic-bezier(0.4, 0, 0.2, 1), transform 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-tooltip]:hover::after {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.top-bar-left [data-tooltip]::after,
.top-bar-right [data-tooltip]::after {
    bottom: auto;
    top: calc(100% + 10px);
    transform: translateX(-50%) translateY(-4px);
}

.top-bar-left [data-tooltip]:hover::after,
.top-bar-right [data-tooltip]:hover::after {
    transform: translateX(-50%) translateY(0);
}

/* Settings Modal */
.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(4px);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

.modal-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    width: 90%;
    max-width: 480px;
    padding: 24px;
    transform: translateY(20px) scale(0.95);
    transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-overlay.open .modal-content {
    transform: translateY(0) scale(1);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.modal-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
}

.modal-body {
    display: flex;
    flex-direction: column;
    gap: 16px;
    color: var(--text-secondary);
    font-size: 14px;
    line-height: 1.5;
}

.shortcut-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-top: 10px;
}

.shortcut-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--accent-light);
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid var(--border-panel);
}

.shortcut-key {
    background: var(--bg-app);
    color: var(--accent);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: monospace;
    font-weight: 700;
    font-size: 12px;
    box-shadow: inset 0 -1px 0 rgba(0,0,0,0.1), var(--shadow-sm);
    border: 1px solid var(--border-panel);
}

/* Touch Device / Responsive Media Queries */
@media (max-width: 768px) {
    .main-toolbar {
        min-width: calc(100% - 32px);
        bottom: 20px;
        padding: 8px;
        gap: 8px;
    }
    
    .toolbar-row {
        flex-wrap: wrap;
        justify-content: center;
        gap: 6px;
    }
    
    .slider-group {
        width: 100%;
        margin-left: 0;
        margin-top: 6px;
        padding: 4px 8px;
    }
    
    .top-bar-left {
        top: 12px;
        left: 12px;
        padding: 4px 8px;
    }
    
    .top-bar-right {
        top: 12px;
        right: 12px;
        padding: 4px 8px;
    }
    
    .zoom-controls {
        bottom: auto;
        top: 72px;
        left: 12px;
        padding: 4px 8px;
        box-shadow: var(--shadow-sm);
    }
    
    .brand span {
        display: none; /* Hide brand name text on mobile */
    }
}

/* Custom Grid Select Options (Floating overlay) */
.grid-dropdown-menu {
    position: absolute;
    top: 50px;
    right: 0;
    width: 160px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 6px;
    border-radius: 12px;
    transform: translateY(8px);
    opacity: 0;
    pointer-events: none;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-lg);
}

.grid-dropdown-menu.show {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all 0.15s ease;
}

.dropdown-item:hover, .dropdown-item.active {
    background: var(--accent-light);
    color: var(--text-primary);
}

.dropdown-item.active {
    font-weight: 600;
}

.dropdown-item-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: transparent;
}

.dropdown-item.active .dropdown-item-dot {
    background-color: var(--accent);
}

/* Watermark */
.watermark {
    position: absolute;
    bottom: 20px;
    right: 20px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    opacity: 0.4;
    pointer-events: none;
    z-index: 5;
    transition: opacity 0.3s;
}

.watermark:hover {
    opacity: 0.8;
}

/* Dynamic Notification Popups */
.toast {
    position: absolute;
    top: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(-20px);
    padding: 10px 18px;
    background: var(--tooltip-bg);
    color: var(--tooltip-text);
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
    box-shadow: var(--shadow-md);
    opacity: 0;
    z-index: 1000;
    pointer-events: none;
    transition: all 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Autocomplete Handwriting Suggestions Panel */
#autocomplete-panel {
    position: absolute;
    bottom: 120px;
    left: 50%;
    transform: translateX(-50%);
    display: none;
    align-items: center;
    gap: 12px;
    padding: 8px 16px;
    z-index: 100;
    max-width: 90%;
    min-width: 320px;
    border-radius: 14px;
}

#autocomplete-panel.show {
    display: flex;
    animation: slideUpFade 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.autocomplete-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-secondary);
    white-space: nowrap;
}

#autocomplete-suggestions {
    display: flex;
    gap: 8px;
    flex-grow: 1;
    overflow-x: auto;
    scrollbar-width: none; /* Firefox */
}

#autocomplete-suggestions::-webkit-scrollbar {
    display: none; /* Safari/Chrome */
}

.autocomplete-btn {
    background: var(--accent-light);
    border: 1px solid rgba(99, 102, 241, 0.15);
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 600;
    padding: 6px 14px;
    border-radius: 10px;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.autocomplete-btn:hover {
    background: var(--accent);
    color: #ffffff;
    border-color: var(--accent);
    transform: translateY(-1px);
}

.autocomplete-btn:active {
    transform: translateY(1px);
}

@keyframes slideUpFade {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* ================================================
   MICROPHONE FAB – Fixed bottom-right, always visible
   ================================================ */

#btn-mic {
    position: fixed;
    bottom: 28px;
    right: 28px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    background: var(--glass-bg, rgba(255,255,255,0.95));
    box-shadow: 0 4px 20px rgba(0,0,0,0.15), 0 1px 4px rgba(0,0,0,0.08);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
    color: var(--text-secondary, #64748b);
    pointer-events: auto;
}

#btn-mic svg {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
}

#mic-label {
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    color: inherit;
    line-height: 1;
}

#btn-mic:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 28px rgba(0,0,0,0.16);
    color: var(--color-purple, #8b5cf6);
    background: rgba(139,92,246,0.08);
}

#btn-mic.recording {
    color: #ef4444;
    background: rgba(239,68,68,0.1);
    box-shadow: 0 0 0 0 rgba(239,68,68,0.4);
    animation: micFabPulse 1.4s ease-in-out infinite;
}

#btn-mic.recording #mic-label {
    color: #ef4444;
}

@keyframes micFabPulse {
    0%   { box-shadow: 0 0 0 0   rgba(239,68,68,0.45), 0 4px 20px rgba(0,0,0,0.10); }
    50%  { box-shadow: 0 0 0 14px rgba(239,68,68,0),    0 4px 20px rgba(0,0,0,0.10); }
    100% { box-shadow: 0 0 0 0   rgba(239,68,68,0),     0 4px 20px rgba(0,0,0,0.10); }
}

/* Live speech floating panel – anchored above the FAB */
#speech-panel {
    position: fixed;
    bottom: 104px;
    right: 28px;
    left: auto;
    transform: none;
    display: none;
    flex-direction: column;
    gap: 8px;
    padding: 12px 16px;
    z-index: 9998;
    min-width: 260px;
    max-width: 420px;
    border-radius: 16px;
    border: 1px solid rgba(239,68,68,0.25);
    pointer-events: auto;
}

#speech-panel.show {
    display: flex;
    animation: slideUpFadeRight 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

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

.speech-panel-header {
    display: flex;
    align-items: center;
    gap: 10px;
}

.speech-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: #ef4444;
    flex-grow: 1;
}

.speech-pulse-ring {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #ef4444;
    flex-shrink: 0;
    animation: ringPulse 1.4s ease-in-out infinite;
}

@keyframes ringPulse {
    0%   { transform: scale(0.9); box-shadow: 0 0 0 0   rgba(239,68,68,0.7); }
    70%  { transform: scale(1);   box-shadow: 0 0 0 8px rgba(239,68,68,0);   }
    100% { transform: scale(0.9); box-shadow: 0 0 0 0   rgba(239,68,68,0);   }
}

.speech-interim {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    font-style: italic;
    min-height: 20px;
    line-height: 1.5;
    word-break: break-word;
}
