:root {
    --primary-bg: #1a1b26;
    --card-bg: rgba(255, 255, 255, 0.08);
    --card-hover: rgba(255, 255, 255, 0.15);
    --text-main: #c0caf5;
    --text-muted: #565f89;
    --accent: #7aa2f7;
    --danger: #f7768e;
    --modal-bg: #24283b;
    --sidebar-bg: rgba(26, 27, 38, 0.95);
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

* { margin: 0; padding: 0; box-sizing: border-box; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }

body {
    background-color: var(--primary-bg);
    background-image: 
        radial-gradient(at 0% 0%, hsla(253,16%,7%,1) 0, transparent 50%), 
        radial-gradient(at 50% 0%, hsla(225,39%,30%,1) 0, transparent 50%), 
        radial-gradient(at 100% 0%, hsla(339,49%,30%,1) 0, transparent 50%);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 2rem 1rem;
    overflow-x: hidden;
}


.header {
    position: relative; 
    z-index: 998; 
    text-align: center;
    margin-bottom: 3rem;
    width: 100%;
    max-width: 600px;
    animation: fadeIn 0.8s ease-out;
    margin-top: 2rem;
}

.clock {
    font-size: 4rem;
    font-weight: 700;
    letter-spacing: -2px;
    margin-bottom: 0.5rem;
    background: linear-gradient(to right, #7aa2f7, #bb9af7);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.date {
    font-size: 1.1rem;
    color: var(--text-muted);
    margin-bottom: 2rem;
}

.search-box {
    position: relative;
    display: flex;
    align-items: center;
    background: var(--card-bg);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 50px;
    padding: 0.5rem 1rem;
    backdrop-filter: blur(10px);
    transition: 0.3s;
}

.search-box:focus-within {
    background: rgba(255,255,255,0.12);
    border-color: var(--accent);
    box-shadow: 0 0 15px rgba(122, 162, 247, 0.3);
}


.search-engine-selector {
    position: relative;
    padding-right: 15px;
    border-right: 1px solid rgba(255,255,255,0.2);
    margin-right: 10px;
    user-select: none;
}

.current-engine-btn {
    background: transparent;
    border: none;
    color: var(--text-main);
    font-weight: bold;
    cursor: pointer;
    padding: 0;
    outline: none;
    display: flex;
    align-items: center;
    gap: 5px;
}

.engine-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 10px;
    background: var(--modal-bg);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 8px;
    box-shadow: var(--shadow);
    z-index: 999; 
    min-width: 150px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s, transform 0.2s;
    transform: translateY(-10px);
}

.engine-dropdown.active {
    opacity: 1;
    pointer-events: all;
    transform: translateY(0);
}

.engine-item, .engine-manage-link {
    padding: 10px 15px;
    color: var(--text-main);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.1s;
}

.engine-item:not(.is-local):hover, .engine-manage-link:hover {
    background: var(--card-hover);
}
.engine-item.active {
    background: var(--accent);
    color: var(--primary-bg);
    font-weight: bold;
}
.engine-manage-link {
    border-top: 1px solid rgba(255,255,255,0.1);
    font-size: 0.9em;
    color: var(--accent);
}


.engine-list {
    list-style: none;
    padding: 0;
    margin: 0;
}
.engine-list-item {
    padding: 12px 15px; 
    margin-bottom: 8px; 
    background: var(--card-bg);
    border-radius: 12px; 
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: grab;
    transition: all 0.2s;
    border: 1px solid rgba(255, 255, 255, 0.05); 
}
.engine-list-item:hover {
    background: var(--card-hover);
    transform: scale(1.01); 
    border-color: rgba(122, 162, 247, 0.3);
}
.engine-list-item.dragging {
    opacity: 0.5;
    transform: scale(1.02);
    border-color: var(--accent);
}
.engine-list-item.is-local {
    cursor: default;
    opacity: 0.7;
    background: rgba(255, 255, 255, 0.05);
    transform: none;
    border-color: transparent;
}
.engine-list-actions {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}
.engine-list-actions button {
    margin-left: 8px;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 0.8rem;
}
.drag-placeholder {
    opacity: 0.4;
    border: 2px dashed var(--accent);
    background: transparent;
    height: 48px; 
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    color: var(--accent);
    transform: none;
}


.search-input {
    flex: 1;
    background: transparent;
    border: none;
    color: white;
    padding: 0.8rem;
    font-size: 1.1rem;
    outline: none;
}


.search-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    margin-left: 8px;
    color: var(--text-muted);
    cursor: pointer;
    transition: color 0.2s, transform 0.2s;
    flex-shrink: 0;
}

.search-icon:hover {
    color: var(--accent);
    transform: scale(1.1);
}

.search-icon svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}


.grid-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 1.5rem;
    width: 100%;
    max-width: 1000px;
    padding: 1rem;
    transition: 0.3s;
    z-index: 5; 
    user-select: none; 
}

.card {
    position: relative;
    background: var(--card-bg);
    border-radius: 16px;
    height: 120px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-decoration: none;
    color: var(--text-main);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid rgba(255,255,255,0.05);
    cursor: grab; 
    overflow: hidden;
    backdrop-filter: blur(5px);
}

.card.dragging {
    opacity: 0.5;
    cursor: grabbing !important;
}


.card.drag-placeholder {
    opacity: 0.3;
    border: 2px dashed var(--accent);
    background: transparent;
    height: 120px; 
    border-radius: 16px;
}


.card:hover {
    transform: translateY(-5px);
    background: var(--card-hover);
    border-color: rgba(122, 162, 247, 0.3);
    box-shadow: 0 10px 20px rgba(0,0,0,0.2);
}

.card img {
    width: 36px;
    height: 36px;
    margin-bottom: 12px;
    border-radius: 8px;
    object-fit: contain;
    transition: transform 0.3s;
}

.card:hover img { transform: scale(1.1); }

.card span {
    font-size: 0.9rem;
    font-weight: 500;
    text-align: center;
    width: 90%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}


.card-actions {
    position: absolute;
    top: 8px;
    right: 8px;
    display: flex;
    gap: 5px;
    opacity: 0;
    transition: opacity 0.2s;
    
    z-index: 10; 
}

.card:hover .card-actions { opacity: 1; }

.action-btn {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: white;
    font-size: 12px;
}

.btn-edit { background: var(--accent); }
.btn-del { background: var(--danger); }


.add-card {
    border: 2px dashed rgba(255,255,255,0.2);
    background: transparent;
    color: rgba(255,255,255,0.4);
    cursor: pointer;
}

.add-card:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: rgba(122, 162, 247, 0.05);
}

.add-icon { font-size: 2rem; }


.menu-btn {
    position: fixed;
    top: 20px;
    left: 20px; 
    z-index: 1001;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    width: 44px;
    height: 44px;
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: 0.3s;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    touch-action: manipulation; 
    -webkit-tap-highlight-color: transparent; 
}

.menu-btn:hover { background: rgba(255, 255, 255, 0.2); transform: scale(1.05); }
.menu-icon { width: 24px; height: 24px; fill: var(--text-main); pointer-events: none; }


.sidebar {
    position: fixed;
    top: 0;
    left: 0; 
    width: 280px;
    height: 100%;
    background: var(--sidebar-bg);
    backdrop-filter: blur(20px);
    border-right: 1px solid rgba(255, 255, 255, 0.1); 
    z-index: 1000;
    transform: translateX(-100%); 
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    padding: 80px 20px 20px;
    display: flex;
    flex-direction: column;
    box-shadow: 10px 0 30px rgba(0,0,0,0.5);
    touch-action: pan-y;
    overflow: hidden;
}

.sidebar.active { transform: translateX(0); }


.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.sidebar-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.sidebar-header {
    font-size: 1.2rem;
    font-weight: bold;
    color: var(--accent);
    margin-bottom: 20px;
    padding-left: 10px;
    border-left: 3px solid var(--accent);
}

.category-list { 
    list-style: none;
    user-select: none;
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1;
    padding-right: 5px;
    margin-right: -5px;
}

.category-list::-webkit-scrollbar {
    width: 6px;
}

.category-list::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 3px;
}

.category-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.category-list::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

.category-item {
    padding: 12px 15px;
    margin-bottom: 8px;
    border-radius: 10px;
    cursor: pointer;
    color: var(--text-muted);
    transition: 0.2s;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 1rem;

    position: relative;
    z-index: 10;
    cursor: grab;
}

.category-item.dragging {
    opacity: 0.5;
    transform: scale(1.05);
    box-shadow: 0 5px 15px rgba(122, 162, 247, 0.4);
    cursor: grabbing;
}
.category-item.drag-over {
    border-top: 2px solid var(--accent);
}

.category-item:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
}

.category-item.active {
    background: rgba(122, 162, 247, 0.15);
    color: var(--accent);
    font-weight: bold;
}

.category-count {
    font-size: 0.75rem;
    background: rgba(255,255,255,0.1);
    padding: 2px 8px;
    border-radius: 12px;
    color: var(--text-muted);
}


.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: 0.3s;
    z-index: 1001;
}

.modal-overlay.active { opacity: 1; pointer-events: all; }

.modal {
    background: var(--modal-bg);
    padding: 2rem;
    border-radius: 16px;
    width: 90%;
    max-width: 400px;
    border: 1px solid rgba(255,255,255,0.1);
    transform: translateY(20px);
    transition: 0.3s;
    box-shadow: 0 20px 50px rgba(0,0,0,0.5);
}

.modal-overlay.active .modal { transform: translateY(0); }

.modal h2 { margin-bottom: 1.5rem; color: white; }

.form-group { margin-bottom: 1.2rem; }
.form-group label { display: block; margin-bottom: 0.5rem; font-size: 0.9rem; color: var(--text-muted); }

.form-input, .form-select {
    width: 100%;
    padding: 12px;
    border-radius: 8px;
    background: rgba(0,0,0,0.2);
    border: 1px solid rgba(255,255,255,0.1);
    color: white;
    font-size: 1rem;
    outline: none;
    transition: 0.3s;
}

.form-select { cursor: pointer; }
.form-select option { background: var(--modal-bg); }

.form-input:focus, .form-select:focus { border-color: var(--accent); }

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 2rem;
}

.btn {
    padding: 10px 20px;
    border-radius: 8px;
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: 0.2s;
}

.btn-cancel { background: transparent; color: var(--text-muted); border: 1px solid rgba(255,255,255,0.1); }
.btn-cancel:hover { background: rgba(255,255,255,0.05); color: white; }

.btn-save { background: var(--accent); color: #1a1b26; }
.btn-save:hover { filter: brightness(1.1); }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}


.context-menu {
    position: fixed;
    z-index: 1002;
    background: var(--modal-bg);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
    padding: 5px 0;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.1s;
}

.context-menu.active {
    opacity: 1;
    pointer-events: all;
}

.context-menu-item {
    padding: 10px 15px;
    cursor: pointer;
    color: var(--text-main);
    font-size: 0.9rem;
    min-width: 150px;
}

.context-menu-item:hover {
    background: var(--accent);
    color: var(--primary-bg);
}




@media (max-width: 768px) {
    body {
        padding: 1.5rem 1rem;
    }
    
    .header {
        margin-top: 1rem;
        margin-bottom: 2rem;
    }
    
    .clock {
        font-size: 3.5rem;
    }
    
    .date {
        font-size: 1rem;
    }
    
    .grid-container {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: 1rem;
        padding: 0.5rem;
    }
    
    .modal {
        width: 95%;
        max-width: 450px;
        padding: 1.5rem;
    }
    
    .sidebar {
        width: 280px;
    }
}


@media (max-width: 480px) {
    body {
        padding: 1rem 0.75rem;
    }
    
    .header {
        margin-top: 0.5rem;
        margin-bottom: 1.5rem;
        max-width: 100%;
    }
    
    .clock {
        font-size: 2.5rem;
        letter-spacing: -1px;
        margin-bottom: 0.25rem;
    }
    
    .date {
        font-size: 0.9rem;
        margin-bottom: 1.5rem;
    }
    
    
    .search-box {
        padding: 0.6rem 0.9rem;
        border-radius: 30px;
    }
    
    .search-input {
        font-size: 1rem;
        padding: 0.5rem 0.8rem;
    }
    
    .search-engine-selector {
        padding-right: 10px;
        margin-right: 8px;
    }
    
    .current-engine-btn {
        font-size: 0.85rem;
    }
    
    .search-icon {
        width: 36px;
        height: 36px;
        min-width: 36px; 
    }
    
    
    .grid-container {
        grid-template-columns: repeat(3, 1fr);
        gap: 0.75rem;
        padding: 0.5rem;
    }
    
    .card {
        height: 95px;
        border-radius: 12px;
    }
    
    .card img {
        width: 32px;
        height: 32px;
        margin-bottom: 0.4rem;
    }
    
    .card span {
        font-size: 0.75rem;
        line-height: 1.2;
        text-align: center;
        padding: 0 4px;
    }
    
    .card-actions {
        opacity: 0 !important; 
        gap: 6px;
    }
    
    .card.show-actions .card-actions {
        opacity: 1 !important; 
    }
    
    
    .card:hover .card-actions {
        opacity: 0;
    }
    
    .btn-edit, .btn-del {
        width: 24px;
        height: 24px;
        min-width: 24px;
        min-height: 24px;
        padding: 0;
        font-size: 11px;
    }
    
    .action-btn {
        width: 24px;
        height: 24px;
        font-size: 11px;
    }
    
    
    .menu-btn {
        top: 15px;
        left: 12px;
        width: 44px;
        height: 44px;
        min-width: 44px;
        min-height: 44px;
    }
    
    .menu-icon {
        width: 22px;
        height: 22px;
    }
    
    
    .sidebar {
        width: 85%;
        max-width: 300px;
        padding: 70px 15px 20px;
    }
    
    .sidebar-header {
        font-size: 1.1rem;
        margin-bottom: 15px;
    }
    
    .category-item {
        padding: 14px 12px;
        font-size: 0.95rem;
    }
    
    
    .modal {
        width: 95%;
        max-width: none;
        padding: 1.5rem 1.25rem;
        border-radius: 12px;
        margin: 1rem;
    }
    
    .modal h2 {
        font-size: 1.3rem;
        margin-bottom: 1.25rem;
    }
    
    .form-group {
        margin-bottom: 1rem;
    }
    
    .form-input, .form-select {
        padding: 14px;
        font-size: 16px; 
        border-radius: 10px;
    }
    
    .form-group label {
        font-size: 0.9rem;
        margin-bottom: 0.4rem;
    }
    
    .modal-footer {
        flex-direction: column-reverse;
        gap: 0.75rem;
        margin-top: 1.5rem;
    }
    
    .btn {
        width: 100%;
        padding: 14px 20px;
        font-size: 1rem;
        min-height: 44px; 
    }
    
    
    .add-card {
        height: 95px;
        font-size: 0.75rem;
    }
    
    
    .context-menu {
        min-width: 140px;
    }
    
    .context-menu-item {
        padding: 12px 15px;
        font-size: 0.95rem;
        min-height: 44px;
        display: flex;
        align-items: center;
    }
}


@media (max-width: 360px) {
    .grid-container {
        grid-template-columns: repeat(3, 1fr);
        gap: 0.5rem;
    }
    
    .card {
        height: 85px;
    }
    
    .card img {
        width: 28px;
        height: 28px;
    }
    
    .card span {
        font-size: 0.7rem;
    }
    
    .clock {
        font-size: 2.2rem;
    }
    
    .search-box {
        padding: 0.5rem 0.75rem;
    }
}


@media (max-width: 768px) and (orientation: landscape) {
    .header {
        margin-top: 0.5rem;
        margin-bottom: 1rem;
    }
    
    .clock {
        font-size: 2.5rem;
    }
    
    .grid-container {
        gap: 0.75rem;
    }
}


.login-container {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--primary-bg);
    background-image: 
        radial-gradient(at 0% 0%, hsla(253,16%,7%,1) 0, transparent 50%), 
        radial-gradient(at 50% 0%, hsla(225,39%,30%,1) 0, transparent 50%), 
        radial-gradient(at 100% 0%, hsla(339,49%,30%,1) 0, transparent 50%);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    opacity: 1;
    transition: opacity 0.3s ease-out;
}

.login-container.hidden {
    opacity: 0;
    pointer-events: none;
}

.login-box {
    background: var(--modal-bg);
    padding: 2.5rem;
    border-radius: 20px;
    width: 90%;
    max-width: 400px;
    border: 1px solid rgba(255,255,255,0.1);
    box-shadow: 0 20px 50px rgba(0,0,0,0.5);
    animation: fadeIn 0.5s ease-out;
}

.login-title {
    font-size: 2rem;
    font-weight: 700;
    text-align: center;
    margin-bottom: 0.5rem;
    background: linear-gradient(to right, #7aa2f7, #bb9af7);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.login-subtitle {
    text-align: center;
    color: var(--text-muted);
    margin-bottom: 2rem;
    font-size: 0.9rem;
}

.login-form-group {
    margin-bottom: 1.5rem;
}

.login-form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.login-input {
    width: 100%;
    padding: 14px;
    border-radius: 10px;
    background: rgba(0,0,0,0.2);
    border: 1px solid rgba(255,255,255,0.1);
    color: white;
    font-size: 1rem;
    outline: none;
    transition: 0.3s;
}

.login-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 10px rgba(122, 162, 247, 0.3);
}

.login-error {
    color: var(--danger);
    font-size: 0.85rem;
    margin-top: 0.5rem;
    text-align: center;
    min-height: 20px;
}

.login-btn {
    width: 100%;
    padding: 14px;
    border-radius: 10px;
    border: none;
    background: var(--accent);
    color: #1a1b26;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: 0.2s;
    margin-top: 1rem;
}

.login-btn:hover {
    filter: brightness(1.1);
    transform: translateY(-2px);
}

.login-btn:active {
    transform: translateY(0);
}


.logout-btn {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1002;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    padding: 10px 20px;
    border-radius: 12px;
    cursor: pointer;
    transition: 0.3s;
    color: var(--text-main);
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.logout-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: scale(1.05);
}

.logout-btn svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}


.main-content {
    display: none;
    width: 100%;
    min-width: 100%;
    min-height: 100vh;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    align-self: stretch;
    flex: 1 1 100%;
    box-sizing: border-box;
}

.main-content.visible {
    display: flex;
}


@media (max-width: 480px) {
    .logout-btn {
        top: 15px;
        right: 12px;
        padding: 8px 16px;
        font-size: 0.85rem;
    }
}


@media (hover: none) and (pointer: coarse) {
    
    .card:hover {
        transform: none;
    }
    
    .card:active {
        transform: scale(0.95);
        background: var(--card-hover);
    }
    
    .btn:active {
        transform: scale(0.98);
    }
    
    .menu-btn:active {
        transform: scale(0.95);
    }
    
    
    .card-actions {
        opacity: 0 !important;
    }
    
    .card.show-actions .card-actions {
        opacity: 1 !important;
    }
    
    
    .card:hover .card-actions {
        opacity: 0 !important;
    }
}


