/* CSS Custom Properties for Theme Support */
:root {
    /* Light theme colors */
    --bg-primary: #f4f4f4;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f8f9fa;
    --bg-hover: #f5f5f5;
    --bg-active: #e9ecef;
    --bg-overlay: rgba(0, 0, 0, 0.6);
    --bg-modal: #ffffff;
    --bg-sidebar: #ffffff;
    --bg-topbar: rgba(248, 249, 250, 0.8);
    --bg-drag-over: #e3f2fd;
    --bg-drag-source: rgba(0, 123, 255, 0.15);
    --bg-drag-target: rgba(40, 167, 69, 0.15);
    
    --text-primary: #333333;
    --text-secondary: #666666;
    --text-muted: #aaaaaa;
    --text-inverse: #ffffff;
    --text-link: #007bff;
    
    --border-primary: #e0e0e0;
    --border-secondary: #dee2e6;
    --border-focus: #007bff;
    --border-edit: #6c757d;
    
    --shadow-light: rgba(0, 0, 0, 0.03);
    --shadow-medium: rgba(0, 0, 0, 0.1);
    --shadow-heavy: rgba(0, 0, 0, 0.2);
    
    --key-bg: linear-gradient(145deg, #f0f0f0, #f8f8f8);
    --tile-bg: #ffffff;
    --modal-header-bg: linear-gradient(135deg, #f8f9fa 0%, #ffffff 100%);
    --favicon-bg: linear-gradient(135deg, #f8f9fa 0%, #ffffff 100%);
    --plus-bg: rgba(255, 255, 255, 0.7);
}

/* Dark theme colors */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-primary: #1a1a1a;
        --bg-secondary: #2d2d2d;
        --bg-tertiary: #3a3a3a;
        --bg-hover: #404040;
        --bg-active: #4a4a4a;
        --bg-overlay: rgba(0, 0, 0, 0.8);
        --bg-modal: #2d2d2d;
        --bg-sidebar: #2d2d2d;
        --bg-topbar: rgba(45, 45, 45, 0.9);
        --bg-drag-over: #1a2332;
        --bg-drag-source: rgba(0, 123, 255, 0.25);
        --bg-drag-target: rgba(40, 167, 69, 0.25);
        
        --text-primary: #e0e0e0;
        --text-secondary: #b0b0b0;
        --text-muted: #808080;
        --text-inverse: #1a1a1a;
        --text-link: #4da6ff;
        
        --border-primary: #404040;
        --border-secondary: #4a4a4a;
        --border-focus: #4da6ff;
        --border-edit: #808080;
        
        --shadow-light: rgba(0, 0, 0, 0.1);
        --shadow-medium: rgba(0, 0, 0, 0.3);
        --shadow-heavy: rgba(0, 0, 0, 0.5);
        
        --key-bg: linear-gradient(145deg, #3a3a3a, #2d2d2d);
        --tile-bg: #2d2d2d;
        --modal-header-bg: linear-gradient(135deg, #3a3a3a 0%, #2d2d2d 100%);
        --favicon-bg: linear-gradient(135deg, #3a3a3a 0%, #2d2d2d 100%);
        --plus-bg: rgba(45, 45, 45, 0.8);
    }
    
    /* Dark mode specific adjustments */
    .key-slot .letter {
        background: rgba(45, 45, 45, 0.8);
    }
    
    .three-dots-btn {
        background: rgba(45, 45, 45, 0.9);
    }
    
    .key::before {
        background-color: var(--border-secondary);
        border-bottom: 1px solid var(--border-primary);
    }
    
    .key.extra-key::before {
        background-color: var(--border-secondary);
    }
}

body {
    margin: 0;
    padding: 0;
    font-family: Arial, sans-serif;
    background-color: var(--bg-primary);
    transition: background-color 0.3s ease;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding-top: 60px; /* Space for top bar */
}

body.drag-over {
    background-color: var(--bg-drag-over);
    position: relative;
}

body.drag-over::before {
    content: '📥 Drop bookmark file here to import';
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 24px;
    font-weight: 600;
    color: var(--text-link);
    background: var(--bg-secondary);
    padding: 30px 50px;
    border-radius: 16px;
    box-shadow: 0 10px 40px var(--shadow-heavy);
    z-index: 10000;
    pointer-events: none;
}

.keyboard {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 15px;
    padding: 5px;
    margin: 0;
    max-width: 2000px; /* Zwiększone dla większych ekranów */
    width: 100%;
    box-sizing: border-box;
    align-content: start;
    overflow-y: auto;
    /* Prevent overlapping */
    min-height: 0;
    min-width: 0;
}

/* Force minimum 3 columns on very small screens */
@media (max-width: 449px) {
    .keyboard {
        grid-template-columns: repeat(3, minmax(100px, 1fr));
    }
}

/* Key slot - szary, statyczny, z literą klawiatury */
.key-slot {
    width: 100%;
    height: 140px;
    border-radius: 12px;
    background: var(--key-bg);
    border: 1px solid var(--border-primary);
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 1px 2px var(--shadow-light);
    /* Prevent overlapping */
    min-width: 0;
    min-height: 0;
    overflow: visible;
}

.key-slot .letter {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    position: absolute;
    top: 6px;
    left: 8px;
    z-index: 1;
    background: rgba(255, 255, 255, 0.6);
    padding: 2px 6px;
    border-radius: 4px;
    box-shadow: 0 1px 2px var(--shadow-light);
}

/* Three-dots button */
.three-dots-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    background: rgba(255, 255, 255, 0.9);
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: all 0.2s ease;
    z-index: 10;
    color: var(--text-secondary);
    box-shadow: 0 2px 4px var(--shadow-medium);
}

.tile:hover .three-dots-btn {
    opacity: 1;
}

.three-dots-btn:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
    transform: scale(1.1);
}

/* Quick actions menu */
.quick-actions-menu {
    background: var(--bg-secondary);
    border-radius: 8px;
    box-shadow: 0 4px 20px var(--shadow-heavy);
    padding: 4px;
    min-width: 180px;
    opacity: 0;
    transform: scale(0.95);
    transition: all 0.2s ease;
}

.quick-actions-menu.show {
    opacity: 1;
    transform: scale(1);
}

.quick-action-item {
    width: 100%;
    padding: 10px 16px;
    border: none;
    background: var(--bg-secondary);
    text-align: left;
    cursor: pointer;
    border-radius: 4px;
    font-size: 14px;
    transition: background 0.2s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-primary);
}

.quick-action-item:hover {
    background: var(--bg-hover);
}

.quick-action-item.danger {
    color: #dc3545;
}

.quick-action-item.danger:hover {
    background: #fee;
}

/* Tile - biały, kwadratowy, ruchomy, z linkiem */
.tile {
    width: 100px;
    height: 100px;
    border-radius: 10px;
    box-shadow: 0 3px 8px var(--shadow-medium), 
                0 1px 3px var(--shadow-light);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    background-color: var(--tile-bg);
    cursor: pointer;
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
    user-select: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    touch-action: manipulation;
}

.tile:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow-heavy);
}

/* Old .key styles for backwards compatibility */
.key {
    width: 100%;
    height: 120px;
    padding-top: 20px;
    border-radius: 10px;
    box-shadow: 0 4px 8px var(--shadow-medium);
    transition: all 0.3s ease;
    background-color: var(--tile-bg);
    cursor: pointer;
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow: hidden;
    user-select: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    touch-action: manipulation;
}

/* Drag and Drop styles */
.key.draggable {
    cursor: grab;
}

.key.draggable:active {
    cursor: grabbing;
}

.key.dragging {
    opacity: 0.5;
    transform: rotate(5deg) scale(1.05);
    z-index: 1000;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
}

.key.drag-over {
    border: 2px dashed var(--border-focus);
    background-color: var(--bg-drag-source);
    transform: scale(1.02);
}

.key.drop-target {
    border: 2px solid #28a745;
    background-color: var(--bg-drag-target);
    animation: pulse 1s infinite;
}

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

/* Drag and Drop styles for tiles */
.tile.draggable {
    cursor: grab;
}

.tile.draggable:active {
    cursor: grabbing;
}

.tile.dragging {
    opacity: 0.85;
    transform: rotate(5deg) scale(1.05);
    z-index: 1000;
    box-shadow: 0 15px 35px var(--shadow-heavy), 0 5px 15px rgba(0, 123, 255, 0.3);
    animation: tile-wobble 0.3s ease-in-out infinite;
    background: linear-gradient(135deg, var(--tile-bg) 0%, #f0f8ff 100%);
}

@keyframes tile-wobble {
    0%, 100% {
        transform: rotate(5deg) scale(1.05);
    }
    50% {
        transform: rotate(-5deg) scale(1.05);
    }
}

/* Shake animation for target tile during drag */
.tile.shake {
    animation: tile-shake 0.3s ease-in-out infinite;
}

@keyframes tile-shake {
    0%, 100% {
        transform: translateX(0);
    }
    25% {
        transform: translateX(-3px) rotate(-2deg);
    }
    75% {
        transform: translateX(3px) rotate(2deg);
    }
}

/* Swap animation - Slide & Cross with subtle flip */
.tile.swapping {
    position: relative;
    z-index: 10000;
    transform-origin: center;
    box-shadow: 0 8px 25px var(--shadow-heavy);
    animation: tile-swap-slide 0.4s ease-in-out forwards;
}

@keyframes tile-swap-slide {
    0% {
        transform: translate(0, 0) scale(1);
        opacity: 1;
    }
    50% {
        transform: translate(calc(var(--swap-x) / 2), calc(var(--swap-y) / 2)) scale(1.05);
        opacity: 0.9;
    }
    100% {
        transform: translate(var(--swap-x), var(--swap-y)) scale(1);
        opacity: 1;
    }
}

/* Bounce animation for tile clicks */
.tile.bounce {
    animation: tile-bounce 0.6s ease-out;
}

@keyframes tile-bounce {
    0% {
        transform: scale(1);
    }
    20% {
        transform: scale(1.2);
    }
    40% {
        transform: scale(0.9);
    }
    60% {
        transform: scale(1.1);
    }
    80% {
        transform: scale(0.95);
    }
    100% {
        transform: scale(1);
    }
}

/* Source slot (where tile was grabbed from) - BLUE (old/source) */
.key-slot.drag-source {
    border: 3px dashed var(--border-focus);
    background: radial-gradient(circle at center, var(--bg-drag-source) 0%, rgba(0, 123, 255, 0.05) 100%);
    box-shadow: 0 0 15px rgba(0, 123, 255, 0.3), inset 0 0 15px rgba(0, 123, 255, 0.1);
}

/* Source slot in edit mode - override gray border with blue highlight */
body.is-editing .key-slot.drag-source {
    border: 3px dashed var(--border-focus) !important;
    background: radial-gradient(circle at center, var(--bg-drag-source) 0%, rgba(0, 123, 255, 0.05) 100%) !important;
    box-shadow: 0 0 15px rgba(0, 123, 255, 0.3), inset 0 0 15px rgba(0, 123, 255, 0.1) !important;
}

/* Target slot (where tile will be dropped) - GREEN (new/target) */
.key-slot.drag-over {
    border: 3px dashed #28a745;
    background: radial-gradient(circle at center, var(--bg-drag-target) 0%, rgba(40, 167, 69, 0.1) 100%);
    animation: slot-pulse-green 0.8s ease-in-out infinite;
    transform: scale(1.03);
    box-shadow: 0 0 20px rgba(40, 167, 69, 0.5), 
                inset 0 0 20px rgba(40, 167, 69, 0.15),
                0 5px 15px var(--shadow-medium);
    position: relative;
}

.key-slot.drag-over::after {
    content: "⬇";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 48px;
    color: rgba(0, 123, 255, 0.3);
    animation: drop-indicator 0.6s ease-in-out infinite;
    pointer-events: none;
    z-index: 0;
}

@keyframes drop-indicator {
    0%, 100% {
        opacity: 0.3;
        transform: translate(-50%, -60%);
    }
    50% {
        opacity: 0.6;
        transform: translate(-50%, -40%);
    }
}

.key-slot.drop-target {
    border: 3px solid #28a745;
    background-color: var(--bg-drag-target);
    animation: drop-success 0.4s ease-out;
}

@keyframes drop-success {
    0% {
        transform: scale(1.1);
        background-color: rgba(40, 167, 69, 0.3);
        box-shadow: 0 0 30px rgba(40, 167, 69, 0.6);
    }
    100% {
        transform: scale(1);
        background-color: rgba(40, 167, 69, 0.15);
        box-shadow: none;
    }
}

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

@keyframes slot-pulse {
    0%, 100% { 
        transform: scale(1.03);
    }
    50% { 
        transform: scale(1.05);
    }
}

@keyframes slot-pulse-green {
    0%, 100% { 
        transform: scale(1.03);
    }
    50% { 
        transform: scale(1.05);
    }
}

@keyframes slot-glow {
    0%, 100% {
        box-shadow: 0 0 20px rgba(0, 123, 255, 0.4), inset 0 0 20px rgba(0, 123, 255, 0.1);
    }
    50% {
        box-shadow: 0 0 30px rgba(0, 123, 255, 0.6), inset 0 0 30px rgba(0, 123, 255, 0.2);
    }
}

.key:hover {
    box-shadow: 0 8px 16px var(--shadow-heavy);
}

.key img {
    width: 30px;
    height: 30px;
    margin-bottom: 10px;
}

.key .letter {
    position: absolute;
    top: 6px;
    left: 50%;
    transform: translateX(-50%);
    color: var(--text-primary);
    font-size: 24px;
    font-weight: bold;
}

.key .name {
    font-size: 14px;
    color: var(--text-primary);
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
    max-width: 100%;
    padding: 0 5px;
    text-align: center;
}

.key::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 25%;
    background-color: var(--border-primary);
    border-bottom: 1px solid var(--border-secondary);
}

.key.extra-key::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 0%;
    background-color: var(--border-primary);
}

/* Top bar with tooltip and controls */
.top-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 20px;
    background-color: var(--bg-topbar);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    box-shadow: 0 2px 4px var(--shadow-light);
    border-radius: 0 0 8px 8px;
}

/* Tooltip section - left side of top bar */
.tooltip-section {
    flex: 1;
    display: flex;
    justify-content: center;
}

/* Controls section - right side of top bar */
.controls-section {
    display: flex;
    align-items: center;
    gap: 15px;
}

.welcome-text {
    text-align: center;
    font-size: 14px;
    color: var(--text-secondary);
    margin: 0;
    padding: 0;
    transition: opacity 0.3s ease;
    cursor: pointer;
}

.welcome-text:hover {
    color: var(--text-link);
    text-decoration: underline;
}

/* Tooltip animation classes */
.welcome-text.fade-out {
    opacity: 0;
    transition: opacity 0.15s ease;
}

.welcome-text.fade-in {
    opacity: 1;
    transition: opacity 0.15s ease;
}

/* Instructions modal styles */
.instructions-content {
    max-height: 70vh;
    overflow-y: auto;
    padding: 10px 0;
}

.instructions-content h4 {
    color: var(--text-primary);
    margin: 20px 0 10px 0;
    font-size: 16px;
    font-weight: 600;
}

.instructions-content h4:first-child {
    margin-top: 0;
}

.instructions-content ul {
    margin: 0 0 15px 0;
    padding-left: 20px;
}

.instructions-content li {
    margin: 8px 0;
    line-height: 1.5;
}

.instructions-content kbd {
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border-secondary);
    border-radius: 3px;
    box-shadow: 0 1px 0 var(--shadow-medium);
    color: var(--text-primary);
    display: inline-block;
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
    padding: 2px 4px;
    white-space: nowrap;
}

.instructions-content strong {
    color: var(--text-link);
    font-weight: 600;
}

/* Modal styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: var(--bg-overlay);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
    overflow-y: auto;
    padding: 20px 0;
}

.modal-content {
    background-color: var(--bg-modal);
    margin: 8% auto;
    padding: 0;
    border-radius: 16px;
    width: 90%;
    max-width: 520px;
    box-shadow: 0 20px 40px var(--shadow-heavy), 0 8px 16px var(--shadow-medium);
    animation: modalSlideIn 0.3s ease-out;
    border: 1px solid var(--border-secondary);
}

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

.modal-header {
    padding: 24px 24px 20px 24px;
    border-bottom: 1px solid var(--border-secondary);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--modal-header-bg);
    border-radius: 16px 16px 0 0;
}

.modal-header h3 {
    margin: 0;
    color: var(--text-primary);
    font-size: 1.4rem;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.close {
    font-size: 24px;
    font-weight: 400;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background-color: transparent;
}

.close:hover {
    color: #dc3545;
    background-color: var(--bg-hover);
    transform: scale(1.1);
}

.modal-body {
    padding: 24px;
    background-color: var(--bg-modal);
}

.form-group {
    margin-bottom: 24px;
}

.form-group:last-child {
    margin-bottom: 0;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.9rem;
    letter-spacing: 0.01em;
}

.form-group input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border-secondary);
    border-radius: 8px;
    font-size: 14px;
    transition: all 0.2s ease;
    box-sizing: border-box;
    background-color: var(--bg-secondary);
    color: var(--text-primary);
}

.form-group input:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
    transform: translateY(-1px);
}

.form-group input[readonly] {
    background-color: var(--bg-tertiary);
    color: var(--text-secondary);
}

/* Favicon preview */
.favicon-preview-container {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    background: var(--favicon-bg);
    border: 2px solid var(--border-secondary);
    border-radius: 10px;
    transition: all 0.2s ease;
}

.favicon-preview-container:hover {
    border-color: var(--border-focus);
    box-shadow: 0 2px 8px rgba(0, 123, 255, 0.1);
}

.favicon-preview {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    box-shadow: 0 2px 4px var(--shadow-medium);
    border: 1px solid var(--border-primary);
}

.btn-small {
    padding: 8px 16px;
    font-size: 12px;
    border: 1px solid var(--border-secondary);
    background: linear-gradient(135deg, var(--bg-tertiary) 0%, var(--bg-active) 100%);
    color: var(--text-primary);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-small:hover {
    background: linear-gradient(135deg, var(--bg-active) 0%, var(--bg-hover) 100%);
    border-color: var(--border-primary);
    transform: translateY(-1px);
}


/* Toggle switch for keyboard shortcuts */
.toggle-option {
    margin: 15px 0;
    padding: 0 20px;
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 15px;
    cursor: pointer;
    padding: 12px 0;
    transition: all 0.2s ease;
    user-select: none;
}

.toggle-label:hover {
    background-color: var(--bg-hover);
    margin: 0 -20px;
    padding: 12px 20px;
    border-radius: 8px;
}

.toggle-slider {
    position: relative;
    width: 50px;
    height: 24px;
    background-color: var(--border-primary);
    border-radius: 12px;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background-color: var(--bg-secondary);
    border-radius: 50%;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px var(--shadow-medium);
}

.toggle-label input[type="checkbox"] {
    display: none;
}

.toggle-label input[type="checkbox"]:checked + .toggle-slider {
    background-color: var(--text-link);
}

.toggle-label input[type="checkbox"]:checked + .toggle-slider::before {
    transform: translateX(26px);
    background-color: var(--text-inverse);
}

.toggle-text {
    font-size: 14px;
    color: var(--text-primary);
    font-weight: 500;
}

/* Hide keyboard letters when shortcuts are disabled */
.keyboard-shortcuts-disabled .key-slot .letter {
    display: none !important;
}

/* Radio buttons */
.radio-option {
    margin: 10px 0;
    padding: 0 20px;
}

.radio-label {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
    cursor: pointer;
    padding: 8px 12px;
    border-radius: 6px;
    transition: all 0.2s ease;
    user-select: none;
}

.radio-label:hover {
    background-color: var(--bg-hover);
}

.radio-text {
    font-size: 14px;
    color: var(--text-primary);
    font-weight: 500;
}

/* Emoji picker */
.emoji-picker {
    border: 1px solid var(--border-primary);
    border-radius: 6px;
    padding: 15px;
    background-color: var(--bg-tertiary);
}

.emoji-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 8px;
    margin-bottom: 15px;
    max-height: 120px;
    overflow-y: auto;
}

.emoji-item {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s ease;
    user-select: none;
}

.emoji-item:hover {
    background-color: var(--bg-hover);
    transform: scale(1.1);
}

.emoji-item.selected {
    background-color: var(--text-link);
    color: var(--text-inverse);
}

/* Emoji picker button */
.btn-emoji-picker {
    width: 100%;
    padding: 12px 16px;
    font-size: 16px;
    border: 2px solid var(--border-primary);
    background-color: var(--bg-secondary);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-bottom: 10px;
}

.btn-emoji-picker:hover {
    border-color: var(--border-focus);
    background-color: var(--bg-hover);
}

.form-group input#link-emoji {
    font-size: 20px;
    text-align: center;
    font-family: 'Apple Color Emoji', 'Segoe UI Emoji', 'Noto Color Emoji', sans-serif;
    width: 100%;
    background-color: var(--bg-tertiary);
}

.modal-footer {
    padding: 20px 24px 24px 24px;
    border-top: 1px solid var(--border-secondary);
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    background: var(--modal-header-bg);
    border-radius: 0 0 16px 16px;
}

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.2s ease;
    min-width: 80px;
    letter-spacing: 0.01em;
}

.btn-primary {
    background: linear-gradient(135deg, #007bff 0%, #0056b3 100%);
    color: white;
    box-shadow: 0 2px 4px rgba(0, 123, 255, 0.3);
}

.btn-primary:hover {
    background: linear-gradient(135deg, #0056b3 0%, #004085 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 123, 255, 0.4);
}

.btn-danger {
    background: linear-gradient(135deg, #dc3545 0%, #c82333 100%);
    color: white;
    box-shadow: 0 2px 4px rgba(220, 53, 69, 0.3);
}

.btn-danger:hover {
    background: linear-gradient(135deg, #c82333 0%, #a71e2a 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(220, 53, 69, 0.4);
}

.btn-secondary {
    background: linear-gradient(135deg, #6c757d 0%, #545b62 100%);
    color: white;
    box-shadow: 0 2px 4px rgba(108, 117, 125, 0.3);
}

.btn-secondary:hover {
    background: linear-gradient(135deg, #545b62 0%, #495057 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(108, 117, 125, 0.4);
}

.btn-warning {
    background: linear-gradient(135deg, #ffc107 0%, #e0a800 100%);
    color: #212529;
    box-shadow: 0 2px 4px rgba(255, 193, 7, 0.3);
}

.btn-warning:hover {
    background: linear-gradient(135deg, #e0a800 0%, #d39e00 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(255, 193, 7, 0.4);
}

/* Tryb edycji - wizualne wskazówki */
body.is-editing .key-slot {
    border: 2px dashed var(--border-edit) !important;
    position: relative;
    background: var(--key-bg) !important;
}

body.is-editing .key-slot::after {
    content: "✏️";
    position: absolute;
    top: 5px;
    right: 5px;
    font-size: 16px;
    z-index: 10;
    background: var(--bg-secondary);
    padding: 2px 4px;
    border-radius: 3px;
    box-shadow: 0 1px 3px var(--shadow-medium);
}

body.is-editing .key-slot:hover {
    border-color: var(--text-primary) !important;
    transform: scale(1.02);
    box-shadow: 0 4px 12px var(--shadow-medium);
}

body.is-editing .tile {
    cursor: pointer !important;
}

/* Style dla przycisku Edit */
.edit-toggle {
    background-color: var(--text-link);
    color: var(--text-inverse);
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 123, 255, 0.3);
}

.edit-toggle:hover {
    background-color: #0056b3;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 123, 255, 0.4);
}

/* Aktywny stan przycisku Edit */
body.is-editing .edit-toggle {
    background-color: #28a745;
    box-shadow: 0 2px 4px rgba(40, 167, 69, 0.3);
}

body.is-editing .edit-toggle:hover {
    background-color: #218838;
    box-shadow: 0 4px 8px rgba(40, 167, 69, 0.4);
}

/* Drag zawsze aktywny - tylko wyłącz w trybie edit */
body:not(.is-editing) .tile {
    cursor: grab;
}

body:not(.is-editing) .tile:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 6px 16px var(--shadow-heavy);
}

.info-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex-grow: 1;
    max-width: 100%;
    padding: 0 8px;
}

.info-container .name {
    font-size: 12px;
    color: var(--text-primary);
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
    max-width: 100%;
    text-align: center;
    line-height: 1.2;
    margin-top: 4px;
}

.favicon {
    width: 32px;
    height: 32px;
    margin-bottom: 8px;
    border-radius: 4px;
}

.emoji-icon {
    font-size: 32px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    user-select: none;
}

/* Style dla pustych kafelków z ikoną plus */
.plus-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100px;
    height: 100px;
}

.plus-icon {
    font-size: 40px;
    color: var(--text-muted);
    font-weight: 300;
    transition: all 0.3s ease;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 70px;
    height: 70px;
    border-radius: 10px;
    border: 2px dashed var(--border-primary);
    background-color: var(--plus-bg);
    box-shadow: 0 2px 6px var(--shadow-light);
}

.key-slot:hover .plus-icon {
    color: var(--text-link);
    border-color: var(--border-focus);
    background-color: rgba(0, 123, 255, 0.1);
    transform: scale(1.05);
}

.key:hover .plus-icon {
    color: var(--text-link);
    border-color: var(--border-focus);
    background-color: rgba(0, 123, 255, 0.1);
    transform: scale(1.1);
}

/* Tryb edycji - style dla pustych kafelków */
body.is-editing .plus-icon {
    color: var(--text-secondary);
    border-color: var(--border-edit);
    background-color: rgba(108, 117, 125, 0.1);
}

body.is-editing .key-slot:hover .plus-icon {
    transform: scale(1.2);
    background-color: rgba(108, 117, 125, 0.2);
}

/* Dyskretne przyciski Edit i Drag */
.history-btn {
    width: 36px;
    height: 36px;
    padding: 0;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: 6px;
    color: var(--text-secondary);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 20px;
    box-shadow: 0 1px 3px var(--shadow-medium);
    display: flex;
    align-items: center;
    justify-content: center;
}

.history-btn:hover:not(:disabled) {
    background-color: var(--bg-hover);
    border-color: var(--text-secondary);
    color: var(--text-secondary);
    transform: translateY(-1px);
    box-shadow: 0 2px 6px var(--shadow-medium);
}

.history-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    border-color: var(--border-primary);
    color: var(--text-muted);
}

.save-indicator {
    font-size: 12px;
    color: #28a745;
    font-weight: 500;
    padding: 6px 12px;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.save-indicator.visible {
    opacity: 1;
}

.save-indicator.saving {
    color: #ffc107;
}

.edit-toggle, .drag-toggle {
    padding: 8px 16px;
    border: 1px solid var(--border-primary);
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.3s ease;
    background-color: var(--bg-secondary);
    color: var(--text-secondary);
    box-shadow: 0 1px 3px var(--shadow-medium);
}

.edit-toggle:hover, .drag-toggle:hover {
    background-color: var(--bg-hover);
    border-color: var(--border-focus);
    color: var(--text-link);
    transform: translateY(-1px);
    box-shadow: 0 2px 6px var(--shadow-medium);
}

.edit-toggle.active, .drag-toggle.active {
    background-color: var(--text-link);
    border-color: var(--border-focus);
    color: var(--text-inverse);
}

.drag-toggle.active {
    background-color: #28a745;
    border-color: #28a745;
}

/* Ikona ustawień */
.settings {
    font-size: 18px;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    background-color: transparent;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    color: var(--text-secondary);
    border: 1px solid transparent;
}

.settings:hover {
    background-color: var(--bg-hover);
    color: var(--text-primary);
    transform: rotate(90deg);
}

/* Sidebar */
.sidebar {
    position: fixed;
    top: 0;
    right: -300px;
    width: 300px;
    height: 100vh;
    background: var(--bg-sidebar);
    box-shadow: -4px 0 20px var(--shadow-heavy);
    transition: right 0.3s ease;
    z-index: 1000;
    display: flex;
    flex-direction: column;
}

.sidebar.open {
    right: 0;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid var(--border-secondary);
    background-color: var(--bg-tertiary);
}

.sidebar-header h3 {
    margin: 0;
    color: var(--text-primary);
    font-size: 18px;
}

.close-sidebar {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 5px;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.close-sidebar:hover {
    background-color: var(--bg-hover);
    color: var(--text-primary);
}

.sidebar-content {
    padding: 20px;
    flex: 1;
}

.sidebar-content h4 {
    margin: 20px 0 10px 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.sidebar-content h4:first-child {
    margin-top: 0;
}

.sidebar-item {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 15px 20px;
    margin-bottom: 10px;
    border: none;
    background: var(--bg-tertiary);
    border-radius: 8px;
    cursor: pointer;
    font-size: 16px;
    color: var(--text-primary);
    transition: all 0.3s ease;
    gap: 12px;
    text-align: left;
}

.sidebar-item:hover {
    background-color: var(--bg-hover);
    transform: translateX(5px);
    box-shadow: 0 4px 12px var(--shadow-medium);
}

.sidebar-item:active {
    background-color: var(--bg-active);
    transform: translateX(2px);
}

/* Overlay dla sidebar */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-overlay);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 999;
}

.sidebar-overlay.open {
    opacity: 1;
    visibility: visible;
}

/* Responsive design */

/* Extra large screens (1920px+) */
@media (min-width: 1920px) {
    .keyboard {
        grid-template-columns: repeat(10, 140px);
        grid-template-rows: repeat(4, 160px);
        gap: 40px;
        padding: 30px;
    }
    
    .key-slot {
        height: 160px;
    }
    
    .tile {
        width: 110px;
        height: 110px;
    }
    
    .plus-container {
        width: 110px;
        height: 110px;
    }
    
    .plus-icon {
        font-size: 36px;
        width: 70px;
        height: 70px;
    }
    
    .favicon, .emoji-icon {
        width: 36px;
        height: 36px;
    }
    
    .key .letter {
        font-size: 13px;
        padding: 3px 8px;
    }
}

/* Large desktops (1440px - 1920px) */
@media (max-width: 1919px) and (min-width: 1441px) {
    .keyboard {
        grid-template-columns: repeat(10, 130px);
        grid-template-rows: repeat(4, 150px);
        gap: 38px;
        padding: 25px;
    }
    
    .key-slot {
        height: 150px;
    }
    
    .tile {
        width: 105px;
        height: 105px;
    }
    
    .plus-container {
        width: 105px;
        height: 105px;
    }
}

/* Standard desktops (1280px - 1440px) */
@media (max-width: 1440px) and (min-width: 1281px) {
    .keyboard {
        gap: 32px;
        padding: 22px;
    }
}

/* Large tablets and small desktops (1024px - 1280px) */
@media (max-width: 1280px) and (min-width: 1025px) {
    .keyboard {
        gap: 28px;
        padding: 20px;
    }
    
    .key-slot {
        height: 135px;
    }
    
    .tile {
        width: 95px;
        height: 95px;
    }
}

/* Tablets landscape (768px - 1024px) */
@media (max-width: 1024px) and (min-width: 769px) {
    .keyboard {
        gap: 25px;
        padding: 18px;
    }
    
    .key-slot {
        height: 130px;
    }
    
    .tile {
        width: 90px;
        height: 90px;
    }
    
    .plus-container {
        width: 90px;
        height: 90px;
    }
    
    .plus-icon {
        font-size: 30px;
        width: 55px;
        height: 55px;
    }
}

/* Tablets portrait and large phones (600px - 768px) */
@media (max-width: 768px) and (min-width: 601px) {
    .welcome-section {
        padding: 8px 15px;
    }
    
    .welcome-text {
        font-size: 12px;
        padding: 0 10px;
    }
    
    .controls {
        gap: 10px;
    }
    
    .edit-toggle {
        padding: 6px 12px;
        font-size: 12px;
    }
    
    .save-indicator {
        font-size: 11px;
    }
    
    .keyboard {
        grid-template-columns: repeat(5, 1fr);
        grid-template-rows: repeat(8, minmax(95px, auto));
        gap: 15px;
        padding: 15px;
        max-height: calc(100vh - 60px);
        overflow-y: auto;
    }
    
    .key-slot {
        height: auto;
        min-height: 95px;
        aspect-ratio: 1;
    }
    
    .tile {
        width: 100%;
        height: 100%;
        max-width: 85px;
        max-height: 85px;
        margin: 0 auto;
    }
    
    .plus-container {
        width: 100%;
        height: 100%;
        max-width: 85px;
        max-height: 85px;
        margin: 0 auto;
    }
    
    .plus-icon {
        font-size: 28px;
        width: 50px;
        height: 50px;
    }
    
    .favicon, .emoji-icon {
        width: 26px;
        height: 26px;
    }
    
    .name {
        font-size: 11px;
    }
    
    .modal-content {
        width: 95%;
        margin: 5% auto;
    }
    
    .sidebar {
        width: 100%;
        right: -100%;
    }
}

/* Medium phones (480px - 600px) */
@media (max-width: 600px) and (min-width: 481px) {
    .welcome-section {
        padding: 8px 12px;
    }
    
    .welcome-text {
        font-size: 12px;
    }
    
    .controls {
        gap: 10px;
    }
    
    .keyboard {
        grid-template-columns: repeat(5, 1fr);
        grid-template-rows: repeat(8, minmax(90px, auto));
        gap: 15px;
        padding: 12px;
        max-height: calc(100vh - 60px);
        overflow-y: auto;
    }
    
    .key-slot {
        height: auto;
        min-height: 90px;
        aspect-ratio: 1;
    }
    
    .tile {
        width: 100%;
        height: 100%;
        max-width: 80px;
        max-height: 80px;
        margin: 0 auto;
    }
    
    .plus-container {
        width: 100%;
        height: 100%;
        max-width: 80px;
        max-height: 80px;
        margin: 0 auto;
    }
    
    .plus-icon {
        font-size: 26px;
        width: 45px;
        height: 45px;
    }
    
    .favicon, .emoji-icon {
        width: 24px;
        height: 24px;
    }
    
    .name {
        font-size: 11px;
    }
    
    .modal-content {
        width: 95%;
        margin: 5% auto;
    }
}

/* Small phones (320px - 480px) */
@media (max-width: 480px) {
    .welcome-section {
        padding: 8px 12px;
    }
    
    .welcome-text {
        font-size: 11px;
        padding: 0 5px;
    }
    
    .controls {
        gap: 8px;
        flex-wrap: nowrap;
    }
    
    .edit-toggle {
        padding: 6px 10px;
        font-size: 11px;
    }
    
    .save-indicator {
        font-size: 10px;
        padding: 4px 6px;
    }
    
    .settings {
        font-size: 18px;
        width: 32px;
        height: 32px;
    }
    
    .keyboard {
        grid-template-columns: repeat(4, 1fr);
        grid-template-rows: repeat(10, minmax(85px, auto));
        gap: 12px;
        padding: 12px;
        max-height: calc(100vh - 60px);
        overflow-y: auto;
    }
    
    .key-slot {
        height: auto;
        min-height: 85px;
        aspect-ratio: 1;
    }
    
    .tile {
        width: 100%;
        height: 100%;
        max-width: 75px;
        max-height: 75px;
        margin: 0 auto;
    }
    
    .plus-container {
        width: 100%;
        height: 100%;
        max-width: 75px;
        max-height: 75px;
        margin: 0 auto;
    }
    
    .plus-icon {
        font-size: 24px;
        width: 40px;
        height: 40px;
    }
    
    .favicon, .emoji-icon {
        width: 22px;
        height: 22px;
    }
    
    .name {
        font-size: 10px;
    }
    
    .modal-content {
        width: 98%;
        margin: 3% auto;
        max-width: none;
    }
    
    .modal-body {
        padding: 16px;
    }
    
    .modal-footer {
        padding: 12px 16px 16px 16px;
        flex-wrap: wrap;
    }
    
    .btn {
        padding: 10px 16px;
        font-size: 13px;
        min-width: 70px;
    }
    
    .edit-toggle {
        padding: 6px 10px;
        font-size: 11px;
    }
}

/* Very small phones (max 360px) */
@media (max-width: 360px) {
    .keyboard {
        grid-template-columns: repeat(4, 1fr);
        grid-template-rows: repeat(10, 80px);
        gap: 12px;
        padding: 6px;
    }
    
    .key-slot {
        height: 80px;
    }
    
    .tile {
        width: 60px;
        height: 60px;
    }
    
    .plus-container {
        width: 60px;
        height: 60px;
    }
    
    .plus-icon {
        font-size: 22px;
        width: 35px;
        height: 35px;
    }
    
    .key .letter {
        font-size: 14px;
    }
    
    .key .name {
        font-size: 8px;
    }
    
    .favicon, .emoji-icon {
        width: 18px;
        height: 18px;
    }
    
    .history-btn {
        width: 26px;
        height: 26px;
        font-size: 14px;
    }
    
    .save-indicator {
        font-size: 11px;
        padding: 4px 8px;
    }
    
    .welcome-text {
        font-size: 10px;
        padding: 0 5px;
    }
    
    .modal-content {
        width: 100%;
        margin: 0;
        border-radius: 12px 12px 0 0;
        position: fixed;
        bottom: 0;
        left: 0;
        max-height: 90vh;
        overflow-y: auto;
    }
    
    .modal-header {
        padding: 16px;
        border-radius: 12px 12px 0 0;
    }
    
    .modal-header h3 {
        font-size: 1.2rem;
    }
    
    .modal-body {
        padding: 12px;
    }
    
    .modal-footer {
        padding: 10px 12px 12px 12px;
    }
    
    .btn {
        padding: 8px 12px;
        font-size: 12px;
        min-width: 60px;
    }
    
    .form-group {
        margin-bottom: 16px;
    }
    
    .form-group label {
        font-size: 0.85rem;
        margin-bottom: 6px;
    }
    
    .form-group input {
        padding: 10px 12px;
        font-size: 13px;
    }
}

/* Landscape orientation for phones */
@media (max-height: 600px) and (orientation: landscape) {
    .keyboard {
        grid-template-columns: repeat(8, 1fr);
        grid-template-rows: repeat(5, 85px);
        gap: 15px;
        padding: 10px;
    }
    
    .key-slot {
        height: 85px;
    }
    
    .tile {
        width: 70px;
        height: 70px;
    }
    
    .plus-container {
        width: 70px;
        height: 70px;
    }
    
    .modal-content {
        max-height: 85vh;
        overflow-y: auto;
    }
}