/* Shared Dropdown System */
.dropdown-container {
    position: relative;
}

.dropdown-menu {
    display: none;
    position: absolute;
    background: #1e293b;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    min-width: 160px;
    z-index: 150;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.6);
    overflow: hidden;
    margin-top: 8px;
    backdrop-filter: blur(20px);
}

.dropdown-container.open .dropdown-menu {
    display: block;
    animation: fadeInScale 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}

.dropdown-item {
    width: 100%;
    padding: 10px 16px;
    background: transparent;
    border: none;
    color: white;
    text-align: left;
    cursor: pointer;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all 0.2s;
    font-family: inherit;
}

.dropdown-item:hover {
    background: rgba(255, 255, 255, 0.08);
}

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

@keyframes fadeInScale {
    from {
        opacity: 0;
        transform: translateY(-10px) scale(0.95);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.export-dropdown .dropdown-menu {
    right: 0;
    top: 100%;
}

.floating-menu {
    display: flex;
    background: rgba(22, 24, 30, 0.8);
    backdrop-filter: var(--glass-blur);
    padding: 4px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.menu-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 8px 20px;
    cursor: pointer;
    border-radius: 8px;
    font-weight: 600;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.menu-btn:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.03);
}

.menu-btn.active {
    background: var(--accent-color);
    color: white;
    box-shadow: 0 4px 12px var(--accent-glow);
}

.action-buttons {
    display: flex;
    gap: 12px;
}

.btn-primary,
.btn-secondary {
    padding: 8px 16px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
}

.btn-primary {
    background: white;
    color: black;
    border: none;
}

.btn-primary:hover {
    background: #e2e8f0;
}

.btn-secondary {
    background: transparent;
    color: white;
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.05);
}

.btn-icon {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-icon:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.08);
}

.zoom-controls-floating {
    position: absolute;
    top: 100px;
    left: 40px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    background: rgba(22, 24, 30, 0.8);
    backdrop-filter: var(--glass-blur);
    padding: 6px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
    z-index: 100;
}

.zoom-level {
    font-size: 0.75rem;
    font-weight: 700;
    margin: 4px 0;
    color: var(--text-secondary);
    width: 100%;
    text-align: center;
}

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

.key-selector {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(50px, 1fr));
    gap: 12px;
}

.key-item {
    aspect-ratio: 1;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: grab;
    transition: all 0.2s;
}

.key-item:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--accent-color);
    transform: translateY(-2px);
}

.key-item img {
    width: 70%;
    height: 70%;
    object-fit: contain;
}

/* Draggable Label */
.mapping-label {
    position: absolute;
    display: flex;
    align-items: center;
    gap: 8px;
    background: #1e293b;
    border: 1px solid var(--border-color);
    padding: 6px 12px;
    border-radius: 12px;
    cursor: move;
    z-index: 10;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    user-select: none;
}

.mapping-label:hover {
    border-color: var(--accent-color);
}

.mapping-label .key-icon {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
    pointer-events: none;
    object-fit: contain;
}

.mapping-label input {
    background: transparent;
    border: none;
    color: white;
    font-family: inherit;
    font-size: 0.9rem;
    outline: none;
    width: 100px;
}

.delete-label {
    opacity: 0;
    color: var(--danger-color);
    cursor: pointer;
    font-size: 1.1rem;
    transition: opacity 0.2s;
    display: flex;
    align-items: center;
}

.mapping-label:hover .delete-label {
    opacity: 1;
}

/* Target Dot */
.target-dot {
    position: absolute;
    width: 10px;
    height: 10px;
    background: var(--accent-color);
    border-radius: 50%;
    border: 2px solid white;
    transform: translate(-50%, -50%);
    cursor: crosshair;
    z-index: 20;
    box-shadow: 0 0 10px var(--accent-glow);
    opacity: 0;
    transition: opacity 0.2s ease, transform 0.2s ease;
    pointer-events: auto;
}

/* Larger hit area to reveal the dot when hovering near the endpoint (Radius: 30px) */
.target-dot::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 60px;
    height: 60px;
    transform: translate(-50%, -50%);
    background: transparent;
}

.mapping-label:hover+.target-dot,
.target-dot:hover {
    opacity: 1;
}

.target-dot:hover {
    transform: translate(-50%, -50%) scale(1.4);
    box-shadow: 0 0 15px var(--accent-color);
}

/* Line Settings */
.line-settings {
    margin-top: 40px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
}

.setting-item {
    margin-bottom: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.setting-item label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.value-badge {
    background: rgba(255, 255, 255, 0.1);
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 0.75rem;
    color: var(--accent-color);
    font-weight: 700;
}

.setting-item .select-trigger {
    background: #1e293b;
    border: 1px solid var(--border-color);
    color: white;
    padding: 10px 14px;
    border-radius: 8px;
    outline: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-family: inherit;
    font-size: 0.9rem;
    width: 100%;
    transition: all 0.2s;
}

.setting-item .select-trigger:hover {
    border-color: var(--accent-color);
    background: #242f3f;
}

.setting-item .dropdown-menu {
    left: 0;
    bottom: 100%;
    margin-bottom: 8px;
    width: 100%;
}

.setting-item input[type="range"] {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    outline: none;
    border: none;
    margin: 15px 0;
}

.setting-item input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    background: var(--accent-color);
    border: 2px solid white;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 0 10px var(--accent-glow);
    transition: transform 0.2s;
}

.setting-item input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

.setting-item input[type="color"] {
    width: 32px;
    height: 32px;
    border: 2px solid white;
    background: transparent;
    cursor: pointer;
    border-radius: 50%;
    padding: 0;
    overflow: hidden;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.4);
}

.setting-item input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
}

.setting-item input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 50%;
}

.setting-item input[type="color"]::-moz-color-swatch {
    border: none;
    border-radius: 50%;
}

/* Coordinate Preview */
.coord-preview {
    position: fixed;
    background: rgba(15, 23, 42, 0.9);
    backdrop-filter: blur(8px);
    color: var(--accent-color);
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 700;
    pointer-events: none;
    z-index: 1000;
    border: 1px solid var(--accent-color);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    font-family: 'JetBrains Mono', monospace;
}

/* Export Overrides */
.export-mode .target-dot,
.export-mode .coord-preview {
    display: none !important;
}

.export-mode .mapping-label {
    box-shadow: none;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.export-mode .mapping-label input {
    /* Ensure text is visible and aligned in export */
    line-height: 1;
    padding: 0;
    margin: 0;
}